| 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 "pu.h" |
| 27 |
#include "joint_internal.h" |
| 28 |
|
| 29 |
|
| 30 |
//**************************************************************************** |
| 31 |
// Prismatic and Universal |
| 32 |
|
| 33 |
dxJointPU::dxJointPU( dxWorld *w ) : |
| 34 |
dxJointUniversal( w ) |
| 35 |
{ |
| 36 |
// Default Position |
| 37 |
// Y ^ Axis2 |
| 38 |
// ^ | |
| 39 |
// / | ^ Axis1 |
| 40 |
// Z^ / | / |
| 41 |
// | / Body 2 | / Body 1 |
| 42 |
// | / +---------+ | / +-----------+ |
| 43 |
// | / / /| | / / /| |
| 44 |
// | / / / + _/ - / / + |
| 45 |
// | / / /-/--------(_)----|--- /-----------/-------> AxisP |
| 46 |
// | / +---------+ / - +-----------+ / |
| 47 |
// | / | |/ | |/ |
| 48 |
// | / +---------+ +-----------+ |
| 49 |
// |/ |
| 50 |
// .-----------------------------------------> X |
| 51 |
// |-----------------> |
| 52 |
// Anchor2 <--------------| |
| 53 |
// Anchor1 |
| 54 |
// |
| 55 |
|
| 56 |
// Setting member variables which are w.r.t body2 |
| 57 |
dSetZero( axis1, 4 ); |
| 58 |
axis1[1] = 1; |
| 59 |
|
| 60 |
// Setting member variables which are w.r.t body2 |
| 61 |
dSetZero( anchor2, 4 ); |
| 62 |
dSetZero( axis2, 4 ); |
| 63 |
axis2[2] = 1; |
| 64 |
|
| 65 |
dSetZero( axisP1, 4 ); |
| 66 |
axisP1[0] = 1; |
| 67 |
|
| 68 |
dSetZero( qrel1, 4 ); |
| 69 |
dSetZero( qrel2, 4 ); |
| 70 |
|
| 71 |
|
| 72 |
limotP.init( world ); |
| 73 |
limot1.init( world ); |
| 74 |
limot2.init( world ); |
| 75 |
} |
| 76 |
|
| 77 |
|
| 78 |
dReal dJointGetPUPosition( dJointID j ) |
| 79 |
{ |
| 80 |
dxJointPU* joint = ( dxJointPU* ) j; |
| 81 |
dUASSERT( joint, "bad joint argument" ); |
| 82 |
checktype( joint, PU ); |
| 83 |
|
| 84 |
dVector3 q; |
| 85 |
// get the offset in global coordinates |
| 86 |
dMultiply0_331( q, joint->node[0].body->posr.R, joint->anchor1 ); |
| 87 |
|
| 88 |
if ( joint->node[1].body ) |
| 89 |
{ |
| 90 |
dVector3 anchor2; |
| 91 |
|
| 92 |
// get the anchor2 in global coordinates |
| 93 |
dMultiply0_331( anchor2, joint->node[1].body->posr.R, joint->anchor2 ); |
| 94 |
|
| 95 |
q[0] = (( joint->node[0].body->posr.pos[0] + q[0] ) - |
| 96 |
( joint->node[1].body->posr.pos[0] + anchor2[0] ) ); |
| 97 |
q[1] = (( joint->node[0].body->posr.pos[1] + q[1] ) - |
| 98 |
( joint->node[1].body->posr.pos[1] + anchor2[1] ) ); |
| 99 |
q[2] = (( joint->node[0].body->posr.pos[2] + q[2] ) - |
| 100 |
( joint->node[1].body->posr.pos[2] + anchor2[2] ) ); |
| 101 |
} |
| 102 |
else |
| 103 |
{ |
| 104 |
//N.B. When there is no body 2 the joint->anchor2 is already in |
| 105 |
// global coordinates |
| 106 |
|
| 107 |
q[0] = (( joint->node[0].body->posr.pos[0] + q[0] ) - |
| 108 |
( joint->anchor2[0] ) ); |
| 109 |
q[1] = (( joint->node[0].body->posr.pos[1] + q[1] ) - |
| 110 |
( joint->anchor2[1] ) ); |
| 111 |
q[2] = (( joint->node[0].body->posr.pos[2] + q[2] ) - |
| 112 |
( joint->anchor2[2] ) ); |
| 113 |
|
| 114 |
if ( joint->flags & dJOINT_REVERSE ) |
| 115 |
{ |
| 116 |
q[0] = -q[0]; |
| 117 |
q[1] = -q[1]; |
| 118 |
q[2] = -q[2]; |
| 119 |
} |
| 120 |
} |
| 121 |
|
| 122 |
dVector3 axP; |
| 123 |
// get prismatic axis in global coordinates |
| 124 |
dMultiply0_331( axP, joint->node[0].body->posr.R, joint->axisP1 ); |
| 125 |
|
| 126 |
return dCalcVectorDot3( axP, q ); |
| 127 |
} |
| 128 |
|
| 129 |
|
| 130 |
dReal dJointGetPUPositionRate( dJointID j ) |
| 131 |
{ |
| 132 |
dxJointPU* joint = ( dxJointPU* ) j; |
| 133 |
dUASSERT( joint, "bad joint argument" ); |
| 134 |
checktype( joint, PU ); |
| 135 |
|
| 136 |
if ( joint->node[0].body ) |
| 137 |
{ |
| 138 |
// We want to find the rate of change of the prismatic part of the joint |
| 139 |
// We can find it by looking at the speed difference between body1 and the |
| 140 |
// anchor point. |
| 141 |
|
| 142 |
// r will be used to find the distance between body1 and the anchor point |
| 143 |
dVector3 r; |
| 144 |
dVector3 anchor2 = {0,0,0}; |
| 145 |
if ( joint->node[1].body ) |
| 146 |
{ |
| 147 |
// Find joint->anchor2 in global coordinates |
| 148 |
dMultiply0_331( anchor2, joint->node[1].body->posr.R, joint->anchor2 ); |
| 149 |
|
| 150 |
r[0] = ( joint->node[0].body->posr.pos[0] - |
| 151 |
( anchor2[0] + joint->node[1].body->posr.pos[0] ) ); |
| 152 |
r[1] = ( joint->node[0].body->posr.pos[1] - |
| 153 |
( anchor2[1] + joint->node[1].body->posr.pos[1] ) ); |
| 154 |
r[2] = ( joint->node[0].body->posr.pos[2] - |
| 155 |
( anchor2[2] + joint->node[1].body->posr.pos[2] ) ); |
| 156 |
} |
| 157 |
else |
| 158 |
{ |
| 159 |
//N.B. When there is no body 2 the joint->anchor2 is already in |
| 160 |
// global coordinates |
| 161 |
// r = joint->node[0].body->posr.pos - joint->anchor2; |
| 162 |
dSubtractVectors3( r, joint->node[0].body->posr.pos, joint->anchor2 ); |
| 163 |
} |
| 164 |
|
| 165 |
// The body1 can have velocity coming from the rotation of |
| 166 |
// the rotoide axis. We need to remove this. |
| 167 |
|
| 168 |
// N.B. We do vel = r X w instead of vel = w x r to have vel negative |
| 169 |
// since we want to remove it from the linear velocity of the body |
| 170 |
dVector3 lvel1; |
| 171 |
dCalcVectorCross3( lvel1, r, joint->node[0].body->avel ); |
| 172 |
|
| 173 |
// lvel1 += joint->node[0].body->lvel; |
| 174 |
dAddVectors3( lvel1, lvel1, joint->node[0].body->lvel ); |
| 175 |
|
| 176 |
// Since we want rate of change along the prismatic axis |
| 177 |
// get axisP1 in global coordinates and get the component |
| 178 |
// along this axis only |
| 179 |
dVector3 axP1; |
| 180 |
dMultiply0_331( axP1, joint->node[0].body->posr.R, joint->axisP1 ); |
| 181 |
|
| 182 |
if ( joint->node[1].body ) |
| 183 |
{ |
| 184 |
// Find the contribution of the angular rotation to the linear speed |
| 185 |
// N.B. We do vel = r X w instead of vel = w x r to have vel negative |
| 186 |
// since we want to remove it from the linear velocity of the body |
| 187 |
dVector3 lvel2; |
| 188 |
dCalcVectorCross3( lvel2, anchor2, joint->node[1].body->avel ); |
| 189 |
|
| 190 |
// lvel1 -= lvel2 + joint->node[1].body->lvel; |
| 191 |
dVector3 tmp; |
| 192 |
dAddVectors3( tmp, lvel2, joint->node[1].body->lvel ); |
| 193 |
dSubtractVectors3( lvel1, lvel1, tmp ); |
| 194 |
|
| 195 |
return dCalcVectorDot3( axP1, lvel1 ); |
| 196 |
} |
| 197 |
else |
| 198 |
{ |
| 199 |
dReal rate = dCalcVectorDot3( axP1, lvel1 ); |
| 200 |
return ( (joint->flags & dJOINT_REVERSE) ? -rate : rate); |
| 201 |
} |
| 202 |
} |
| 203 |
|
| 204 |
return 0.0; |
| 205 |
} |
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
void |
| 210 |
dxJointPU::getSureMaxInfo( SureMaxInfo* info ) |
| 211 |
{ |
| 212 |
info->max_m = 6; |
| 213 |
} |
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
void |
| 218 |
dxJointPU::getInfo1( dxJoint::Info1 *info ) |
| 219 |
{ |
| 220 |
info->m = 3; |
| 221 |
info->nub = 3; |
| 222 |
|
| 223 |
// powered needs an extra constraint row |
| 224 |
|
| 225 |
// see if we're at a joint limit. |
| 226 |
limotP.limit = 0; |
| 227 |
if (( limotP.lostop > -dInfinity || limotP.histop < dInfinity ) && |
| 228 |
limotP.lostop <= limotP.histop ) |
| 229 |
{ |
| 230 |
// measure joint position |
| 231 |
dReal pos = dJointGetPUPosition( this ); |
| 232 |
limotP.testRotationalLimit( pos ); // N.B. The function is ill named |
| 233 |
} |
| 234 |
|
| 235 |
if ( limotP.limit || limotP.fmax > 0 ) info->m++; |
| 236 |
|
| 237 |
|
| 238 |
bool limiting1 = ( limot1.lostop >= -M_PI || limot1.histop <= M_PI ) && |
| 239 |
limot1.lostop <= limot1.histop; |
| 240 |
bool limiting2 = ( limot2.lostop >= -M_PI || limot2.histop <= M_PI ) && |
| 241 |
limot2.lostop <= limot2.histop; |
| 242 |
|
| 243 |
// We need to call testRotationLimit() even if we're motored, since it |
| 244 |
// records the result. |
| 245 |
limot1.limit = 0; |
| 246 |
limot2.limit = 0; |
| 247 |
if ( limiting1 || limiting2 ) |
| 248 |
{ |
| 249 |
dReal angle1, angle2; |
| 250 |
getAngles( &angle1, &angle2 ); |
| 251 |
if ( limiting1 ) |
| 252 |
limot1.testRotationalLimit( angle1 ); |
| 253 |
if ( limiting2 ) |
| 254 |
limot2.testRotationalLimit( angle2 ); |
| 255 |
} |
| 256 |
|
| 257 |
if ( limot1.limit || limot1.fmax > 0 ) info->m++; |
| 258 |
if ( limot2.limit || limot2.fmax > 0 ) info->m++; |
| 259 |
} |
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
void |
| 264 |
dxJointPU::getInfo2( dReal worldFPS, dReal worldERP, |
| 265 |
int rowskip, dReal *J1, dReal *J2, |
| 266 |
int pairskip, dReal *pairRhsCfm, dReal *pairLoHi, |
| 267 |
int *findex ) |
| 268 |
{ |
| 269 |
const dReal k = worldFPS * worldERP; |
| 270 |
|
| 271 |
// ====================================================================== |
| 272 |
// The angular constraint |
| 273 |
// |
| 274 |
dVector3 ax1, ax2; // Global axes of rotation |
| 275 |
getAxis(this, ax1, axis1); |
| 276 |
getAxis2(this,ax2, axis2); |
| 277 |
|
| 278 |
dVector3 uniPerp; // Axis perpendicular to axes of rotation |
| 279 |
dCalcVectorCross3(uniPerp,ax1,ax2); |
| 280 |
dNormalize3( uniPerp ); |
| 281 |
|
| 282 |
dCopyVector3( J1 + GI2__JA_MIN, uniPerp ); |
| 283 |
|
| 284 |
dxBody *body1 = node[1].body; |
| 285 |
|
| 286 |
if ( body1 ) { |
| 287 |
dCopyNegatedVector3( J2 + GI2__JA_MIN , uniPerp ); |
| 288 |
} |
| 289 |
// Corrective velocity attempting to keep uni axes perpendicular |
| 290 |
dReal val = dCalcVectorDot3( ax1, ax2 ); |
| 291 |
// Small angle approximation : |
| 292 |
// theta = asin(val) |
| 293 |
// theta is approximately val when val is near zero. |
| 294 |
pairRhsCfm[GI2_RHS] = -k * val; |
| 295 |
|
| 296 |
// ========================================================================== |
| 297 |
// Handle axes orthogonal to the prismatic |
| 298 |
dVector3 an1, an2; // Global anchor positions |
| 299 |
dVector3 axP, sep; // Prismatic axis and separation vector |
| 300 |
getAnchor(this, an1, anchor1); |
| 301 |
getAnchor2(this, an2, anchor2); |
| 302 |
|
| 303 |
if (flags & dJOINT_REVERSE) { |
| 304 |
getAxis2(this, axP, axisP1); |
| 305 |
} else { |
| 306 |
getAxis(this, axP, axisP1); |
| 307 |
} |
| 308 |
dSubtractVectors3(sep, an2, an1); |
| 309 |
|
| 310 |
dVector3 p, q; |
| 311 |
dPlaneSpace(axP, p, q); |
| 312 |
|
| 313 |
dCopyVector3( J1 + rowskip + GI2__JL_MIN, p ); |
| 314 |
dCopyVector3( J1 + 2 * rowskip + GI2__JL_MIN, q ); |
| 315 |
// Make the anchors be body local |
| 316 |
// Aliasing isn't a problem here. |
| 317 |
dSubtractVectors3(an1, an1, node[0].body->posr.pos); |
| 318 |
dCalcVectorCross3( J1 + rowskip + GI2__JA_MIN, an1, p ); |
| 319 |
dCalcVectorCross3( J1 + 2 * rowskip + GI2__JA_MIN, an1, q ); |
| 320 |
|
| 321 |
if (body1) { |
| 322 |
dCopyNegatedVector3( J2 + rowskip + GI2__JL_MIN, p ); |
| 323 |
dCopyNegatedVector3( J2 + 2 * rowskip + GI2__JL_MIN, q ); |
| 324 |
dSubtractVectors3(an2, an2, body1->posr.pos); |
| 325 |
dCalcVectorCross3( J2 + rowskip + GI2__JA_MIN, p, an2 ); |
| 326 |
dCalcVectorCross3( J2 + 2 * rowskip + GI2__JA_MIN, q, an2 ); |
| 327 |
} |
| 328 |
|
| 329 |
pairRhsCfm[pairskip + GI2_RHS] = k * dCalcVectorDot3( p, sep ); |
| 330 |
pairRhsCfm[2 * pairskip + GI2_RHS] = k * dCalcVectorDot3( q, sep ); |
| 331 |
|
| 332 |
// ========================================================================== |
| 333 |
// Handle the limits/motors |
| 334 |
int currRowSkip = 3 * rowskip, currPairSkip = 3 * pairskip; |
| 335 |
|
| 336 |
if (limot1.addLimot( this, worldFPS, J1 + currRowSkip, J2 + currRowSkip, pairRhsCfm + currPairSkip, pairLoHi + currPairSkip, ax1, 1 )) { |
| 337 |
currRowSkip += rowskip; currPairSkip += pairskip; |
| 338 |
} |
| 339 |
|
| 340 |
if (limot2.addLimot( this, worldFPS, J1 + currRowSkip, J2 + currRowSkip, pairRhsCfm + currPairSkip, pairLoHi + currPairSkip, ax2, 1 )) { |
| 341 |
currRowSkip += rowskip; currPairSkip += pairskip; |
| 342 |
} |
| 343 |
|
| 344 |
if ( body1 || (flags & dJOINT_REVERSE) == 0 ) { |
| 345 |
limotP.addTwoPointLimot( this, worldFPS, J1 + currRowSkip, J2 + currRowSkip, pairRhsCfm + currPairSkip, pairLoHi + currPairSkip, axP, an1, an2 ); |
| 346 |
} else { |
| 347 |
dNegateVector3(axP); |
| 348 |
limotP.addTwoPointLimot ( this, worldFPS, J1 + currRowSkip, J2 + currRowSkip, pairRhsCfm + currPairSkip, pairLoHi + currPairSkip, axP, an1, an2 ); |
| 349 |
} |
| 350 |
} |
| 351 |
|
| 352 |
void dJointSetPUAnchor( dJointID j, dReal x, dReal y, dReal z ) |
| 353 |
{ |
| 354 |
dxJointPU* joint = ( dxJointPU* ) j; |
| 355 |
dUASSERT( joint, "bad joint argument" ); |
| 356 |
checktype( joint, PU ); |
| 357 |
setAnchors( joint, x, y, z, joint->anchor1, joint->anchor2 ); |
| 358 |
joint->computeInitialRelativeRotations(); |
| 359 |
} |
| 360 |
|
| 361 |
/** |
| 362 |
* This function initialize the anchor and the relative position of each body |
| 363 |
* as if body2 was at its current position + [dx,dy,dy]. |
| 364 |
* Ex: |
| 365 |
* <PRE> |
| 366 |
* dReal offset = 1; |
| 367 |
* dVector3 dir; |
| 368 |
* dJointGetPUAxis3(jId, dir); |
| 369 |
* dJointSetPUAnchor(jId, 0, 0, 0); |
| 370 |
* // If you request the position you will have: dJointGetPUPosition(jId) == 0 |
| 371 |
* dJointSetPUAnchorDelta(jId, 0, 0, 0, dir[X]*offset, dir[Y]*offset, dir[Z]*offset); |
| 372 |
* // If you request the position you will have: dJointGetPUPosition(jId) == -offset |
| 373 |
* </PRE> |
| 374 |
|
| 375 |
* @param j The PU joint for which the anchor point will be set |
| 376 |
* @param x The X position of the anchor point in world frame |
| 377 |
* @param y The Y position of the anchor point in world frame |
| 378 |
* @param z The Z position of the anchor point in world frame |
| 379 |
* @param dx A delta to be added to the X position as if the anchor was set |
| 380 |
* when body1 was at current_position[X] + dx |
| 381 |
* @param dx A delta to be added to the Y position as if the anchor was set |
| 382 |
* when body1 was at current_position[Y] + dy |
| 383 |
* @param dx A delta to be added to the Z position as if the anchor was set |
| 384 |
* when body1 was at current_position[Z] + dz |
| 385 |
* @note Should have the same meaning as dJointSetSliderAxisDelta |
| 386 |
*/ |
| 387 |
void dJointSetPUAnchorDelta( dJointID j, dReal x, dReal y, dReal z, |
| 388 |
dReal dx, dReal dy, dReal dz ) |
| 389 |
{ |
| 390 |
dxJointPU* joint = ( dxJointPU* ) j; |
| 391 |
dUASSERT( joint, "bad joint argument" ); |
| 392 |
checktype( joint, PU ); |
| 393 |
|
| 394 |
if ( joint->node[0].body ) |
| 395 |
{ |
| 396 |
joint->node[0].body->posr.pos[0] += dx; |
| 397 |
joint->node[0].body->posr.pos[1] += dy; |
| 398 |
joint->node[0].body->posr.pos[2] += dz; |
| 399 |
} |
| 400 |
|
| 401 |
setAnchors( joint, x, y, z, joint->anchor1, joint->anchor2 ); |
| 402 |
|
| 403 |
if ( joint->node[0].body ) |
| 404 |
{ |
| 405 |
joint->node[0].body->posr.pos[0] -= dx; |
| 406 |
joint->node[0].body->posr.pos[1] -= dy; |
| 407 |
joint->node[0].body->posr.pos[2] -= dz; |
| 408 |
} |
| 409 |
|
| 410 |
joint->computeInitialRelativeRotations(); |
| 411 |
} |
| 412 |
|
| 413 |
/** |
| 414 |
* \brief This function initialize the anchor and the relative position of each body |
| 415 |
* such that dJointGetPUPosition will return the dot product of axis and [dx,dy,dy]. |
| 416 |
* |
| 417 |
* The body 1 is moved to [-dx, -dy, -dx] then the anchor is set. This will be the |
| 418 |
* position 0 for the prismatic part of the joint. Then the body 1 is moved to its |
| 419 |
* original position. |
| 420 |
* |
| 421 |
* Ex: |
| 422 |
* <PRE> |
| 423 |
* dReal offset = 1; |
| 424 |
* dVector3 dir; |
| 425 |
* dJointGetPUAxis3(jId, dir); |
| 426 |
* dJointSetPUAnchor(jId, 0, 0, 0); |
| 427 |
* // If you request the position you will have: dJointGetPUPosition(jId) == 0 |
| 428 |
* dJointSetPUAnchorDelta(jId, 0, 0, 0, dir[X]*offset, dir[Y]*offset, dir[Z]*offset); |
| 429 |
* // If you request the position you will have: dJointGetPUPosition(jId) == offset |
| 430 |
* </PRE> |
| 431 |
|
| 432 |
* @param j The PU joint for which the anchor point will be set |
| 433 |
* @param x The X position of the anchor point in world frame |
| 434 |
* @param y The Y position of the anchor point in world frame |
| 435 |
* @param z The Z position of the anchor point in world frame |
| 436 |
* @param dx A delta to be added to the X position as if the anchor was set |
| 437 |
* when body1 was at current_position[X] + dx |
| 438 |
* @param dx A delta to be added to the Y position as if the anchor was set |
| 439 |
* when body1 was at current_position[Y] + dy |
| 440 |
* @param dx A delta to be added to the Z position as if the anchor was set |
| 441 |
* when body1 was at current_position[Z] + dz |
| 442 |
* @note Should have the same meaning as dJointSetSliderAxisDelta |
| 443 |
*/ |
| 444 |
void dJointSetPUAnchorOffset( dJointID j, dReal x, dReal y, dReal z, |
| 445 |
dReal dx, dReal dy, dReal dz ) |
| 446 |
{ |
| 447 |
dxJointPU* joint = ( dxJointPU* ) j; |
| 448 |
dUASSERT( joint, "bad joint argument" ); |
| 449 |
checktype( joint, PU ); |
| 450 |
|
| 451 |
if (joint->flags & dJOINT_REVERSE) |
| 452 |
{ |
| 453 |
dx = -dx; |
| 454 |
dy = -dy; |
| 455 |
dz = -dz; |
| 456 |
} |
| 457 |
|
| 458 |
if ( joint->node[0].body ) |
| 459 |
{ |
| 460 |
joint->node[0].body->posr.pos[0] -= dx; |
| 461 |
joint->node[0].body->posr.pos[1] -= dy; |
| 462 |
joint->node[0].body->posr.pos[2] -= dz; |
| 463 |
} |
| 464 |
|
| 465 |
setAnchors( joint, x, y, z, joint->anchor1, joint->anchor2 ); |
| 466 |
|
| 467 |
if ( joint->node[0].body ) |
| 468 |
{ |
| 469 |
joint->node[0].body->posr.pos[0] += dx; |
| 470 |
joint->node[0].body->posr.pos[1] += dy; |
| 471 |
joint->node[0].body->posr.pos[2] += dz; |
| 472 |
} |
| 473 |
|
| 474 |
joint->computeInitialRelativeRotations(); |
| 475 |
} |
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
void dJointSetPUAxis1( dJointID j, dReal x, dReal y, dReal z ) |
| 482 |
{ |
| 483 |
dxJointPU* joint = ( dxJointPU* ) j; |
| 484 |
dUASSERT( joint, "bad joint argument" ); |
| 485 |
checktype( joint, PU ); |
| 486 |
if ( joint->flags & dJOINT_REVERSE ) |
| 487 |
setAxes( joint, x, y, z, NULL, joint->axis2 ); |
| 488 |
else |
| 489 |
setAxes( joint, x, y, z, joint->axis1, NULL ); |
| 490 |
joint->computeInitialRelativeRotations(); |
| 491 |
} |
| 492 |
|
| 493 |
void dJointSetPUAxis2( dJointID j, dReal x, dReal y, dReal z ) |
| 494 |
{ |
| 495 |
dxJointPU* joint = ( dxJointPU* ) j; |
| 496 |
dUASSERT( joint, "bad joint argument" ); |
| 497 |
checktype( joint, PU ); |
| 498 |
if ( joint->flags & dJOINT_REVERSE ) |
| 499 |
setAxes( joint, x, y, z, joint->axis1, NULL ); |
| 500 |
else |
| 501 |
setAxes( joint, x, y, z, NULL, joint->axis2 ); |
| 502 |
joint->computeInitialRelativeRotations(); |
| 503 |
} |
| 504 |
|
| 505 |
|
| 506 |
void dJointSetPUAxisP( dJointID id, dReal x, dReal y, dReal z ) |
| 507 |
{ |
| 508 |
dJointSetPUAxis3( id, x, y, z ); |
| 509 |
} |
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
void dJointSetPUAxis3( dJointID j, dReal x, dReal y, dReal z ) |
| 514 |
{ |
| 515 |
dxJointPU* joint = ( dxJointPU* ) j; |
| 516 |
dUASSERT( joint, "bad joint argument" ); |
| 517 |
checktype( joint, PU ); |
| 518 |
|
| 519 |
setAxes( joint, x, y, z, joint->axisP1, 0 ); |
| 520 |
|
| 521 |
joint->computeInitialRelativeRotations(); |
| 522 |
} |
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
void dJointGetPUAngles( dJointID j, dReal *angle1, dReal *angle2 ) |
| 528 |
{ |
| 529 |
dxJointUniversal* joint = ( dxJointUniversal* ) j; |
| 530 |
dUASSERT( joint, "bad joint argument" ); |
| 531 |
checktype( joint, PU ); |
| 532 |
if ( joint->flags & dJOINT_REVERSE ) |
| 533 |
joint->getAngles( angle2, angle1 ); |
| 534 |
else |
| 535 |
joint->getAngles( angle1, angle2 ); |
| 536 |
} |
| 537 |
|
| 538 |
|
| 539 |
dReal dJointGetPUAngle1( dJointID j ) |
| 540 |
{ |
| 541 |
dxJointUniversal* joint = ( dxJointUniversal* ) j; |
| 542 |
dUASSERT( joint, "bad joint argument" ); |
| 543 |
checktype( joint, PU ); |
| 544 |
if ( joint->flags & dJOINT_REVERSE ) |
| 545 |
return joint->getAngle2(); |
| 546 |
else |
| 547 |
return joint->getAngle1(); |
| 548 |
} |
| 549 |
|
| 550 |
|
| 551 |
dReal dJointGetPUAngle2( dJointID j ) |
| 552 |
{ |
| 553 |
dxJointUniversal* joint = ( dxJointUniversal* ) j; |
| 554 |
dUASSERT( joint, "bad joint argument" ); |
| 555 |
checktype( joint, PU ); |
| 556 |
if ( joint->flags & dJOINT_REVERSE ) |
| 557 |
return joint->getAngle1(); |
| 558 |
else |
| 559 |
return joint->getAngle2(); |
| 560 |
} |
| 561 |
|
| 562 |
|
| 563 |
dReal dJointGetPUAngle1Rate( dJointID j ) |
| 564 |
{ |
| 565 |
dxJointPU* joint = ( dxJointPU* ) j; |
| 566 |
dUASSERT( joint, "bad joint argument" ); |
| 567 |
checktype( joint, PU ); |
| 568 |
|
| 569 |
if ( joint->node[0].body ) |
| 570 |
{ |
| 571 |
dVector3 axis; |
| 572 |
|
| 573 |
if ( joint->flags & dJOINT_REVERSE ) |
| 574 |
getAxis2( joint, axis, joint->axis2 ); |
| 575 |
else |
| 576 |
getAxis( joint, axis, joint->axis1 ); |
| 577 |
|
| 578 |
dReal rate = dCalcVectorDot3( axis, joint->node[0].body->avel ); |
| 579 |
if ( joint->node[1].body ) rate -= dCalcVectorDot3( axis, joint->node[1].body->avel ); |
| 580 |
return rate; |
| 581 |
} |
| 582 |
return 0; |
| 583 |
} |
| 584 |
|
| 585 |
|
| 586 |
dReal dJointGetPUAngle2Rate( dJointID j ) |
| 587 |
{ |
| 588 |
dxJointPU* joint = ( dxJointPU* ) j; |
| 589 |
dUASSERT( joint, "bad joint argument" ); |
| 590 |
checktype( joint, PU ); |
| 591 |
|
| 592 |
if ( joint->node[0].body ) |
| 593 |
{ |
| 594 |
dVector3 axis; |
| 595 |
|
| 596 |
if ( joint->flags & dJOINT_REVERSE ) |
| 597 |
getAxis( joint, axis, joint->axis1 ); |
| 598 |
else |
| 599 |
getAxis2( joint, axis, joint->axis2 ); |
| 600 |
|
| 601 |
dReal rate = dCalcVectorDot3( axis, joint->node[0].body->avel ); |
| 602 |
if ( joint->node[1].body ) rate -= dCalcVectorDot3( axis, joint->node[1].body->avel ); |
| 603 |
return rate; |
| 604 |
} |
| 605 |
return 0; |
| 606 |
} |
| 607 |
|
| 608 |
|
| 609 |
void dJointSetPUParam( dJointID j, int parameter, dReal value ) |
| 610 |
{ |
| 611 |
dxJointPU* joint = ( dxJointPU* ) j; |
| 612 |
dUASSERT( joint, "bad joint argument" ); |
| 613 |
checktype( joint, PU ); |
| 614 |
|
| 615 |
switch ( parameter & 0xff00 ) |
| 616 |
{ |
| 617 |
case dParamGroup1: |
| 618 |
joint->limot1.set( parameter, value ); |
| 619 |
break; |
| 620 |
case dParamGroup2: |
| 621 |
joint->limot2.set( parameter & 0xff, value ); |
| 622 |
break; |
| 623 |
case dParamGroup3: |
| 624 |
joint->limotP.set( parameter & 0xff, value ); |
| 625 |
break; |
| 626 |
} |
| 627 |
} |
| 628 |
|
| 629 |
void dJointGetPUAnchor( dJointID j, dVector3 result ) |
| 630 |
{ |
| 631 |
dxJointPU* joint = ( dxJointPU* ) j; |
| 632 |
dUASSERT( joint, "bad joint argument" ); |
| 633 |
dUASSERT( result, "bad result argument" ); |
| 634 |
checktype( joint, PU ); |
| 635 |
|
| 636 |
if ( joint->node[1].body ) |
| 637 |
getAnchor2( joint, result, joint->anchor2 ); |
| 638 |
else |
| 639 |
{ |
| 640 |
// result[i] = joint->anchor2[i]; |
| 641 |
dCopyVector3( result, joint->anchor2 ); |
| 642 |
} |
| 643 |
} |
| 644 |
|
| 645 |
void dJointGetPUAxis1( dJointID j, dVector3 result ) |
| 646 |
{ |
| 647 |
dxJointPU* joint = ( dxJointPU* ) j; |
| 648 |
dUASSERT( joint, "bad joint argument" ); |
| 649 |
dUASSERT( result, "bad result argument" ); |
| 650 |
checktype( joint, PU ); |
| 651 |
if ( joint->flags & dJOINT_REVERSE ) |
| 652 |
getAxis2( joint, result, joint->axis2 ); |
| 653 |
else |
| 654 |
getAxis( joint, result, joint->axis1 ); |
| 655 |
} |
| 656 |
|
| 657 |
void dJointGetPUAxis2( dJointID j, dVector3 result ) |
| 658 |
{ |
| 659 |
dxJointPU* joint = ( dxJointPU* ) j; |
| 660 |
dUASSERT( joint, "bad joint argument" ); |
| 661 |
dUASSERT( result, "bad result argument" ); |
| 662 |
checktype( joint, PU ); |
| 663 |
if ( joint->flags & dJOINT_REVERSE ) |
| 664 |
getAxis( joint, result, joint->axis1 ); |
| 665 |
else |
| 666 |
getAxis2( joint, result, joint->axis2 ); |
| 667 |
} |
| 668 |
|
| 669 |
/** |
| 670 |
* @brief Get the prismatic axis |
| 671 |
* @ingroup joints |
| 672 |
* |
| 673 |
* @note This function was added for convenience it is the same as |
| 674 |
* dJointGetPUAxis3 |
| 675 |
*/ |
| 676 |
void dJointGetPUAxisP( dJointID id, dVector3 result ) |
| 677 |
{ |
| 678 |
dJointGetPUAxis3( id, result ); |
| 679 |
} |
| 680 |
|
| 681 |
|
| 682 |
void dJointGetPUAxis3( dJointID j, dVector3 result ) |
| 683 |
{ |
| 684 |
dxJointPU* joint = ( dxJointPU* ) j; |
| 685 |
dUASSERT( joint, "bad joint argument" ); |
| 686 |
dUASSERT( result, "bad result argument" ); |
| 687 |
checktype( joint, PU ); |
| 688 |
getAxis( joint, result, joint->axisP1 ); |
| 689 |
} |
| 690 |
|
| 691 |
dReal dJointGetPUParam( dJointID j, int parameter ) |
| 692 |
{ |
| 693 |
dxJointPU* joint = ( dxJointPU* ) j; |
| 694 |
dUASSERT( joint, "bad joint argument" ); |
| 695 |
checktype( joint, PU ); |
| 696 |
|
| 697 |
switch ( parameter & 0xff00 ) |
| 698 |
{ |
| 699 |
case dParamGroup1: |
| 700 |
return joint->limot1.get( parameter ); |
| 701 |
break; |
| 702 |
case dParamGroup2: |
| 703 |
return joint->limot2.get( parameter & 0xff ); |
| 704 |
break; |
| 705 |
case dParamGroup3: |
| 706 |
return joint->limotP.get( parameter & 0xff ); |
| 707 |
break; |
| 708 |
} |
| 709 |
|
| 710 |
return 0; |
| 711 |
} |
| 712 |
|
| 713 |
|
| 714 |
dJointType |
| 715 |
dxJointPU::type() const |
| 716 |
{ |
| 717 |
return dJointTypePU; |
| 718 |
} |
| 719 |
|
| 720 |
|
| 721 |
size_t |
| 722 |
dxJointPU::size() const |
| 723 |
{ |
| 724 |
return sizeof( *this ); |
| 725 |
} |
| 726 |
|
| 727 |
|
| 728 |
void |
| 729 |
dxJointPU::setRelativeValues() |
| 730 |
{ |
| 731 |
dVector3 anchor; |
| 732 |
dJointGetPUAnchor(this, anchor); |
| 733 |
setAnchors( this, anchor[0], anchor[1], anchor[2], anchor1, anchor2 ); |
| 734 |
|
| 735 |
dVector3 ax1, ax2, ax3; |
| 736 |
dJointGetPUAxis1(this, ax1); |
| 737 |
dJointGetPUAxis2(this, ax2); |
| 738 |
dJointGetPUAxis3(this, ax3); |
| 739 |
|
| 740 |
if ( flags & dJOINT_REVERSE ) |
| 741 |
{ |
| 742 |
setAxes( this, ax1[0], ax1[1], ax1[2], NULL, axis2 ); |
| 743 |
setAxes( this, ax2[0], ax2[1], ax2[2], axis1, NULL ); |
| 744 |
} |
| 745 |
else |
| 746 |
{ |
| 747 |
setAxes( this, ax1[0], ax1[1], ax1[2], axis1, NULL ); |
| 748 |
setAxes( this, ax2[0], ax2[1], ax2[2], NULL, axis2 ); |
| 749 |
} |
| 750 |
|
| 751 |
|
| 752 |
setAxes( this, ax3[0], ax3[1], ax3[2], axisP1, NULL ); |
| 753 |
|
| 754 |
computeInitialRelativeRotations(); |
| 755 |
} |
| 756 |
|