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 #ifndef opengl_CRenderizable_H
00029 #define opengl_CRenderizable_H
00030
00031 #include <mrpt/utils/utils_defs.h>
00032 #include <mrpt/utils/CSerializable.h>
00033
00034 #include <mrpt/synch/CCriticalSection.h>
00035
00036 namespace mrpt
00037 {
00038 namespace poses { class CPose3D; }
00039 namespace utils { class CStringList; }
00040
00041 namespace opengl
00042 {
00043 class COpenGLViewport;
00044 class CSetOfObjects;
00045
00046
00047 DEFINE_SERIALIZABLE_PRE( CRenderizable )
00048
00049
00057 class MRPTDLLIMPEXP CRenderizable : public mrpt::utils::CSerializable
00058 {
00059 DEFINE_VIRTUAL_SERIALIZABLE( CRenderizable )
00060
00061 friend class mrpt::opengl::COpenGLViewport;
00062 friend class mrpt::opengl::CSetOfObjects;
00063
00064 protected:
00065 std::string m_name;
00066 bool m_show_name;
00067 double m_color_R,m_color_G,m_color_B,m_color_A;
00068 double m_x,m_y,m_z;
00069 double m_yaw,m_pitch,m_roll;
00070 float m_scale_x, m_scale_y, m_scale_z;
00071
00072 public:
00073 void setName(const std::string &n) { m_name=n; }
00074 std::string getName() const { return m_name; }
00075
00076 void enableShowName(bool showName=true) { m_show_name=showName; }
00077
00078 static void renderTextBitmap( const char *str, void *fontStyle );
00079
00082 CRenderizable() :
00083 m_name(),
00084 m_show_name(false),
00085 m_color_R(1),m_color_G(1),m_color_B(1),m_color_A(1),
00086 m_x(0),m_y(0),m_z(0),
00087 m_yaw(0),m_pitch(0),m_roll(0),
00088 m_scale_x(1), m_scale_y(1), m_scale_z(1)
00089 {
00090 }
00091
00092 virtual ~CRenderizable() { }
00093
00095 CRenderizable * clone() const
00096 {
00097 return static_cast<CRenderizable*>( this->duplicate() );
00098 }
00099
00102 virtual void render() const = 0;
00103
00104 void setPose( const mrpt::poses::CPose3D &o );
00105
00106 void setLocation(double x,double y,double z) { m_x=x; m_y=y; m_z=z; }
00107
00108 double getPoseX() const { return m_x; }
00109 double getPoseY() const { return m_y; }
00110 double getPoseZ() const { return m_z; }
00111 double getPoseYaw() const { return m_yaw; }
00112 double getPosePitch() const { return m_pitch; }
00113 double getPoseRoll() const { return m_roll; }
00114
00115 double getColorR() const { return m_color_R; }
00116 double getColorG() const { return m_color_G; }
00117 double getColorB() const { return m_color_B; }
00118 double getColorA() const { return m_color_A; }
00119
00120 virtual void setColorR(const double r) {m_color_R=r;}
00121 virtual void setColorG(const double g) {m_color_G=g;}
00122 virtual void setColorB(const double b) {m_color_B=b;}
00123 virtual void setColorA(const double a) {m_color_A=a;}
00124
00125 void setScale(float s) { m_scale_x=m_scale_y=m_scale_z = s; }
00126 void setScale(float sx,float sy,float sz) { m_scale_x=sx; m_scale_y=sy; m_scale_z = sz; }
00127 float getScaleX() const { return m_scale_x; }
00128 float getScaleY() const { return m_scale_y; }
00129 float getScaleZ() const { return m_scale_z; }
00130
00131
00132 mrpt::utils::TColorf getColor() const { return mrpt::utils::TColorf(m_color_R,m_color_G,m_color_B,m_color_A); }
00133 virtual void setColor( const mrpt::utils::TColorf &c) { m_color_R = c.R; m_color_G=c.G; m_color_B=c.B;m_color_A=c.A; }
00134
00135
00140 virtual bool traceRay(const mrpt::poses::CPose3D &o,float &dist) const;
00141
00143 virtual void setColor( double R, double G, double B, double A=1);
00144
00145 protected:
00147 static void checkOpenGLError();
00148
00149 void writeToStreamRender(utils::CStream &out) const;
00150 void readFromStreamRender(utils::CStream &in);
00151
00153 static unsigned int getNewTextureNumber();
00154 static void releaseTextureName(unsigned int i);
00155
00156 };
00157
00158
00159
00160 }
00161
00162 }
00163
00164
00165 #endif