Jump to content
  • Advertisement
Sign in to follow this  
ajm113

OpenGL glRotate and Camera View

This topic is 3759 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

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...

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
What is this line of code:
glRotatef(objCamera.mView.x,0,objCamera.mView.z, 0);
Supposed to do? And what does mView represent exactly?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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);


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!