Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/vs-enhencements/src/world_entities/tools/camera.h @ 10662

Last change on this file since 10662 was 10618, checked in by bknecht, 18 years ago

merged cleanup into trunk (only improvements)

File size: 5.2 KB
Line 
1/*!
2 * @file camera.h
3 * Viewpoint controlling class definitions
4*/
5
6#ifndef _CAMERA_H
7#define _CAMERA_H
8
9#include "world_entity.h"
10#include "event_listener.h"
11#include "plane.h"
12
13
14class World;
15class CameraTarget;
16class Event;
17
18//! Camera
19/**
20 * This class controls the viewpoint from which the World is rendered.
21*/
22class Camera : public WorldEntity, public EventListener
23{
24  friend class CameraTarget;
25  friend class CameraMan;
26  ObjectListDeclaration(Camera);
27public:
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 draw() const;
78  void tick(float dt);
79  void apply ();
80  void project();
81
82  void process(const Event &event);
83  //CameraTarget*     target;          //!< The Target of the Camera (where this Camera Looks at)
84
85  virtual void loadParams(const TiXmlElement* root);
86
87  void              setViewTopFovy(float fovy);
88  void              setViewLeftFovy(float fovy);
89  void              setViewRightFovy(float fovy);
90  void              setViewBehindFovy(float fovy);
91  void              setViewFrontFovy(float fovy);
92  void              setViewNormalFovy(float fovy);
93
94  void              setViewTopDistance(float Distance);
95  void              setViewLeftDistance(float Distance);
96  void              setViewRightDistance(float Distance);
97  void              setViewBehindDistance(float Distance);
98  void              setViewFrontDistance(float Distance);
99  void              setViewNormalDistance(float Distance);
100
101private:
102
103  void              init();
104
105  CameraTarget*     target;          //!< The Target of the Camera (where this Camera Looks at)
106
107  bool              eventHandling;    //!< True, if the Camera handles the processing of events itself. Set false to overwrite the standard handling.
108
109  float             fovy;            //!< The field of view Angle (in degrees).
110  float             aspectRatio;     //!< The aspect ratio (width / height).
111  float             nearClip;        //!< The near clipping plane.
112  float             farClip;         //!< The far clipping plane.
113
114  float             toFovy;          //!< The fovy-mode to iterate to.
115  Camera::ViewMode  currentMode;     //!< The ViewMode the camera is in
116
117  Vector            delay;
118  Plane             frustumPlane;    //!< plane that marks the view frustum
119  Vector            viewVector;      //!< the direction of the camera view
120  Vector            upVector;        //!< direction of the up vector
121
122  float             viewTopFovy;
123  float             viewLeftFovy;
124  float             viewRightFovy;
125  float             viewBehindFovy;
126  float             viewFrontFovy;
127  float             viewNormalFovy;
128
129  float             viewTopDistance;
130  float             viewLeftDistance;
131  float             viewRightDistance;
132  float             viewBehindDistance;
133  float             viewFrontDistance;
134  float             viewNormalDistance;
135
136};
137
138//! A CameraTarget is where the Camera is looking at.
139class CameraTarget : public PNode
140{
141  friend class Camera;        //! The CameraTarget is a friend of Camera. noone else needs a CameraTarget, so noone else can create it.
142  ObjectListDeclaration(CameraTarget);
143
144private:
145  CameraTarget();
146  virtual ~CameraTarget() {}
147  float speed;
148  PNode* target;
149  PNode* freeTarget;
150  Camera* masta;
151  Vector translateTo;
152  Vector rotateBy;
153
154
155public:
156
157  void detach();
158  void atach(PNode* object);
159  Vector iterate(float dt, const Vector* target, const Vector* cam);
160  void translate(float dt);
161  void changeSpeed(float speed);
162  Vector* rotate(Vector* newPos, float speed);
163  void jump(float x, float y, float z);
164  void translateNow(Vector* vec);
165  PNode* createStick();
166  void trans(float x, float y, float z);
167  bool isDone();
168};
169
170
171
172
173#endif /* _CAMERA_H */
174
Note: See TracBrowser for help on using the repository browser.