Bullet Collision Detection & Physics Library: btUniversalConstraint.cpp Source File

Bullet Collision Detection & Physics Library

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

btUniversalConstraint.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 "btUniversalConstraint.h"
19 #include "BulletDynamics/Dynamics/btRigidBody.h"
20 #include "LinearMath/btTransformUtil.h"
21
22
23
24 #define UNIV_EPS btScalar(0.01f)
25
26
27 // constructor
28 // anchor, axis1 and axis2 are in world coordinate system
29 // axis1 must be orthogonal to axis2
30 btUniversalConstraint::btUniversalConstraint(btRigidBody& rbA, btRigidBody& rbB, const btVector3& anchor, const btVector3& axis1, const btVector3& axis2)
31 : btGeneric6DofConstraint(rbA, rbB, btTransform::getIdentity(), btTransform::getIdentity(), true),
32 m_anchor(anchor),
33 m_axis1(axis1),
34 m_axis2(axis2)
35 {
36 // build frame basis
37 // 6DOF constraint uses Euler angles and to define limits
38 // it is assumed that rotational order is :
39 // Z - first, allowed limits are (-PI,PI);
40 // new position of Y - second (allowed limits are (-PI/2 + epsilon, PI/2 - epsilon), where epsilon is a small positive number
41 // used to prevent constraint from instability on poles;
42 // new position of X, allowed limits are (-PI,PI);
43 // So to simulate ODE Universal joint we should use parent axis as Z, child axis as Y and limit all other DOFs
44 // Build the frame in world coordinate system first
45 btVector3 zAxis = m_axis1.normalize();
46 btVector3 yAxis = m_axis2.normalize();
47 btVector3 xAxis = yAxis.cross(zAxis); // we want right coordinate system
48 btTransform frameInW;
49 frameInW.setIdentity();
50 frameInW.getBasis().setValue( xAxis[0], yAxis[0], zAxis[0],
51 xAxis[1], yAxis[1], zAxis[1],
52 xAxis[2], yAxis[2], zAxis[2]);
53 frameInW.setOrigin(anchor);
54 // now get constraint frame in local coordinate systems
55 m_frameInA = rbA.getCenterOfMassTransform().inverse() * frameInW;
56 m_frameInB = rbB.getCenterOfMassTransform().inverse() * frameInW;
57 // sei limits
58 setLinearLowerLimit(btVector3(0., 0., 0.));
59 setLinearUpperLimit(btVector3(0., 0., 0.));
60 setAngularLowerLimit(btVector3(0.f, -SIMD_HALF_PI + UNIV_EPS, -SIMD_PI + UNIV_EPS));
61 setAngularUpperLimit(btVector3(0.f, SIMD_HALF_PI - UNIV_EPS, SIMD_PI - UNIV_EPS));
62 }
63
64 void btUniversalConstraint::setAxis(const btVector3& axis1,const btVector3& axis2)
65 {
66 m_axis1 = axis1;
67 m_axis2 = axis2;
68
69 btVector3 zAxis = axis1.normalized();
70 btVector3 yAxis = axis2.normalized();
71 btVector3 xAxis = yAxis.cross(zAxis); // we want right coordinate system
72
73 btTransform frameInW;
74 frameInW.setIdentity();
75 frameInW.getBasis().setValue( xAxis[0], yAxis[0], zAxis[0],
76 xAxis[1], yAxis[1], zAxis[1],
77 xAxis[2], yAxis[2], zAxis[2]);
78 frameInW.setOrigin(m_anchor);
79
80 // now get constraint frame in local coordinate systems
81 m_frameInA = m_rbA.getCenterOfMassTransform().inverse() * frameInW;
82 m_frameInB = m_rbB.getCenterOfMassTransform().inverse() * frameInW;
83
84 calculateTransforms();
85 }
86
87
btTransform::setOrigin
void setOrigin(const btVector3 &origin)
Set the translational element.
Definition: btTransform.h:150
btTransformUtil.h
btUniversalConstraint.h
UNIV_EPS
#define UNIV_EPS
Definition: btUniversalConstraint.cpp:24
btTypedConstraint::m_rbA
btRigidBody & m_rbA
Definition: btTypedConstraint.h:102
btGeneric6DofConstraint
btGeneric6DofConstraint between two rigidbodies each with a pivotpoint that descibes the axis locatio...
Definition: btGeneric6DofConstraint.h:279
btTransform::setIdentity
void setIdentity()
Set this transformation to the identity.
Definition: btTransform.h:172
btGeneric6DofConstraint::setAngularUpperLimit
void setAngularUpperLimit(const btVector3 &angularUpper)
Definition: btGeneric6DofConstraint.h:487
btUniversalConstraint::m_axis1
btVector3 m_axis1
Definition: btUniversalConstraint.h:38
btRigidBody.h
SIMD_HALF_PI
#define SIMD_HALF_PI
Definition: btScalar.h:478
btUniversalConstraint::setAxis
void setAxis(const btVector3 &axis1, const btVector3 &axis2)
Definition: btUniversalConstraint.cpp:64
btVector3::normalize
btVector3 & normalize()
Normalize this vector x^2 + y^2 + z^2 = 1.
Definition: btVector3.h:297
btGeneric6DofConstraint::calculateTransforms
void calculateTransforms()
Definition: btGeneric6DofConstraint.cpp:384
SIMD_PI
#define SIMD_PI
Definition: btScalar.h:476
btRigidBody::getCenterOfMassTransform
const btTransform & getCenterOfMassTransform() const
Definition: btRigidBody.h:356
btVector3::cross
btVector3 cross(const btVector3 &v) const
Return the cross product between this and another vector.
Definition: btVector3.h:377
btTransform::getBasis
btMatrix3x3 & getBasis()
Return the basis matrix for the rotation.
Definition: btTransform.h:112
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
btRigidBody
The btRigidBody is the main class for rigid body objects.
Definition: btRigidBody.h:62
btTransform::inverse
btTransform inverse() const
Return the inverse of this transform.
Definition: btTransform.h:188
btVector3
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:83
btGeneric6DofConstraint::m_frameInA
btTransform m_frameInA
relative_frames
Definition: btGeneric6DofConstraint.h:285
btTransform
The btTransform class supports rigid transforms with only translation and rotation and no scaling/she...
Definition: btTransform.h:34
btTypedConstraint::m_rbB
btRigidBody & m_rbB
Definition: btTypedConstraint.h:103
btVector3::normalized
btVector3 normalized() const
Return a normalized version of this vector.
Definition: btVector3.h:952
btGeneric6DofConstraint::m_frameInB
btTransform m_frameInB
the constraint space w.r.t body B
Definition: btGeneric6DofConstraint.h:286
btUniversalConstraint::m_axis2
btVector3 m_axis2
Definition: btUniversalConstraint.h:39
btGeneric6DofConstraint::setLinearLowerLimit
void setLinearLowerLimit(const btVector3 &linearLower)
Definition: btGeneric6DofConstraint.h:455
btUniversalConstraint::m_anchor
btVector3 m_anchor
Definition: btUniversalConstraint.h:37
btUniversalConstraint::btUniversalConstraint
btUniversalConstraint(btRigidBody &rbA, btRigidBody &rbB, const btVector3 &anchor, const btVector3 &axis1, const btVector3 &axis2)
Definition: btUniversalConstraint.cpp:30
btGeneric6DofConstraint::setLinearUpperLimit
void setLinearUpperLimit(const btVector3 &linearUpper)
Definition: btGeneric6DofConstraint.h:465
btGeneric6DofConstraint::setAngularLowerLimit
void setAngularLowerLimit(const btVector3 &angularLower)
Definition: btGeneric6DofConstraint.h:475