File indexing completed on 2024-04-28 07:28:20
0001 /* 0002 * box2dprismaticjoint.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 BOX2PULLEYJOINT_H 0027 #define BOX2PULLEYJOINT_H 0028 0029 #include "box2djoint.h" 0030 #include <Box2D.h> 0031 0032 class Box2DPulleyJoint : public Box2DJoint 0033 { 0034 Q_OBJECT 0035 0036 Q_PROPERTY(QPointF groundAnchorA READ groundAnchorA WRITE setGroundAnchorA NOTIFY groundAnchorAChanged) 0037 Q_PROPERTY(QPointF groundAnchorB READ groundAnchorB WRITE setGroundAnchorB NOTIFY groundAnchorBChanged) 0038 Q_PROPERTY(QPointF localAnchorA READ localAnchorA WRITE setLocalAnchorA NOTIFY localAnchorAChanged) 0039 Q_PROPERTY(QPointF localAnchorB READ localAnchorB WRITE setLocalAnchorB NOTIFY localAnchorBChanged) 0040 Q_PROPERTY(float lengthA READ lengthA WRITE setLengthA NOTIFY lengthAChanged) 0041 Q_PROPERTY(float lengthB READ lengthB WRITE setLengthB NOTIFY lengthBChanged) 0042 Q_PROPERTY(float ratio READ ratio WRITE setRatio NOTIFY ratioChanged) 0043 0044 public: 0045 explicit Box2DPulleyJoint(QObject *parent = 0); 0046 0047 QPointF groundAnchorA() const; 0048 void setGroundAnchorA(const QPointF &groundAnchorA); 0049 0050 QPointF groundAnchorB() const; 0051 void setGroundAnchorB(const QPointF &groundAnchorB); 0052 0053 QPointF localAnchorA() const; 0054 void setLocalAnchorA(const QPointF &localAnchorA); 0055 0056 QPointF localAnchorB() const; 0057 void setLocalAnchorB(const QPointF &localAnchorB); 0058 0059 float lengthA() const; 0060 void setLengthA(float lengthA); 0061 0062 float lengthB() const; 0063 void setLengthB(float lengthB); 0064 0065 float ratio() const; 0066 void setRatio(float ratio); 0067 0068 b2PulleyJoint *pulleyJoint() const; 0069 0070 Q_INVOKABLE float getCurrentLengthA() const; 0071 Q_INVOKABLE float getCurrentLengthB() const; 0072 Q_INVOKABLE QPointF getReactionForce(float32 inv_dt) const; 0073 Q_INVOKABLE float getReactionTorque(float32 inv_dt) const; 0074 0075 signals: 0076 void groundAnchorAChanged(); 0077 void groundAnchorBChanged(); 0078 void localAnchorAChanged(); 0079 void localAnchorBChanged(); 0080 void lengthAChanged(); 0081 void lengthBChanged(); 0082 void ratioChanged(); 0083 0084 protected: 0085 b2Joint *createJoint(); 0086 0087 private: 0088 QPointF m_groundAnchorA; 0089 QPointF m_groundAnchorB; 0090 QPointF m_localAnchorA; 0091 QPointF m_localAnchorB; 0092 float m_lengthA; 0093 float m_lengthB; 0094 float m_ratio; 0095 0096 bool m_defaultLocalAnchorA; 0097 bool m_defaultLocalAnchorB; 0098 bool m_defaultLengthA; 0099 bool m_defaultLengthB; 0100 }; 0101 0102 inline QPointF Box2DPulleyJoint::groundAnchorA() const 0103 { 0104 return m_groundAnchorA; 0105 } 0106 0107 inline QPointF Box2DPulleyJoint::groundAnchorB() const 0108 { 0109 return m_groundAnchorB; 0110 } 0111 0112 inline QPointF Box2DPulleyJoint::localAnchorA() const 0113 { 0114 return m_localAnchorA; 0115 } 0116 0117 inline QPointF Box2DPulleyJoint::localAnchorB() const 0118 { 0119 return m_localAnchorB; 0120 } 0121 0122 inline float Box2DPulleyJoint::lengthA() const 0123 { 0124 return m_lengthA; 0125 } 0126 0127 inline float Box2DPulleyJoint::lengthB() const 0128 { 0129 return m_lengthB; 0130 } 0131 0132 inline float Box2DPulleyJoint::ratio() const 0133 { 0134 return m_ratio; 0135 } 0136 0137 inline b2PulleyJoint *Box2DPulleyJoint::pulleyJoint() const 0138 { 0139 return static_cast<b2PulleyJoint*>(joint()); 0140 } 0141 0142 #endif // BOX2PULLEYJOINT_H