File indexing completed on 2024-03-24 15:14:08
0001 /* 0002 * box2drevolutejoint.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 BOX2DWHEELJOINT_H 0028 #define BOX2DWHEELJOINT_H 0029 0030 #include "box2djoint.h" 0031 #include <Box2D.h> 0032 0033 class Box2DWheelJoint : public Box2DJoint 0034 { 0035 Q_OBJECT 0036 0037 Q_PROPERTY(QPointF localAnchorA READ localAnchorA WRITE setLocalAnchorA NOTIFY localAnchorAChanged) 0038 Q_PROPERTY(QPointF localAnchorB READ localAnchorB WRITE setLocalAnchorB NOTIFY localAnchorBChanged) 0039 Q_PROPERTY(QPointF localAxisA READ localAxisA WRITE setLocalAxisA NOTIFY localAxisAChanged) 0040 Q_PROPERTY(float dampingRatio READ dampingRatio WRITE setDampingRatio NOTIFY dampingRatioChanged) 0041 Q_PROPERTY(float frequencyHz READ frequencyHz WRITE setFrequencyHz NOTIFY frequencyHzChanged) 0042 Q_PROPERTY(float maxMotorTorque READ maxMotorTorque WRITE setMaxMotorTorque NOTIFY maxMotorTorqueChanged) 0043 Q_PROPERTY(float motorSpeed READ motorSpeed WRITE setMotorSpeed NOTIFY motorSpeedChanged) 0044 Q_PROPERTY(bool enableMotor READ enableMotor WRITE setEnableMotor NOTIFY enableMotorChanged) 0045 0046 public: 0047 explicit Box2DWheelJoint(QObject *parent = 0); 0048 0049 QPointF localAnchorA() const; 0050 void setLocalAnchorA(const QPointF &localAnchorA); 0051 0052 QPointF localAnchorB() const; 0053 void setLocalAnchorB(const QPointF &localAnchorB); 0054 0055 QPointF localAxisA() const; 0056 void setLocalAxisA(const QPointF &localAxisA); 0057 0058 bool enableMotor() const; 0059 void setEnableMotor(bool enableMotor); 0060 0061 float maxMotorTorque() const; 0062 void setMaxMotorTorque(float maxMotorTorque); 0063 0064 float motorSpeed() const; 0065 void setMotorSpeed(float motorSpeed); 0066 0067 float frequencyHz() const; 0068 void setFrequencyHz(float frequencyHz); 0069 0070 float dampingRatio() const; 0071 void setDampingRatio(float dampingRatio); 0072 0073 b2WheelJoint *wheelJoint() const; 0074 0075 Q_INVOKABLE QPointF getReactionForce(float32 inv_dt) const; 0076 Q_INVOKABLE float getReactionTorque(float32 inv_dt) const; 0077 Q_INVOKABLE float getJointTranslation() const; 0078 Q_INVOKABLE float getJointSpeed() const; 0079 0080 signals: 0081 void localAnchorAChanged(); 0082 void localAnchorBChanged(); 0083 void localAxisAChanged(); 0084 void enableMotorChanged(); 0085 void maxMotorTorqueChanged(); 0086 void motorSpeedChanged(); 0087 void frequencyHzChanged(); 0088 void dampingRatioChanged(); 0089 0090 protected: 0091 b2Joint *createJoint(); 0092 0093 private: 0094 QPointF m_localAnchorA; 0095 QPointF m_localAnchorB; 0096 QPointF m_localAxisA; 0097 bool m_enableMotor; 0098 float m_maxMotorTorque; 0099 float m_motorSpeed; 0100 float m_frequencyHz; 0101 float m_dampingRatio; 0102 0103 bool m_defaultLocalAnchorA; 0104 bool m_defaultLocalAnchorB; 0105 bool m_defaultLocalAxisA; 0106 }; 0107 0108 inline QPointF Box2DWheelJoint::localAnchorA() const 0109 { 0110 return m_localAnchorA; 0111 } 0112 0113 inline QPointF Box2DWheelJoint::localAnchorB() const 0114 { 0115 return m_localAnchorB; 0116 } 0117 0118 inline QPointF Box2DWheelJoint::localAxisA() const 0119 { 0120 return m_localAxisA; 0121 } 0122 0123 inline bool Box2DWheelJoint::enableMotor() const 0124 { 0125 return m_enableMotor; 0126 } 0127 0128 inline float Box2DWheelJoint::maxMotorTorque() const 0129 { 0130 return m_maxMotorTorque; 0131 } 0132 0133 inline float Box2DWheelJoint::motorSpeed() const 0134 { 0135 return m_motorSpeed; 0136 } 0137 0138 inline float Box2DWheelJoint::frequencyHz() const 0139 { 0140 return m_frequencyHz; 0141 } 0142 0143 inline float Box2DWheelJoint::dampingRatio() const 0144 { 0145 return m_dampingRatio; 0146 } 0147 0148 inline b2WheelJoint *Box2DWheelJoint::wheelJoint() const 0149 { 0150 return static_cast<b2WheelJoint*>(joint()); 0151 } 0152 0153 #endif // BOX2DWHEELJOINT_H