1 #pragma once 2 3 #include "icamera.h" 4 #include "math/Vector3.h" 5 #include "math/matrix.h" 6 #include "../timer.h" 7 #include "gtkutil/cursor.h" 8 #include "generic/callback.h" 9 #include "view.h" 10 11 #define SPEED_MOVE 32 12 #define SPEED_TURN 22.5 13 14 const unsigned int MOVE_NONE = 0; 15 const unsigned int MOVE_FORWARD = 1 << 0; 16 const unsigned int MOVE_BACK = 1 << 1; 17 const unsigned int MOVE_ROTRIGHT = 1 << 2; 18 const unsigned int MOVE_ROTLEFT = 1 << 3; 19 const unsigned int MOVE_STRAFERIGHT = 1 << 4; 20 const unsigned int MOVE_STRAFELEFT = 1 << 5; 21 const unsigned int MOVE_UP = 1 << 6; 22 const unsigned int MOVE_DOWN = 1 << 7; 23 const unsigned int MOVE_PITCHUP = 1 << 8; 24 const unsigned int MOVE_PITCHDOWN = 1 << 9; 25 const unsigned int MOVE_ALL = MOVE_FORWARD | MOVE_BACK | MOVE_ROTRIGHT | MOVE_ROTLEFT | MOVE_STRAFERIGHT 26 | MOVE_STRAFELEFT | MOVE_UP | MOVE_DOWN | MOVE_PITCHUP | MOVE_PITCHDOWN; 27 28 class Camera 29 { 30 private: 31 Vector3 origin; 32 Vector3 angles; 33 34 Vector3 color; // background 35 Vector3 vup, vright; // view matrix (taken from the modelview matrix) 36 unsigned int movementflags; // movement flags 37 float fieldOfView; 38 39 View* m_view; 40 Callback m_update; 41 42 static void motionDelta (int x, int y, void* data); 43 static gboolean camera_keymove (gpointer data); 44 45 void moveUpdateAxes (); 46 void keyControl (float dtime); 47 void keyMove (); 48 // Returns true if cubic clipping is "on" 49 bool farClipEnabled () const; 50 public: 51 int width, height; 52 53 Vector3 forward, right; // move matrix (TTimo: used to have up but it was not updated) 54 Vector3 vpn; // view matrix (taken from the modelview matrix) 55 56 Matrix4 projection; 57 Matrix4 modelview; 58 59 bool m_strafe; // true when in strafemode toggled by the ctrl-key 60 bool m_strafe_forward; // true when in strafemode by ctrl-key and shift is pressed for forward strafing 61 62 Timer m_keycontrol_timer; 63 guint m_keymove_handler; 64 65 DeferredMotionDelta m_mouseMove; 66 67 Camera (View* view, const Callback& update); 68 69 void setMovementFlags (unsigned int mask); 70 void clearMovementFlags (unsigned int mask); 71 72 void updateVectors (); 73 void updateModelview (); 74 void updateProjection (); 75 76 float getFarClipPlane () const; 77 78 void freemoveUpdateAxes (); 79 80 const Vector3& getOrigin () const; 81 void setOrigin (const Vector3& newOrigin); 82 83 void mouseMove (int x, int y); 84 void freeMove (int dx, int dy); 85 86 void setAngles (const Vector3& newAngles); 87 const Vector3& getAngles () const; 88 89 void pitchUpDiscrete (); 90 void pitchDownDiscrete (); 91 void rotateRightDiscrete (); 92 void rotateLeftDiscrete (); 93 void moveRightDiscrete (); 94 void moveLeftDiscrete (); 95 void moveDownDiscrete (); 96 void moveUpDiscrete (); 97 void moveBackDiscrete (); 98 void moveForwardDiscrete (); 99 100 }; // class Camera 101