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