View Full Version : Looking with Camera?
04-24-2012, 06:07 AM
Hey, I'm trying to make a camera but when I use the arrow keys to look around like a head, I can only look 90 degrees in any direction. How do I get it to go a complete circle?
04-24-2012, 07:31 AM
Store facing angle in a variable, and glRotate modelview with it (provided you use reset the modelview each frame, and you should).
Then each time the left key is down, increment it with rotSpeed/frameTime. When right key is down, decrement.
If still can not solve it yourself, be more precise about what you have written, and post some code in proper [ code ] tags.
04-24-2012, 09:11 AM
I was trying to something similar, I have:
gluLookAt(cam.Posx, cam.Posy, cam.Posz, cam.ForwardX, cam.ForwardY, cam.ForwardZ, cam.upx, cam.upy, cam.upz);
So every frame I increment/decrement Forward.x to look around, I then tried incrementing ForwardZ when turning right but that still only allowed me to rotate 180 no matter what I set it too.
04-24-2012, 09:40 AM
rotate 180 no matter what I set it too.
Well that's 90 degrees better than in your first post :-)
Post some code, properly formatted so we can see your camera code.
04-24-2012, 10:42 AM
Haha, still not much use though. Heres my Camera code:
float cosR, cosP, cosY;
float sinR, sinP, sinY;
cosY = cosf(cam.GetYaw()*3.1415/180);
cosP = cosf(cam.GetPitch()*3.1415/180);
cosR = cosf(cam.GetRoll()*3.1415/180);
sinY = sinf(cam.GetYaw()*3.1415/180);
sinP = sinf(cam.GetPitch()*3.1415/180);
sinR = sinf(cam.GetRoll()*3.1415/180);
ForwardVectorX = sinY * cosP*360;
ForwardVectorZ = sinP*360;
ForwardVectorY = cosP * -cosY*360;
// Look At Point
cam.ForwardX = cam.Posx + ForwardVectorX;
cam.ForwardY = cam.Posy + ForwardVectorZ;
cam.ForwardZ = cam.Posz + ForwardVectorY;
// Up Vector
cam.upx = -cosY * sinR - sinY * sinP * cosR;
cam.upy = cosP * cosR;
cam.upz = -sinY * sinR - sinP * cosR * -cosY;
Yaw, Pitch and Roll are all 1.0,
I then put the values into gluLookAt and changed them using:
Thats for the 90 degrees turn, for 180 I just incremented/decremented cam.ForwardZ aswell.
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.