• Advertisement

Archived

This topic is now archived and is closed to further replies.

glTranslatef() question...

This topic is 5555 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am quite new to 3D programming but I have worked in programs such as Rhinocerous3D, 3DS Max 4, and gmax, and I have learned some 3D math in my pre-calculus class... Yet, I am having loads of trouble understanding glTranslatef()...why are the increments so low, why in the like, first tutorial, did I already need to move the screen. Like, why couldn''t I have just drew the polygon, on the screen already. And is translatef used to move the "camera" or is it something different (ie, move the coordinate system instead of the viewport...) I''m sorry I had to post this but before I begin actually coding the main part of my engine, I thought I should know this... Thank you to anyone who helps! <- http://www.digitalexplosions.com -> "Discipline is my sword, faith is my shield do not dive into uncertainty, and you may live to reap the rewards" - (Unreal Championship)

Share this post


Link to post
Share on other sites
Advertisement
glTranslate, glRotate, glScale, glLoadMatrix, glMultMatrix, etc, all effect the currently active matrix, which is almost always the modelview matrix.
What this matrix does is simply 'modify' the coordinates you pass in using your vertex arrays (don't learn with glTexCoord,glVertex,ect, it's of no use at all in your future)... ie, if the matrix is rotated, the coordinates you pass in will be rotated before rendering. The same if they are translated (moved). This simply means that you don't have to manually rotate/move every vertex you place. you can simply use the video card to your advantage and let it do it for you.
this means if you have a object you want to render 50 times (which is common, say a tree) then you create a vertex array and index array once for that object, and then just reuse it over and over again every frame... compared to the likes of glVertex, this is massivly faster for the cpu.. you use glTranslate and the like to move/rotate/scale to where you want to render that object. You can even do similar things for animation, but it's a lot harder. (it's all part of lifting the burden off the cpu)

The general idea is to set your camera position (the easy, but very rough way is with glLookAt - good for beginners but not much else), then, to push that matrix, translate/rotate to the object you want to draw (ideally done with a single call to glMultMatrix with a matrix thats stored in the object), draw it, then pop the matrix (go back to the camera)... Repeat this for every object (ignoring setting the camera, of course).

hopfully this makes you realise that the likes of glTranslate arn't just for setting where the camera is... they are absolutly key to efficient rendering.

you likly won't see any direct benifit from doing what I've said now, ie, using glTranslate instead of manually shifting each vertex, and using pre generated/loaded vertex data in arrays instead of the impossibly aweful glVertex... In fact most people wont... but as soon as you start really trying to push the cpu for other things (physics, ai, etc) THEN you will notice it... If you cpu is already working flat out with glVertex calls, and the like, then all the physics, ai, etc, all has to be computed once all the rendering is finished (literally) but if your simply passing in positions to render from, and arrays to render out of, the video card can effectivly get on with the job, leaving the cpu free to get on with other things... ie, physics and ai... Learning this way from the start will help you emmensly in the future, ESPECIALLY when you move over to direct3d (which virtually forces you to write this way)


| - Project-X - my mega project.. big things comming soon - | - adDeath - an ad blocker I made - | - email me - |

[edited by - RipTorn on December 5, 2002 7:38:28 PM]

Share this post


Link to post
Share on other sites
ok...

but wut are the default coordinates that are drawn...? or do u have to translate or lookat to a position?

<- http://www.digitalexplosions.com ->
"Discipline is my sword, faith is my shield
do not dive into uncertainty, and you may live to reap the rewards" - (Unreal Championship)

Share this post


Link to post
Share on other sites
do some research on glTranslatef and gluLookAt

an "engine" before knowing any of the above?

good luck!

~~~~~~~~~~~~~~~~~~~~~~~~~

http://on.to/oni

Share this post


Link to post
Share on other sites
Well, I am trying to write a menu class, but I don't know what coordinates to draw the image with...

here is the source for my menu class to render it... please bear with my noobiness


void Menu::RenderMenu()
{
glBindTexture(GL_TEXTURE_2D, background[0]);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 0.0f); // Upper Left
glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 0.0f); // Upper Right
glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f,-1.0f, 0.0f); // Lower Right
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f,-1.0f, 0.0f); // Lower Left
glEnd();
}


EDIT 1: Ok, so I made sure that the Texture is getting bound, now its time to play around with translate...(im trying to keep this updated because I do not feel like I should be asking for help and instead I should be searching around for answers on websites, but that never works for me...k brb with some more updates...hopefully...)

<- http://www.digitalexplosions.com ->
"Discipline is my sword, faith is my shield
do not dive into uncertainty, and you may live to reap the rewards" - (Unreal Championship)

[edited by - Krisc on December 5, 2002 8:34:47 PM]

[edited by - Krisc on December 5, 2002 8:40:04 PM]

Share this post


Link to post
Share on other sites
for a menu you can always change the viewport to 60x480 or something using:
glOrtho(0.0f,640.0f,0.0f,480.0f,-10.0f,10.0f);
then change it back to normal after the menu is done

My Homepage
How many Microsoft employees does it take to screw in a light bulb?
None, they just declare drakness as a new standard.

Share this post


Link to post
Share on other sites
the reason u have to translate is so that u keep the triangle in the middle of the coordinate system for when u rotate...

see the way it works is.. if u were to draw the triangle with vertices where u wanted them, instead of how they are (with the triangle center at (0,0,0) u would have to translate them back to (0,0,0) and then rotate the triangle, and then translate them back to where u want them

i must be confusing the hell out of u... lol

Share this post


Link to post
Share on other sites
ooooooooooohhh, that helps, a bit...
as in my understandment
but it confuses me now on what the heck i do! lol! ill try that glOrtho() thing! just to let u know, im running at 1024x768x32...well the engine is...


EDIT 1: btw, wut is normal for ortho?
EDIT 2: Also, I think there may be something wrong with my texture coordinates and my vertex placements...

[edited by - Krisc on December 5, 2002 8:46:10 PM]

[edited by - Krisc on December 5, 2002 8:51:47 PM]

Share this post


Link to post
Share on other sites

  • Advertisement