• Advertisement

Archived

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

"Saving" the rotation.

This topic is 5555 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 don''t really know what to call this sort of thing that I want. I have a function that draws a scene, and if a certain button is pressed, that scene is rotated and when pressed again, stops rotating. However, when the scene stops, the "camera" restes itself so it is looking at the spot where it was looking before, and not where it was looking when the rotation stopped, like I want it to do. My scene drawing code is here:
  
bool DrawScene () {
	// This function is what is called when we want to draw anything, so everything

	// that is drawn to the screen when we render the scene is either hardcoded in here

	// or the function that does additional drawing is called from here.


	// Clear both the colour and the depth buffers, so we have a fresh canvas to

	// draw on to.

	static rotator;
	glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	// Load the identity matrix of the current matrix.

	glLoadIdentity ();
	glTranslatef (0.0, 0.0, 0.0);
	if (rotate == true) {
		glTranslatef (MAPSIZE / 2, 0.0, MAPSIZE / 2);
		glRotatef (rotator, 0.0, 1.0, 0.0);
	}
	gluLookAt ((MAPSIZE / 8 + eyeX), (50.0 + eyeZ), (MAPSIZE / 8 + eyeY), (0.0 + eyeX), (0.0 + eyeZ), (0.0 + eyeY), 0.0, 1.0, 0.0);
	glScalef (SCALE, SCALE * RATIO, SCALE);
	RenderMap ();
	rotator ++;
	return true;
}
  
Sorry if the comments are verbose, but it''s for an A Level computing project where the examiner may not know the language used. Does anyone have any ideas as to how best to implement what I''m looking for? Any more information needed, just ask. TIA.

Share this post


Link to post
Share on other sites
Advertisement
Put the if(rotate == true) check around the increment for rotator, instead of around the actual rotation. This way, you''re always rotating the same amount as the last rotation, but not updating the angle of rotation unless the button is pressed.


  
glLoadIdentity ();
glTranslatef (0.0, 0.0, 0.0);
glTranslatef (MAPSIZE / 2, 0.0, MAPSIZE / 2);
glRotatef (rotator, 0.0, 1.0, 0.0);
gluLookAt ((MAPSIZE / 8 + eyeX), (50.0 + eyeZ), (MAPSIZE / 8 + eyeY), (0.0 + eyeX), (0.0 + eyeZ), (0.0 + eyeY), 0.0, 1.0, 0.0);
glScalef (SCALE, SCALE * RATIO, SCALE);
RenderMap ();
if(rotate == true)
{
rotator++;
}


Hope that makes sense.

----------------
Interesting quote deleted at request of owner

Share this post


Link to post
Share on other sites
Thank you very much! Exactly what I needed. I have another question regarding rotate, I''m sure it is relatively easy, and been answered many times, but the forum search is down.

If I wish to rotate my scene about any point, such as the middle of my map itself, how would I go about doing this? glRotatef seems to want to rotate my whole scene around the origin, and when I try and put values into it other than the normal ones of what I''ve been using, I get weird rotations.

Thanks for any help.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Look into glPushMatrix and glPopMatrix. They are used to save and restore matrices.

Share this post


Link to post
Share on other sites

  • Advertisement