Skip to main content
gamedev.net
🔒 Locked 🎮 Unity

camera class

Started by web_scripter Sep 5, 2005 at 9:30 PM 1 replies 600+ views
Original Post
web_scripter
web_scripter
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
Nychold
Nychold
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.
Mykre
Mykre
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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.