| 1 | /*! |
|---|
| 2 | * @file camera.h |
|---|
| 3 | * Viewpoint controlling class definitions |
|---|
| 4 | */ |
|---|
| 5 | |
|---|
| 6 | #ifndef _CAMERA_H |
|---|
| 7 | #define _CAMERA_H |
|---|
| 8 | |
|---|
| 9 | #include "p_node.h" |
|---|
| 10 | #include "event_listener.h" |
|---|
| 11 | #include "plane.h" |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | class World; |
|---|
| 15 | class CameraTarget; |
|---|
| 16 | class Event; |
|---|
| 17 | |
|---|
| 18 | //! Camera |
|---|
| 19 | /** |
|---|
| 20 | * This class controls the viewpoint from which the World is rendered. |
|---|
| 21 | */ |
|---|
| 22 | class Camera : public PNode, public EventListener |
|---|
| 23 | { |
|---|
| 24 | friend class CameraTarget; |
|---|
| 25 | friend class CameraMan; |
|---|
| 26 | ObjectListDeclaration(Camera); |
|---|
| 27 | public: |
|---|
| 28 | //! an enumerator for different types of view |
|---|
| 29 | typedef enum ViewMode |
|---|
| 30 | { |
|---|
| 31 | ViewNormal, |
|---|
| 32 | ViewBehind, |
|---|
| 33 | ViewFront, |
|---|
| 34 | ViewLeft, |
|---|
| 35 | ViewRight, |
|---|
| 36 | ViewTop |
|---|
| 37 | }; |
|---|
| 38 | public: |
|---|
| 39 | Camera(); |
|---|
| 40 | Camera(const TiXmlElement* root); |
|---|
| 41 | virtual ~Camera(); |
|---|
| 42 | |
|---|
| 43 | void lookAt(PNode* target); |
|---|
| 44 | CameraTarget* getTarget() const { return this->target; }; |
|---|
| 45 | PNode* getTargetNode() const; |
|---|
| 46 | void setTargetNode(PNode* target); |
|---|
| 47 | void setAspectRatio(float aspectRatio); |
|---|
| 48 | inline float getAspectRatio() {return this->aspectRatio;}; |
|---|
| 49 | |
|---|
| 50 | void setClipRegion(float nearClip, float farClip); |
|---|
| 51 | |
|---|
| 52 | /** @param fovy new field of view factor (in degrees) */ |
|---|
| 53 | inline void setFovy(float fovy) |
|---|
| 54 | { |
|---|
| 55 | this->fovy = fovy; |
|---|
| 56 | this->toFovy = fovy; |
|---|
| 57 | }; |
|---|
| 58 | |
|---|
| 59 | inline float getFovy() {return this->fovy;}; |
|---|
| 60 | /** @param fovy new field of view factor (in degrees) to iterate to */ |
|---|
| 61 | void setToFovy(float toFovy) { this->toFovy = toFovy; }; |
|---|
| 62 | |
|---|
| 63 | void setViewMode(Camera::ViewMode mode); |
|---|
| 64 | inline const Vector& getViewVector() const { return this->viewVector; } |
|---|
| 65 | inline const Vector& getUpVector() const { return this->upVector; } |
|---|
| 66 | inline const Plane& getViewFrustum() const { return this->frustumPlane; } |
|---|
| 67 | |
|---|
| 68 | inline float distance(const Vector& distance) const { return this->frustumPlane.distancePoint(distance); } |
|---|
| 69 | inline float distance(const PNode* node) const { return distance(node->getAbsCoor()); } |
|---|
| 70 | |
|---|
| 71 | inline void setEventHandling(bool b) {this->eventHandling = b;} |
|---|
| 72 | inline bool getEventHandling() {return this->eventHandling;} |
|---|
| 73 | |
|---|
| 74 | void glLookAt(float eyex, float eyey, float eyez, float centerx, float centery, float centerz, float upx, float upy, float upz); |
|---|
| 75 | Vector* VectorProd(Vector* v1, Vector* v2); |
|---|
| 76 | void Rotate(); |
|---|
| 77 | void tick(float dt); |
|---|
| 78 | void apply (); |
|---|
| 79 | void project(); |
|---|
| 80 | |
|---|
| 81 | void process(const Event &event); |
|---|
| 82 | //CameraTarget* target; //!< The Target of the Camera (where this Camera Looks at) |
|---|
| 83 | |
|---|
| 84 | virtual void loadParams(const TiXmlElement* root); |
|---|
| 85 | |
|---|
| 86 | void setViewTopFovy(float fovy); |
|---|
| 87 | void setViewLeftFovy(float fovy); |
|---|
| 88 | void setViewRightFovy(float fovy); |
|---|
| 89 | void setViewBehindFovy(float fovy); |
|---|
| 90 | void setViewFrontFovy(float fovy); |
|---|
| 91 | void setViewNormalFovy(float fovy); |
|---|
| 92 | |
|---|
| 93 | void setViewTopDistance(float Distance); |
|---|
| 94 | void setViewLeftDistance(float Distance); |
|---|
| 95 | void setViewRightDistance(float Distance); |
|---|
| 96 | void setViewBehindDistance(float Distance); |
|---|
| 97 | void setViewFrontDistance(float Distance); |
|---|
| 98 | void setViewNormalDistance(float Distance); |
|---|
| 99 | |
|---|
| 100 | private: |
|---|
| 101 | |
|---|
| 102 | void init(); |
|---|
| 103 | |
|---|
| 104 | CameraTarget* target; //!< The Target of the Camera (where this Camera Looks at) |
|---|
| 105 | |
|---|
| 106 | bool eventHandling; //!< True, if the Camera handles the processing of events itself. Set false to overwrite the standard handling. |
|---|
| 107 | |
|---|
| 108 | float fovy; //!< The field of view Angle (in degrees). |
|---|
| 109 | float aspectRatio; //!< The aspect ratio (width / height). |
|---|
| 110 | float nearClip; //!< The near clipping plane. |
|---|
| 111 | float farClip; //!< The far clipping plane. |
|---|
| 112 | |
|---|
| 113 | float toFovy; //!< The fovy-mode to iterate to. |
|---|
| 114 | Camera::ViewMode currentMode; //!< The ViewMode the camera is in |
|---|
| 115 | |
|---|
| 116 | Vector delay; |
|---|
| 117 | Plane frustumPlane; //!< plane that marks the view frustum |
|---|
| 118 | Vector viewVector; //!< the direction of the camera view |
|---|
| 119 | Vector upVector; //!< direction of the up vector |
|---|
| 120 | |
|---|
| 121 | float viewTopFovy; |
|---|
| 122 | float viewLeftFovy; |
|---|
| 123 | float viewRightFovy; |
|---|
| 124 | float viewBehindFovy; |
|---|
| 125 | float viewFrontFovy; |
|---|
| 126 | float viewNormalFovy; |
|---|
| 127 | |
|---|
| 128 | float viewTopDistance; |
|---|
| 129 | float viewLeftDistance; |
|---|
| 130 | float viewRightDistance; |
|---|
| 131 | float viewBehindDistance; |
|---|
| 132 | float viewFrontDistance; |
|---|
| 133 | float viewNormalDistance; |
|---|
| 134 | |
|---|
| 135 | }; |
|---|
| 136 | |
|---|
| 137 | //! A CameraTarget is where the Camera is looking at. |
|---|
| 138 | class CameraTarget : public PNode |
|---|
| 139 | { |
|---|
| 140 | friend class Camera; //! The CameraTarget is a friend of Camera. noone else needs a CameraTarget, so noone else can create it. |
|---|
| 141 | ObjectListDeclaration(CameraTarget); |
|---|
| 142 | |
|---|
| 143 | private: |
|---|
| 144 | CameraTarget(); |
|---|
| 145 | virtual ~CameraTarget() {} |
|---|
| 146 | float speed; |
|---|
| 147 | PNode* target; |
|---|
| 148 | PNode* freeTarget; |
|---|
| 149 | Camera* masta; |
|---|
| 150 | Vector translateTo; |
|---|
| 151 | Vector rotateBy; |
|---|
| 152 | |
|---|
| 153 | |
|---|
| 154 | public: |
|---|
| 155 | |
|---|
| 156 | void detach(); |
|---|
| 157 | void atach(PNode* object); |
|---|
| 158 | Vector iterate(float dt, const Vector* target, const Vector* cam); |
|---|
| 159 | void translate(float dt); |
|---|
| 160 | void changeSpeed(float speed); |
|---|
| 161 | Vector* rotate(Vector* newPos, float speed); |
|---|
| 162 | void jump(float x, float y, float z); |
|---|
| 163 | void translateNow(Vector* vec); |
|---|
| 164 | PNode* createStick(); |
|---|
| 165 | void trans(float x, float y, float z); |
|---|
| 166 | bool isDone(); |
|---|
| 167 | }; |
|---|
| 168 | |
|---|
| 169 | |
|---|
| 170 | |
|---|
| 171 | |
|---|
| 172 | #endif /* _CAMERA_H */ |
|---|
| 173 | |
|---|