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 | class World; |
---|
14 | class CameraTarget; |
---|
15 | class Event; |
---|
16 | |
---|
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 | ObjectListDeclaration(Camera); |
---|
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 | }; |
---|
36 | |
---|
37 | Camera(); |
---|
38 | Camera(const TiXmlElement* root); |
---|
39 | virtual ~Camera(); |
---|
40 | |
---|
41 | void lookAt(PNode* target); |
---|
42 | CameraTarget* getTarget() const { return this->target; }; |
---|
43 | PNode* getTargetNode() const; |
---|
44 | |
---|
45 | void setAspectRatio(float aspectRatio); |
---|
46 | void setClipRegion(float nearClip, float farClip); |
---|
47 | |
---|
48 | /** @param fovy new field of view factor (in degrees) */ |
---|
49 | inline void setFovy(float fovy) |
---|
50 | { |
---|
51 | this->fovy = fovy; |
---|
52 | this->toFovy = fovy; |
---|
53 | }; |
---|
54 | /** @param fovy new field of view factor (in degrees) to iterate to */ |
---|
55 | void setToFovy(float toFovy) { this->toFovy = toFovy; }; |
---|
56 | |
---|
57 | void setViewMode(Camera::ViewMode mode); |
---|
58 | inline const Vector& getViewVector() const { return this->viewVector; } |
---|
59 | inline const Vector& getUpVector() const { return this->upVector; } |
---|
60 | inline const Plane& getViewFrustum() const { return this->frustumPlane; } |
---|
61 | |
---|
62 | inline float distance(const Vector& distance) const { return this->frustumPlane.distancePoint(distance); } |
---|
63 | inline float distance(const PNode* node) const { return distance(node->getAbsCoor()); } |
---|
64 | |
---|
65 | inline void setEventHandling(bool b) {this->eventHandling = b;} |
---|
66 | inline bool getEventHandling() {return this->eventHandling;} |
---|
67 | |
---|
68 | void tick(float dt); |
---|
69 | void apply (); |
---|
70 | void project(); |
---|
71 | |
---|
72 | void process(const Event &event); |
---|
73 | |
---|
74 | //virtual void loadParams(const TiXmlElement* root); |
---|
75 | |
---|
76 | void setViewTopFovy(float fovy); |
---|
77 | void setViewLeftFovy(float fovy); |
---|
78 | void setViewRightFovy(float fovy); |
---|
79 | void setViewBehindFovy(float fovy); |
---|
80 | void setViewFrontFovy(float fovy); |
---|
81 | void setViewNormalFovy(float fovy); |
---|
82 | |
---|
83 | void setViewTopDistance(float Distance); |
---|
84 | void setViewLeftDistance(float Distance); |
---|
85 | void setViewRightDistance(float Distance); |
---|
86 | void setViewBehindDistance(float Distance); |
---|
87 | void setViewFrontDistance(float Distance); |
---|
88 | void setViewNormalDistance(float Distance); |
---|
89 | |
---|
90 | private: |
---|
91 | |
---|
92 | void init(); |
---|
93 | |
---|
94 | CameraTarget* target; //!< The Target of the Camera (where this Camera Looks at) |
---|
95 | |
---|
96 | bool eventHandling; //!< True, if the Camera handles the processing of events itself. Set false to overwrite the standard handling. |
---|
97 | |
---|
98 | float fovy; //!< The field of view Angle (in degrees). |
---|
99 | float aspectRatio; //!< The aspect ratio (width / height). |
---|
100 | float nearClip; //!< The near clipping plane. |
---|
101 | float farClip; //!< The far clipping plane. |
---|
102 | |
---|
103 | float toFovy; //!< The fovy-mode to iterate to. |
---|
104 | Camera::ViewMode currentMode; //!< The ViewMode the camera is in |
---|
105 | |
---|
106 | Vector delay; |
---|
107 | Plane frustumPlane; //!< plane that marks the view frustum |
---|
108 | Vector viewVector; //!< the direction of the camera view |
---|
109 | Vector upVector; //!< direction of the up vector |
---|
110 | |
---|
111 | float viewTopFovy; |
---|
112 | float viewLeftFovy; |
---|
113 | float viewRightFovy; |
---|
114 | float viewBehindFovy; |
---|
115 | float viewFrontFovy; |
---|
116 | float viewNormalFovy; |
---|
117 | |
---|
118 | float viewTopDistance; |
---|
119 | float viewLeftDistance; |
---|
120 | float viewRightDistance; |
---|
121 | float viewBehindDistance; |
---|
122 | float viewFrontDistance; |
---|
123 | float viewNormalDistance; |
---|
124 | |
---|
125 | }; |
---|
126 | |
---|
127 | //! A CameraTarget is where the Camera is looking at. |
---|
128 | class CameraTarget : public PNode |
---|
129 | { |
---|
130 | friend class Camera; //! The CameraTarget is a friend of Camera. noone else needs a CameraTarget, so noone else can create it. |
---|
131 | ObjectListDeclaration(CameraTarget); |
---|
132 | |
---|
133 | private: |
---|
134 | CameraTarget(); |
---|
135 | |
---|
136 | public: |
---|
137 | }; |
---|
138 | |
---|
139 | |
---|
140 | #endif /* _CAMERA_H */ |
---|