File indexing completed on 2024-04-21 14:43:24
0001 /* 0002 * box2ddistancejoint.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 BOX2DDISTANCEJOINT_H 0027 #define BOX2DDISTANCEJOINT_H 0028 0029 #include "box2djoint.h" 0030 #include <Box2D.h> 0031 0032 class Box2DDistanceJoint : public Box2DJoint 0033 { 0034 Q_OBJECT 0035 0036 Q_PROPERTY(QPointF localAnchorA READ localAnchorA WRITE setLocalAnchorA NOTIFY localAnchorAChanged) 0037 Q_PROPERTY(QPointF localAnchorB READ localAnchorB WRITE setLocalAnchorB NOTIFY localAnchorBChanged) 0038 Q_PROPERTY(float length READ length WRITE setLength NOTIFY lengthChanged) 0039 Q_PROPERTY(float frequencyHz READ frequencyHz WRITE setFrequencyHz NOTIFY frequencyHzChanged) 0040 Q_PROPERTY(float dampingRatio READ dampingRatio WRITE setDampingRatio NOTIFY dampingRatioChanged) 0041 0042 public: 0043 explicit Box2DDistanceJoint(QObject *parent = 0); 0044 0045 QPointF localAnchorA() const; 0046 void setLocalAnchorA(const QPointF &localAnchorA); 0047 0048 QPointF localAnchorB() const; 0049 void setLocalAnchorB(const QPointF &localAnchorB); 0050 0051 float length() const; 0052 void setLength(float length); 0053 0054 float frequencyHz() const; 0055 void setFrequencyHz(float frequencyHz); 0056 0057 float dampingRatio() const; 0058 void setDampingRatio(float dampingRatio); 0059 0060 b2DistanceJoint *distanceJoint() const; 0061 0062 Q_INVOKABLE QPointF getReactionForce(float32 inv_dt) const; 0063 Q_INVOKABLE float getReactionTorque(float32 inv_dt) const; 0064 0065 signals: 0066 void localAnchorAChanged(); 0067 void localAnchorBChanged(); 0068 void lengthChanged(); 0069 void frequencyHzChanged(); 0070 void dampingRatioChanged(); 0071 0072 protected: 0073 b2Joint *createJoint(); 0074 0075 private: 0076 QPointF m_localAnchorA; 0077 QPointF m_localAnchorB; 0078 float m_length; 0079 float m_frequencyHz; 0080 float m_dampingRatio; 0081 bool m_defaultLocalAnchorA; 0082 bool m_defaultLocalAnchorB; 0083 bool m_defaultLength; 0084 }; 0085 0086 inline QPointF Box2DDistanceJoint::localAnchorA() const 0087 { 0088 return m_localAnchorA; 0089 } 0090 0091 inline QPointF Box2DDistanceJoint::localAnchorB() const 0092 { 0093 return m_localAnchorB; 0094 } 0095 0096 inline float Box2DDistanceJoint::length() const 0097 { 0098 return m_length; 0099 } 0100 0101 inline float Box2DDistanceJoint::frequencyHz() const 0102 { 0103 return m_frequencyHz; 0104 } 0105 0106 inline float Box2DDistanceJoint::dampingRatio() const 0107 { 0108 return m_dampingRatio; 0109 } 0110 0111 inline b2DistanceJoint *Box2DDistanceJoint::distanceJoint() const 0112 { 0113 return static_cast<b2DistanceJoint*>(joint()); 0114 } 0115 0116 #endif // BOX2DDISTANCEJOINT_H