1 /* 2 * box2dmousejoint.h 3 * Copyright (c) 2011 Joonas Erkinheimo <joonas.erkinheimo@nokia.com> 4 * 5 * This file is part of the Box2D QML plugin. 6 * 7 * This software is provided 'as-is', without any express or implied warranty. 8 * In no event will the authors be held liable for any damages arising from 9 * the use of this software. 10 * 11 * Permission is granted to anyone to use this software for any purpose, 12 * including commercial applications, and to alter it and redistribute it 13 * freely, subject to the following restrictions: 14 * 15 * 1. The origin of this software must not be misrepresented; you must not 16 * claim that you wrote the original software. If you use this software in 17 * a product, an acknowledgment in the product documentation would be 18 * appreciated but is not required. 19 * 20 * 2. Altered source versions must be plainly marked as such, and must not be 21 * misrepresented as being the original software. 22 * 23 * 3. This notice may not be removed or altered from any source distribution. 24 */ 25 26 #ifndef BOX2DMOUSEJOINT_H 27 #define BOX2DMOUSEJOINT_H 28 29 #include "box2djoint.h" 30 #include <Box2D.h> 31 32 class Box2DMouseJoint : public Box2DJoint 33 { 34 Q_OBJECT 35 36 Q_PROPERTY(QPointF target READ target WRITE setTarget NOTIFY targetChanged) 37 Q_PROPERTY(float maxForce READ maxForce WRITE setMaxForce NOTIFY maxForceChanged) 38 Q_PROPERTY(float frequencyHz READ frequencyHz WRITE setFrequencyHz NOTIFY frequencyHzChanged) 39 Q_PROPERTY(float dampingRatio READ dampingRatio WRITE setDampingRatio NOTIFY dampingRatioChanged) 40 41 public: 42 explicit Box2DMouseJoint(QObject *parent = 0); 43 44 float dampingRatio() const; 45 void setDampingRatio(float dampingRatio); 46 47 float frequencyHz() const; 48 void setFrequencyHz(float frequencyHz); 49 50 float maxForce() const; 51 void setMaxForce(float maxForce); 52 53 QPointF target() const; 54 void setTarget(const QPointF &target); 55 56 Q_INVOKABLE QPointF getReactionForce(float32 inv_dt) const; 57 Q_INVOKABLE float getReactionTorque(float32 inv_dt) const; 58 59 b2MouseJoint *mouseJoint() const; 60 61 signals: 62 void targetChanged(); 63 void maxForceChanged(); 64 void frequencyHzChanged(); 65 void dampingRatioChanged(); 66 67 protected: 68 b2Joint *createJoint(); 69 70 private: 71 QPointF m_target; 72 float m_maxForce; 73 float m_frequencyHz; 74 float m_dampingRatio; 75 }; 76 dampingRatio()77inline float Box2DMouseJoint::dampingRatio() const 78 { 79 return m_dampingRatio; 80 } 81 frequencyHz()82inline float Box2DMouseJoint::frequencyHz() const 83 { 84 return m_frequencyHz; 85 } 86 maxForce()87inline float Box2DMouseJoint::maxForce() const 88 { 89 return m_maxForce; 90 } 91 target()92inline QPointF Box2DMouseJoint::target() const 93 { 94 return m_target; 95 } 96 mouseJoint()97inline b2MouseJoint *Box2DMouseJoint::mouseJoint() const 98 { 99 return static_cast<b2MouseJoint*>(joint()); 100 } 101 102 #endif // BOX2DMOUSEJOINT_H 103