~ubuntu-branches/debian/sid/ember/sid

« back to all changes in this revision

Viewing changes to src/components/ogre/ogreopcode/src/OgreBoxCollisionShape.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michael Koch
  • Date: 2009-07-23 07:46:40 UTC
  • Revision ID: james.westby@ubuntu.com-20090723074640-wh0ukzis0kda36qv
Tags: upstream-0.5.6
ImportĀ upstreamĀ versionĀ 0.5.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
///////////////////////////////////////////////////////////////////////////////
 
2
///  @file OgreBoxCollisionShape.cpp
 
3
///  @brief <TODO: insert file description here>
 
4
///
 
5
///  @author The OgreOpcode Team @date 28-05-2005
 
6
///
 
7
///////////////////////////////////////////////////////////////////////////////
 
8
///
 
9
///  This file is part of OgreOpcode.
 
10
///
 
11
///  A lot of the code is based on the Nebula Opcode Collision module, see docs/Nebula_license.txt
 
12
///
 
13
///  OgreOpcode is free software; you can redistribute it and/or
 
14
///  modify it under the terms of the GNU Lesser General Public
 
15
///  License as published by the Free Software Foundation; either
 
16
///  version 2.1 of the License, or (at your option) any later version.
 
17
///
 
18
///  OgreOpcode is distributed in the hope that it will be useful,
 
19
///  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
20
///  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
21
///  Lesser General Public License for more details.
 
22
///
 
23
///  You should have received a copy of the GNU Lesser General Public
 
24
///  License along with OgreOpcode; if not, write to the Free Software
 
25
///  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
26
///
 
27
///////////////////////////////////////////////////////////////////////////////
 
28
#include "OgreOpcodeExports.h"
 
29
#include "OgreBoxCollisionShape.h"
 
30
#include "OgreCollisionReporter.h"
 
31
#include "OgreCollisionManager.h"
 
32
#include "OgreOpcodeMath.h"
 
33
#include "OgreOpcodeUtils.h"
 
34
 
 
35
using namespace Ogre;
 
36
namespace OgreOpcode
 
