1 | #include "OgreOdePrecompiledHeaders.h" |
---|
2 | #include "OgreOdeTriangleMeshData.h" |
---|
3 | |
---|
4 | #include "OgreOdeTriangleMeshDataManager.h" |
---|
5 | |
---|
6 | using namespace OgreOde; |
---|
7 | using namespace Ogre; |
---|
8 | |
---|
9 | |
---|
10 | //------------------------------------------------------------------------------------------------ |
---|
11 | TriangleMeshData::TriangleMeshData(String name, |
---|
12 | Vector3 scale, |
---|
13 | const Ogre::Vector3* vertices, |
---|
14 | unsigned int vertex_count, |
---|
15 | const TriangleIndex* indices, |
---|
16 | unsigned int index_count |
---|
17 | ) : |
---|
18 | _vertex_count (vertex_count), |
---|
19 | _index_count (index_count) |
---|
20 | { |
---|
21 | _name = name; |
---|
22 | _scale = scale; |
---|
23 | _vertex_count = vertex_count; |
---|
24 | _index_count = index_count; |
---|
25 | _vertices = new dVector3[vertex_count]; |
---|
26 | _indices = new TriangleIndex[index_count]; |
---|
27 | |
---|
28 | for(unsigned int i = 0;i < vertex_count;i++) |
---|
29 | { |
---|
30 | _vertices[i][0] = (dReal)vertices[i].x; |
---|
31 | _vertices[i][1] = (dReal)vertices[i].y; |
---|
32 | _vertices[i][2] = (dReal)vertices[i].z; |
---|
33 | } |
---|
34 | |
---|
35 | memcpy(_indices, indices, sizeof(unsigned int) * index_count); |
---|
36 | |
---|
37 | _data = dGeomTriMeshDataCreate(); |
---|
38 | dGeomTriMeshDataBuildSimple(_data, (const dReal*)_vertices, (int)vertex_count, (dTriIndex*)_indices, (int)index_count); |
---|
39 | |
---|
40 | } |
---|
41 | |
---|
42 | |
---|
43 | |
---|
44 | |
---|
45 | //------------------------------------------------------------------------------------------------ |
---|
46 | TriangleMeshData::~TriangleMeshData() |
---|
47 | { |
---|
48 | |
---|
49 | //printf ("destroy TriangleMeshData\n"); |
---|
50 | |
---|
51 | dGeomTriMeshDataDestroy(_data); |
---|
52 | |
---|
53 | TriangleMeshDataManager::getSingleton().removeTriangleMeshData(_name, _scale); |
---|
54 | |
---|
55 | delete[] _vertices; |
---|
56 | delete[] _indices; |
---|
57 | } |
---|
58 | |
---|
59 | |
---|