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 #ifndef opengl_COpenGLStandardObject_H
00029 #define opengl_COpenGLStandardObject_H
00030
00031 #include <mrpt/opengl/CRenderizableDisplayList.h>
00032 #include <mrpt/math/geometry.h>
00033
00034 #include <mrpt/utils/stl_extensions.h>
00035
00036 namespace mrpt {
00037 namespace opengl {
00038 typedef uint32_t _GLENUM;
00039 using namespace mrpt::utils;
00040 using namespace mrpt::math;
00041 class OPENGL_IMPEXP COpenGLStandardObject;
00042 DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE(COpenGLStandardObject,CRenderizableDisplayList, OPENGL_IMPEXP)
00043
00044
00045
00046 class OPENGL_IMPEXP COpenGLStandardObject:public CRenderizableDisplayList {
00047 DEFINE_SERIALIZABLE(COpenGLStandardObject)
00048 protected:
00049
00050
00051
00052 _GLENUM type;
00053
00054
00055
00056 std::vector<TPoint3D> vertices;
00057
00058
00059
00060 uint32_t chunkSize;
00061
00062
00063
00064 std::vector<_GLENUM> enabled;
00065 float normal[3];
00066 public:
00067
00068
00069
00070
00071 virtual void render_dl() const;
00072
00073
00074
00075
00076 virtual bool traceRay(const mrpt::poses::CPose3D &o,float &dist) const;
00077
00078
00079
00080
00081 static COpenGLStandardObjectPtr Create(_GLENUM t,const std::vector<TPoint3D> &v,uint32_t cs=0,const std::vector<_GLENUM> &en=std::vector<_GLENUM>()) {
00082 if (cs!=0&&v.size()%cs!=0) throw std::logic_error("Vertices vector does not match chunk size");
00083 return COpenGLStandardObjectPtr(new COpenGLStandardObject(t,v,cs,en));
00084 }
00085
00086
00087
00088 inline void enable(_GLENUM flag) {
00089 if (find(enabled.begin(),enabled.end(),flag)==enabled.end()) enabled.push_back(flag);
00090 CRenderizableDisplayList::notifyChange();
00091 }
00092
00093
00094
00095 inline void disable(_GLENUM flag) {
00096 std::remove(enabled.begin(),enabled.end(),flag);
00097 CRenderizableDisplayList::notifyChange();
00098 }
00099
00100
00101
00102 inline bool isEnabled(_GLENUM flag) const {
00103 return find(enabled.begin(),enabled.end(),flag)!=enabled.end();
00104 }
00105
00106
00107
00108 inline void getEnabledFlags(std::vector<_GLENUM> &v) const {
00109 v=enabled;
00110 }
00111
00112
00113
00114 inline void setFlags(const std::vector<_GLENUM> &v) {
00115 enabled=v;
00116 CRenderizableDisplayList::notifyChange();
00117 }
00118
00119
00120
00121 inline void setNormal(const float (&n)[3]) {
00122 for (size_t i=0;i<3;i++) normal[i]=n[i];
00123 CRenderizableDisplayList::notifyChange();
00124 }
00125
00126
00127
00128 inline void getNormal(float (&n)[3]) const {
00129 for (size_t i=0;i<3;i++) n[i]=normal[i];
00130 }
00131 private:
00132
00133
00134
00135 COpenGLStandardObject(_GLENUM t,const std::vector<TPoint3D> &v,uint32_t cs,const vector<_GLENUM> &en):type(t),vertices(v),chunkSize(cs),enabled(en) {
00136 for (size_t i=0;i<3;i++) normal[i]=0.0;
00137 }
00138
00139
00140
00141 COpenGLStandardObject():type(0),vertices(std::vector<TPoint3D>(0)),chunkSize(0),enabled(std::vector<_GLENUM>()) {
00142 for (size_t i=0;i<3;i++) normal[i]=0.0;
00143 }
00144
00145
00146
00147 virtual ~COpenGLStandardObject() {}
00148 };
00149 }
00150 }
00151 #endif