Advertisement

Placing Object on screen

Started by January 19, 2004 08:55 AM
2 comments, last by Ructions 21 years, 1 month ago
i have 2 objects moving around the screen using the mouse and buttons.using the x and y co-ordinates. glTexCoord2f(0.0f, 1.0f); glVertex3f(0.3f + ball.x , 0.3f + ball.y , 0.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.3f + ball.x , 0.3f + ball.y, 0.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.3f + ball.x , -0.3f + ball.y, 0.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f(0.3f + ball.x , -0.3f + ball.y, 0.0f) i was wonder how do you place other objects on the screen with out using the x and y coordinates. using the same translation glTranslatef(0.0f,-6.5f,-20.0f); at the moment i have another object on the screen but it is at the bottom and dont know how to move it to the top. i am using this code at moment. glTexCoord2f(0.0f, 1.0f); glVertex3f(Wall[1].BottomRightX, Wal[1].BottomRightY,0.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f(Wall[1].BottomLeftX, Wall[1].BottomLeftY, 0.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f(Wall[1].TopLeftX, Wall[1].TopLeftY,0.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f(Wall[1].TopRightX, Wall[1].TopRightY,0.0f); any help would be greatful. this is a simple question for ye but you have to learn some how. thanks
Really, I can''t understand what you''re aking for...
Advertisement
You can do 3 things:
1. Re-translating the scene by calling glTranslatef again after drawing the translated code but then giving the negative of all values (like in your example it would be glTranslatef(0.0f,6.5f,20.0f); ). You should make a call to all functions modifying the modelview matrix (also glRotatef and some others)with reverse arguments, filo wise!!!

2. Reloading the identity matrix using glLoadIdentity(). This is not really an option i recomment but it's one. You should then of course again call all translating code from before the translate command you want to undo.

3. Using glPushMatrix() and glPopMatrix(). glPushMatrix() saves a copy of the modelview matrix (the array of values that is used to position everything correctly) into stack memory. If you want to reload that state again, call glPopMatrix() which sets the modelview matrix to the first copy in stack (and that copy will be deleted after that). I use this method an awfull lot and i think more people use it as much. I would recommend this one for sure.

[edited by - Tree Penguin on January 19, 2004 6:51:09 PM]
Yep push() and pop() for me too

glPushMatrix();

up here translate the other parts of the screen
such as crates in a room
........

glPopMatrix();

Down here translate say'' an md2 model
........

glPushMatrix();
glTranslatef(<the model>);

glColor3f( 1.0f, 1.0f, 1.0f );
AnimateMD2Model(&g_3DModel);

glPopMatrix();

works for me

This topic is closed to new replies.

Advertisement