[4592] | 1 | /*! |
---|
[5005] | 2 | * @file camera.h |
---|
| 3 | * Viewpoint controlling class definitions |
---|
[4592] | 4 | */ |
---|
[2068] | 5 | |
---|
[3224] | 6 | #ifndef _CAMERA_H |
---|
| 7 | #define _CAMERA_H |
---|
[2068] | 8 | |
---|
[3635] | 9 | #include "p_node.h" |
---|
[4414] | 10 | #include "event_listener.h" |
---|
[7009] | 11 | #include "plane.h" |
---|
[2100] | 12 | |
---|
[2636] | 13 | class World; |
---|
[3635] | 14 | class CameraTarget; |
---|
[4414] | 15 | class Event; |
---|
[2100] | 16 | |
---|
[3635] | 17 | |
---|
[2096] | 18 | //! Camera |
---|
| 19 | /** |
---|
[5005] | 20 | * This class controls the viewpoint from which the World is rendered. |
---|
[2096] | 21 | */ |
---|
[4414] | 22 | class Camera : public PNode, public EventListener |
---|
[3635] | 23 | { |
---|
[7347] | 24 | public: |
---|
| 25 | //! an enumerator for different types of view |
---|
| 26 | typedef enum ViewMode |
---|
| 27 | { |
---|
| 28 | ViewNormal, |
---|
| 29 | ViewBehind, |
---|
| 30 | ViewFront, |
---|
| 31 | ViewLeft, |
---|
| 32 | ViewRight, |
---|
| 33 | ViewTop |
---|
| 34 | }; |
---|
| 35 | |
---|
[4746] | 36 | Camera(); |
---|
| 37 | virtual ~Camera(); |
---|
[3635] | 38 | |
---|
| 39 | void lookAt(PNode* target); |
---|
[7014] | 40 | CameraTarget* getTarget() const { return this->target; }; |
---|
| 41 | PNode* getTargetNode() const; |
---|
[3636] | 42 | |
---|
| 43 | void setAspectRatio(float aspectRatio); |
---|
| 44 | void setClipRegion(float nearClip, float farClip); |
---|
| 45 | |
---|
[7173] | 46 | /** @param fovy new field of view factor (in degrees) */ |
---|
| 47 | void setFovy(float fovy) { this->fovy = fovy; }; |
---|
| 48 | /** @param fovy new field of view factor (in degrees) to iterate to */ |
---|
| 49 | void setToFovy(float toFovy) { this->toFovy = toFovy; }; |
---|
| 50 | |
---|
[7347] | 51 | void setViewMode(Camera::ViewMode mode); |
---|
[7009] | 52 | inline const Vector& getViewVector() const { return this->viewVector; } |
---|
| 53 | inline const Vector& getUpVector() const { return this->upVector; } |
---|
| 54 | inline const Plane& getViewFrustum() const { return this->frustumPlane; } |
---|
| 55 | |
---|
[7013] | 56 | inline float distance(const Vector& distance) const { return this->frustumPlane.distancePoint(distance); } |
---|
| 57 | inline float distance(const PNode* node) const { return distance(node->getAbsCoor()); } |
---|
[7009] | 58 | |
---|
[3639] | 59 | void tick(float dt); |
---|
[4746] | 60 | void apply (); |
---|
[7108] | 61 | void project(); |
---|
[4414] | 62 | |
---|
| 63 | void process(const Event &event); |
---|
[4490] | 64 | |
---|
[7347] | 65 | private: |
---|
[4490] | 66 | CameraTarget* target; //!< The Target of the Camera (where this Camera Looks at) |
---|
| 67 | |
---|
| 68 | float fovy; //!< The field of view Angle (in degrees). |
---|
| 69 | float aspectRatio; //!< The aspect ratio (width / height). |
---|
| 70 | float nearClip; //!< The near clipping plane. |
---|
| 71 | float farClip; //!< The far clipping plane. |
---|
| 72 | |
---|
[4986] | 73 | float toFovy; //!< The fovy-mode to iterate to. |
---|
[7347] | 74 | Camera::ViewMode currentMode; //!< The ViewMode the camera is in |
---|
[6999] | 75 | |
---|
| 76 | Vector delay; |
---|
[7009] | 77 | Plane frustumPlane; //!< plane that marks the view frustum |
---|
| 78 | Vector viewVector; //!< the direction of the camera view |
---|
| 79 | Vector upVector; //!< direction of the up vector |
---|
[3635] | 80 | }; |
---|
[2068] | 81 | |
---|
[3635] | 82 | //! A CameraTarget is where the Camera is looking at. |
---|
[4592] | 83 | class CameraTarget : public PNode |
---|
[3635] | 84 | { |
---|
[3636] | 85 | friend class Camera; //! The CameraTarget is a friend of Camera. noone else needs a CameraTarget, so noone else can create it. |
---|
[4592] | 86 | |
---|
[7347] | 87 | private: |
---|
[4746] | 88 | CameraTarget(); |
---|
[4592] | 89 | |
---|
[7347] | 90 | public: |
---|
[3635] | 91 | }; |
---|
[2068] | 92 | |
---|
| 93 | |
---|
[3224] | 94 | #endif /* _CAMERA_H */ |
---|