37
{
 
38
        //------------------------------------------------------------------------
 
39
        BoxCollisionShape::BoxCollisionShape(const Ogre::String& name)
 
40
                : ICollisionShape(name)
 
41
        {
 
42
        }
 
43
 
 
44
        //------------------------------------------------------------------------
 
45
        BoxCollisionShape::~BoxCollisionShape()
 
46
        {
 
47
                delete[] mVertexBuf;
 
48
                delete[] mFaceBuf;
 
49
        }
 
50
 
 
51
        //------------------------------------------------------------------------
 
52
        void BoxCollisionShape::_prepareOpcodeCreateParams(Opcode::OPCODECREATE& opcc)
 
53
        {
 
54
                opcc.mIMesh = &opcMeshAccess;
 
55
                //opcc.mSettings.mRules = Opcode::SPLIT_BEST_AXIS;//Opcode::SPLIT_SPLATTER_POINTS;   // split by splattering primitive centers (???)
 
56
                opcc.mSettings.mRules = Opcode::SPLIT_GEOM_CENTER | Opcode::SPLIT_SPLATTER_POINTS; // Recommended by Opcode manual
 
57
                opcc.mSettings.mLimit = 1;             // build a complete tree, 1 primitive/node
 
58
                opcc.mNoLeaf    = true; // false;
 
59
                opcc.mQuantized = false; // true;
 
60
        }
 
61
        //------------------------------------------------------------------------
 
62
        /// <TODO: insert function description here>
 
63
        /// @param [in, out]  ent Entity *    <TODO: insert parameter description here>
 
64
        /// @return bool <TODO: insert return value description here>
 
65
        bool BoxCollisionShape::load(SceneNode* scnNode, int height, int width, int depth)
 
66
        {
 
67
                assert(!mVertexBuf && !mFaceBuf);
 
68
 
 
69
                mParentNode = scnNode;
 
70
                
 
71
                // Set up the 8 corners of the cube
 
72
                float top     =  height; 
 
73
                float bottom  = -height;
 
74
                float front   = -width; 
 
75
                float back    =  width; 
 
76
                float left    = -depth; 
 
77
                float right   =  depth; 
 
78
 
 
79
                numVertices = 8;
 
80
                numFaces = 12;
 
81
                mVertexBuf = new float[numVertices*3];
 
82
                mFaceBuf = new size_t[numFaces*3];
 
83
 
 
84
                mVertexBuf[0] = left;
 
85
                mVertexBuf[1] = bottom;
 
86
                mVertexBuf[2] = front;
 
87
                mVertexBuf[3] = right;
 
88
                mVertexBuf[4] = bottom;
 
89
                mVertexBuf[5] = front;
 
90
                mVertexBuf[6] = left;
 
91
                mVertexBuf[7] = top;
 
92
                mVertexBuf[8] = front;
 
93
                mVertexBuf[9] = right;
 
94
                mVertexBuf[10] = top;
 
95
                mVertexBuf[11] = front;
 
96
                mVertexBuf[12] = left;
 
97
                mVertexBuf[13] = bottom;
 
98
                mVertexBuf[14] = back;
 
99
                mVertexBuf[15] = right;
 
100
                mVertexBuf[16] = bottom;
 
101
                mVertexBuf[17] = back;
 
102
                mVertexBuf[18] = left;
 
103
                mVertexBuf[19] = top;
 
104
                mVertexBuf[20] = back;
 
105
                mVertexBuf[21] = right;
 
106
                mVertexBuf[22] = top;
 
107
                mVertexBuf[23] = back;
 
108
 
 
109
                int leftbottomfront   = 1; 
 
110
                int rightbottomfront  = 0; 
 
111
                int lefttopfront      = 3; 
 
112
                int righttopfront     = 2;
 
113
                int leftbottomback    = 5;
 
114
                int rightbottomback   = 4; 
 
115
                int lefttopback       = 7;
 
116
                int righttopback      = 6; 
 
117
                //int leftbottomfront   = 0; 
 
118
                //int rightbottomfront  = 1; 
 
119
                //int lefttopfront      = 2; 
 
120
                //int righttopfront     = 3;
 
121
                //int leftbottomback    = 4;
 
122
                //int rightbottomback   = 5; 
 
123
                //int lefttopback       = 6;
 
124
                //int righttopback      = 7; 
 
125
 
 
126
                // Left faces
 
127
                mFaceBuf[0] = lefttopfront;
 
128
                mFaceBuf[1] = lefttopback;
 
129
                mFaceBuf[2] = leftbottomback;
 
130
                mFaceBuf[3] = leftbottomback;
 
131
                mFaceBuf[4] = leftbottomfront;
 
132
                mFaceBuf[5] = lefttopfront;
 
133
                // Front faces
 
134
                mFaceBuf[6] = lefttopfront;
 
135
                mFaceBuf[7] = leftbottomfront;
 
136
                mFaceBuf[8] = rightbottomfront;
 
137
                mFaceBuf[9] = rightbottomfront;
 
138
                mFaceBuf[10] = righttopfront;
 
139
                mFaceBuf[11] = lefttopfront;
 
140
                // Right faces
 
141
                mFaceBuf[12] = righttopback;
 
142
                mFaceBuf[13] = righttopfront;
 
143
                mFaceBuf[14] = rightbottomfront;
 
144
                mFaceBuf[15] = rightbottomfront;
 
145
                mFaceBuf[16] = rightbottomback;
 
146
                mFaceBuf[17] = righttopback;
 
147
                // Back faces
 
148
                mFaceBuf[18] = leftbottomback;
 
149
                mFaceBuf[19] = lefttopback;
 
150
                mFaceBuf[20] = righttopback;
 
151
                mFaceBuf[21] = righttopback;
 
152
                mFaceBuf[22] = rightbottomback;
 
153
                mFaceBuf[23] = leftbottomback;
 
154
                // Top faces
 
155
                mFaceBuf[24] = righttopfront;
 
156
                mFaceBuf[25] = righttopback;
 
157
                mFaceBuf[26] = lefttopback;
 
158
                mFaceBuf[27] = lefttopback;
 
159
                mFaceBuf[28] = lefttopfront;
 
160
                mFaceBuf[29] = righttopfront;
 
161
                // Bottom faces
 
162
                mFaceBuf[30] = leftbottomfront;
 
163
                mFaceBuf[31] = leftbottomback;
 
164
                mFaceBuf[32] = rightbottomback;
 
165
                mFaceBuf[33] = rightbottomback;
 
166
                mFaceBuf[34] = rightbottomfront;
 
167
                mFaceBuf[35] = leftbottomfront;
 
168
 
 
169
                //numVertices = 4;
 
170
                //numFaces = 2;
 
171
                //mVertexBuf = new float[numVertices*3];
 
172
                //mFaceBuf = new int[numFaces*3];
 
173
                //
 
174
                //mVertexBuf[0] = -size;
 
175
                //mVertexBuf[1] = 0;
 
176
                //mVertexBuf[2] = -size;
 
177
                //mVertexBuf[3] = -size;
 
178
                //mVertexBuf[4] = 0;
 
179
                //mVertexBuf[5] = size;
 
180
                //mVertexBuf[6] = size;
 
181
                //mVertexBuf[7] = 0;
 
182
                //mVertexBuf[8] = size;
 
183
                //mVertexBuf[9] = size;
 
184
                //mVertexBuf[10] = 0;
 
185
                //mVertexBuf[11] = -size;
 
186
 
 
187
                //mFaceBuf[0] = 0;
 
188
                //mFaceBuf[1] = 1;
 
189
                //mFaceBuf[2] = 2;
 
190
                //mFaceBuf[3] = 0;
 
191
                //mFaceBuf[4] = 2;
 
192
                //mFaceBuf[5] = 3;
 
193
 
 
194
                opcMeshAccess.SetNbTriangles(numFaces);
 
195
                opcMeshAccess.SetNbVertices(numVertices);
 
196
                opcMeshAccess.SetPointers((IceMaths::IndexedTriangle*)mFaceBuf, (IceMaths::Point*)mVertexBuf);
 
197
                //opcMeshAccess.SetStrides(sizeof(int) * 3, sizeof(float) * 3);
 
198
 
 
199
                assert(mVertexBuf && mFaceBuf);
 
200
 
 
201
                Opcode::OPCODECREATE opcc;
 
202
                _prepareOpcodeCreateParams(opcc);
 
203
                opcModel.Build(opcc);
 
204
 
 
205
                calculateSize();
 
206
 
 
207
                mParentNode->getWorldTransforms(&mFullTransform);
 
208
                //mFullTransform = mParentNode->_getFullTransform();
 
209
 
 
210
                return true;
 
211
        }
 
212
 
 
213
        //------------------------------------------------------------------------
 
214
        /// <TODO: insert function description here>
 
215
        /// @return bool <TODO: insert return value description here>
 
216
        //bool BoxCollisionShape::rebuild()
 
217
        //{
 
218
        //      opcMeshAccess.SetNbTriangles(numFaces);
 
219
        //      opcMeshAccess.SetNbVertices(numVertices);
 
220
        //      opcMeshAccess.SetPointers((IceMaths::IndexedTriangle*)mFaceBuf, (IceMaths::Point*)mVertexBuf);
 
221
        //      opcMeshAccess.SetStrides(sizeof(int) * 3, sizeof(float) * 3);
 
222
 
 
223
        //      return _rebuildFromCachedData();
 
224
 
 
225
        //}
 
226
 
 
227
        //------------------------------------------------------------------------
 
228
        /// <TODO: insert function description here>
 
229
        /// @return bool <TODO: insert return value description here>
 
230
        //bool BoxCollisionShape::_rebuildFromCachedData()
 
231
        //{
 
232
        //      assert(mVertexBuf && mFaceBuf);
 
233
 
 
234
        //      Opcode::OPCODECREATE opcc;
 
235
        //      _prepareOpcodeCreateParams(opcc);
 
236
        //      opcModel.Build(opcc);
 
237
 
 
238
        //      calculateSize();
 
239
 
 
240
        //      if (_debug_obj) {
 
241
        //              setDebug(true);
 
242
        //      }
 
243
 
 
244
        //      return true;
 
245
        //}
 
246
}
 
247
 
 
248
//------------------------------------------------------------------------