This topic is now archived and is closed to further replies.


Camera class

Recommended Posts

FlamePixel    122
I am trying to develop a Camera class that balances power and flexibility, but frankly, I don''t know where to start. I know that I want it to be very open ( a game-specific class controls the camera, the camera does not control itself ), not a Pandora''s Box type of thing. That way, the class will be usable in a variety of genres and/or control mechanisms. Can someone please point me in the right direction by giving brainstorming ideas, things to consider, and possible problems that may arise? I don''t have much experience with 3D games, so I''m not sure I can tell a good idea I think of from a bad one. Thank you very much for your time, I really appreciate being able to come here to ask my questions and get so much help. Sincerely, FlamePixel

Share this post

Link to post
Share on other sites
Raloth    379
Start by asking yourself the question, "What can a camera do?" After that it should be easy . The only thing your camera class should do is control the viewpoint. If you find yourself adding anything else in then select the file in explorer, hit shift+delete, and click ok.

Share this post

Link to post
Share on other sites
FlamePixel    122
I think I see your point. I should just stop worrying and start typing. I do have one more question though. Does it make sense to implement a velocity vector in the camera class, or should the class controlling the camera do something like that if needed.

[edited by - FlamePixel on August 13, 2003 9:28:09 AM]

Share this post

Link to post
Share on other sites
Pipo DeClown    804
OOP could come in handy: Make a standard cCamera class, and derive a cMovingCamera and cRotatingCamera.
If you want it to move AND to rotate, derive a cPortableCamera out of cMovingCamera and cRotatingCamera (multi-inheritance).

[EDIT] I forgot, if you want to take a screenshot: cDigitalCamera.


[edited by - Pipo DeClown on August 13, 2003 9:39:45 AM]

Share this post

Link to post
Share on other sites
JohnBolton    1372
Cameras don't really do very much. Raloth's point wasn't "just stop worrying and start typing", it was "The only thing your camera class should do is control the viewpoint."

Here is a basic D3D camera class:

class Camera

/// Constructor

Camera( IDirect3DDevice9 * pDevice,
float angleOfView,
float nearDistance,
float farDistance,
D3DXVECTOR3 const & position = Vector3Origin(),
D3DXQUATERNION const & orientation = QuaternionIdentity() );

/// Destructor

virtual ~Camera();

/// Sets D3D's projection matrix based on the aspect ratio, near and far distance, and center.

void Reshape( int w, int h, float x = 0.f, float y = 0.f );

/// Sets D3D's view matrix based on the current position and orientation of the camera.

void Look() const;

/// Set the camera's frame of reference.

void SetFrame( Frame const & frame );

/// Returns the camera's current frame of reference.

Frame GetFrame() const;

/// Sets the camera's current position.

void SetPosition( D3DXVECTOR3 const & position );

/// Returns the camera's current position.

D3DXVECTOR3 GetPosition() const;

/// Sets the camera's current orientation.

void SetOrientation( D3DXQUATERNION const & orientation );

/// Returns the camera's current orientation.

D3DXQUATERNION GetOrientation() const;

/// Sets the camera's position and orientation

void LookAt( D3DXVECTOR3 const & to, D3DXVECTOR3 const & from, D3DXVECTOR3 const & up );

/// Sets the distance to the near clipping plane.

void SetNearDistance( float nearDistance );

/// Returns the distance to the near clipping plane.

float GetNearDistance() const;

/// Sets the distance to the far clipping plane.

void SetFarDistance( float farDistance );

/// Returns the distance to the far clipping plane.

float GetFarDistance() const;

/// Sets the angle of view.

void SetAngleOfView( float angle );

/// Returns the angle of view.

float GetAngleOfView() const;

/// Rotates the camera.

void Turn( D3DXQUATERNION const & rotation );

/// Rotates the camera.

void Turn( float angle, D3DXVECTOR3 const & axis );

/// Moves the camera.

void Move( D3DXVECTOR3 const & distance );

/// Returns the direction vector

D3DXVECTOR3 GetDirection() const;

/// Returns the up vector.

D3DXVECTOR3 GetUp() const;

/// Returns the right vector.

D3DXVECTOR3 GetRight() const;

/// Returns the view matrix

D3DXMATRIX GetViewMatrix() const;

/// Returns the projection matrix

D3DXMATRIX GetProjectionMatrix() const;

/// Returns the view-projection matrix

D3DXMATRIX GetViewProjectionMatrix() const;


IDirect3DDevice9 * m_pDevice; ///< Display device

Frame m_Frame; ///< View transformation

float m_NearDistance; ///< The distance to the near clipping plane

float m_FarDistance; ///< The distance to the far clipping plane

float m_AngleOfView; ///< Angle of view of the height of the display (in radians)

mutable D3DXMATRIX m_ViewMatrix; ///< The current world-view transformation

D3DXMATRIX m_ProjectionMatrix; ///< The current projection transformation


[edited by - JohnBolton on August 14, 2003 11:51:43 AM]

Share this post

Link to post
Share on other sites