/*! * @file camera.h * Viewpoint controlling class definitions */ #ifndef _CAMERA_H #define _CAMERA_H #include "p_node.h" #include "event_listener.h" #include "plane.h" class World; class CameraTarget; class Event; //! Camera /** * This class controls the viewpoint from which the World is rendered. */ class Camera : public PNode, public EventListener { ObjectListDeclaration(Camera); public: //! an enumerator for different types of view typedef enum ViewMode { ViewNormal, ViewBehind, ViewFront, ViewLeft, ViewRight, ViewTop }; Camera(); virtual ~Camera(); void lookAt(PNode* target); CameraTarget* getTarget() const { return this->target; }; PNode* getTargetNode() const; void setAspectRatio(float aspectRatio); void setClipRegion(float nearClip, float farClip); /** @param fovy new field of view factor (in degrees) */ void setFovy(float fovy) { this->fovy = fovy; }; /** @param fovy new field of view factor (in degrees) to iterate to */ void setToFovy(float toFovy) { this->toFovy = toFovy; }; void setViewMode(Camera::ViewMode mode); inline const Vector& getViewVector() const { return this->viewVector; } inline const Vector& getUpVector() const { return this->upVector; } inline const Plane& getViewFrustum() const { return this->frustumPlane; } inline float distance(const Vector& distance) const { return this->frustumPlane.distancePoint(distance); } inline float distance(const PNode* node) const { return distance(node->getAbsCoor()); } void glLookAt(float eyex, float eyey, float eyez, float centerx, float centery, float centerz, float upx, float upy, float upz); Vector* VectorProd(Vector* v1, Vector* v2); void Rotate(); void tick(float dt); void apply (); void project(); void process(const Event &event); private: CameraTarget* target; //!< The Target of the Camera (where this Camera Looks at) float fovy; //!< The field of view Angle (in degrees). float aspectRatio; //!< The aspect ratio (width / height). float nearClip; //!< The near clipping plane. float farClip; //!< The far clipping plane. float toFovy; //!< The fovy-mode to iterate to. Camera::ViewMode currentMode; //!< The ViewMode the camera is in Vector delay; Plane frustumPlane; //!< plane that marks the view frustum Vector viewVector; //!< the direction of the camera view Vector upVector; //!< direction of the up vector }; //! A CameraTarget is where the Camera is looking at. class CameraTarget : public PNode { friend class Camera; //! The CameraTarget is a friend of Camera. noone else needs a CameraTarget, so noone else can create it. ObjectListDeclaration(CameraTarget); private: CameraTarget(); virtual ~CameraTarget() {} float speed; PNode* target; public: Vector translateTo; Vector rotateBy; void detach(); void atach(PNode* object); Vector iterate(float dt, const Vector* target, const Vector* cam); void translate(float speed, float dt); void changeSpeed(float speed); Vector* rotate(Vector* newPos, float speed); void jump(Vector* newPos); void test(); void translateNow(Vector* vec); }; #endif /* _CAMERA_H */