00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef WP_CAMERA_H
00018 #define WP_CAMERA_H
00019
00020 #include "WPCG.h"
00021
00022 namespace WPCG
00023 {
00024
00025 class WP_Object;
00026
00045 class WP_Camera
00046 {
00047 public:
00048 ~WP_Camera(){};
00049
00056 inline void slide(scalar deltaU, scalar deltaV, scalar deltaN)
00057 {
00058 WP_Vector3D translateU(u * deltaU);
00059 WP_Vector3D translateV(v * deltaV);
00060 WP_Vector3D translateN(n * deltaN);
00061
00062 WP_Vector3D translate = translateU + translateV + translateN;
00063 eye += translate;
00064 setModelViewMatrixGL();
00065 }
00066
00073 void rotate(scalar angleU, scalar angleV, scalar angleN);
00074
00079 inline void pitch(scalar angle)
00080 {
00081 rotate(angle, 0.0f, 0.0f);
00082 }
00083
00088 inline void roll(scalar angle)
00089 {
00090 rotate(0.0f, 0.0f, angle);
00091 }
00092
00097 inline void yaw(scalar angle)
00098 {
00099 rotate(0.0f, angle, 0.0f);
00100 }
00101
00106 static WP_Camera* getInstance()
00107 {
00108 if (!_instance)
00109 {
00110 _instance = new WP_Camera();
00111 }
00112 return _instance;
00113 };
00114
00118 void followObject();
00119
00131 void setFrustumAndCamera(scalar _viewAngle, unsigned int width, unsigned int height, scalar _nearPlane, scalar _farPlane,
00132 const WP_Point3D& _eye, const WP_Point3D& _look, const WP_Vector3D& _up);
00133
00141 void setPickingVolume(int width, int height, int x, int y);
00142
00146 inline void setRenderVolume()
00147 {
00148 if (!normal_viewing_volume)
00149 {
00150 state->projection();
00151 glPopMatrix();
00152 state->modelview();
00153 normal_viewing_volume = true;
00154 }
00155 }
00156
00163 inline WP_Ray3D createRayForTracing(int x, int y) const
00164 {
00165 WP_Ray3D ray;
00166 ray.start = eye;
00167
00168 float H = nearPlane * tan(math->degreeToRad((int)(viewAngle / 2.0f)));
00169 float W = H * aspectRatio;
00170
00171 ray.direction = n * -nearPlane + u * (-W + (W * ((x * 2.0f) / (float)screen_width))) + v * (-H + (H * ((y * 2.0f) / (float)screen_height)));
00172 return ray;
00173 }
00174
00178 WP_Point3D eye;
00179
00183 WP_Point3D look;
00184
00188 WP_Vector3D up;
00189
00193 WP_Matrix3D matrix;
00194
00198 const WP_Object* fixed_object;
00199
00203 scalar follow_distance;
00204
00208 int follow_angleX;
00209
00213 int follow_angleY;
00214
00218 int follow_angleZ;
00219
00223 int objects_in_frustum;
00224
00228 unsigned int screen_width;
00229
00233 unsigned int screen_height;
00234
00238 bool normal_viewing_volume;
00239
00240 Plane* getFrustum()
00241 {
00242 return frustum;
00243 }
00244
00245 private:
00246 WP_Camera();
00247
00251 WP_Vector3D u;
00252
00256 WP_Vector3D v;
00257
00261 WP_Vector3D n;
00262
00266 scalar viewAngle;
00267
00271 scalar aspectRatio;
00272
00276 scalar nearPlane;
00277
00281 scalar farPlane;
00282
00286 Plane frustum[6];
00287
00291 static WP_Camera* _instance;
00292
00296 inline void setModelViewMatrixGL()
00297 {
00298 matrix = WP_Matrix3D(eye.toVector(), u, v, n);
00299 glLoadMatrixf(matrix.data);
00300 computeFrustum();
00301 }
00302
00306 void computeFrustum();
00307
00311 WP_Math* math;
00312
00316 WP_GLState* state;
00317 };
00318 }
00319 #endif
00320