File indexing completed on 2024-04-21 14:43:26

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 BOX2DREVOLUTEJOINT_H
0028 #define BOX2DREVOLUTEJOINT_H
0029 
0030 #include "box2djoint.h"
0031 #include <Box2D.h>
0032 
0033 class Box2DRevoluteJoint : 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(float referenceAngle READ referenceAngle WRITE setReferenceAngle NOTIFY referenceAngleChanged)
0040     Q_PROPERTY(bool enableLimit READ enableLimit WRITE setEnableLimit NOTIFY enableLimitChanged)
0041     Q_PROPERTY(float lowerAngle READ lowerAngle WRITE setLowerAngle NOTIFY lowerAngleChanged)
0042     Q_PROPERTY(float upperAngle READ upperAngle WRITE setUpperAngle NOTIFY upperAngleChanged)
0043     Q_PROPERTY(bool enableMotor READ enableMotor WRITE setEnableMotor NOTIFY enableMotorChanged)
0044     Q_PROPERTY(float motorSpeed READ motorSpeed WRITE setMotorSpeed NOTIFY motorSpeedChanged)
0045     Q_PROPERTY(float maxMotorTorque READ maxMotorTorque WRITE setMaxMotorTorque NOTIFY maxMotorTorqueChanged)
0046 
0047 public:
0048     explicit Box2DRevoluteJoint(QObject *parent = 0);
0049 
0050     QPointF localAnchorA() const;
0051     void setLocalAnchorA(const QPointF &localAnchorA);
0052 
0053     QPointF localAnchorB() const;
0054     void setLocalAnchorB(const QPointF &localAnchorB);
0055 
0056     float referenceAngle() const;
0057     void setReferenceAngle(float referenceAngle);
0058 
0059     bool enableLimit() const;
0060     void setEnableLimit(bool enableLimit);
0061 
0062     float lowerAngle() const;
0063     void setLowerAngle(float lowerAngle);
0064 
0065     float upperAngle() const;
0066     void setUpperAngle(float upperAngle);
0067 
0068     bool enableMotor() const;
0069     void setEnableMotor(bool enableMotor);
0070 
0071     float motorSpeed() const;
0072     void setMotorSpeed(float motorSpeed);
0073 
0074     float maxMotorTorque() const;
0075     void setMaxMotorTorque(float maxMotorTorque);
0076 
0077     b2RevoluteJoint *revoluteJoint() const;
0078 
0079     Q_INVOKABLE float getJointAngle() const;
0080     Q_INVOKABLE float getJointSpeed() const;
0081 
0082 signals:
0083     void localAnchorAChanged();
0084     void localAnchorBChanged();
0085     void referenceAngleChanged();
0086     void enableLimitChanged();
0087     void lowerAngleChanged();
0088     void upperAngleChanged();
0089     void enableMotorChanged();
0090     void motorSpeedChanged();
0091     void maxMotorTorqueChanged();
0092 
0093 protected:
0094     b2Joint *createJoint();
0095 
0096 private:
0097     QPointF m_localAnchorA;
0098     QPointF m_localAnchorB;
0099     float m_referenceAngle;
0100     bool m_enableLimit;
0101     float m_lowerAngle;
0102     float m_upperAngle;
0103     bool m_enableMotor;
0104     float m_motorSpeed;
0105     float m_maxMotorTorque;
0106     bool m_defaultLocalAnchorA;
0107     bool m_defaultLocalAnchorB;
0108     bool m_defaultReferenceAngle;
0109 };
0110 
0111 inline QPointF Box2DRevoluteJoint::localAnchorA() const
0112 {
0113     return m_localAnchorA;
0114 }
0115 
0116 inline QPointF Box2DRevoluteJoint::localAnchorB() const
0117 {
0118     return m_localAnchorB;
0119 }
0120 
0121 inline float Box2DRevoluteJoint::referenceAngle() const
0122 {
0123     return m_referenceAngle;
0124 }
0125 
0126 inline float Box2DRevoluteJoint::lowerAngle() const
0127 {
0128     return m_lowerAngle;
0129 }
0130 
0131 inline float Box2DRevoluteJoint::upperAngle() const
0132 {
0133     return m_upperAngle;
0134 }
0135 
0136 inline float Box2DRevoluteJoint::maxMotorTorque() const
0137 {
0138     return m_maxMotorTorque;
0139 }
0140 
0141 inline float Box2DRevoluteJoint::motorSpeed() const
0142 {
0143     return m_motorSpeed;
0144 }
0145 
0146 inline bool Box2DRevoluteJoint::enableLimit() const
0147 {
0148     return m_enableLimit;
0149 }
0150 
0151 inline bool Box2DRevoluteJoint::enableMotor() const
0152 {
0153     return m_enableMotor;
0154 }
0155 
0156 inline b2RevoluteJoint *Box2DRevoluteJoint::revoluteJoint() const
0157 {
0158     return static_cast<b2RevoluteJoint*>(joint());
0159 }
0160 
0161 #endif // BOX2DREVOLUTEJOINT_H