Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/physics_new/src/ogrebullet/Collisions/Shapes/OgreBulletCollisionsGImpactShape.cpp @ 2119

Last change on this file since 2119 was 2119, checked in by rgrieder, 15 years ago

Merged physics branch into physics_new branch.

  • Property svn:eol-style set to native
File size: 5.6 KB
Line 
1/***************************************************************************
2
3This source file is part of OGREBULLET
4(Object-oriented Graphics Rendering Engine Bullet Wrapper)
5For the latest info, see http://www.ogre3d.org/phpBB2addons/viewforum.php?f=10
6
7Copyright (c) 2007 tuan.kuranes@gmail.com (Use it Freely, even Statically, but have to contribute any changes)
8
9
10
11This program is free software; you can redistribute it and/or modify it under
12the terms of the GPL General Public License with runtime exception as published by the Free Software
13Foundation; either version 2 of the License, or (at your option) any later
14version.
15
16This program is distributed in the hope that it will be useful, but WITHOUT
17ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18FOR A PARTICULAR PURPOSE. See the GPL General Public License with runtime exception for more details.
19
20You should have received a copy of the GPL General Public License with runtime exception along with
21this program; if not, write to the Free Software Foundation, Inc., 59 Temple
22Place - Suite 330, Boston, MA 02111-1307, USA, or go to
23http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
24-----------------------------------------------------------------------------
25*/
26
27#include "OgreBulletCollisions.h"
28
29#include "Shapes/OgreBulletCollisionsGImpactShape.h"
30
31/***************************************************************************
32
33This source file is part of OGREBULLET
34(Object-oriented Graphics Rendering Engine Bullet Wrapper)
35For the latest info, see http://www.ogre3d.org/phpBB2addons/viewforum.php?f=10
36
37Copyright (c) 2007 tuan.kuranes@gmail.com (Use it Freely, even Statically, but have to contribute any changes)
38
39
40
41This program is free software; you can redistribute it and/or modify it under
42the terms of the GPL General Public License with runtime exception as published by the Free Software
43Foundation; either version 2 of the License, or (at your option) any later
44version.
45
46This program is distributed in the hope that it will be useful, but WITHOUT
47ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
48FOR A PARTICULAR PURPOSE. See the GPL General Public License with runtime exception for more details.
49
50You should have received a copy of the GPL General Public License with runtime exception along with
51this program; if not, write to the Free Software Foundation, Inc., 59 Temple
52Place - Suite 330, Boston, MA 02111-1307, USA, or go to
53http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
54-----------------------------------------------------------------------------
55*/
56
57#include "Shapes/OgreBulletCollisionsTrimeshShape.h"
58#include "Debug/OgreBulletCollisionsDebugLines.h"
59#include "Utils/OgreBulletConverter.h"
60
61using namespace Ogre;
62using namespace OgreBulletCollisions;
63
64namespace OgreBulletCollisions
65{
66        GImpactConcaveShape::GImpactConcaveShape(
67                Ogre::Vector3 *_vertices,
68                unsigned int _vertex_count,
69                unsigned int *_indices,
70                unsigned int int_index_count) : CollisionShape(), mTriMesh(0)
71        {
72                mTriMesh = new btTriangleMesh();
73
74                unsigned int numFaces = int_index_count / 3;
75
76                btVector3    vertexPos[3];
77                for (size_t n = 0; n < numFaces; ++n)
78                {
79                        for (unsigned int i = 0; i < 3; ++i)
80                        {
81                                const Vector3 &vec = _vertices[*_indices];
82                                vertexPos[i][0] = vec.x;
83                                vertexPos[i][1] = vec.y;
84                                vertexPos[i][2] = vec.z;
85                                *_indices++;
86                        }
87
88                        mTriMesh->addTriangle(vertexPos[0], vertexPos[1], vertexPos[2]);
89                }
90
91                btGImpactMeshShape * trimesh = new btGImpactMeshShape(mTriMesh);
92                trimesh->setLocalScaling(btVector3(1, 1, 1));
93                trimesh->updateBound();
94                mShape = trimesh;
95        }
96
97        GImpactConcaveShape::~GImpactConcaveShape()
98        {
99        }
100        // -------------------------------------------------------------------------
101        bool GImpactConcaveShape::drawWireFrame(DebugLines *wire, 
102                const Ogre::Vector3 &pos, 
103                const Ogre::Quaternion &quat) const
104        {
105                const int numTris = mTriMesh->getNumTriangles ();
106                if (numTris > 0)
107                {
108
109                        const int numSubParts = mTriMesh->getNumSubParts ();
110                        for (int currSubPart = 0; currSubPart < numSubParts; currSubPart++)
111                        {
112                                const unsigned char* vertexBase = NULL;
113                                int numVerts;
114                                PHY_ScalarType vertexType;
115                                int vertexStride;
116                                const unsigned char* indexBase = NULL;
117                                int indexStride;
118                                int numFaces;
119                                PHY_ScalarType indexType;
120
121                                mTriMesh->getLockedReadOnlyVertexIndexBase (&vertexBase, numVerts, 
122                                        vertexType, vertexStride, 
123                                        &indexBase, indexStride, numFaces, indexType, currSubPart);
124
125                                float* p;
126                                btVector3 vert0;
127                                btVector3 vert1;
128                                btVector3 vert2;
129                                for (int t = 0; t < numFaces; t++)
130                                {
131#define setVector(A, B) {A.setX(B[0]);A.setY(B[1]);A.setZ(B[2]);};
132
133                                        if (indexType == PHY_SHORT)
134                                        {
135                                                short int* index = (short int*)(indexBase + t*indexStride);
136
137                                                p = (float*)(vertexBase + index[0]*vertexStride);
138                                                setVector(vert0, p);                                           
139                                                p = (float*)(vertexBase + index[1]*vertexStride);
140                                                setVector(vert1, p);                   
141                                                p = (float*)(vertexBase + index[2]*vertexStride);
142                                                setVector(vert2, p);           
143                                        } 
144                                        else
145                                        {
146                                                int* index = (int*)(indexBase + t*indexStride);
147
148                                                p = (float*)(vertexBase + index[0]*vertexStride);
149                                                setVector(vert0, p);                                           
150                                                p = (float*)(vertexBase + index[1]*vertexStride);
151                                                setVector(vert1, p);                   
152                                                p = (float*)(vertexBase + index[2]*vertexStride);
153                                                setVector(vert2, p);           
154                                        }
155#undef setVector
156
157                                        wire->addLine (BtOgreConverter::to(vert0), BtOgreConverter::to(vert1));
158                                        wire->addLine (BtOgreConverter::to(vert1), BtOgreConverter::to(vert2));
159                                        wire->addLine (BtOgreConverter::to(vert2), BtOgreConverter::to(vert0));
160                                }
161                        }
162                        return true;
163                }
164                return false;
165        }
166}
Note: See TracBrowser for help on using the repository browser.