Jump to content
  • Advertisement
Sign in to follow this  
Cacks

Camera Rotations

This topic is 4644 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 guys, Im currently making a CAD tool. Im making a camera class that holds the position of the camera and what its looking at & some other stuff. I can get my camera to translate correctly by using gluLookAt() and passing appropriate values to this function. Eg to move on the x-axis I pass a larger x-axis value than the current. For my camera rotaions this isn't so easy. Currently I Im using a custom function to calculate the rotation positions. Is there an easier way of doing this? Thanks for any help given!

Share this post


Link to post
Share on other sites
Advertisement
This is the method that manipulates my camera. 'cameraPosition' is a vector that holds the camera position. 'calculateDistancesAfterRotation()' is a function that uses trig to determine the next position of the camera. Its not completely working yet. I've only defined the left rotation & it has a sticking problem when the camera is moved in a full circle.



void Camera::moveCamera(CameraMovement movCam)
{
switch(movCam)
{
case translateUp: cameraPosition[1] += cameraMovementFactor;
cameraLookAt[1] += cameraMovementFactor;
break;
case translateDown: cameraPosition[1] -= cameraMovementFactor;
cameraLookAt[1] -= cameraMovementFactor;
break;
case translateLeft: cameraPosition[0] -= cameraMovementFactor;
cameraLookAt[0] -= cameraMovementFactor;
break;
case translateRight: cameraPosition[0] += cameraMovementFactor;
cameraLookAt[0] += cameraMovementFactor;
break;
case translateForward: cameraPosition[2] -= cameraMovementFactor;
break;
case translateBackward: cameraPosition[2] += cameraMovementFactor;
break;
case rotateUp:
break;
case rotateDown: break;
case rotateLeft: if(cameraPosition[0] < 0.0) //X <0
{
if(cameraPosition[2] < 0.0 )//Z <0
{
cameraPosition[0] += calculateDistancesAfterRotation().sideOrTilt;
cameraPosition[2] -= calculateDistancesAfterRotation().distFromLookAtPoint;
}
else//Z >0
{
cameraPosition[0] -= calculateDistancesAfterRotation().sideOrTilt;
cameraPosition[2] -= calculateDistancesAfterRotation().distFromLookAtPoint;
}
}
else//X>0
{
if(cameraPosition[2] < 0.0 )//Z <0
{
cameraPosition[0] -= calculateDistancesAfterRotation().sideOrTilt;
cameraPosition[2] += calculateDistancesAfterRotation().distFromLookAtPoint;
}
else//Z >0
{
cameraPosition[0] -= calculateDistancesAfterRotation().sideOrTilt;
cameraPosition[2] -= calculateDistancesAfterRotation().distFromLookAtPoint;
}
}
break;
case rotateRight: cameraPosition[0] -= calculateDistancesAfterRotation().sideOrTilt;
cameraPosition[2] += calculateDistancesAfterRotation().distFromLookAtPoint;
break;
}
}
[/SOURCE]



Has any1 got a better away of calculating, storing and performing camera manipulations?

Thanks!

Share this post


Link to post
Share on other sites


void transform(float tx, float ty, float tz, float ax, float ay, float az)
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(fov, w / h, 1.0, 60.0);
glTranslatef(tx, ty, tz);
glRotatef(ax, 1, 0, 0);
glRotatef(ay, 0, 1, 0);
glRotatef(az, 0, 0, 1);
}






Try this.
I'm not sure if it actually works. (I've never programmed a camera before. Never needed it.)

[EDIT]

Forget about it.
It was a dumb idea. (It doesn't work at all...)

[Edited by - mrbig on January 2, 2006 11:03:10 AM]

Share this post


Link to post
Share on other sites
Yeah I was considering using gl commands but I want to record where my camera is. I haven't much experience with transformations through.

Share this post


Link to post
Share on other sites
I think I got what you need in my old software engine.
It's just a few lines of simple code.
I'll post it later. (As soon as I find it...)

Share this post


Link to post
Share on other sites


void transform(float tx, float ty, float tz, float ax, float ay, float az)
{
glTranslatef(-tx, -ty, -tz);
glRotatef(-ax, 1, 0, 0);
glRotatef(-ay, 0, 1, 0);
glRotatef(-az, 0, 0, 1);
}




Try that instead. Load the indentity matrix and set up the view elsewhere.

Whatever the camera does the scene does the opposite. Thos transformations are what needs to be applied to the scene to get the correct position of the scene.

To change the postioning of the camera you just adjust the tx,ty,tz and ax,ay,az variables.

If you want to change the postion of the camera by rotating it around a specific axis then you will need to use matrix math and apply that to the camera's coordinates.

Try this

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!