Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #ifndef WAVE_GLUT_GLUT_CAMERA_H__
00040 #define WAVE_GLUT_GLUT_CAMERA_H__
00041
00042
00043 #include <math.h>
00044
00045 #include "geometry/placement.h"
00046 #include "perf/perf.h"
00047
00048
00049 namespace glut {
00050
00051
00052
00053
00054
00055
00056
00057
00058 class Viewer {
00059 public:
00060
00061 Viewer(void) throw();
00062
00063
00064 void clear(void) throw();
00065 void rotateY(IN float dy) throw();
00066 void rotateUp(IN float dz) throw();
00067 void move(IN float forward, IN float sideways, IN float up) throw();
00068 void setPosition(IN const point3d_t& pos) throw() { m_position = pos; }
00069 void setYRotation(IN float rot) throw() { m_yRot = rot; }
00070 void setUpRotation(IN float rot) throw() { m_upRot = rot; }
00071 point3d_t getPosition(void) const throw() { return m_position; }
00072 float getYRotation(void) const throw() { return m_yRot; }
00073 float getUpRotation(void) const throw() { return m_upRot; }
00074 point3d_t getFacing(void) const throw();
00075 point3d_t getUp(void) const throw();
00076
00077 protected:
00078
00079 point3d_t m_position;
00080 float m_yRot;
00081 float m_upRot;
00082 };
00083
00084
00085
00086
00087
00088 struct camera_t {
00089
00090 camera_t(void) throw() { this->clear(); }
00091 void clear(void) throw() {
00092 fovy = 45.0;
00093 aspect = 1.0;
00094 zNear = 0.2;
00095 zFar = 5000.0;
00096 }
00097 float getFovy(void) const throw() { return fovy; }
00098 float getAspect(void) const throw() { return aspect; }
00099 float getZNear(void) const throw() { return zNear; }
00100 float getZFar(void) const throw() { return zFar; }
00101
00102 void setAspect(IN float a) throw() { aspect = a; }
00103 void setAspect(IN int width, IN int height) throw()
00104 {
00105 ASSERT(width > 0, "Bad width: %d", width);
00106 ASSERT(height > 0, "Bad height: %d", height);
00107 this->setAspect((1.0 * width) / height);
00108 }
00109 void setZFar(IN float z) throw() { zFar = z; }
00110
00111 protected:
00112
00113 float fovy;
00114 float aspect;
00115 float zNear;
00116 float zFar;
00117 };
00118
00119
00120
00121
00122
00123
00124 struct fps_t {
00125 fps_t(void) throw() { }
00126 fps_t(IN const perf::time_t& startTime) throw() { this->init(startTime); }
00127 void init(IN const perf::time_t& startTime) throw() {
00128 m_startTime = startTime;
00129 m_frames = 0;
00130 m_fps = 0.0;
00131 }
00132 void tick(IN const perf::time_t& currTime) throw() {
00133 ++m_frames;
00134 perf::time_t delta = currTime;
00135 delta.decrement(m_startTime);
00136 const float maxDelta = 3.0;
00137 float deltaS = delta.getSeconds();
00138 if (deltaS >= maxDelta) {
00139 m_fps = m_frames / deltaS;
00140 m_startTime = currTime;
00141 m_frames = 0;
00142 }
00143 }
00144 float getFPS(void) const throw() { return m_fps; }
00145
00146
00147 perf::time_t m_startTime;
00148 long m_frames;
00149 float m_fps;
00150 };
00151
00152
00153
00154 void getTrailingViewer(IN const Viewer& subject,
00155 IN float distance_back,
00156 OUT Viewer& view) throw();
00157
00158
00159 void setOpenGLProjection(IN const camera_t& camera) throw();
00160
00161
00162 void setOpenGLViewer(IN const Viewer& viewer) throw();
00163
00164
00165 void addQuaternionRotation(IN const quaternion_t& q) throw();
00166
00167
00168 void setPlacement(IN const placement_t& p) throw();
00169
00170
00171 };
00172
00173 #endif // WAVE_GLUT_GLUT_CAMERA_H__
00174