Sign in to follow this  

camera class

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

How would i go about creating a camera class which can rotate around a specified point? would the camera have to be quaternion? Also how would i be able to rotate the camera using the mouse? Thanks Web_scripter

Share this post


Link to post
Share on other sites
It's not essential to make it a quarternion. A few simple 3D vectors would do the trick (position, up vector, and look vector). To rotate about a specific point, it's simple trigonometry. Ie: flaten the rotation into a two dimension plane, and using sine and cosine. Both DirectX and OpenGL have functions to produce a transformation matrix using those three vectors. Here's a quick example:


class TVector
{
private:
protected:
public:
float x,y,z;
// Constructors, functions, blah blah blah
};

class TCamera
{
private:
TVector position;
TVector up;
TVector look;
protected:
public:
void RotateAboutX(float theta)
{
position.y=position.z*sin(theta) + position.y*cos(theta);
position.z=position.z*cos(theta) - position.y*sin(theta);
};

void RotateAboutY(float theta)
{
position.x=position.z*cos(theta) - position.x*sin(theta);
position.z=position.z*sin(theta) + position.x*cos(theta);
};

void RotateAboutZ(float theta)
{
position.x=position.x*cos(theta) - position.y*sin(theta);
position.y=position.y*sin(theta) + position.x*cos(theta);
};
};


Or something like that.

As for your second question, just keep track of a delta change in the mouse, and translate that into some theta which you would pass to the rotation functions.

Share this post


Link to post
Share on other sites
You might want to have a look at the sample framework that ships with the DX SDK, if you dig into the code they have a modelview camera that does what you are looking for. You may not want to use the framework, but the code that does the process might help.

Share this post


Link to post
Share on other sites

This topic is 4481 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this