"Saving" the rotation.

Started by
4 comments, last by MDI 21 years, 4 months ago
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.
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
----------------Amusing quote deleted at request of owner
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.
Look into glPushMatrix and glPopMatrix. They are used to save and restore matrices.
Make ''rotator'' a global variable. Every time you exit the function, rotator is deleted, and then reset when you re-enter.

|.dev-c++.|.the gimp.|.seti@home.|.dbpoweramp.|.torn.|.=w=.|
quote:Original post by Erunama
Make ''rotator'' a global variable. Every time you exit the function, rotator is deleted, and then reset when you re-enter.

|.dev-c++.|.the gimp.|.seti@home.|.dbpoweramp.|.torn.|.=w=.|


As it is a static, it won''t be deleted after leaving the function.
[My Lousy Page | Kings Of Chaos | Vampires | [email=lordlethis@hotmail.com]email.me[/email]]

This topic is closed to new replies.

Advertisement