开发者

is glTranslation() function gives position of object in opengl?

If i have a object on plane its translation value is glTranslatef(0,10,-5) so can i assume开发者_如何学Go my object position is (0,10,-5) ? Is translation gives position of objects ?


No, glTranslatef() sets a Matrix that makes sure that all objects drawn after this statement are translated by the given amount. If you want to translate (position) just one object, use the following.

glLoadIdentity()
glPushMatrix();
glTranslatef(0,10,-5);
//DrawObjectOne
glPopMatrix();
//DrawObjectTwo

This code does the following:

First it loads the identity matrix, this literally means no change in position, rotation or scale. Then a new matrix is pushed onto the matrix stack. All changes to the current WorldMatrix will hold until glPopMatrix() is called.

We modify the current world matrix by setting a translation of (0,10,-5) and then we draw that object at that location.

Now we pop the current world matrix, the current world matrix now disappears and we return to the previous WorldMatrix (which was the identity matrix)

Then we draw object two, which is just being drawn at (0,0,0).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