File indexing completed on 2024-03-24 15:14:08

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 BOX2DPRISMATICJOINT_H
0027 #define BOX2DPRISMATICJOINT_H
0028 
0029 #include "box2djoint.h"
0030 #include <Box2D.h>
0031 
0032 class Box2DPrismaticJoint : 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(QPointF localAxisA READ localAxisA WRITE setLocalAxisA NOTIFY localAxisAChanged)
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 lowerTranslation READ lowerTranslation WRITE setLowerTranslation NOTIFY lowerTranslationChanged)
0042     Q_PROPERTY(float upperTranslation READ upperTranslation WRITE setUpperTranslation NOTIFY upperTranslationChanged)
0043     Q_PROPERTY(bool enableMotor READ enableMotor WRITE setEnableMotor NOTIFY enableMotorChanged)
0044     Q_PROPERTY(float maxMotorForce READ maxMotorForce WRITE setMaxMotorForce NOTIFY maxMotorForceChanged)
0045     Q_PROPERTY(float motorSpeed READ motorSpeed WRITE setMotorSpeed NOTIFY motorSpeedChanged)
0046 
0047 public:
0048     explicit Box2DPrismaticJoint(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     QPointF localAxisA() const;
0057     void setLocalAxisA(const QPointF &localAxisA);
0058 
0059     float referenceAngle() const;
0060     void setReferenceAngle(float referenceAngle);
0061 
0062     bool enableLimit() const;
0063     void setEnableLimit(bool enableLimit);
0064 
0065     float lowerTranslation() const;
0066     void setLowerTranslation(float lowerTranslation);
0067 
0068     float upperTranslation() const;
0069     void setUpperTranslation(float upperTranslation);
0070 
0071     bool enableMotor() const;
0072     void setEnableMotor(bool enableMotor);
0073 
0074     float maxMotorForce() const;
0075     void setMaxMotorForce(float maxMotorForce);
0076 
0077     float motorSpeed() const;
0078     void setMotorSpeed(float motorSpeed);
0079 
0080     Q_INVOKABLE float getJointTranslation() const;
0081     Q_INVOKABLE float getJointSpeed() const;
0082 
0083     b2PrismaticJoint *prismaticJoint() const;
0084 
0085 signals:
0086     void localAnchorAChanged();
0087     void localAnchorBChanged();
0088     void localAxisAChanged();
0089     void referenceAngleChanged();
0090     void enableLimitChanged();
0091     void lowerTranslationChanged();
0092     void upperTranslationChanged();
0093     void enableMotorChanged();
0094     void maxMotorForceChanged();
0095     void motorSpeedChanged();
0096 
0097 protected:
0098     b2Joint *createJoint();
0099 
0100 private:
0101     QPointF m_localAnchorA;
0102     QPointF m_localAnchorB;
0103     QPointF m_localAxisA;
0104     float m_referenceAngle;
0105     bool m_enableLimit;
0106     float m_lowerTranslation;
0107     float m_upperTranslation;
0108     bool m_enableMotor;
0109     float m_maxMotorForce;
0110     float m_motorSpeed;
0111 
0112     bool m_defaultLocalAnchorA;
0113     bool m_defaultLocalAnchorB;
0114     bool m_defaultReferenceAngle;
0115 };
0116 
0117 inline QPointF Box2DPrismaticJoint::localAnchorA() const
0118 {
0119     return m_localAnchorA;
0120 }
0121 
0122 inline QPointF Box2DPrismaticJoint::localAnchorB() const
0123 {
0124     return m_localAnchorB;
0125 }
0126 
0127 inline QPointF Box2DPrismaticJoint::localAxisA() const
0128 {
0129     return m_localAxisA;
0130 }
0131 
0132 inline float Box2DPrismaticJoint::referenceAngle() const
0133 {
0134     return m_referenceAngle;
0135 }
0136 
0137 inline bool Box2DPrismaticJoint::enableLimit() const
0138 {
0139     return m_enableLimit;
0140 }
0141 
0142 inline float Box2DPrismaticJoint::lowerTranslation() const
0143 {
0144     return m_lowerTranslation;
0145 }
0146 
0147 inline float Box2DPrismaticJoint::upperTranslation() const
0148 {
0149     return m_upperTranslation;
0150 }
0151 
0152 inline bool Box2DPrismaticJoint::enableMotor() const
0153 {
0154     return m_enableMotor;
0155 }
0156 
0157 inline float Box2DPrismaticJoint::maxMotorForce() const
0158 {
0159     return m_maxMotorForce;
0160 }
0161 
0162 inline float Box2DPrismaticJoint::motorSpeed() const
0163 {
0164     return m_motorSpeed;
0165 }
0166 
0167 inline b2PrismaticJoint *Box2DPrismaticJoint::prismaticJoint() const
0168 {
0169     return static_cast<b2PrismaticJoint*>(joint());
0170 }
0171 
0172 #endif // BOX2DPRISMATICJOINT_H