Jump to content
  • Advertisement
Sign in to follow this  
opendep

Restoring previous position

This topic is 3761 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 need to restore a rendered object to its initial(when rendered at first) position on pressing a glui button. I am using GLUI translation and rotation. I tried with glLoadIdentity and then assigning an identity matrix to the current rotation matrix and 0 to translation values. But it didnt work. Can anyone help me with this..? Thank you.

Share this post


Link to post
Share on other sites
Advertisement
why don't you simple save the initial position and rotation values.. and when you need to restore them then use the saved values.

regards,
Peter Wraae Marino

Share this post


Link to post
Share on other sites
hi,
My code is

gui_variables->translate_xy[2]= (0.0,0.0);
gui_variables->translate_z = 0.0;
rotation_matrix[16] = ( 1.0, 0.0, 0.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0 );
glui_window->sync_live();
glLoadIdentity();

sync_live function is to synchronise the values of rotation and translation matrices with their respective glui controls.

Thanks a lot..

Share this post


Link to post
Share on other sites
I'm not an expert of GLUI, however, here is what I would do in the same situation. The example is in pure OpenGL but I guess you can adapt it easily to use GLUI functions.


#define START_ROT_X 0.0f // Initial X-axis rotation
#define START_ROT_Y 0.0f // Initial Y-axis rotation
#define START_ROT_Z 0.0f // Initial Z-axis rotation

#define START_TRASL_X 0.0f // Initial X-axis translation
#define START_TRASL_Y 0.0f // Initial Y-axis translation
#define START_TRASL_Z 0.0f // Initial Z-axis translation

GLfloat g_fRotX = START_ROT_X; // Current X-axis rotation
GLfloat g_fRotY = START_ROT_Y; // Current Y-axis rotation
GLfloat g_fRotZ = START_ROT_Z; // Current Z-axis rotation

GLfloat g_fTraslX = START_ROT_X; // Current X-axis translation
GLfloat g_fTraslY = START_ROT_Y; // Current Y-axis translation
GLfloat g_fTraslZ = START_ROT_Z; // Current Z-axis translation


// Render the scene:
void RenderScene ( void )
{
glPushMatrix();

// Apply current rotations:
glRotatef( g_fRotX, 1.0f, 0.0f, 0.0f );
glRotatef( g_fRotY, 0.0f, 1.0f, 0.0f );
glRotatef( g_fRotZ, 0.0f, 0.0f, 1.0f );

// Apply current translations:
glTranslatef( g_fTraslX, g_fTraslY, g_fTraslZ );

// Draw the object:
draw_object()

glPophMatrix();
}


// Reset the object translations and rotations to default:
void ResetObjPosition ( void )
{
g_fRotX = START_ROT_X;
g_fRotY = START_ROT_Y;
g_fRotZ = START_ROT_Z;

g_fTraslX = START_ROT_X;
g_fTraslY = START_ROT_Y;
g_fTraslZ = START_ROT_Z;
}









As you can see, I'm storing current translations and rotations into globals. These globals values can be changed during the program execution (i.e. when the user moves the object around). When you need to restore the object in its original position just call ResetObjPosition() and the globals will be reset to the initial values ans hence next time RenderScene() is called the object will be drawn in the initial position. (Yes, this is the same solution proposed by Crisium :-) )

I hope this can help.

[Edited by - LordOrion on April 2, 2008 10:19:38 AM]

Share this post


Link to post
Share on other sites
hi,
Thanks a lot guys. I seemed to have overlooked a simple function provided by GLUI.
Its working now... :)

regards,
AM

Share this post


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

  • 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!