MeshShapeData.h

Go to the documentation of this file.
00001 /*************************************************************************
00002  *                                                                       *
00003  * Open Physics Abstraction Layer                                        *
00004  * Copyright (C) 2004-2005                                               *
00005  * Alan Fischer  alan.fischer@gmail.com                                  *
00006  * Andres Reinot  andres@reinot.com                                      *
00007  * Tyler Streeter  tylerstreeter@gmail.com                               *
00008  * All rights reserved.                                                  *
00009  * Web: opal.sourceforge.net                                             *
00010  *                                                                       *
00011  * This library is free software; you can redistribute it and/or         *
00012  * modify it under the terms of EITHER:                                  *
00013  *   (1) The GNU Lesser General Public License as published by the Free  *
00014  *       Software Foundation; either version 2.1 of the License, or (at  *
00015  *       your option) any later version. The text of the GNU Lesser      *
00016  *       General Public License is included with this library in the     *
00017  *       file license-LGPL.txt.                                          *
00018  *   (2) The BSD-style license that is included with this library in     *
00019  *       the file license-BSD.txt.                                       *
00020  *                                                                       *
00021  * This library is distributed in the hope that it will be useful,       *
00022  * but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00023  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files    *
00024  * license-LGPL.txt and license-BSD.txt for more details.                *
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                         // Compute the AABB from the vertex data.
00100                         if (vertexArray)
00101                         {
00102                                 for (unsigned int i = 0; i < numVertices; ++i)
00103                                 {
00104                                         unsigned int vertexIndex = i * 3;
00105 
00106                                         // Check x component.
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                                         // Check y component.
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                                         // Check z component.
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

Generated on Tue May 16 17:49:51 2006 for OPAL by  doxygen 1.4.6-NO