Gazebo logo

Camera.hh

Go to the documentation of this file.
00001 /*
00002  *  Gazebo - Outdoor Multi-Robot Simulator
00003  *  Copyright (C) 2003  
00004  *     Nate Koenig & Andrew Howard
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  *
00020  */
00021 /* Desc: A persepective X11 OpenGL Camera Sensor
00022  * Author: Nate Koenig
00023  * Date: 15 July 2003
00024  * CVS: $Id: Camera.hh,v 1.39 2005/10/20 17:02:11 natepak Exp $
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 // Forward Declarations
00038 class World;
00039 class WorldFile;
00040 class WorldFileNode;
00041 class Body;
00042 
00043 //class ShaderManager;
00044 //class ShaderObject;
00045 
00051 class Camera : public Sensor
00052 {
00053   // Constructor
00054   public: Camera( World *world );
00055 
00056   // Destructor
00057   public: virtual ~Camera();
00058 
00069   public: int Init(int width, int height, double hfov,
00070                    double minDepth, double maxDepth, const char *method, 
00071                    int zBufferDepth);
00072 
00073   public: void InitContext( GLContext &context );
00074 
00076   public: int Fini();
00077 
00079   public: void Update();
00080 
00082   public: void SetPose(GzPose pose);
00083 
00085   public: GzPose GetPose();
00086 
00088   public: void SetFOV(double fov);
00089 
00091   public: double GetFOV() const;
00092 
00094   public: void SetRenderOptions(const RenderOptions *opt);
00095 
00097   public: void GetRenderOptions(RenderOptions *opt) const;
00098 
00100   public: void GetImageSize(int *w, int *h);
00101 
00103   public: const unsigned char *GetImageData() const {return this->rgbImage;}
00104 
00110   public: double GetZValue(int x, int y);
00111 
00132   public: GzPose CalcCameraDelta(int mode, GzVector a, GzVector b);
00133   
00134   // Render the scene from the camera perspective
00135   private: void Render();
00136 
00137   // Render the models
00138   private: void RenderModels( int pass );  
00139 
00141   public: void SetSavePath(const char *pathname);
00142 
00144   public: void EnableSaveFrame(bool enable);
00145 
00146   // Save the camera frame
00147   private: void SaveFrame();
00148  
00149   private: GLuint LoadShader(GLenum target, const char *file);
00150 
00151   private: float *Mult( float *a, float *b);
00152   private: void RenderDepthTexture();
00153 
00154   // GL rendering context
00155   private: GLContext context;
00156 
00157   // Geom rendering options
00158   private: RenderOptions renderOpt;
00159 
00160   // Camera pose
00161   private: GzPose cameraPose;
00162 
00163   // Lens options
00164   private: double hfov;
00165   private: double nearClip, farClip;
00166 
00167   // Image dimensions
00168   private: int imageWidth, imageHeight;
00169   
00170   // RGB image buffer
00171   private: uint8_t *rgbImage;
00172 
00173   // Store projection matrix for GUI calculations
00174   private: GLfloat cameraProjectionMatrix[16];
00175   private: GLfloat cameraViewMatrix[16];
00176 
00177   // Info for saving images
00178   private: bool saveEnable;
00179   private: const char *savePathname;
00180   private: unsigned int saveCount;
00181 
00182   private: GLfloat lightProjectionMatrix[16];
00183   private: GLfloat lightViewMatrix[16];
00184 
00185 //  private: ShaderManager *shaderManager;
00186   //private: ShaderObject *shaderObject;
00187 };
00188 
00189 #endif
00190 

Last updated 12 September 2005 21:38:45