glRotate and Camera View

Started by
9 comments, last by ajm113 15 years, 8 months ago
I have asked this in the math area, but no one helped, so I am woundering if this is a OpenGL question now, since I see billboard topics come up with OpenGL tutorials showing rotation with the camera. Ok, I am using Marrowland's 3rd person camera from the OpenGL tutorials, and I made a 3rd person space ship I want to rotate where the camera is facing, but I keep over shooting the calculation of the rotation of the ship, can also someone show me a way to have it so the ship won't rotate really fast, so it looks real? I an no math genuis so I can't really figure this out...
Check out my open source code projects/libraries! My Homepage You may learn something.
Advertisement
[smile] Can you explain the problem a bit better please?

Like, is the ship not following the camera, or is the ship following the camera too abruptly, can you actually get the ship to turn to face the camera at all times/correctly?
"I am a donut! Ask not how many tris/batch, but rather how many batches/frame!" -- Matthias Wloka & Richard Huddy, (GDC, DirectX 9 Performance)

http://www.silvermace.com/ -- My personal website
When the game starts and I move the camera around the ship stays with the camera as the speed of the camera moves.

Its just if I rotate it to the left it goes there the same speed, but if I wanted it to rotate back to the right it then keeps moving to the left or the model rotates its front right past the camera and eather stays their until keep rotating the camera left or right.

This is how I have it set up:
		// use this function for opengl target camera	gluLookAt(objCamera.mPos.x,  objCamera.mPos.y,  objCamera.mPos.z,				  objCamera.mView.x, objCamera.mView.y, objCamera.mView.z,				  objCamera.mUp.x,   objCamera.mUp.y,   objCamera.mUp.z);	glPushMatrix();	glTranslatef(objCamera.mView.x,0.0f,objCamera.mView.z);	glRotatef(objCamera.mView.x,0,objCamera.mView.z, 0);


BTW, I forgot to ask is how can I keep the model to rotate to the position I want even if the camera is not moving?
Check out my open source code projects/libraries! My Homepage You may learn something.
Did you remember to call glPopMatrix afterwards?
Yep, though I don't know what that has to do with my model if I am only rendering one model on the screen, that is having calculation problems rotating the correct position I want it to face.

I am not trying to be pushy or nothing, I just kinda odd that this isn't much someone can think off the top of their heads to help here. For a feature made in almost every game even in First Person shooters. (Rotation Of The Gun)

[Edited by - ajm113 on August 2, 2008 6:56:49 PM]
Check out my open source code projects/libraries! My Homepage You may learn something.
What is this line of code:
glRotatef(objCamera.mView.x,0,objCamera.mView.z, 0);
Supposed to do? And what does mView represent exactly?
That is supposed to rotate the model where the camera is facing at, but it doesn't do it... That mView, just holds the camera's facing direction in xyz cords.

For a better/faster response here is how it's set up in gluLookAt


	gluLookAt(objCamera.mPos.x,  objCamera.mPos.y,  objCamera.mPos.z,				  objCamera.mView.x, objCamera.mView.y, objCamera.mView.z,				  objCamera.mUp.x,   objCamera.mUp.y,   objCamera.mUp.z);


If you have any other questions about the code, I will be more then happy to answer them.

Thanks, Ajm113.
Check out my open source code projects/libraries! My Homepage You may learn something.
glRotate(a, x, y, z) rotates a degrees about the axis (x, y, z). So your glRotate rotates mView.x degrees about the axis (0, mView.z, 0). If you think about that, and how you use mView in glLookAt, it makes absolutely no sense at all.
I used most of the code for the 3rd person from here:
http://www.morrowland.com/apron/tut_gl.php

CAMERA 4 Tutorial, but also I created something like this, which I thought would work, but won't that I added on. Same thing again, but looks as if it works for a bit....

I added a player struct called pl1.YRot where it holds the model's rotation value.

if(pl1.YRot > objCamera.mUp.z){		pl1.YRot -= CAMERASPEED;		}		if(pl1.YRot < objCamera.mUp.z)		{		pl1.YRot += CAMERASPEED;		}			 glTranslatef(0.0,-25.0,-30); //150			glRotatef(pl1.YRot,0.0,1.0, 0.0);			glRotatef(-90.0f, 90.0, 0.0, 0.0);		
Check out my open source code projects/libraries! My Homepage You may learn something.
I'm new here .... I'm chinese
I found this website from google when I input "opengl"
Nice to meet u guys.

This topic is closed to new replies.

Advertisement