Using glRotate and glTranslate with collision detection

Let's say I use glRotateto translate the current view based on some arbitrary user input (i.e. if you press the left key, then rtri+=2.5f)

glRotatef(rtri,0.0f,1.0f,0.0f);

Then I draw a triangle in a rotated position:

glBegin(GL_TRIANGLES);  // Drawing Using Triangles
    glVertex3f( 0.0f, 1.0f, 0.0f);  // Top
    glVertex3f(-1.0f,-1.0f, 0.0f);  // Bottom Left
    glVertex3f( 1.0f,-1.0f, 0.0f);  // Bottom Right
glEnd();  // Finished Drawing The Triangle

How to get the resulting translated vertices for use in detecting conflicts? Or will I have to manually apply the conversion and thereby double the work?

The reason I am asking is because I would not miss the display lists.

+3
source share
2 answers

, , , . , , . , - , , , .

+3

( ++):

void Scene::Draw()
{
    this->setClearColor(0.0f, 0.0f, 0.0f);

    for(std::vector<GameObject*>::iterator it = this->begin(); it != this->end(); ++it)
    {
        this->updateColliders(it);
        glPushMatrix();
            glRotatef(it->rotation.angle, it->rotation.x, it->rotation.y, it->rotation.z);
            glTranslatef(it->position.x, it->position.y, it->position.z);
            glScalef(it->scale.x, it->scale.y, it->scale.z);

            it->Draw();

        glPopMatrix();
    }

    this->runNextFrame(this->Draw, Scene::MAX_FPS);
}

, , , draw :

  • (rgb: (0,0,0))
    • .
    • ModelView
    • ModelView (, , )
    • ModelView
    • FPS .

** Scene

, !:)

0

Source: https://habr.com/ru/post/1738436/


All Articles