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

0001 /*
0002  * box2dmotorjoint.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 BOX2DMOTORJOINT_H
0028 #define BOX2DMOTORJOINT_H
0029 
0030 #include "box2djoint.h"
0031 #include <Box2D.h>
0032 
0033 class Box2DMotorJoint : public Box2DJoint
0034 {
0035     Q_OBJECT
0036 
0037     Q_PROPERTY(QPointF linearOffset READ linearOffset WRITE setLinearOffset NOTIFY linearOffsetChanged)
0038     Q_PROPERTY(float angularOffset READ angularOffset WRITE setAngularOffset NOTIFY angularOffsetChanged)
0039     Q_PROPERTY(float maxForce READ maxForce WRITE setMaxForce NOTIFY maxForceChanged)
0040     Q_PROPERTY(float maxTorque READ maxTorque WRITE setMaxTorque NOTIFY maxTorqueChanged)
0041     Q_PROPERTY(float correctionFactor READ correctionFactor WRITE setCorrectionFactor NOTIFY correctionFactorChanged)
0042 
0043 public:
0044     explicit Box2DMotorJoint(QObject *parent = 0);
0045 
0046     QPointF linearOffset() const;
0047     void setLinearOffset(const QPointF & linearOffset);
0048 
0049     float angularOffset() const;
0050     void setAngularOffset(float angularOffset);
0051 
0052     float maxForce() const;
0053     void setMaxForce(float maxForce);
0054 
0055     float maxTorque() const;
0056     void setMaxTorque(float maxTorque);
0057 
0058     float correctionFactor() const;
0059     void setCorrectionFactor(float correctionFactor);
0060 
0061     b2MotorJoint *motorJoint() const;
0062 
0063 signals:
0064     void linearOffsetChanged();
0065     void angularOffsetChanged();
0066     void maxForceChanged();
0067     void maxTorqueChanged();
0068     void correctionFactorChanged();
0069 
0070 protected:
0071     b2Joint *createJoint();
0072 
0073 private:
0074     QPointF m_linearOffset;
0075     float m_angularOffset;
0076     float m_maxForce;
0077     float m_maxTorque;
0078     float m_correctionFactor;
0079     bool m_defaultLinearOffset;
0080     bool m_defaultAngularOffset;
0081 };
0082 
0083 inline QPointF Box2DMotorJoint::linearOffset() const
0084 {
0085     return m_linearOffset;
0086 }
0087 
0088 inline float Box2DMotorJoint::angularOffset() const
0089 {
0090     return m_angularOffset;
0091 }
0092 
0093 inline float Box2DMotorJoint::maxForce() const
0094 {
0095     return m_maxForce;
0096 }
0097 
0098 inline float Box2DMotorJoint::maxTorque() const
0099 {
0100     return m_maxTorque;
0101 }
0102 
0103 inline float Box2DMotorJoint::correctionFactor() const
0104 {
0105     return m_correctionFactor;
0106 }
0107 
0108 inline b2MotorJoint *Box2DMotorJoint::motorJoint() const
0109 {
0110     return static_cast<b2MotorJoint*>(joint());
0111 }
0112 
0113 #endif // BOX2DMOTORJOINT_H