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 OPAL_MESH_SHAPE_DATA_H
00029 #define OPAL_MESH_SHAPE_DATA_H
00030
00031 #include "Defines.h"
00032 #include "ShapeData.h"
00033
00034 namespace opal
00035 {
00049 class MeshShapeData : public ShapeData
00050 {
00051 public:
00052 OPAL_DECL MeshShapeData()
00053 : ShapeData()
00054 {
00055 mType = MESH_SHAPE;
00056 vertexArray = NULL;
00057 numVertices = 0;
00058 triangleArray = NULL;
00059 numTriangles = 0;
00060
00061 for (unsigned int i = 0; i < 6; ++i)
00062 {
00063 localAABB[i] = 0;
00064 }
00065 }
00066
00068 OPAL_DECL MeshShapeData(const MeshShapeData& data)
00069 {
00070 (*this) = data;
00071 }
00072
00073 OPAL_DECL virtual ~MeshShapeData()
00074 {
00075 }
00076
00078 OPAL_DECL virtual void OPAL_CALL operator=(const MeshShapeData& data)
00079 {
00080 mType = data.mType;
00081 offset = data.offset;
00082 material = data.material;
00083 contactGroup = data.contactGroup;
00084 vertexArray = data.vertexArray;
00085 numVertices = data.numVertices;
00086 triangleArray = data.triangleArray;
00087 numTriangles = data.numTriangles;
00088
00089 for (unsigned int i = 0; i < 6; ++i)
00090 {
00091 localAABB[i] = data.localAABB[i];
00092 }
00093 }
00094
00097 OPAL_DECL virtual void OPAL_CALL getLocalAABB(real aabb[6])
00098 {
00099
00100 if (vertexArray)
00101 {
00102 for (unsigned int i = 0; i < numVertices; ++i)
00103 {
00104 unsigned int vertexIndex = i * 3;
00105
00106
00107 if (vertexArray[vertexIndex] < localAABB[0])
00108 {
00109 localAABB[0] = vertexArray[vertexIndex];
00110 }
00111 else if (vertexArray[vertexIndex] > localAABB[1])
00112 {
00113 localAABB[1] = vertexArray[vertexIndex];
00114 }
00115
00116
00117 if (vertexArray[vertexIndex + 1] < localAABB[2])
00118 {
00119 localAABB[2] = vertexArray[vertexIndex + 1];
00120 }
00121 else if (vertexArray[vertexIndex + 1] > localAABB[3])
00122 {
00123 localAABB[3] = vertexArray[vertexIndex + 1];
00124 }
00125
00126
00127 if (vertexArray[vertexIndex + 2] < localAABB[4])
00128 {
00129 localAABB[4] = vertexArray[vertexIndex + 2];
00130 }
00131 else if (vertexArray[vertexIndex + 2] > localAABB[5])
00132 {
00133 localAABB[5] = vertexArray[vertexIndex+ 2];
00134 }
00135 }
00136 }
00137
00138 for (unsigned int i = 0; i < 6; ++i)
00139 {
00140 aabb[i] = localAABB[i];
00141 }
00142 }
00143
00151 real* vertexArray;
00152
00154 unsigned int numVertices;
00155
00165 unsigned int* triangleArray;
00166
00168 unsigned int numTriangles;
00169
00170 protected:
00175 real localAABB[6];
00176
00177 private:
00178 };
00179 }
00180
00181 #endif