00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef _PHYSICSJOINTS_
00019 #define _PHYSICSJOINTS_
00020
00021 #include <iostream>
00022 #include <string>
00023
00024 #include "util/Attribute.h"
00025 #include "util/Vector2.h"
00026
00027 #define TO_B2VEC2(vec) b2Vec2(vec._x, vec._y)
00028 #define TO_VECTOR2(vec) Vector2(vec.x, vec.y)
00029
00030 struct DistanceJoint
00031 {
00032 DistanceJoint() { }
00033 DistanceJoint(const Vector2& anchor1, const Vector2& anchor2)
00034 :_anchor1(anchor1), _anchor2(anchor2)
00035 {
00036 }
00037
00038 Vector2 _anchor1;
00039 Vector2 _anchor2;
00040 };
00041
00042 void JointFromAttribute(const Attribute * pRoot, DistanceJoint & joint);
00043 std::ostream & operator<<(std::ostream & os, const DistanceJoint & def);
00044 std::istream & operator>>(std::istream & is, DistanceJoint & def);
00045
00046 struct RevoluteJoint
00047 {
00048 RevoluteJoint()
00049 :_fMinAngle(0.0f), _fMaxAngle(0.0f), _fMaxMotorTorque(0.0f), _fMotorSpeed(0.0f)
00050 {
00051 }
00052
00053 RevoluteJoint(const Vector2 & anchor, const float fMinAngle = 0.0f, const float fMaxAngle = 0.0f,
00054 const float fMaxMotorTorque = 0.0f, const float fMotorSpeed = 0.0f)
00055 :_anchor(anchor), _fMinAngle(fMinAngle), _fMaxAngle(fMaxAngle), _fMaxMotorTorque(fMaxMotorTorque),
00056 _fMotorSpeed(fMotorSpeed)
00057 {
00058 }
00059
00060 Vector2 _anchor;
00061 float _fMinAngle;
00062 float _fMaxAngle;
00063 float _fMaxMotorTorque;
00064 float _fMotorSpeed;
00065 };
00066
00067 void JointFromAttribute(const Attribute * pRoot, RevoluteJoint & joint);
00068 std::ostream & operator<<(std::ostream & os, const RevoluteJoint & def);
00069 std::istream & operator>>(std::istream & is, RevoluteJoint & def);
00070
00071 struct PrismaticJoint
00072 {
00073 PrismaticJoint()
00074 :_fMinTranslation(0.0f), _fMaxTranslation(0.0f), _fMaxMotorForce(0.0f), _fMotorSpeed(0.0f)
00075 {
00076 }
00077
00078 PrismaticJoint(const Vector2 & anchor, const Vector2 & axis, const float fMinTranslation = 0.0f,
00079 const float fMaxTranslation = 0.0f, const float fMaxMotorForce = 0.0f, const float fMotorSpeed = 0.0f)
00080 :_anchor(anchor), _axis(axis), _fMinTranslation(fMinTranslation), _fMaxTranslation(fMaxTranslation),
00081 _fMaxMotorForce(fMaxMotorForce), _fMotorSpeed(fMotorSpeed)
00082 {
00083 }
00084
00085 Vector2 _anchor;
00086 Vector2 _axis;
00087 float _fMinTranslation;
00088 float _fMaxTranslation;
00089 float _fMaxMotorForce;
00090 float _fMotorSpeed;
00091 };
00092
00093 void JointFromAttribute(const Attribute * pRoot,PrismaticJoint & joint);
00094 std::ostream & operator<<(std::ostream & os, const PrismaticJoint & def);
00095 std::istream & operator>>(std::istream & is, PrismaticJoint & def);
00096
00097 struct PulleyJoint
00098 {
00099 PulleyJoint()
00100 :_fRatio(0.0f), _fMaxLength1(0.0f), _fMaxLength2(0.0f)
00101 {
00102 }
00103
00104 PulleyJoint(const Vector2& anchor1, const Vector2& anchor2, const Vector2& groundAnchor1,
00105 const Vector2& groundAnchor2, const float fRatio = 1.0f, const float fMaxLength1 = 0.0f,
00106 const float fMaxLength2 = 0.0f)
00107 :_anchor1(anchor1), _anchor2(anchor2), _groundAnchor1(groundAnchor1), _groundAnchor2(groundAnchor2),
00108 _fRatio(fRatio), _fMaxLength1(fMaxLength1), _fMaxLength2(fMaxLength2)
00109 {
00110 }
00111
00112 Vector2 _anchor1;
00113 Vector2 _anchor2;
00114 Vector2 _groundAnchor1;
00115 Vector2 _groundAnchor2;
00116 float _fRatio;
00117 float _fMaxLength1;
00118 float _fMaxLength2;
00119 };
00120
00121 void JointFromAttribute(const Attribute * pRoot, PulleyJoint & joint);
00122 std::ostream & operator<<(std::ostream & os, const PulleyJoint & def);
00123 std::istream & operator>>(std::istream & is, PulleyJoint & def);
00124
00125 struct GearJoint
00126 {
00127 GearJoint()
00128 :_fRatio(0.0f)
00129 {
00130 }
00131
00132 GearJoint(const std::string & constraint1, const std::string & constraint2, const float fRatio = 1.0f)
00133 :_constraint1(constraint1), _constraint2(constraint2)
00134 {
00135 }
00136
00137 std::string _constraint1;
00138 std::string _constraint2;
00139 float _fRatio;
00140 };
00141
00142 void JointFromAttribute(const Attribute * pRoot, GearJoint & joint);
00143 std::ostream & operator<<(std::ostream & os, const GearJoint & def);
00144 std::istream & operator>>(std::istream & is, GearJoint & def);
00145
00146 #endif