[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 | |
---|
[10122] | 13 | |
---|
[2636] | 14 | class World; |
---|
[3635] | 15 | class CameraTarget; |
---|
[4414] | 16 | class Event; |
---|
[2100] | 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 | { |
---|
[9869] | 24 | ObjectListDeclaration(Camera); |
---|
[7347] | 25 | public: |
---|
| 26 | //! an enumerator for different types of view |
---|
| 27 | typedef enum ViewMode |
---|
| 28 | { |
---|
| 29 | ViewNormal, |
---|
| 30 | ViewBehind, |
---|
| 31 | ViewFront, |
---|
| 32 | ViewLeft, |
---|
| 33 | ViewRight, |
---|
| 34 | ViewTop |
---|
| 35 | }; |
---|
[10198] | 36 | public: |
---|
[4746] | 37 | Camera(); |
---|
| 38 | virtual ~Camera(); |
---|
[3635] | 39 | |
---|
| 40 | void lookAt(PNode* target); |
---|
[7014] | 41 | CameraTarget* getTarget() const { return this->target; }; |
---|
| 42 | PNode* getTargetNode() const; |
---|
[10204] | 43 | void setTargetNode(PNode* target); |
---|
[3636] | 44 | void setAspectRatio(float aspectRatio); |
---|
| 45 | void setClipRegion(float nearClip, float farClip); |
---|
| 46 | |
---|
[7173] | 47 | /** @param fovy new field of view factor (in degrees) */ |
---|
| 48 | void setFovy(float fovy) { this->fovy = fovy; }; |
---|
| 49 | /** @param fovy new field of view factor (in degrees) to iterate to */ |
---|
| 50 | void setToFovy(float toFovy) { this->toFovy = toFovy; }; |
---|
| 51 | |
---|
[7347] | 52 | void setViewMode(Camera::ViewMode mode); |
---|
[7009] | 53 | inline const Vector& getViewVector() const { return this->viewVector; } |
---|
| 54 | inline const Vector& getUpVector() const { return this->upVector; } |
---|
| 55 | inline const Plane& getViewFrustum() const { return this->frustumPlane; } |
---|
| 56 | |
---|
[7013] | 57 | inline float distance(const Vector& distance) const { return this->frustumPlane.distancePoint(distance); } |
---|
| 58 | inline float distance(const PNode* node) const { return distance(node->getAbsCoor()); } |
---|
[7009] | 59 | |
---|
[10065] | 60 | void glLookAt(float eyex, float eyey, float eyez, float centerx, float centery, float centerz, float upx, float upy, float upz); |
---|
| 61 | Vector* VectorProd(Vector* v1, Vector* v2); |
---|
| 62 | void Rotate(); |
---|
[3639] | 63 | void tick(float dt); |
---|
[4746] | 64 | void apply (); |
---|
[7108] | 65 | void project(); |
---|
[4414] | 66 | |
---|
| 67 | void process(const Event &event); |
---|
[10204] | 68 | CameraTarget* target; //!< The Target of the Camera (where this Camera Looks at) |
---|
[4490] | 69 | |
---|
[7347] | 70 | private: |
---|
[4490] | 71 | |
---|
| 72 | float fovy; //!< The field of view Angle (in degrees). |
---|
| 73 | float aspectRatio; //!< The aspect ratio (width / height). |
---|
| 74 | float nearClip; //!< The near clipping plane. |
---|
| 75 | float farClip; //!< The far clipping plane. |
---|
| 76 | |
---|
[4986] | 77 | float toFovy; //!< The fovy-mode to iterate to. |
---|
[7347] | 78 | Camera::ViewMode currentMode; //!< The ViewMode the camera is in |
---|
[6999] | 79 | |
---|
| 80 | Vector delay; |
---|
[7009] | 81 | Plane frustumPlane; //!< plane that marks the view frustum |
---|
| 82 | Vector viewVector; //!< the direction of the camera view |
---|
| 83 | Vector upVector; //!< direction of the up vector |
---|
[3635] | 84 | }; |
---|
[2068] | 85 | |
---|
[3635] | 86 | //! A CameraTarget is where the Camera is looking at. |
---|
[4592] | 87 | class CameraTarget : public PNode |
---|
[3635] | 88 | { |
---|
[10204] | 89 | friend class Camera; //! The CameraTarget is a friend of Camera. noone else needs a CameraTarget, so noone else can create it. |
---|
[9869] | 90 | ObjectListDeclaration(CameraTarget); |
---|
[4592] | 91 | |
---|
[7347] | 92 | private: |
---|
[4746] | 93 | CameraTarget(); |
---|
[10068] | 94 | virtual ~CameraTarget() {} |
---|
[10105] | 95 | float speed; |
---|
[10116] | 96 | PNode* target; |
---|
[10236] | 97 | PNode* freeTarget; |
---|
[10238] | 98 | Camera* masta; |
---|
| 99 | Vector translateTo; |
---|
| 100 | Vector rotateBy; |
---|
[4592] | 101 | |
---|
[10238] | 102 | |
---|
[7347] | 103 | public: |
---|
[10238] | 104 | |
---|
[10068] | 105 | void detach(); |
---|
[10093] | 106 | void atach(PNode* object); |
---|
[10105] | 107 | Vector iterate(float dt, const Vector* target, const Vector* cam); |
---|
[10204] | 108 | void translate(float dt); |
---|
[10103] | 109 | void changeSpeed(float speed); |
---|
[10105] | 110 | Vector* rotate(Vector* newPos, float speed); |
---|
[10206] | 111 | void jump(float x, float y, float z); |
---|
[10110] | 112 | void test(); |
---|
| 113 | void translateNow(Vector* vec); |
---|
[10128] | 114 | PNode* createStick(); |
---|
| 115 | void trans(float x, float y, float z); |
---|
| 116 | void test2(); |
---|
[3635] | 117 | }; |
---|
[2068] | 118 | |
---|
| 119 | |
---|
[10116] | 120 | |
---|
| 121 | |
---|
[3224] | 122 | #endif /* _CAMERA_H */ |
---|
[10116] | 123 | |
---|