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