• Advertisement
Sign in to follow this  

Translated/Translatef

This topic is 3205 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

Sorry about all the questions. I have (attempted) research on all OpenGL related topics and this is one (very basic I assume) principle that I just don't seem to get. How does Translate work? When placed inside a PushMatrix/PopMatrix and before the drawing of an object, I assume it would translate it by the specified 3D coordinates. ie, translatef(0.0, 0.0, 1.0f) would move the object 1 unit away from the camera. From the tutorials, I can tell that I'm clearly wrong about the z. When I try it myself, it moves the object down by 1 unit. Someone, please correct me and my mistake. How does translate REALLY work (I'd prefer if you don't go until matrices unless that's the only way to explain). And how would you move the object 1 unit away like I intended? Again, thanks for any and all help I recieve. [Edited by - Caglow on April 5, 2009 8:30:07 PM]

Share this post


Link to post
Share on other sites
Advertisement
Hey,

your understanding of translatef should be correct, you just didn't notice that we're having a right handed coordinate system where +X goes to the right, +Y to the top and +Z towards the camera, so just pass -1.0 to glTranslatef and you should get the expected result.



-Carsten

Share this post


Link to post
Share on other sites
I see...well, that fixes the X/Y part of it but the Z axis still doesn't seem to want to work as you say it should.

The code:

PushMatrix();
glTranslated(0, 0, 10);
glutSolidSphere(1.4, 150, 150);
PopMatrix();

According to what you say, that should move the "glutSolidSphere" closer to me by 10 units. However, this is what it does: http://aciqra.sf.net/images/z10.PNG

This is the original without a translate: http://aciqra.sf.net/images/z0.PNG

I'm not sure what it's exactly doing here...it's either moving the camera around the object or it's moving the light source.

Thanks.

EDIT: From what I just realized...I think translating an object closer or farther doesn't change its size. How would I go about "linking" the translate with a size change? It feels very obvious but I can't figure it out.

Share this post


Link to post
Share on other sites
Set a perspective projection instead of an orthographic one. Check out glFrustum or gluPerspective instead of glOrtho or gluOrtho2D.

Share this post


Link to post
Share on other sites
well according to your code it does move towards the screen, the only problem is that it moves "behind" the camera, and it can do this because i think you have an orthographic projection matrix and not a perspective one as one normally uses.
thus no matter how it moves along the z the size won't change.

the code for that looks something like this

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f,1.3f,0.1f,1000.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

just place it as the first thing in your rendering loop

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement