Jump to content
  • Advertisement

Archived

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

player2

OpenGL OpenGL transformation question

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

Hi, I have a question about rotational transformation in OpenGL, and would be grateful if anyone can help. Say I have a data structure that holds the vertices information(x, y and z values) of a 3D object, and I want to translate and rotate the object. Is it better to calculate the end result of those transformation and store the new value back into the data structure, or is better to store the tranformation steps and then apply those transformation by calling glTranslate and glRotate every time the object is rendered? I know that it''s probably better to compute and store the result since it only has to be done once when the position and the orientation of the object changes, but I''m worried about the rotational transformation since it might have rounding errors. If I do enough rotational transformation on one vertex, it might not have the right value even if it''s rotated back to its original position. For example, if it''s rotated 20 -> store -> rotate80 -> store -> rotate260 -> store, now it should be back to it''s original position after 360 degree rotation, but since there''s a rounding error, it will have a slightly different value. And if it''s done enough times, the margine of error will become significant. Any input will be appreciated. thanks, player2

Share this post


Link to post
Share on other sites
Advertisement
If you want to take advantage of hardware transformation then use glTranslate/glRotate. The red book also says that building your own matrix is a bad idea. I say use the opengl commands.

The fanatic is incorruptible: if he kills for an idea, he can just as well get himself killed for one; in either case, tyrant or martyr, he is a monster.
--EM Cioran

Opere Citato

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
nothing wrong with using your own matrices as longs as u use glLoadMatrix() glMultMatrix() these take advantage of hardware tnl

Share this post


Link to post
Share on other sites
Thanks for the suggestions, but I''m sorry my explaination was probably not very clear.

Say the data structure is as follow:
typedef struct _vertex
{
flaot x, y, z;
} Vertex;

Vertex* object;


Is it better to do the transformation on the object everytime the frame is rendered:

float dispX=0, dispY=0, dispZ=0;
float angle=0;

RenderFrame()
{
...
glTranslate(dispX, dispY, dispZ);
glRotate(angel, 1, 0, 0);
DrawObject( object );
...
}

DoKeys()
{
...
if( isPressed(UP) ) dispX += 1;
if( isPressed(DOWN) ) dispX -= 1;
if( isPressed(RIGHT) ) angle += 1;
...
}

Or is it better to calculate the result just once when the keys are pressed:

RenderFrame()
{
...
DrawObject( object );
...
}

DoKeys()
{
...
if( isPressed(UP) ) Translate( Object, 1, 0, 0 );
if( isPressed(DOWN) ) Traslate( Object,- 1, 0, 0 );
if( isPressed(RIGHT) ) Rotate( Object, 1, 1, 0, 0 );
// rotate the object 1 degree along the line with direction (1, 0, 0) and update the vertices coordinates in Object
...
}

Thanks for any helps.
Player2

Share this post


Link to post
Share on other sites
the first one is correct. imagine you have more than 1 object...
furthermore it is more precise.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!