File indexing completed on 2024-04-21 14:43:25
0001 /* 0002 * box2dmousejoint.h 0003 * Copyright (c) 2011 Joonas Erkinheimo <joonas.erkinheimo@nokia.com> 0004 * 0005 * This file is part of the Box2D QML plugin. 0006 * 0007 * This software is provided 'as-is', without any express or implied warranty. 0008 * In no event will the authors be held liable for any damages arising from 0009 * the use of this software. 0010 * 0011 * Permission is granted to anyone to use this software for any purpose, 0012 * including commercial applications, and to alter it and redistribute it 0013 * freely, subject to the following restrictions: 0014 * 0015 * 1. The origin of this software must not be misrepresented; you must not 0016 * claim that you wrote the original software. If you use this software in 0017 * a product, an acknowledgment in the product documentation would be 0018 * appreciated but is not required. 0019 * 0020 * 2. Altered source versions must be plainly marked as such, and must not be 0021 * misrepresented as being the original software. 0022 * 0023 * 3. This notice may not be removed or altered from any source distribution. 0024 */ 0025 0026 #ifndef BOX2DMOUSEJOINT_H 0027 #define BOX2DMOUSEJOINT_H 0028 0029 #include "box2djoint.h" 0030 #include <Box2D.h> 0031 0032 class Box2DMouseJoint : public Box2DJoint 0033 { 0034 Q_OBJECT 0035 0036 Q_PROPERTY(QPointF target READ target WRITE setTarget NOTIFY targetChanged) 0037 Q_PROPERTY(float maxForce READ maxForce WRITE setMaxForce NOTIFY maxForceChanged) 0038 Q_PROPERTY(float frequencyHz READ frequencyHz WRITE setFrequencyHz NOTIFY frequencyHzChanged) 0039 Q_PROPERTY(float dampingRatio READ dampingRatio WRITE setDampingRatio NOTIFY dampingRatioChanged) 0040 0041 public: 0042 explicit Box2DMouseJoint(QObject *parent = 0); 0043 0044 float dampingRatio() const; 0045 void setDampingRatio(float dampingRatio); 0046 0047 float frequencyHz() const; 0048 void setFrequencyHz(float frequencyHz); 0049 0050 float maxForce() const; 0051 void setMaxForce(float maxForce); 0052 0053 QPointF target() const; 0054 void setTarget(const QPointF &target); 0055 0056 Q_INVOKABLE QPointF getReactionForce(float32 inv_dt) const; 0057 Q_INVOKABLE float getReactionTorque(float32 inv_dt) const; 0058 0059 b2MouseJoint *mouseJoint() const; 0060 0061 signals: 0062 void targetChanged(); 0063 void maxForceChanged(); 0064 void frequencyHzChanged(); 0065 void dampingRatioChanged(); 0066 0067 protected: 0068 b2Joint *createJoint(); 0069 0070 private: 0071 QPointF m_target; 0072 float m_maxForce; 0073 float m_frequencyHz; 0074 float m_dampingRatio; 0075 }; 0076 0077 inline float Box2DMouseJoint::dampingRatio() const 0078 { 0079 return m_dampingRatio; 0080 } 0081 0082 inline float Box2DMouseJoint::frequencyHz() const 0083 { 0084 return m_frequencyHz; 0085 } 0086 0087 inline float Box2DMouseJoint::maxForce() const 0088 { 0089 return m_maxForce; 0090 } 0091 0092 inline QPointF Box2DMouseJoint::target() const 0093 { 0094 return m_target; 0095 } 0096 0097 inline b2MouseJoint *Box2DMouseJoint::mouseJoint() const 0098 { 0099 return static_cast<b2MouseJoint*>(joint()); 0100 } 0101 0102 #endif // BOX2DMOUSEJOINT_H