Hello everyone,
I am learning about the glTranslate function and I was wondering if anyone here could give me insight on this function. I would like to note that I am drawing in 2D So far, I have two cases.
Case 1:
if(event.GetKeyCode() == LETTER_W || event.GetKeyCode() == LETTER_w)
{
cameraY -= 16.0f;
}
else if(event.GetKeyCode() == LETTER_S || event.GetKeyCode() == LETTER_s)
{
cameraY += 16.0f;
}
else if(event.GetKeyCode() == LETTER_A || event.GetKeyCode() == LETTER_a)
{
cameraX -= 16.0f;
}
else if(event.GetKeyCode() == LETTER_d || event.GetKeyCode() == LETTER_D)
{
cameraX += 16.0f;
}
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glLoadIdentity();
glTranslated(cameraX, cameraY, 0.0f);
glPushMatrix();
In the first case, we see glTranslate function between a pop and push matrix. When this occurs, the view is translated.
case 2:
// Clears the color buffer
glClear(GL_COLOR_BUFFER_BIT);
//Reset to modelview matrix
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glPushMatrix();
glTranslatef(canvasWidth / 2.0f, canvasHeight / 2.0f, 0.0f);
//Red quad
glBegin( GL_QUADS );
glColor3f( 1.f, 1.f, 1.f );
glVertex2f( -canvasWidth / 4.f, -canvasHeight / 4.f );
glVertex2f( canvasWidth / 4.f, -canvasHeight / 4.f );
glVertex2f( canvasWidth / 4.f, canvasHeight / 4.f );
glVertex2f( -canvasWidth / 4.f, canvasHeight / 4.f );
glEnd();
//Move to the right of the screen
glTranslatef( canvasWidth, 0.f, 0.f );
//Green quad
glBegin( GL_QUADS );
glColor3f( 0.f, 1.f, 0.f );
glVertex2f( -canvasWidth / 4.f, -canvasHeight / 4.f );
glVertex2f( canvasWidth / 4.f, -canvasHeight / 4.f );
glVertex2f( canvasWidth / 4.f, canvasHeight / 4.f );
glVertex2f( -canvasWidth / 4.f, canvasHeight / 4.f );
glEnd();
In the second case, first, a white square is drawn at the center (even though comment says red it is white) and then, a green square is drawn screen. Note that the glTranslate function is not in between push or pop; therefor, the view is not changed.
Are these reasonable conclusions on how to use glTranslate function. In order to change the view (in order to pan around my drawing), then I need to place glTranslate between a push and pop sequence. If I want to drawn something far off in the distance (or beyond my view), then I do not place glTranslate between a push and pop sequence. This will then only effect the model’s placement.
Are these reasonable conclusions that I should understand in order to use glTranslate function properly?
I do not specify glTranslated or glTranslatef becuase I am assuming that this applies to both forms.