1 /* 2 * box2drevolutejoint.h 3 * Copyright (c) 2011 Joonas Erkinheimo <joonas.erkinheimo@nokia.com> 4 * Copyright (c) 2011 Markus Kivioja <markus.kivioja@digia.com> 5 * 6 * This file is part of the Box2D QML plugin. 7 * 8 * This software is provided 'as-is', without any express or implied warranty. 9 * In no event will the authors be held liable for any damages arising from 10 * the use of this software. 11 * 12 * Permission is granted to anyone to use this software for any purpose, 13 * including commercial applications, and to alter it and redistribute it 14 * freely, subject to the following restrictions: 15 * 16 * 1. The origin of this software must not be misrepresented; you must not 17 * claim that you wrote the original software. If you use this software in 18 * a product, an acknowledgment in the product documentation would be 19 * appreciated but is not required. 20 * 21 * 2. Altered source versions must be plainly marked as such, and must not be 22 * misrepresented as being the original software. 23 * 24 * 3. This notice may not be removed or altered from any source distribution. 25 */ 26 27 #ifndef BOX2DREVOLUTEJOINT_H 28 #define BOX2DREVOLUTEJOINT_H 29 30 #include "box2djoint.h" 31 #include <Box2D.h> 32 33 class Box2DRevoluteJoint : public Box2DJoint 34 { 35 Q_OBJECT 36 37 Q_PROPERTY(QPointF localAnchorA READ localAnchorA WRITE setLocalAnchorA NOTIFY localAnchorAChanged) 38 Q_PROPERTY(QPointF localAnchorB READ localAnchorB WRITE setLocalAnchorB NOTIFY localAnchorBChanged) 39 Q_PROPERTY(float referenceAngle READ referenceAngle WRITE setReferenceAngle NOTIFY referenceAngleChanged) 40 Q_PROPERTY(bool enableLimit READ enableLimit WRITE setEnableLimit NOTIFY enableLimitChanged) 41 Q_PROPERTY(float lowerAngle READ lowerAngle WRITE setLowerAngle NOTIFY lowerAngleChanged) 42 Q_PROPERTY(float upperAngle READ upperAngle WRITE setUpperAngle NOTIFY upperAngleChanged) 43 Q_PROPERTY(bool enableMotor READ enableMotor WRITE setEnableMotor NOTIFY enableMotorChanged) 44 Q_PROPERTY(float motorSpeed READ motorSpeed WRITE setMotorSpeed NOTIFY motorSpeedChanged) 45 Q_PROPERTY(float maxMotorTorque READ maxMotorTorque WRITE setMaxMotorTorque NOTIFY maxMotorTorqueChanged) 46 47 public: 48 explicit Box2DRevoluteJoint(QObject *parent = 0); 49 50 QPointF localAnchorA() const; 51 void setLocalAnchorA(const QPointF &localAnchorA); 52 53 QPointF localAnchorB() const; 54 void setLocalAnchorB(const QPointF &localAnchorB); 55 56 float referenceAngle() const; 57 void setReferenceAngle(float referenceAngle); 58 59 bool enableLimit() const; 60 void setEnableLimit(bool enableLimit); 61 62 float lowerAngle() const; 63 void setLowerAngle(float lowerAngle); 64 65 float upperAngle() const; 66 void setUpperAngle(float upperAngle); 67 68 bool enableMotor() const; 69 void setEnableMotor(bool enableMotor); 70 71 float motorSpeed() const; 72 void setMotorSpeed(float motorSpeed); 73 74 float maxMotorTorque() const; 75 void setMaxMotorTorque(float maxMotorTorque); 76 77 b2RevoluteJoint *revoluteJoint() const; 78 79 Q_INVOKABLE float getJointAngle() const; 80 Q_INVOKABLE float getJointSpeed() const; 81 82 signals: 83 void localAnchorAChanged(); 84 void localAnchorBChanged(); 85 void referenceAngleChanged(); 86 void enableLimitChanged(); 87 void lowerAngleChanged(); 88 void upperAngleChanged(); 89 void enableMotorChanged(); 90 void motorSpeedChanged(); 91 void maxMotorTorqueChanged(); 92 93 protected: 94 b2Joint *createJoint(); 95 96 private: 97 QPointF m_localAnchorA; 98 QPointF m_localAnchorB; 99 float m_referenceAngle; 100 bool m_enableLimit; 101 float m_lowerAngle; 102 float m_upperAngle; 103 bool m_enableMotor; 104 float m_motorSpeed; 105 float m_maxMotorTorque; 106 bool m_defaultLocalAnchorA; 107 bool m_defaultLocalAnchorB; 108 bool m_defaultReferenceAngle; 109 }; 110 localAnchorA()111inline QPointF Box2DRevoluteJoint::localAnchorA() const 112 { 113 return m_localAnchorA; 114 } 115 localAnchorB()116inline QPointF Box2DRevoluteJoint::localAnchorB() const 117 { 118 return m_localAnchorB; 119 } 120 referenceAngle()121inline float Box2DRevoluteJoint::referenceAngle() const 122 { 123 return m_referenceAngle; 124 } 125 lowerAngle()126inline float Box2DRevoluteJoint::lowerAngle() const 127 { 128 return m_lowerAngle; 129 } 130 upperAngle()131inline float Box2DRevoluteJoint::upperAngle() const 132 { 133 return m_upperAngle; 134 } 135 maxMotorTorque()136inline float Box2DRevoluteJoint::maxMotorTorque() const 137 { 138 return m_maxMotorTorque; 139 } 140 motorSpeed()141inline float Box2DRevoluteJoint::motorSpeed() const 142 { 143 return m_motorSpeed; 144 } 145 enableLimit()146inline bool Box2DRevoluteJoint::enableLimit() const 147 { 148 return m_enableLimit; 149 } 150 enableMotor()151inline bool Box2DRevoluteJoint::enableMotor() const 152 { 153 return m_enableMotor; 154 } 155 revoluteJoint()156inline b2RevoluteJoint *Box2DRevoluteJoint::revoluteJoint() const 157 { 158 return static_cast<b2RevoluteJoint*>(joint()); 159 } 160 161 #endif // BOX2DREVOLUTEJOINT_H 162