Bullet Collision Detection & Physics Library
btUniversalConstraint.cpp
Go to the documentation of this file.
1/*
2Bullet Continuous Collision Detection and Physics Library, http://bulletphysics.org
3Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
4
5This software is provided 'as-is', without any express or implied warranty.
6In no event will the authors be held liable for any damages arising from the use of this software.
7Permission is granted to anyone to use this software for any purpose,
8including commercial applications, and to alter it and redistribute it freely,
9subject to the following restrictions:
10
111. 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.
122. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
133. This notice may not be removed or altered from any source distribution.
14*/
15
19
20#define UNIV_EPS btScalar(0.01f)
21
22// constructor
23// anchor, axis1 and axis2 are in world coordinate system
24// axis1 must be orthogonal to axis2
26 : btGeneric6DofConstraint(rbA, rbB, btTransform::getIdentity(), btTransform::getIdentity(), true),
27 m_anchor(anchor),
28 m_axis1(axis1),
29 m_axis2(axis2)
30{
31 // build frame basis
32 // 6DOF constraint uses Euler angles and to define limits
33 // it is assumed that rotational order is :
34 // Z - first, allowed limits are (-PI,PI);
35 // new position of Y - second (allowed limits are (-PI/2 + epsilon, PI/2 - epsilon), where epsilon is a small positive number
36 // used to prevent constraint from instability on poles;
37 // new position of X, allowed limits are (-PI,PI);
38 // So to simulate ODE Universal joint we should use parent axis as Z, child axis as Y and limit all other DOFs
39 // Build the frame in world coordinate system first
42 btVector3 xAxis = yAxis.cross(zAxis); // we want right coordinate system
45 frameInW.getBasis().setValue(xAxis[0], yAxis[0], zAxis[0],
46 xAxis[1], yAxis[1], zAxis[1],
47 xAxis[2], yAxis[2], zAxis[2]);
48 frameInW.setOrigin(anchor);
49 // now get constraint frame in local coordinate systems
50 m_frameInA = rbA.getCenterOfMassTransform().inverse() * frameInW;
51 m_frameInB = rbB.getCenterOfMassTransform().inverse() * frameInW;
52 // sei limits
53 setLinearLowerLimit(btVector3(0., 0., 0.));
54 setLinearUpperLimit(btVector3(0., 0., 0.));
57}
58
60{
61 m_axis1 = axis1;
62 m_axis2 = axis2;
63
66 btVector3 xAxis = yAxis.cross(zAxis); // we want right coordinate system
67
70 frameInW.getBasis().setValue(xAxis[0], yAxis[0], zAxis[0],
71 xAxis[1], yAxis[1], zAxis[1],
72 xAxis[2], yAxis[2], zAxis[2]);
73 frameInW.setOrigin(m_anchor);
74
75 // now get constraint frame in local coordinate systems
78
80}
const T & btMax(const T &a, const T &b)
Definition btMinMax.h:27
#define SIMD_PI
Definition btScalar.h:526
#define SIMD_HALF_PI
Definition btScalar.h:528
#define UNIV_EPS
btGeneric6DofConstraint between two rigidbodies each with a pivotpoint that descibes the axis locatio...
btTransform m_frameInA
relative_frames
void setLinearLowerLimit(const btVector3 &linearLower)
void setAngularLowerLimit(const btVector3 &angularLower)
btTransform m_frameInB
the constraint space w.r.t body B
void setAngularUpperLimit(const btVector3 &angularUpper)
void setLinearUpperLimit(const btVector3 &linearUpper)
The btRigidBody is the main class for rigid body objects.
Definition btRigidBody.h:60
const btTransform & getCenterOfMassTransform() const
The btTransform class supports rigid transforms with only translation and rotation and no scaling/she...
Definition btTransform.h:30
btTransform inverse() const
Return the inverse of this transform.
void setIdentity()
Set this transformation to the identity.
void setAxis(const btVector3 &axis1, const btVector3 &axis2)
btUniversalConstraint(btRigidBody &rbA, btRigidBody &rbB, const btVector3 &anchor, const btVector3 &axis1, const btVector3 &axis2)
btVector3 can be used to represent 3D points and vectors.
Definition btVector3.h:82
btVector3 cross(const btVector3 &v) const
Return the cross product between this and another vector.
Definition btVector3.h:380
btVector3 normalized() const
Return a normalized version of this vector.
Definition btVector3.h:949
btVector3 & normalize()
Normalize this vector x^2 + y^2 + z^2 = 1.
Definition btVector3.h:303