Open Dynamics Engine
collision_std.h
1 /*************************************************************************
2  * *
3  * Open Dynamics Engine, Copyright (C) 2001,2002 Russell L. Smith. *
4  * All rights reserved. Email: russ@q12.org Web: www.q12.org *
5  * *
6  * This library is free software; you can redistribute it and/or *
7  * modify it under the terms of EITHER: *
8  * (1) The GNU Lesser General Public License as published by the Free *
9  * Software Foundation; either version 2.1 of the License, or (at *
10  * your option) any later version. The text of the GNU Lesser *
11  * General Public License is included with this library in the *
12  * file LICENSE.TXT. *
13  * (2) The BSD-style license that is included with this library in *
14  * the file LICENSE-BSD.TXT. *
15  * *
16  * This library is distributed in the hope that it will be useful, *
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files *
19  * LICENSE.TXT and LICENSE-BSD.TXT for more details. *
20  * *
21  *************************************************************************/
22 
23 /*
24 
25 the standard ODE geometry primitives.
26 
27 */
28 
29 #ifndef _ODE_COLLISION_STD_H_
30 #define _ODE_COLLISION_STD_H_
31 
32 #include <ode/common.h>
33 #include "collision_kernel.h"
34 
35 
36 // primitive collision functions - these have the dColliderFn interface, i.e.
37 // the same interface as dCollide(). the first and second geom arguments must
38 // have the specified types.
39 
40 int dCollideSphereSphere (dxGeom *o1, dxGeom *o2, int flags,
41  dContactGeom *contact, int skip);
42 int dCollideSphereBox (dxGeom *o1, dxGeom *o2, int flags,
43  dContactGeom *contact, int skip);
44 int dCollideSpherePlane (dxGeom *o1, dxGeom *o2, int flags,
45  dContactGeom *contact, int skip);
46 int dCollideBoxBox (dxGeom *o1, dxGeom *o2, int flags,
47  dContactGeom *contact, int skip);
48 int dCollideBoxPlane (dxGeom *o1, dxGeom *o2,
49  int flags, dContactGeom *contact, int skip);
50 int dCollideCapsuleSphere (dxGeom *o1, dxGeom *o2, int flags,
51  dContactGeom *contact, int skip);
52 int dCollideCapsuleBox (dxGeom *o1, dxGeom *o2, int flags,
53  dContactGeom *contact, int skip);
54 int dCollideCapsuleCapsule (dxGeom *o1, dxGeom *o2,
55  int flags, dContactGeom *contact, int skip);
56 int dCollideCapsulePlane (dxGeom *o1, dxGeom *o2, int flags,
57  dContactGeom *contact, int skip);
58 int dCollideRaySphere (dxGeom *o1, dxGeom *o2, int flags,
59  dContactGeom *contact, int skip);
60 int dCollideRayBox (dxGeom *o1, dxGeom *o2, int flags,
61  dContactGeom *contact, int skip);
62 int dCollideRayCapsule (dxGeom *o1, dxGeom *o2,
63  int flags, dContactGeom *contact, int skip);
64 int dCollideRayPlane (dxGeom *o1, dxGeom *o2, int flags,
65  dContactGeom *contact, int skip);
66 int dCollideRayCylinder (dxGeom *o1, dxGeom *o2, int flags,
67  dContactGeom *contact, int skip);
68 
69 // Cylinder - Box/Sphere by (C) CroTeam
70 // Ported by Nguyen Binh
71 int dCollideCylinderBox(dxGeom *o1, dxGeom *o2,
72  int flags, dContactGeom *contact, int skip);
73 int dCollideCylinderSphere(dxGeom *gCylinder, dxGeom *gSphere,
74  int flags, dContactGeom *contact, int skip);
75 int dCollideCylinderPlane(dxGeom *gCylinder, dxGeom *gPlane,
76  int flags, dContactGeom *contact, int skip);
77 
78 //--> Convex Collision
79 int dCollideConvexPlane (dxGeom *o1, dxGeom *o2, int flags,
80  dContactGeom *contact, int skip);
81 int dCollideSphereConvex (dxGeom *o1, dxGeom *o2, int flags,
82  dContactGeom *contact, int skip);
83 int dCollideConvexBox (dxGeom *o1, dxGeom *o2, int flags,
84  dContactGeom *contact, int skip);
85 int dCollideConvexCapsule (dxGeom *o1, dxGeom *o2,
86  int flags, dContactGeom *contact, int skip);
87 int dCollideConvexConvex (dxGeom *o1, dxGeom *o2, int flags,
88  dContactGeom *contact, int skip);
89 int dCollideRayConvex (dxGeom *o1, dxGeom *o2, int flags,
90  dContactGeom *contact, int skip);
91 //<-- Convex Collision
92 
93 // dHeightfield
94 int dCollideHeightfield( dxGeom *o1, dxGeom *o2,
95  int flags, dContactGeom *contact, int skip );
96 
97 //****************************************************************************
98 // the basic geometry objects
99 
100 struct dxSphere : public dxGeom {
101  dReal radius; // sphere radius
102  dxSphere (dSpaceID space, dReal _radius);
103  void computeAABB();
104 };
105 
106 
107 struct dxBox : public dxGeom {
108  dVector3 side; // side lengths (x,y,z)
109  dxBox (dSpaceID space, dReal lx, dReal ly, dReal lz);
110  void computeAABB();
111 };
112 
113 
114 struct dxCapsule : public dxGeom {
115  dReal radius,lz; // radius, length along z axis
116  dxCapsule (dSpaceID space, dReal _radius, dReal _length);
117  void computeAABB();
118 };
119 
120 
121 struct dxCylinder : public dxGeom {
122  dReal radius,lz; // radius, length along z axis
123  dxCylinder (dSpaceID space, dReal _radius, dReal _length);
124  void computeAABB();
125 };
126 
127 
128 struct dxPlane : public dxGeom {
129  dReal p[4];
130  dxPlane (dSpaceID space, dReal a, dReal b, dReal c, dReal d);
131  void computeAABB();
132 };
133 
134 
135 struct dxRay : public dxGeom {
136  dReal length;
137  dxRay (dSpaceID space, dReal _length);
138  void computeAABB();
139 };
140 
141 struct dxConvex : public dxGeom
142 {
143  dReal *planes;
146  dReal *points;
147  unsigned int *polygons;
148  unsigned int planecount;
149  unsigned int pointcount;
150  unsigned int edgecount;
151  dReal saabb[6];
152  dxConvex(dSpaceID space,
153  dReal *planes,
154  unsigned int planecount,
155  dReal *points,
156  unsigned int pointcount,
157  unsigned int *polygons);
158  ~dxConvex()
159  {
160  if((edgecount!=0)&&(edges!=NULL)) delete[] edges;
161  }
162  void computeAABB();
163  struct edge
164  {
165  unsigned int first;
166  unsigned int second;
167  };
168  edge* edges;
169 
174  inline unsigned int SupportIndex(dVector3 dir)
175  {
176  dVector3 rdir;
177  unsigned int index=0;
178  dMultiply1_331 (rdir,final_posr->R,dir);
179  dReal max = dCalcVectorDot3(points,rdir);
180  dReal tmp;
181  for (unsigned int i = 1; i < pointcount; ++i)
182  {
183  tmp = dCalcVectorDot3(points+(i*3),rdir);
184  if (tmp > max)
185  {
186  index=i;
187  max = tmp;
188  }
189  }
190  return index;
191  }
192 
193 private:
194  // For Internal Use Only
197  void FillEdges();
198 #if 0
199  /*
200  What this does is the same as the Support function by doing some preprocessing
201  for optimization. Not complete yet.
202  */
203  // Based on Eberly's Game Physics Book page 307
204  struct Arc
205  {
206  // indices of polyhedron normals that form the spherical arc
207  int normals[2];
208  // index of edge shared by polyhedron faces
209  int edge;
210  };
211  struct Polygon
212  {
213  // indices of polyhedron normals that form the spherical polygon
214  std::vector<int> normals;
215  // index of extreme vertex corresponding to this polygon
216  int vertex;
217  };
218  // This is for extrem feature query and not the usual level BSP structure (that comes later)
219  struct BSPNode
220  {
221  // Normal index (interior node), vertex index (leaf node)
222  int normal;
223  // if Dot (E,D)>=0, D gets propagated to this child
224  BSPNode* right;
225  // if Dot (E,D)<0, D gets propagated to this child
226  BSPNode* left;
227  };
228  void CreateTree();
229  BSPNode* CreateNode(std::vector<Arc> Arcs,std::vector<Polygon> Polygons);
230  void GetFacesSharedByVertex(int i, std::vector<int> f);
231  void GetFacesSharedByEdge(int i, int* f);
232  void GetFaceNormal(int i, dVector3 normal);
233  BSPNode* tree;
234 #endif
235 };
236 
237 
238 #endif
Definition: collision_std.h:107
Describe the contact point between two geoms.
Definition: contact.h:88
unsigned int edgecount
Definition: collision_std.h:150
Definition: collision_std.h:141
Definition: collision_std.h:121
unsigned int SupportIndex(dVector3 dir)
A Support mapping function for convex shapes.
Definition: collision_std.h:174
dReal saabb[6]
Definition: collision_std.h:151
dReal * points
Definition: collision_std.h:146
Definition: collision_std.h:163
unsigned int pointcount
Definition: collision_std.h:149
Definition: collision_std.h:100
void FillEdges()
Fills the edges dynamic array based on points and polygons.
Definition: convex.cpp:124
Definition: collision_std.h:114
Definition: collision_std.h:128
Definition: collision_kernel.h:96
Definition: collision_kernel.h:202
unsigned int planecount
Definition: collision_std.h:148
Definition: collision_std.h:135
dReal * planes
Definition: collision_std.h:143