aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionShapes/StridingMeshInterface.cs
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionShapes/StridingMeshInterface.cs')
-rw-r--r--libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionShapes/StridingMeshInterface.cs115
1 files changed, 115 insertions, 0 deletions
diff --git a/libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionShapes/StridingMeshInterface.cs b/libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionShapes/StridingMeshInterface.cs
new file mode 100644
index 0000000..2a2ce27
--- /dev/null
+++ b/libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionShapes/StridingMeshInterface.cs
@@ -0,0 +1,115 @@
1/*
2 Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru
3 Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com
4
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
8
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
12
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
20*/
21
22using System;
23using System.Collections.Generic;
24using System.Text;
25using MonoXnaCompactMaths;
26
27namespace XnaDevRu.BulletX
28{
29 /// <summary>
30 /// PHY_ScalarType enumerates possible scalar types.
31 /// See the StridingMeshInterface for its use
32 /// </summary>
33 public enum PHY_ScalarType
34 {
35 PHY_FLOAT,
36 PHY_DOUBLE,
37 PHY_INTEGER,
38 PHY_SHORT,
39 PHY_FIXEDPOINT88
40 }
41
42 /// <summary>
43 /// StridingMeshInterface is the interface class for high performance access to triangle meshes
44 /// It allows for sharing graphics and collision meshes. Also it provides locking/unlocking of graphics meshes that are in gpu memory.
45 /// </summary>
46 public abstract class StridingMeshInterface
47 {
48 protected Vector3 _scaling;
49
50 public StridingMeshInterface()
51 {
52 _scaling = new Vector3(1f,1f,1f);
53 }
54
55 public void InternalProcessAllTriangles(ITriangleIndexCallback callback, Vector3 aabbMin, Vector3 aabbMax)
56 {
57 int numtotalphysicsverts = 0;
58 int numtriangles, gfxindex;
59 int part, graphicssubparts = SubPartsCount();
60 Vector3[] triangle = new Vector3[3];
61 List<Vector3> verts;
62 List<int> indicies;
63
64 Vector3 meshScaling = Scaling;
65
66 //if the number of parts is big, the performance might drop due to the innerloop switch on indextype
67 for (part = 0; part < graphicssubparts; part++)
68 {
69 GetLockedReadOnlyVertexIndexBase(out verts, out indicies, out numtriangles, part);
70 numtotalphysicsverts += numtriangles * 3; //upper bound
71
72 for (gfxindex = 0; gfxindex < numtriangles; gfxindex++)
73 {
74 triangle[0] = verts[indicies[gfxindex * 3 + 0]];
75 triangle[1] = verts[indicies[gfxindex * 3 + 1]];
76 triangle[2] = verts[indicies[gfxindex * 3 + 2]];
77
78 callback.ProcessTriangleIndex(triangle, part, gfxindex);
79 }
80
81 UnLockReadOnlyVertexBase(part);
82 }
83 }
84
85
86 // get read and write access to a subpart of a triangle mesh
87 // this subpart has a continuous array of vertices and indices
88 // in this way the mesh can be handled as chunks of memory with striding
89 // very similar to OpenGL vertexarray support
90 // make a call to unLockVertexBase when the read and write access is finished
91 public abstract void GetLockedVertexIndexBase(out List<Vector3> verts, out List<int> indicies, out int numfaces, int subpart);
92
93 public abstract void GetLockedReadOnlyVertexIndexBase(out List<Vector3> verts, out List<int> indicies, out int numfaces, int subpart);
94
95 // unLockVertexBase finishes the access to a subpart of the triangle mesh
96 // make a call to unLockVertexBase when the read and write access (using getLockedVertexIndexBase) is finished
97 public abstract void UnLockVertexBase(int subpart);
98
99 public abstract void UnLockReadOnlyVertexBase(int subpart);
100
101
102 // getNumSubParts returns the number of seperate subparts
103 // each subpart has a continuous array of vertices and indices
104 public abstract int SubPartsCount();
105
106 public abstract void PreallocateVertices(int numverts);
107 public abstract void PreallocateIndices(int numindices);
108
109 public Vector3 Scaling
110 {
111 get { return _scaling; }
112 set { _scaling = value; }
113 }
114 }
115}