Debian Codegraph @

source/unix/odesrc/joints/lmotor.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 "lmotor.h"
27 #include "joint_internal.h"
28
29
30 //****************************************************************************
31 // lmotor joint
32 dxJointLMotor::dxJointLMotor( dxWorld *w ) :
33 dxJoint( w )
34 {
35 int i;
36 num = 0;
37 for ( i = 0;i < 3;i++ )
38 {
39 dSetZero( axis[i], 4 );
40 limot[i].init( world );
41 }
42 }
43
44 void
45 dxJointLMotor::computeGlobalAxes( dVector3 ax[3] )
46 {
47 for ( int i = 0; i < num; i++ )
48 {
49 if ( rel[i] == 1 )
50 {
51 dMultiply0_331( ax[i], node[0].body->posr.R, axis[i] );
52 }
53 else if ( rel[i] == 2 )
54 {
55 if ( node[1].body ) // jds: don't assert, just ignore
56 {
57 dMultiply0_331( ax[i], node[1].body->posr.R, axis[i] );
58 }
59 }
60 else
61 {
62 ax[i][0] = axis[i][0];
63 ax[i][1] = axis[i][1];
64 ax[i][2] = axis[i][2];
65 }
66 }
67 }
68
69 void
70 dxJointLMotor::getSureMaxInfo( SureMaxInfo* info )
71 {
72 info->max_m = num;
73 }
74
75 void
76 dxJointLMotor::getInfo1( dxJoint::Info1 *info )
77 {
78 info->m = 0;
79 info->nub = 0;
80 for ( int i = 0; i < num; i++ )
81 {
82 if ( limot[i].fmax > 0 )
83 {
84 info->m++;
85 }
86 }
87 }
88
89 void
90 dxJointLMotor::getInfo2( dReal worldFPS, dReal /*worldERP*/,
91 int rowskip, dReal *J1, dReal *J2,
92 int pairskip, dReal *pairRhsCfm, dReal *pairLoHi,
93 int *findex )
94 {
95 dVector3 ax[3];
96 computeGlobalAxes( ax );
97
98 int currRowSkip = 0, currPairSkip = 0;
99 for ( int i = 0; i < num; ++i ) {
100 if (limot[i].addLimot( this, worldFPS, J1 + currRowSkip, J2 + currRowSkip, pairRhsCfm + currPairSkip, pairLoHi + currPairSkip, ax[i], 0 )) {
101 currRowSkip += rowskip; currPairSkip += pairskip;
102 }
103 }
104 }
105
106 void dJointSetLMotorAxis( dJointID j, int anum, int rel, dReal x, dReal y, dReal z )
107 {
108 dxJointLMotor* joint = ( dxJointLMotor* )j;
109 //for now we are ignoring rel!
110 dAASSERT( joint && anum >= 0 && anum <= 2 && rel >= 0 && rel <= 2 );
111 checktype( joint, LMotor );
112
113 if ( anum < 0 ) anum = 0;
114 if ( anum > 2 ) anum = 2;
115
116 if ( !joint->node[1].body && rel == 2 ) rel = 1; //ref 1
117
118 joint->rel[anum] = rel;
119
120 dVector3 r;
121 r[0] = x;
122 r[1] = y;
123 r[2] = z;
124 r[3] = 0;
125 if ( rel > 0 )
126 {
127 if ( rel == 1 )
128 {
129 dMultiply1_331( joint->axis[anum], joint->node[0].body->posr.R, r );
130 }
131 else
132 {
133 //second body has to exists thanks to ref 1 line
134 dMultiply1_331( joint->axis[anum], joint->node[1].body->posr.R, r );
135 }
136 }
137 else
138 {
139 joint->axis[anum][0] = r[0];
140 joint->axis[anum][1] = r[1];
141 joint->axis[anum][2] = r[2];
142 }
143
144 dNormalize3( joint->axis[anum] );
145 }
146
147 void dJointSetLMotorNumAxes( dJointID j, int num )
148 {
149 dxJointLMotor* joint = ( dxJointLMotor* )j;
150 dAASSERT( joint && num >= 0 && num <= 3 );
151 checktype( joint, LMotor );
152 if ( num < 0 ) num = 0;
153 if ( num > 3 ) num = 3;
154 joint->num = num;
155 }
156
157 void dJointSetLMotorParam( dJointID j, int parameter, dReal value )
158 {
159 dxJointLMotor* joint = ( dxJointLMotor* )j;
160 dAASSERT( joint );
161 checktype( joint, LMotor );
162 int anum = parameter >> 8;
163 if ( anum < 0 ) anum = 0;
164 if ( anum > 2 ) anum = 2;
165 parameter &= 0xff;
166 joint->limot[anum].set( parameter, value );
167 }
168
169 int dJointGetLMotorNumAxes( dJointID j )
170 {
171 dxJointLMotor* joint = ( dxJointLMotor* )j;
172 dAASSERT( joint );
173 checktype( joint, LMotor );
174 return joint->num;
175 }
176
177
178 void dJointGetLMotorAxis( dJointID j, int anum, dVector3 result )
179 {
180 dxJointLMotor* joint = ( dxJointLMotor* )j;
181 dAASSERT( joint && anum >= 0 && anum < 3 );
182 checktype( joint, LMotor );
183 if ( anum < 0 ) anum = 0;
184 if ( anum > 2 ) anum = 2;
185 result[0] = joint->axis[anum][0];
186 result[1] = joint->axis[anum][1];
187 result[2] = joint->axis[anum][2];
188 }
189
190 dReal dJointGetLMotorParam( dJointID j, int parameter )
191 {
192 dxJointLMotor* joint = ( dxJointLMotor* )j;
193 dAASSERT( joint );
194 checktype( joint, LMotor );
195 int anum = parameter >> 8;
196 if ( anum < 0 ) anum = 0;
197 if ( anum > 2 ) anum = 2;
198 parameter &= 0xff;
199 return joint->limot[anum].get( parameter );
200 }
201
202 dJointType
203 dxJointLMotor::type() const
204 {
205 return dJointTypeLMotor;
206 }
207
208
209 size_t
210 dxJointLMotor::size() const
211 {
212 return sizeof( *this );
213 }
214