1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
The ODE Model Processor
-----------------------
Copyright 2007, Department of Information Science,
University of Otago, Dunedin, New Zealand.
Author: Richard Barrington <barri662@student.otago.ac.nz>
This is a Content Processor and Tag library written for use with
Microsoft Visual C# 2005 Express Edition and Microsoft XNA Game
Studio Express 1.0.
It can be used to read .x model vertex and index data before
insertion into the content pipeline. This is used to build ODE
Triangle Meshes which are then used for collision detection that
is more accurate than the default XNA bounding boxes or spheres.
Usage is fairly simple:
Build the library and reference the DLL in your project.
Add the DLL to the Content Pipeline
Set the content processor for you .x models to OdeModelProcessor.
Create triangle meshes as follows:
1) Create a space, but only one for all of models.
2) Create a triangle data.
3) Load the model.
4) Retreive the tag from the model.
6) Build the triangle mesh by calling d.GeomTriMeshDataBuildSimple.
Eg:
IntPtr space = d.SimpleSpaceCreate(IntPtr.Zero);
IntPtr triangleData = d.GeomTriMeshDataCreate();
Model obj = content.Load<Model>("Content\\mycube");
OdeTag tag = (OdeTag)obj.Tag;
IntPtr vertexArray = tag.getVertices();
IntPtr indexArray = tag.getIndices();
d.GeomTriMeshDataBuildSimple
(
triangleData,
vertexArray, tag.getVertexStride(), tag.getVertexCount(),
indexArray, tag.getIndexCount(), tag.getIndexStride()
);
IntPtr triangleMesh = d.CreateTriMesh(space, triangleData, null, null, null);
You can load multiple models and test for collisions with something
like this in the update method:
d.GeomSetPosition(odeTri1, obj1Position.X, obj1Position.Y, obj1Position.Z);
d.GeomSetPosition(odeTri2, obj2Position.X, obj2Position.Y, obj2Position.Z);
int numberOfContacts = d.Collide(odeTri1, odeTri2, ODE_CONTACTS,
contactGeom, d.ContactGeom.SizeOf);
Where odeTri1 and odeTri2 are triangle meshes you've created, obj1Position
and obj2Position are the positions of your rendered models in the scene,
ODE_CONTACTS is a constant defining the maximum number of contacts
to test for, contactGeom is a d.ContactGeom[] of length ODE_CONTACTS.
If numberOfContacts is greater than 0, you have a collision.
Other ODE functions such as d.SpaceCollide() also work; see ODE.NET BoxTest.cs.
This library is free software; you can redistribute it and/or
modify it under the same terms as the ODE and ODE.Net libraries.
Specifically, the terms are one of EITHER:
(1) The GNU Lesser General Public License as published by the Free
Software Foundation; either version 2.1 of the License, or (at
your option) any later version. The text of the GNU Lesser
General Public License is included with this library in the
file LICENSE.TXT.
(2) The BSD-style license that is included with this library in
the file LICENSE-BSD.TXT.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files
LICENSE.TXT and LICENSE-BSD.TXT for more details.
|