AppEasy Core SDK
1.5.0
Cross platform mobile and desktop app and game development SDK - The easy way to make apps
|
00001 // 00002 // 00003 // AppEasy SDK - Cross Platform Multi-purpose Game and App Engine 00004 // 00005 // Developed by Matthew Hopwood of Pocketeers Limited - www.pocketeers.co.uk 00006 // 00007 // For updates, tutorials and more details check out www.appeasymobile.com 00008 // 00009 // This code is provided free of charge and without any warranty whatsoever. You must ensure that this whole notice is present in all files and derivatives, so the reader knows its origin. 00010 // If you use this SDK in your product then please ensure that you credit AppEasy's usage appropriately. Please see www.appeasymobile.com for licensing details and support 00011 // 00012 // 00013 00014 #if !defined(_CZ_BOX2D_JOINT_H_) 00015 #define _CZ_BOX2D_JOINT_H_ 00016 00017 #include "CzUtil.h" 00018 #include "CzString.h" 00019 #include "CzXoml.h" 00020 #include "CzShapes.h" 00021 00022 #include "Box2D/Box2D.h" 00023 00024 class CzBox2dWorld; 00025 class CzBox2dBody; 00026 00027 // 00028 // 00029 // 00030 // 00031 // CzBox2dJoint - Box2D physics joint 00032 // 00033 // 00034 // 00035 // 00036 enum eCzBox2dJointType 00037 { 00038 JT_Weld, 00039 JT_Distance, 00040 JT_Revolute, 00041 JT_Prismatic, 00042 JT_Pulley, 00043 JT_Wheel, 00044 }; 00045 00046 struct IzBox2dJoint 00047 { 00048 eCzBox2dJointType Type; ///< Type of joint 00049 #if defined (_DEBUG) 00050 CzString Name; ///< Joint name 00051 #endif // _DEBUG 00052 unsigned int NameHash; ///< Joint name hash 00053 CzBox2dBody* BodyA; ///< Body A 00054 CzBox2dBody* BodyB; ///< Body B 00055 b2Vec2 AnchorA; ///< Body A world anchor pos 00056 b2Vec2 AnchorB; ///< Body B world anchor pos 00057 bool SelfCollide; ///< True to allow self collision 00058 00059 virtual void Create(CzBox2dWorld* world) = 0; 00060 virtual b2Joint* getJoint() = 0; 00061 void setName(const char* name) 00062 { 00063 #if defined (_DEBUG) 00064 Name = name; 00065 #endif // _DEBUG 00066 NameHash = CzString::CalculateHash(name); 00067 } 00068 }; 00069 00070 struct CzBox2dJointWeld : public IzBox2dJoint 00071 { 00072 float ReferenceAngle; // Reference angle 00073 b2WeldJoint* Joint; 00074 00075 CzBox2dJointWeld() { Type = JT_Distance; } 00076 00077 // Initialise the joint 00078 void Create(CzBox2dWorld* world); 00079 b2Joint* getJoint() { return Joint; } 00080 }; 00081 00082 struct CzBox2dJointDistance : public IzBox2dJoint 00083 { 00084 float Length; // Max length between bosy A and B 00085 float Frequency; // Harmonic oscilation Frequency in Hz 00086 float Damping; // Oscillation damping (1.0 for no oscillation) 00087 b2DistanceJoint* Joint; 00088 00089 CzBox2dJointDistance() : Length(-1), Frequency(-1), Damping(-1) { Type = JT_Distance; } 00090 00091 // Initialise the joint 00092 void Create(CzBox2dWorld* world); 00093 b2Joint* getJoint() { return Joint; } 00094 }; 00095 00096 struct CzBox2dJointRevolute : public IzBox2dJoint 00097 { 00098 bool LimitJoint; // Imited joint rotation 00099 bool MotorEnabled; // Enable motor 00100 float LowerAngle; // Lower rotation limit 00101 float UpperAngle; // Upper rotation limit 00102 float MotorSpeed; // Motor speed 00103 float MaxMotorTorque; // Max motor torque 00104 float ReferenceAngle; // Reference angle 00105 b2RevoluteJoint* Joint; 00106 00107 CzBox2dJointRevolute() : LimitJoint(false), MotorEnabled(false), ReferenceAngle(0) { Type = JT_Revolute; } 00108 00109 // Initialise the joint 00110 void Create(CzBox2dWorld* world); 00111 b2Joint* getJoint() { return Joint; } 00112 }; 00113 00114 struct CzBox2dJointPrismatic : public IzBox2dJoint 00115 { 00116 b2Vec2 Axis; // Axis of movement 00117 bool LimitJoint; // Limit joint translation 00118 bool MotorEnabled; // Emable motor 00119 float LowerTranslation; // Lower translation limit 00120 float UpperTranslation; // Upper translation limit 00121 float MotorSpeed; // Motor speed 00122 float MaxMotorForce; // Max motor force 00123 float ReferenceAngle; // Reference angle 00124 b2PrismaticJoint* Joint; 00125 00126 CzBox2dJointPrismatic() : LimitJoint(false), MotorEnabled(false), ReferenceAngle(0) { Type = JT_Prismatic; } 00127 00128 // Initialise the joint 00129 void Create(CzBox2dWorld* world); 00130 b2Joint* getJoint() { return Joint; } 00131 }; 00132 00133 struct CzBox2dJointPulley : public IzBox2dJoint 00134 { 00135 b2Vec2 GroundAnchorA; // Body A world ground anchor pos 00136 b2Vec2 GroundAnchorB; // Body B world ground anchor pos 00137 float LengthA; // Distance between Body A and Ground Anchor A 00138 float LengthB; // Distance between Body B and Ground Anchor B 00139 float Ratio; // Ratio between rate of change of both sides 00140 b2PulleyJoint* Joint; 00141 00142 CzBox2dJointPulley() : Ratio(1.0f), LengthA(0), LengthB(0) { Type = JT_Pulley; } 00143 00144 // Initialise the joint 00145 void Create(CzBox2dWorld* world); 00146 b2Joint* getJoint() { return Joint; } 00147 }; 00148 00149 struct CzBox2dJointWheel : public IzBox2dJoint 00150 { 00151 b2Vec2 Axis; // Axis 00152 bool MotorEnabled; // Motor enabled 00153 float MotorSpeed; // Motor speed 00154 float MaxMotorTorque; // Max motor torque 00155 float Frequency; // Harmonic oscilation Frequency in Hz 00156 float Damping; // Oscillation damping (1.0 for no oscillation) 00157 b2WheelJoint* Joint; 00158 00159 CzBox2dJointWheel() : MotorEnabled(false) { Type = JT_Wheel; } 00160 00161 // Initialise the joint 00162 void Create(CzBox2dWorld* world); 00163 b2Joint* getJoint() { return Joint; } 00164 }; 00165 00166 // 00167 // 00168 // 00169 // 00170 // CzBox2dJoints - Box2D physics joints XOML command 00171 // 00172 // 00173 // 00174 // 00175 class CzBox2dJoints : public IzXomlResource 00176 { 00177 public: 00178 CzBox2dJoints() { setClassType("joints"); } 00179 00180 // Implementation of IzXomlResource interface 00181 int LoadFromXoml(IzXomlResource* parent, bool load_children, CzXmlNode* node); 00182 }; 00183 00184 // 00185 // CzBox2dJointsCreator - Creates an instance of Box2DJoints object 00186 // 00187 class CzBox2dJointsCreator : public IzXomlClassCreator 00188 { 00189 public: 00190 CzBox2dJointsCreator() 00191 { 00192 setClassName("joints"); 00193 } 00194 IzXomlResource* CreateInstance(IzXomlResource* parent) { return new CzBox2dJoints(); } 00195 }; 00196 00197 00198 00199 #endif // _CZ_BOX2D_JOINT_H_