Hello! I make a game. Entity is not drawn as intended.
It should be : enter image description here
How come :
enter image description here
I understand that the problem is somewhere in glTranslatef. What do you think?

void MasterRenderer::renderScene() { prepareRenderer(); glTranslatef(-tanks.at(0).getX() + 650.0f, -tanks.at(0).getY() + 300.0f, 0.0f); //screen - 1300 x 600 renderEntities(); renderTanks(); renderBullets(); glutSwapBuffers(); glTranslatef(tanks.at(0).getX() - 650.0f, tanks.at(0).getY() - 300.0f, 0.0f); } void MasterRenderer::renderEntities() { std::pair<std::multimap<int, Entity>::iterator, std::multimap<int, Entity>::iterator> range; for(int i = 0; i < 5; i++) { range = entities.equal_range(i); glBindTexture(GL_TEXTURE_2D, textures.at(i).getTexture()); for (std::multimap<int, Entity>::iterator it = range.first; it != range.second; ++it) { glTranslatef((*it).second.getX(), (*it).second.getY(), 0.0f); glRotatef((*it).second.getAngle(), 0.0, 0.0, 1.0); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex2f((float)(*it).second.getWidth() / -2.0f, (float)(*it).second.getLength() / -2.0f); glTexCoord2f(1.0f, 0.0f); glVertex2f((float)(*it).second.getWidth() / 2.0f, (float)(*it).second.getLength() / -2.0f); glTexCoord2f(1.0f, 1.0f); glVertex2f((float)(*it).second.getWidth() / 2.0f, (float)(*it).second.getLength() / 2.0f); glTexCoord2f(0.0f, 1.0f); glVertex2f((float)(*it).second.getWidth() / -2.0f, (float)(*it).second.getLength() / 2.0f); glEnd(); glRotatef(-(*it).second.getAngle(), 0.0, 0.0, 1.0); glTranslatef(-(*it).second.getX(), -(*it).second.getY(), 0.0f); } glBindTexture(GL_TEXTURE_2D, 0); } } void MasterRenderer::renderTanks() { glBindTexture(GL_TEXTURE_2D, textures.at(0).getTexture()); for(Tank tank : tanks) { // танк glTranslatef(tank.getX(), tank.getY(), 0.0f); glRotatef(-tank.getAngle(), 0.0, 0.0, 1.0); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex2f(tank.getWidth() / -2.0, tank.getLength() / -2.0); glTexCoord2f(1.0f, 0.0f); glVertex2f(tank.getWidth() / 2.0, tank.getLength() / -2.0); glTexCoord2f(1.0f, 1.0f); glVertex2f(tank.getWidth() / 2.0, tank.getLength() / 2.0); glTexCoord2f(0.0f, 1.0f); glVertex2f(tank.getWidth() / -2.0, tank.getLength() / 2.0); glEnd(); glRotatef(tank.getAngle(), 0.0, 0.0, 1.0); glTranslatef(-tank.getX(), -tank.getY(), 0.0f); } // Башня glBindTexture(GL_TEXTURE_2D, textures.at(1).getTexture()); for(Tank tank : tanks) { glTranslatef(tank.getX(), tank.getY(), 0.0f); glRotatef(-tank.getTurretAngle(), 0.0f, 0.0f, 1.0f); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex2f(tank.getTurretWidth() / -2.0f, tank.getTurretLength() / -2.0f + tank.getTurretOffset()); glTexCoord2f(1.0f, 0.0f); glVertex2f(tank.getTurretWidth() / 2.0f, tank.getTurretLength() / -2.0f + tank.getTurretOffset()); glTexCoord2f(1.0f, 1.0f); glVertex2f(tank.getTurretWidth() / 2.0f, tank.getTurretLength() / 2.0f + tank.getTurretOffset()); glTexCoord2f(0.0f, 1.0f); glVertex2f(tank.getTurretWidth() / -2.0f, tank.getTurretLength() / 2.0f + tank.getTurretOffset()); glEnd(); glRotatef(tank.getTurretAngle(), 0.0f, 0.0f, 1.0f); glTranslatef(-tank.getX(), -tank.getY(), 0.0f); } glBindTexture(GL_TEXTURE_2D, 0); } void MasterRenderer::renderBullets() { glBindTexture(GL_TEXTURE_2D, textures.at(2).getTexture()); for(int i = 0; i < bullets.size(); i++) { glTranslatef(bullets.at(i).getX(), bullets.at(i).getY(), 0); glRotatef(-bullets.at(i).getAngle(), 0.0f, 0.0f, 1.0f); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex2f(bullets.at(i).width / -2.0f, bullets.at(i).length / -2.0f); glTexCoord2f(1.0f, 0.0f); glVertex2f(bullets.at(i).width / 2.0f, bullets.at(i).length / -2.0f); glTexCoord2f(1.0f, 1.0f); glVertex2f(bullets.at(i).width / 2.0f, bullets.at(i).length / 2.0f); glTexCoord2f(0.0f, 1.0f); glVertex2f(bullets.at(i).width / -2.0f, bullets.at(i).length / 2.0f); glEnd(); glRotatef(bullets.at(i).getAngle(), 0.0f, 0.0f, 1.0f); glTranslatef(-bullets.at(i).getX(), -bullets.at(i).getY(), 0); bullets.at(i).move(); bullets.at(i).setLife(bullets.at(i).getLife() + 0.01f); if(bullets.at(i).getLife() >= 2.0f) bullets.erase(bullets.begin() + i); std::vector<Bullet>(bullets).swap(bullets); } glBindTexture(GL_TEXTURE_2D, 0); } void MasterRenderer::prepareRenderer() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.0f, 1300.0f, 600.0f, 0.0f, 0.0f, 1.0f); glMatrixMode(GL_MODELVIEW); glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } 

Help me please.

  • Could you give X, Y, Angle values ​​for each Entity and their sizes? You can also use glPush / glPopMatrix to avoid calling glRotatef and glTranslatef with inverse transformations. - Unick
  • 323.0 100.0 Angle: 0 Dimensions: 297 60 / 201.0 160.0 Angle: 0 Dimensions: 122 276 / 352.0 328.0 Angle: -37 Dimensions: 288 196 - Yuri Bilas
  • Apparently, these coordinates are not accurate. Try to ask yourself a task and draw one rectangle correctly. Then you can understand what's going on. I think you need to figure out where your rectangles have a point (0, 0). Apparently, this is the top corner and, based on this, set the position. Try to lay out the skinshots of the entire screen, and not only. It is very difficult to navigate on them, the more you have a tank displacement there. It is good to remove it for debugging problems. - Unick

0