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/CRenderizable.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 MRPTDLLIMPEXP COpenGLStandardObject;
00042 DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE(COpenGLStandardObject,CRenderizable)
00043
00044
00045
00046 class MRPTDLLIMPEXP COpenGLStandardObject:public CRenderizable {
00047 DEFINE_SERIALIZABLE(COpenGLStandardObject)
00048 protected:
00049
00050
00051
00052 _GLENUM type;
00053
00054
00055
00056 vector<TPoint3D> vertices;
00057
00058
00059
00060 uint32_t chunkSize;
00061
00062
00063
00064 vector<_GLENUM> enabled;
00065 float normal[3];
00066 public:
00067
00068
00069
00070
00071 virtual void render() 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 vector<_GLENUM> &en=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 }
00091
00092
00093
00094 inline void disable(_GLENUM flag) {
00095 std::remove(enabled.begin(),enabled.end(),flag);
00096 }
00097
00098
00099
00100 inline bool isEnabled(_GLENUM flag) const {
00101 return find(enabled.begin(),enabled.end(),flag)!=enabled.end();
00102 }
00103
00104
00105
00106 inline void getEnabledFlags(std::vector<_GLENUM> &v) const {
00107 v=enabled;
00108 }
00109
00110
00111
00112 inline void setFlags(const std::vector<_GLENUM> &v) {
00113 enabled=v;
00114 }
00115
00116
00117
00118 inline void setNormal(const float (&n)[3]) {
00119 for (size_t i=0;i<3;i++) normal[i]=n[i];
00120 }
00121
00122
00123
00124 inline void getNormal(float (&n)[3]) const {
00125 for (size_t i=0;i<3;i++) n[i]=normal[i];
00126 }
00127 private:
00128
00129
00130
00131 COpenGLStandardObject(_GLENUM t,const std::vector<TPoint3D> &v,uint32_t cs,const vector<_GLENUM> &en):type(t),vertices(v),chunkSize(cs),enabled(en) {
00132 for (size_t i=0;i<3;i++) normal[i]=0.0;
00133 }
00134
00135
00136
00137 COpenGLStandardObject():type(0),vertices(std::vector<TPoint3D>(0)),chunkSize(0),enabled(vector<_GLENUM>()) {
00138 for (size_t i=0;i<3;i++) normal[i]=0.0;
00139 }
00140
00141
00142
00143 virtual ~COpenGLStandardObject() {}
00144 };
00145 }
00146 }
00147 #endif