Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/hud/src/world_entities/tools/camera.h @ 10647

Last change on this file since 10647 was 10647, checked in by bknecht, 17 years ago

Camera:

  • Added new ViewMode ViewFPS

FPSPlayer:

  • fixed crosshair bug

FPSPlayer/KeyMapper/Globals:

  • started to implement crouch function
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    ViewFPS
38  };
39  public:
40  Camera();
41  Camera(const TiXmlElement* root);
42  virtual ~Camera();
43
44  void lookAt(PNode* target);
45  CameraTarget* getTarget() const { return this->target; };
46  PNode* getTargetNode() const;
47  void setTargetNode(PNode* target);
48  void setAspectRatio(float aspectRatio);
49  inline float getAspectRatio() {return this->aspectRatio;};
50
51  void setClipRegion(float nearClip, float farClip);
52
53  /** @param fovy new field of view factor (in degrees) */
54  inline void setFovy(float fovy)
55  {
56    this->fovy = fovy;
57    this->toFovy = fovy;
58  };
59
60  inline float getFovy() {return this->fovy;};
61  /** @param fovy new field of view factor (in degrees) to iterate to */
62  void setToFovy(float toFovy) { this->toFovy = toFovy; };
63
64  void setViewMode(Camera::ViewMode mode);
65  inline const Vector& getViewVector() const { return this->viewVector; }
66  inline const Vector& getUpVector() const { return this->upVector; }
67  inline const Plane& getViewFrustum() const { return this->frustumPlane; }
68
69  inline float distance(const Vector& distance) const { return this->frustumPlane.distancePoint(distance); }
70  inline float distance(const PNode* node) const { return distance(node->getAbsCoor()); }
71
72  inline void setEventHandling(bool b) {this->eventHandling = b;}
73  inline bool getEventHandling() {return this->eventHandling;}
74
75  void glLookAt(float eyex, float eyey, float eyez, float centerx, float centery, float centerz, float upx, float upy, float upz);
76  Vector* VectorProd(Vector* v1, Vector* v2);
77  void Rotate();
78  void draw() const;
79  void tick(float dt);
80  void apply ();
81  void project();
82
83  void process(const Event &event);
84  //CameraTarget*     target;          //!< The Target of the Camera (where this Camera Looks at)
85
86  virtual void loadParams(const TiXmlElement* root);
87
88  void              setViewTopFovy(float fovy);
89  void              setViewLeftFovy(float fovy);
90  void              setViewRightFovy(float fovy);
91  void              setViewBehindFovy(float fovy);
92  void              setViewFrontFovy(float fovy);
93  void              setViewNormalFovy(float fovy);
94
95  void              setViewTopDistance(float Distance);
96  void              setViewLeftDistance(float Distance);
97  void              setViewRightDistance(float Distance);
98  void              setViewBehindDistance(float Distance);
99  void              setViewFrontDistance(float Distance);
100  void              setViewNormalDistance(float Distance);
101
102private:
103
104  void              init();
105
106  CameraTarget*     target;          //!< The Target of the Camera (where this Camera Looks at)
107
108  bool              eventHandling;    //!< True, if the Camera handles the processing of events itself. Set false to overwrite the standard handling.
109
110  float             fovy;            //!< The field of view Angle (in degrees).
111  float             aspectRatio;     //!< The aspect ratio (width / height).
112  float             nearClip;        //!< The near clipping plane.
113  float             farClip;         //!< The far clipping plane.
114
115  float             toFovy;          //!< The fovy-mode to iterate to.
116  Camera::ViewMode  currentMode;     //!< The ViewMode the camera is in
117
118  Vector            delay;
119  Plane             frustumPlane;    //!< plane that marks the view frustum
120  Vector            viewVector;      //!< the direction of the camera view
121  Vector            upVector;        //!< direction of the up vector
122
123  float             viewTopFovy;
124  float             viewLeftFovy;
125  float             viewRightFovy;
126  float             viewBehindFovy;
127  float             viewFrontFovy;
128  float             viewNormalFovy;
129
130  float             viewTopDistance;
131  float             viewLeftDistance;
132  float             viewRightDistance;
133  float             viewBehindDistance;
134  float             viewFrontDistance;
135  float             viewNormalDistance;
136
137};
138
139//! A CameraTarget is where the Camera is looking at.
140class CameraTarget : public PNode
141{
142  friend class Camera;        //! The CameraTarget is a friend of Camera. noone else needs a CameraTarget, so noone else can create it.
143  ObjectListDeclaration(CameraTarget);
144
145private:
146  CameraTarget();
147  virtual ~CameraTarget() {}
148  float speed;
149  PNode* target;
150  PNode* freeTarget;
151  Camera* masta;
152  Vector translateTo;
153  Vector rotateBy;
154
155
156public:
157
158  void detach();
159  void atach(PNode* object);
160  Vector iterate(float dt, const Vector* target, const Vector* cam);
161  void translate(float dt);
162  void changeSpeed(float speed);
163  Vector* rotate(Vector* newPos, float speed);
164  void jump(float x, float y, float z);
165  void translateNow(Vector* vec);
166  PNode* createStick();
167  void trans(float x, float y, float z);
168  bool isDone();
169};
170
171
172
173
174#endif /* _CAMERA_H */
175
Note: See TracBrowser for help on using the repository browser.