b2PrismaticJoint.h
Go to the documentation of this file.
00001 /*
00002 * Copyright (c) 2006-2011 Erin Catto http://www.box2d.org
00003 *
00004 * This software is provided 'as-is', without any express or implied
00005 * warranty.  In no event will the authors be held liable for any damages
00006 * arising from the use of this software.
00007 * Permission is granted to anyone to use this software for any purpose,
00008 * including commercial applications, and to alter it and redistribute it
00009 * freely, subject to the following restrictions:
00010 * 1. The origin of this software must not be misrepresented; you must not
00011 * claim that you wrote the original software. If you use this software
00012 * in a product, an acknowledgment in the product documentation would be
00013 * appreciated but is not required.
00014 * 2. Altered source versions must be plainly marked as such, and must not be
00015 * misrepresented as being the original software.
00016 * 3. This notice may not be removed or altered from any source distribution.
00017 */
00018 
00019 #ifndef B2_PRISMATIC_JOINT_H
00020 #define B2_PRISMATIC_JOINT_H
00021 
00022 #include <Box2D/Dynamics/Joints/b2Joint.h>
00023 
00030 struct b2PrismaticJointDef : public b2JointDef
00031 {
00032         b2PrismaticJointDef()
00033         {
00034                 type = e_prismaticJoint;
00035                 localAnchorA.SetZero();
00036                 localAnchorB.SetZero();
00037                 localAxisA.Set(1.0f, 0.0f);
00038                 referenceAngle = 0.0f;
00039                 enableLimit = false;
00040                 lowerTranslation = 0.0f;
00041                 upperTranslation = 0.0f;
00042                 enableMotor = false;
00043                 maxMotorForce = 0.0f;
00044                 motorSpeed = 0.0f;
00045         }
00046 
00049         void Initialize(b2Body* bodyA, b2Body* bodyB, const b2Vec2& anchor, const b2Vec2& axis);
00050 
00052         b2Vec2 localAnchorA;
00053 
00055         b2Vec2 localAnchorB;
00056 
00058         b2Vec2 localAxisA;
00059 
00061         float32 referenceAngle;
00062 
00064         bool enableLimit;
00065 
00067         float32 lowerTranslation;
00068 
00070         float32 upperTranslation;
00071 
00073         bool enableMotor;
00074 
00076         float32 maxMotorForce;
00077 
00079         float32 motorSpeed;
00080 };
00081 
00086 class b2PrismaticJoint : public b2Joint
00087 {
00088 public:
00089         b2Vec2 GetAnchorA() const;
00090         b2Vec2 GetAnchorB() const;
00091 
00092         b2Vec2 GetReactionForce(float32 inv_dt) const;
00093         float32 GetReactionTorque(float32 inv_dt) const;
00094 
00096         const b2Vec2& GetLocalAnchorA() const { return m_localAnchorA; }
00097 
00099         const b2Vec2& GetLocalAnchorB() const  { return m_localAnchorB; }
00100 
00102         const b2Vec2& GetLocalAxisA() const { return m_localXAxisA; }
00103 
00105         float32 GetReferenceAngle() const { return m_referenceAngle; }
00106 
00108         float32 GetJointTranslation() const;
00109 
00111         float32 GetJointSpeed() const;
00112 
00114         bool IsLimitEnabled() const;
00115 
00117         void EnableLimit(bool flag);
00118 
00120         float32 GetLowerLimit() const;
00121 
00123         float32 GetUpperLimit() const;
00124 
00126         void SetLimits(float32 lower, float32 upper);
00127 
00129         bool IsMotorEnabled() const;
00130 
00132         void EnableMotor(bool flag);
00133 
00135         void SetMotorSpeed(float32 speed);
00136 
00138         float32 GetMotorSpeed() const;
00139 
00141         void SetMaxMotorForce(float32 force);
00142         float32 GetMaxMotorForce() const { return m_maxMotorForce; }
00143 
00145         float32 GetMotorForce(float32 inv_dt) const;
00146 
00148         void Dump();
00149 
00150 protected:
00151         friend class b2Joint;
00152         friend class b2GearJoint;
00153         b2PrismaticJoint(const b2PrismaticJointDef* def);
00154 
00155         void InitVelocityConstraints(const b2SolverData& data);
00156         void SolveVelocityConstraints(const b2SolverData& data);
00157         bool SolvePositionConstraints(const b2SolverData& data);
00158 
00159         // Solver shared
00160         b2Vec2 m_localAnchorA;
00161         b2Vec2 m_localAnchorB;
00162         b2Vec2 m_localXAxisA;
00163         b2Vec2 m_localYAxisA;
00164         float32 m_referenceAngle;
00165         b2Vec3 m_impulse;
00166         float32 m_motorImpulse;
00167         float32 m_lowerTranslation;
00168         float32 m_upperTranslation;
00169         float32 m_maxMotorForce;
00170         float32 m_motorSpeed;
00171         bool m_enableLimit;
00172         bool m_enableMotor;
00173         b2LimitState m_limitState;
00174 
00175         // Solver temp
00176         int32 m_indexA;
00177         int32 m_indexB;
00178         b2Vec2 m_localCenterA;
00179         b2Vec2 m_localCenterB;
00180         float32 m_invMassA;
00181         float32 m_invMassB;
00182         float32 m_invIA;
00183         float32 m_invIB;
00184         b2Vec2 m_axis, m_perp;
00185         float32 m_s1, m_s2;
00186         float32 m_a1, m_a2;
00187         b2Mat33 m_K;
00188         float32 m_motorMass;
00189 };
00190 
00191 inline float32 b2PrismaticJoint::GetMotorSpeed() const
00192 {
00193         return m_motorSpeed;
00194 }
00195 
00196 #endif


mvsim
Author(s):
autogenerated on Thu Jun 6 2019 22:08:35