1 /*************************************************************************
3 * Open Dynamics Engine, Copyright (C) 2001-2003 Russell L. Smith. *
4 * All rights reserved. Email: russ@q12.org Web: www.q12.org *
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 *
13 * (2) The BSD-style license that is included with this library in *
14 * the file LICENSE-BSD.TXT. *
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. *
21 *************************************************************************/
25 standard ODE geometry primitives: public API and pairwise collision functions.
27 the rule is that only the low level primitive collision functions should set
28 dContactGeom::g1 and dContactGeom::g2.
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>
38 #include "collision_kernel.h"
39 #include "collision_std.h"
40 #include "collision_util.h"
43 #pragma warning(disable:4291) // for VC++, no complaints about "no matching operator delete found"
46 // flat cylinder public API
48 dxCylinder::dxCylinder (dSpaceID space
, dReal _radius
, dReal _length
) :
51 dAASSERT (_radius
>= 0 && _length
>= 0);
52 type
= dCylinderClass
;
55 updateZeroSizedFlag(!_radius
|| !_length
);
59 void dxCylinder::computeAABB()
61 const dMatrix3
& R
= final_posr
->R
;
62 const dVector3
& pos
= final_posr
->pos
;
64 dReal xrange
= dFabs (R
[0] * radius
) + dFabs (R
[1] * radius
) + REAL(0.5)* dFabs (R
[2] *
66 dReal yrange
= dFabs (R
[4] * radius
) + dFabs (R
[5] * radius
) + REAL(0.5)* dFabs (R
[6] *
68 dReal zrange
= dFabs (R
[8] * radius
) + dFabs (R
[9] * radius
) + REAL(0.5)* dFabs (R
[10] *
70 aabb
[0] = pos
[0] - xrange
;
71 aabb
[1] = pos
[0] + xrange
;
72 aabb
[2] = pos
[1] - yrange
;
73 aabb
[3] = pos
[1] + yrange
;
74 aabb
[4] = pos
[2] - zrange
;
75 aabb
[5] = pos
[2] + zrange
;
79 dGeomID
dCreateCylinder (dSpaceID space
, dReal radius
, dReal length
)
81 return new dxCylinder (space
,radius
,length
);
84 void dGeomCylinderSetParams (dGeomID cylinder
, dReal radius
, dReal length
)
86 dUASSERT (cylinder
&& cylinder
->type
== dCylinderClass
,"argument not a ccylinder");
87 dAASSERT (radius
>= 0 && length
>= 0);
88 dxCylinder
*c
= (dxCylinder
*) cylinder
;
91 c
->updateZeroSizedFlag(!radius
|| !length
);
92 dGeomMoved (cylinder
);
95 void dGeomCylinderGetParams (dGeomID cylinder
, dReal
*radius
, dReal
*length
)
97 dUASSERT (cylinder
&& cylinder
->type
== dCylinderClass
,"argument not a ccylinder");
98 dxCylinder
*c
= (dxCylinder
*) cylinder
;