# camera class

This topic is 4887 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

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

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 15
• 9
• 11
• 9
• 9
• ### Forum Statistics

• Total Topics
634135
• Total Posts
3015754
×