Debian Codegraph @

source/unix/odesrc/joints/ball.cpp

raw
1 /*************************************************************************
2 * *
3 * Open Dynamics Engine, Copyright (C) 2001,2002 Russell L. Smith. *
4 * All rights reserved. Email: [email protected] 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 #include <ode/odeconfig.h>
25 #include "config.h"
26 #include "ball.h"
27 #include "joint_internal.h"
28
29 //****************************************************************************
30 // ball and socket
31
32 dxJointBall::dxJointBall( dxWorld *w ) :
33 dxJoint( w )
34 {
35 dSetZero( anchor1, 4 );
36 dSetZero( anchor2, 4 );
37 erp = world->global_erp;
38 cfm = world->global_cfm;
39 }
40
41
42 void
43 dxJointBall::getSureMaxInfo( SureMaxInfo* info )
44 {
45 info->max_m = 3;
46 }
47
48
49 void
50 dxJointBall::getInfo1( dxJoint::Info1 *info )
51 {
52 info->m = 3;
53 info->nub = 3;
54 }
55
56
57 void
58 dxJointBall::getInfo2( dReal worldFPS, dReal /*worldERP*/,
59 int rowskip, dReal *J1, dReal *J2,
60 int pairskip, dReal *pairRhsCfm, dReal *pairLoHi,
61 int *findex )
62 {
63 pairRhsCfm[GI2_CFM] = cfm;
64 pairRhsCfm[pairskip + GI2_CFM] = cfm;
65 pairRhsCfm[2 * pairskip + GI2_CFM] = cfm;
66 setBall( this, worldFPS, this->erp, rowskip, J1, J2, pairskip, pairRhsCfm, anchor1, anchor2 );
67 }
68
69
70
71
72
73 void dJointSetBallAnchor( dJointID j, dReal x, dReal y, dReal z )
74 {
75 dxJointBall* joint = ( dxJointBall* )j;
76 dUASSERT( joint, "bad joint argument" );
77 checktype( joint, Ball );
78 setAnchors( joint, x, y, z, joint->anchor1, joint->anchor2 );
79 }
80
81
82 void dJointSetBallAnchor2( dJointID j, dReal x, dReal y, dReal z )
83 {
84 dxJointBall* joint = ( dxJointBall* )j;
85 dUASSERT( joint, "bad joint argument" );
86 checktype( joint, Ball );
87 joint->anchor2[0] = x;
88 joint->anchor2[1] = y;
89 joint->anchor2[2] = z;
90 joint->anchor2[3] = 0;
91 }
92
93 void dJointGetBallAnchor( dJointID j, dVector3 result )
94 {
95 dxJointBall* joint = ( dxJointBall* )j;
96 dUASSERT( joint, "bad joint argument" );
97 dUASSERT( result, "bad result argument" );
98 checktype( joint, Ball );
99 if ( joint->flags & dJOINT_REVERSE )
100 getAnchor2( joint, result, joint->anchor2 );
101 else
102 getAnchor( joint, result, joint->anchor1 );
103 }
104
105
106 void dJointGetBallAnchor2( dJointID j, dVector3 result )
107 {
108 dxJointBall* joint = ( dxJointBall* )j;
109 dUASSERT( joint, "bad joint argument" );
110 dUASSERT( result, "bad result argument" );
111 checktype( joint, Ball );
112 if ( joint->flags & dJOINT_REVERSE )
113 getAnchor( joint, result, joint->anchor1 );
114 else
115 getAnchor2( joint, result, joint->anchor2 );
116 }
117
118
119 void dxJointBall::set( int num, dReal value )
120 {
121 switch ( num )
122 {
123 case dParamCFM:
124 cfm = value;
125 break;
126 case dParamERP:
127 erp = value;
128 break;
129 }
130 }
131
132
133 dReal dxJointBall::get( int num )
134 {
135 switch ( num )
136 {
137 case dParamCFM:
138 return cfm;
139 case dParamERP:
140 return erp;
141 default:
142 return 0;
143 }
144 }
145
146
147 void dJointSetBallParam( dJointID j, int parameter, dReal value )
148 {
149 dxJointBall* joint = ( dxJointBall* )j;
150 dUASSERT( joint, "bad joint argument" );
151 checktype( joint, Ball );
152 joint->set( parameter, value );
153 }
154
155
156 dReal dJointGetBallParam( dJointID j, int parameter )
157 {
158 dxJointBall* joint = ( dxJointBall* )j;
159 dUASSERT( joint, "bad joint argument" );
160 checktype( joint, Ball );
161 return joint->get( parameter );
162 }
163
164
165 dJointType
166 dxJointBall::type() const
167 {
168 return dJointTypeBall;
169 }
170
171 size_t
172 dxJointBall::size() const
173 {
174 return sizeof( *this );
175 }
176
177 void
178 dxJointBall::setRelativeValues()
179 {
180 dVector3 anchor;
181 dJointGetBallAnchor(this, anchor);
182 setAnchors( this, anchor[0], anchor[1], anchor[2], anchor1, anchor2 );
183 }
184
185
186