Jump to content

  • Log In with Google      Sign In   
  • Create Account


Translated/Translatef


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 Caglow   Members   -  Reputation: 122

Like
0Likes
Like

Posted 05 April 2009 - 12:39 PM

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]

Sponsor:

#2 Caste   Moderators   -  Reputation: 969

Like
0Likes
Like

Posted 07 April 2009 - 09:02 PM

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

#3 Caglow   Members   -  Reputation: 122

Like
0Likes
Like

Posted 11 April 2009 - 08:58 AM

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.

#4 Brother Bob   Moderators   -  Reputation: 7905

Like
0Likes
Like

Posted 11 April 2009 - 10:43 AM

Set a perspective projection instead of an orthographic one. Check out glFrustum or gluPerspective instead of glOrtho or gluOrtho2D.

#5 lc_overlord   Members   -  Reputation: 435

Like
0Likes
Like

Posted 11 April 2009 - 10:47 AM

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

#6 Caglow   Members   -  Reputation: 122

Like
0Likes
Like

Posted 12 April 2009 - 05:02 AM

Now THAT works like magic! Thanks for the help!




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS