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 #ifndef CAMERA_HH
00028 #define CAMERA_HH
00029
00030 #include "Error.hh"
00031 #include "Sensor.hh"
00032 #include "Vector.hh"
00033 #include "RenderOptions.hh"
00034 #include "GLContext.hh"
00035
00036
00037 class World;
00038 class WorldFile;
00039 class WorldFileNode;
00040 class Body;
00041 class ShaderManager;
00042 class ShaderObject;
00043
00049 class Camera : public Sensor
00050 {
00051
00052 public: Camera( World *world );
00053
00054
00055 public: virtual ~Camera();
00056
00067 public: int Init(int width, int height, double hfov,
00068 double minDepth, double maxDepth, const char *method,
00069 int zBufferDepth);
00070
00071 public: void InitContext( GLContext &context );
00072
00074 public: int Fini();
00075
00077 public: void Update();
00078
00080 public: void SetPose(GzPose pose);
00081
00083 public: GzPose GetPose();
00084
00086 public: void SetFOV(double fov);
00087
00089 public: double GetFOV() const;
00090
00092 public: void SetRenderOptions(const RenderOptions *opt);
00093
00095 public: void GetRenderOptions(RenderOptions *opt) const;
00096
00098 public: void GetImageSize(int *w, int *h);
00099
00101 public: const unsigned char *GetImageData() const {return this->rgbImage;}
00102
00108 public: double GetZValue(int x, int y);
00109
00130 public: GzPose CalcCameraDelta(int mode, GzVector a, GzVector b);
00131
00132
00133 private: void Render();
00134
00135
00136 private: void RenderModels( int pass );
00137
00138
00139 private: void RenderShadowMaps();
00140
00141
00142 private: void RenderAxes(Body *body);
00143
00144
00145 private: void DrawAxis(GzPose pose, double size, const char *text);
00146
00148 public: void SetSavePath(const char *pathname);
00149
00151 public: void EnableSaveFrame(bool enable);
00152
00153
00154 private: void SaveFrame();
00155
00156 private: GLuint LoadShader(GLenum target, const char *file);
00157
00158 private: float *Mult( float *a, float *b);
00159 private: void RenderDepthTexture();
00160
00161
00162 private: GLContext context;
00163
00164
00165 private: RenderOptions renderOpt;
00166
00167
00168 private: GzPose cameraPose;
00169
00170
00171 private: double hfov;
00172 private: double nearClip, farClip;
00173
00174
00175 private: int imageWidth, imageHeight;
00176
00177
00178 private: uint8_t *rgbImage;
00179
00180
00181 private: GLfloat cameraProjectionMatrix[16];
00182 private: GLfloat cameraViewMatrix[16];
00183
00184
00185 private: bool saveEnable;
00186 private: const char *savePathname;
00187 private: unsigned int saveCount;
00188
00189
00190 private: GLContext shadowMapContext;
00191 private: GLuint shadowMapTexture;
00192 private: int shadowMapSize;
00193 private: uint8_t *shadowImage;
00194
00195 private: GLfloat lightProjectionMatrix[16];
00196 private: GLfloat lightViewMatrix[16];
00197
00198 private: void SaveShadowFrame();
00199 private: ShaderManager *shaderManager;
00200 private: ShaderObject *shaderObject;
00201 };
00202
00203 #endif
00204