|
1 /************************************************************************* |
|
2 * * |
|
3 * Open Dynamics Engine, Copyright (C) 2001-2003 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 standard ODE geometry primitives: public API and pairwise collision functions. |
|
26 |
|
27 the rule is that only the low level primitive collision functions should set |
|
28 dContactGeom::g1 and dContactGeom::g2. |
|
29 |
|
30 */ |
|
31 |
|
32 #include <ode/common.h> |
|
33 #include <ode/collision.h> |
|
34 #include <ode/matrix.h> |
|
35 #include <ode/rotation.h> |
|
36 #include <ode/odemath.h> |
|
37 #include "collision_kernel.h" |
|
38 #include "collision_std.h" |
|
39 #include "collision_util.h" |
|
40 |
|
41 // flat cylinder public API |
|
42 |
|
43 dxCylinder::dxCylinder (dSpaceID space, dReal _radius, dReal _length) : |
|
44 dxGeom (space,1) |
|
45 { |
|
46 |
|
47 type = dCylinderClass; |
|
48 radius = _radius; |
|
49 lz = _length; |
|
50 } |
|
51 |
|
52 |
|
53 void dxCylinder::computeAABB() |
|
54 { |
|
55 const dMatrix3& R = final_posr->R; |
|
56 const dVector3& pos = final_posr->pos; |
|
57 |
|
58 dReal xrange = dFabs (dMUL(R[0],radius)) + dFabs (dMUL(R[1],radius)) + dMUL(REAL(0.5),dFabs (dMUL(R[2],lz))); |
|
59 dReal yrange = dFabs (dMUL(R[4],radius)) + dFabs (dMUL(R[5],radius)) + dMUL(REAL(0.5),dFabs (dMUL(R[6],lz))); |
|
60 dReal zrange = dFabs (dMUL(R[8],radius)) + dFabs (dMUL(R[9],radius)) + dMUL(REAL(0.5),dFabs (dMUL(R[10],lz))); |
|
61 aabb[0] = pos[0] - xrange; |
|
62 aabb[1] = pos[0] + xrange; |
|
63 aabb[2] = pos[1] - yrange; |
|
64 aabb[3] = pos[1] + yrange; |
|
65 aabb[4] = pos[2] - zrange; |
|
66 aabb[5] = pos[2] + zrange; |
|
67 } |
|
68 |
|
69 |
|
70 EXPORT_C dGeomID dCreateCylinder (dSpaceID space, dReal radius, dReal length) |
|
71 { |
|
72 return new dxCylinder (space,radius,length); |
|
73 } |
|
74 |
|
75 EXPORT_C void dGeomCylinderSetParams (dGeomID cylinder, dReal radius, dReal length) |
|
76 { |
|
77 |
|
78 dxCylinder *c = (dxCylinder*) cylinder; |
|
79 c->radius = radius; |
|
80 c->lz = length; |
|
81 dGeomMoved (cylinder); |
|
82 } |
|
83 |
|
84 EXPORT_C void dGeomCylinderGetParams (dGeomID cylinder, dReal *radius, dReal *length) |
|
85 { |
|
86 |
|
87 dxCylinder *c = (dxCylinder*) cylinder; |
|
88 *radius = c->radius; |
|
89 *length = c->lz; |
|
90 } |
|
91 |
|
92 |