Debian Codegraph @

source/unix/odesrc/joints/fixed.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 "fixed.h"
27 #include "joint_internal.h"
28
29
30
31 //****************************************************************************
32 // fixed joint
33
34 dxJointFixed::dxJointFixed ( dxWorld *w ) :
35 dxJoint ( w )
36 {
37 dSetZero ( offset, 4 );
38 dSetZero ( qrel, 4 );
39 erp = world->global_erp;
40 cfm = world->global_cfm;
41 }
42
43
44 void
45 dxJointFixed::getSureMaxInfo( SureMaxInfo* info )
46 {
47 info->max_m = 6;
48 }
49
50
51 void
52 dxJointFixed::getInfo1 ( dxJoint::Info1 *info )
53 {
54 info->m = 6;
55 info->nub = 6;
56 }
57
58
59 void
60 dxJointFixed::getInfo2 ( dReal worldFPS, dReal worldERP,
61 int rowskip, dReal *J1, dReal *J2,
62 int pairskip, dReal *pairRhsCfm, dReal *pairLoHi,
63 int *findex )
64 {
65 // Three rows for orientation
66 setFixedOrientation ( this, worldFPS, worldERP,
67 rowskip, J1 + dSA__MAX * rowskip, J2 + dSA__MAX * rowskip,
68 pairskip, pairRhsCfm + dSA__MAX * pairskip, qrel );
69
70 // Three rows for position.
71 // set Jacobian
72 J1[GI2_JLX] = 1;
73 J1[rowskip + GI2_JLY] = 1;
74 J1[2 * rowskip + GI2_JLZ] = 1;
75
76 dReal k = worldFPS * this->erp;
77 dxBody *b0 = node[0].body, *b1 = node[1].body;
78
79 dVector3 ofs;
80 dMultiply0_331 ( ofs, b0->posr.R, offset );
81
82 if ( b1 ) {
83 dSetCrossMatrixPlus( J1 + GI2__JA_MIN, ofs, rowskip );
84
85 J2[GI2_JLX] = -1;
86 J2[rowskip + GI2_JLY] = -1;
87 J2[2 * rowskip + GI2_JLZ] = -1;
88 }
89
90 // set right hand side for the first three rows (linear)
91 if ( b1 ) {
92 for ( int j = 0, currPairSkip = 0; j < 3; currPairSkip += pairskip, ++j ) {
93 pairRhsCfm[currPairSkip + GI2_RHS] = k * ( b1->posr.pos[j] - b0->posr.pos[j] + ofs[j] );
94 }
95 } else {
96 for ( int j = 0, currPairSkip = 0; j < 3; currPairSkip += pairskip, ++j ) {
97 pairRhsCfm[currPairSkip + GI2_RHS] = k * ( offset[j] - b0->posr.pos[j] );
98 }
99 }
100
101 dReal cfm = this->cfm;
102 pairRhsCfm[GI2_CFM] = cfm;
103 pairRhsCfm[pairskip + GI2_CFM] = cfm;
104 pairRhsCfm[2 * pairskip + GI2_CFM] = cfm;
105 }
106
107
108 void dJointSetFixed ( dJointID j )
109 {
110 dxJointFixed* joint = ( dxJointFixed* ) j;
111 dUASSERT ( joint, "bad joint argument" );
112 checktype ( joint, Fixed );
113 int i;
114
115 // This code is taken from dJointSetSliderAxis(), we should really put the
116 // common code in its own function.
117 // compute the offset between the bodies
118 if ( joint->node[0].body )
119 {
120 if ( joint->node[1].body )
121 {
122 dReal ofs[4];
123 for ( i = 0; i < 4; i++ )
124 ofs[i] = joint->node[0].body->posr.pos[i] - joint->node[1].body->posr.pos[i];
125 dMultiply1_331 ( joint->offset, joint->node[0].body->posr.R, ofs );
126 }
127 else
128 {
129 joint->offset[0] = joint->node[0].body->posr.pos[0];
130 joint->offset[1] = joint->node[0].body->posr.pos[1];
131 joint->offset[2] = joint->node[0].body->posr.pos[2];
132 }
133 }
134
135 joint->computeInitialRelativeRotation();
136 }
137
138 void dxJointFixed::set ( int num, dReal value )
139 {
140 switch ( num )
141 {
142 case dParamCFM:
143 cfm = value;
144 break;
145 case dParamERP:
146 erp = value;
147 break;
148 }
149 }
150
151
152 dReal dxJointFixed::get ( int num )
153 {
154 switch ( num )
155 {
156 case dParamCFM:
157 return cfm;
158 case dParamERP:
159 return erp;
160 default:
161 return 0;
162 }
163 }
164
165
166 void dJointSetFixedParam ( dJointID j, int parameter, dReal value )
167 {
168 dxJointFixed* joint = ( dxJointFixed* ) j;
169 dUASSERT ( joint, "bad joint argument" );
170 checktype ( joint, Fixed );
171 joint->set ( parameter, value );
172 }
173
174
175 dReal dJointGetFixedParam ( dJointID j, int parameter )
176 {
177 dxJointFixed* joint = ( dxJointFixed* ) j;
178 dUASSERT ( joint, "bad joint argument" );
179 checktype ( joint, Fixed );
180 return joint->get ( parameter );
181 }
182
183
184 dJointType
185 dxJointFixed::type() const
186 {
187 return dJointTypeFixed;
188 }
189
190
191 size_t
192 dxJointFixed::size() const
193 {
194 return sizeof ( *this );
195 }
196
197 void
198 dxJointFixed::computeInitialRelativeRotation()
199 {
200 if (node[0].body )
201 {
202 if (node[1].body )
203 {
204 dQMultiply1 (qrel, node[0].body->q, node[1].body->q );
205 }
206 else
207 {
208 // set qrel to the transpose of the first body q
209 qrel[0] = node[0].body->q[0];
210 qrel[1] = -node[0].body->q[1];
211 qrel[2] = -node[0].body->q[2];
212 qrel[3] = -node[0].body->q[3];
213 }
214 }
215 }
216