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