Camera class

Started by
6 comments, last by FlamePixel 20 years, 8 months ago
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
Advertisement
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.
____________________________________________________________AAAAA: American Association Against Adobe AcrobatYou know you hate PDFs...
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]
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.


.lick


[edited by - Pipo DeClown on August 13, 2003 9:39:45 AM]
I was thinking more like one camera class that is under full control by a game specifice class.
I wasn''t very very serious about it though.

.lick
Does anyone have some serious suggestions?
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{public:    /// 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;protected:    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]
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!

This topic is closed to new replies.

Advertisement