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

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 BOX2FRICTIONJOINT_H
0027 #define BOX2FRICTIONJOINT_H
0028 
0029 #include "box2djoint.h"
0030 #include <Box2D.h>
0031 
0032 class Box2DFrictionJoint : 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(float maxForce READ maxForce WRITE setMaxForce NOTIFY maxForceChanged)
0039     Q_PROPERTY(float maxTorque READ maxTorque WRITE setMaxTorque NOTIFY maxTorqueChanged)
0040 
0041 public:
0042     explicit Box2DFrictionJoint(QObject *parent = 0);
0043 
0044     QPointF localAnchorA() const;
0045     void setLocalAnchorA(const QPointF &localAnchorA);
0046 
0047     QPointF localAnchorB() const;
0048     void setLocalAnchorB(const QPointF &localAnchorB);
0049 
0050     float maxForce() const;
0051     void setMaxForce(float maxForce);
0052 
0053     float maxTorque() const;
0054     void setMaxTorque(float maxTorque);
0055 
0056     b2FrictionJoint *frictionJoint() 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 maxForceChanged();
0065     void maxTorqueChanged();
0066 
0067 protected:
0068     b2Joint *createJoint();
0069 
0070 private:
0071     QPointF m_localAnchorA;
0072     QPointF m_localAnchorB;
0073     float m_maxForce;
0074     float m_maxTorque;
0075     bool m_defaultLocalAnchorA;
0076     bool m_defaultLocalAnchorB;
0077 };
0078 
0079 inline QPointF Box2DFrictionJoint::localAnchorA() const
0080 {
0081     return m_localAnchorA;
0082 }
0083 
0084 inline QPointF Box2DFrictionJoint::localAnchorB() const
0085 {
0086     return m_localAnchorB;
0087 }
0088 
0089 inline float Box2DFrictionJoint::maxForce() const
0090 {
0091     return m_maxForce;
0092 }
0093 
0094 inline float Box2DFrictionJoint::maxTorque() const
0095 {
0096     return m_maxTorque;
0097 }
0098 
0099 inline b2FrictionJoint *Box2DFrictionJoint::frictionJoint() const
0100 {
0101     return static_cast<b2FrictionJoint*>(joint());
0102 }
0103 
0104 #endif // BOX2FRICTIONJOINT_H