Bullet Collision Detection & Physics Library
btHinge2Constraint.cpp
Go to the documentation of this file.
1 /*
2 Bullet Continuous Collision Detection and Physics Library, http://bulletphysics.org
3 Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
4 
5 This software is provided 'as-is', without any express or implied warranty.
6 In no event will the authors be held liable for any damages arising from the use of this software.
7 Permission is granted to anyone to use this software for any purpose,
8 including commercial applications, and to alter it and redistribute it freely,
9 subject to the following restrictions:
10 
11 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
12 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
13 3. This notice may not be removed or altered from any source distribution.
14 */
15 
16 
17 
18 #include "btHinge2Constraint.h"
21 
22 
23 
24 // constructor
25 // anchor, axis1 and axis2 are in world coordinate system
26 // axis1 must be orthogonal to axis2
28 : btGeneric6DofSpring2Constraint(rbA, rbB, btTransform::getIdentity(), btTransform::getIdentity(),RO_XYZ),
29  m_anchor(anchor),
30  m_axis1(axis1),
31  m_axis2(axis2)
32 {
33  // build frame basis
34  // 6DOF constraint uses Euler angles and to define limits
35  // it is assumed that rotational order is :
36  // Z - first, allowed limits are (-PI,PI);
37  // new position of Y - second (allowed limits are (-PI/2 + epsilon, PI/2 - epsilon), where epsilon is a small positive number
38  // used to prevent constraint from instability on poles;
39  // new position of X, allowed limits are (-PI,PI);
40  // So to simulate ODE Universal joint we should use parent axis as Z, child axis as Y and limit all other DOFs
41  // Build the frame in world coordinate system first
42  btVector3 zAxis = axis1.normalize();
43  btVector3 xAxis = axis2.normalize();
44  btVector3 yAxis = zAxis.cross(xAxis); // we want right coordinate system
45  btTransform frameInW;
46  frameInW.setIdentity();
47  frameInW.getBasis().setValue( xAxis[0], yAxis[0], zAxis[0],
48  xAxis[1], yAxis[1], zAxis[1],
49  xAxis[2], yAxis[2], zAxis[2]);
50  frameInW.setOrigin(anchor);
51  // now get constraint frame in local coordinate systems
52  m_frameInA = rbA.getCenterOfMassTransform().inverse() * frameInW;
53  m_frameInB = rbB.getCenterOfMassTransform().inverse() * frameInW;
54  // sei limits
55  setLinearLowerLimit(btVector3(0.f, 0.f, -1.f));
56  setLinearUpperLimit(btVector3(0.f, 0.f, 1.f));
57  // like front wheels of a car
58  setAngularLowerLimit(btVector3(1.f, 0.f, -SIMD_HALF_PI * 0.5f));
59  setAngularUpperLimit(btVector3(-1.f, 0.f, SIMD_HALF_PI * 0.5f));
60  // enable suspension
61  enableSpring(2, true);
62  setStiffness(2, SIMD_PI * SIMD_PI * 4.f);
63  setDamping(2, 0.01f);
65 }
66 
btRigidBody
The btRigidBody is the main class for rigid body objects.
Definition: btRigidBody.h:62
RO_XYZ
@ RO_XYZ
Definition: btGeneric6DofSpring2Constraint.h:61
btGeneric6DofSpring2Constraint::setLinearUpperLimit
void setLinearUpperLimit(const btVector3 &linearUpper)
Definition: btGeneric6DofSpring2Constraint.h:366
btTransform::inverse
btTransform inverse() const
Return the inverse of this transform.
Definition: btTransform.h:188
SIMD_HALF_PI
#define SIMD_HALF_PI
Definition: btScalar.h:506
btVector3::cross
btVector3 cross(const btVector3 &v) const
Return the cross product between this and another vector.
Definition: btVector3.h:389
btGeneric6DofSpring2Constraint
Definition: btGeneric6DofSpring2Constraint.h:277
SIMD_PI
#define SIMD_PI
Definition: btScalar.h:504
btRigidBody.h
btGeneric6DofSpring2Constraint::setStiffness
void setStiffness(int index, btScalar stiffness, bool limitIfNeeded=true)
Definition: btGeneric6DofSpring2Constraint.cpp:1079
btTransformUtil.h
btRigidBody::getCenterOfMassTransform
const btTransform & getCenterOfMassTransform() const
Definition: btRigidBody.h:359
btTransform::setIdentity
void setIdentity()
Set this transformation to the identity.
Definition: btTransform.h:172
btGeneric6DofSpring2Constraint::m_frameInB
btTransform m_frameInB
Definition: btGeneric6DofSpring2Constraint.h:282
btGeneric6DofSpring2Constraint::enableSpring
void enableSpring(int index, bool onOff)
Definition: btGeneric6DofSpring2Constraint.cpp:1070
btGeneric6DofSpring2Constraint::setEquilibriumPoint
void setEquilibriumPoint()
Definition: btGeneric6DofSpring2Constraint.cpp:1103
btGeneric6DofSpring2Constraint::setAngularLowerLimit
void setAngularLowerLimit(const btVector3 &angularLower)
Definition: btGeneric6DofSpring2Constraint.h:369
btTransform::getBasis
btMatrix3x3 & getBasis()
Return the basis matrix for the rotation.
Definition: btTransform.h:112
btTransform
The btTransform class supports rigid transforms with only translation and rotation and no scaling/she...
Definition: btTransform.h:34
btVector3
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:83
btGeneric6DofSpring2Constraint::setLinearLowerLimit
void setLinearLowerLimit(const btVector3 &linearLower)
Definition: btGeneric6DofSpring2Constraint.h:364
btMatrix3x3::setValue
void setValue(const btScalar &xx, const btScalar &xy, const btScalar &xz, const btScalar &yx, const btScalar &yy, const btScalar &yz, const btScalar &zx, const btScalar &zy, const btScalar &zz)
Set the values of the matrix explicitly (row major)
Definition: btMatrix3x3.h:198
btHinge2Constraint::btHinge2Constraint
btHinge2Constraint(btRigidBody &rbA, btRigidBody &rbB, btVector3 &anchor, btVector3 &axis1, btVector3 &axis2)
Definition: btHinge2Constraint.cpp:27
btGeneric6DofSpring2Constraint::m_frameInA
btTransform m_frameInA
Definition: btGeneric6DofSpring2Constraint.h:281
btGeneric6DofSpring2Constraint::setDamping
void setDamping(int index, btScalar damping, bool limitIfNeeded=true)
Definition: btGeneric6DofSpring2Constraint.cpp:1091
btGeneric6DofSpring2Constraint::setAngularUpperLimit
void setAngularUpperLimit(const btVector3 &angularUpper)
Definition: btGeneric6DofSpring2Constraint.h:393
btTransform::setOrigin
void setOrigin(const btVector3 &origin)
Set the translational element.
Definition: btTransform.h:150
btVector3::normalize
btVector3 & normalize()
Normalize this vector x^2 + y^2 + z^2 = 1.
Definition: btVector3.h:309
btHinge2Constraint.h