Restoring previous position
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.
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
regards,
Peter Wraae Marino
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..
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..
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.
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]
#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 translationGLfloat g_fRotX = START_ROT_X; // Current X-axis rotationGLfloat g_fRotY = START_ROT_Y; // Current Y-axis rotationGLfloat g_fRotZ = START_ROT_Z; // Current Z-axis rotationGLfloat g_fTraslX = START_ROT_X; // Current X-axis translationGLfloat g_fTraslY = START_ROT_Y; // Current Y-axis translationGLfloat 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]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement