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

0001 /*
0002  * box2dcontact.h
0003  * Copyright (c) 2014 Moukhlynin Ruslan <ruslan@khvmntk.ru>
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 BOX2DCONTACT_H
0027 #define BOX2DCONTACT_H
0028 
0029 #include <QObject>
0030 #include <Box2D.h>
0031 
0032 class Box2DFixture;
0033 
0034 class Box2DContact : public QObject
0035 {
0036     Q_OBJECT
0037     Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled)
0038     Q_PROPERTY(Box2DFixture *fixtureA READ fixtureA)
0039     Q_PROPERTY(Box2DFixture *fixtureB READ fixtureB)
0040     Q_PROPERTY(int childIndexA READ childIndexA)
0041     Q_PROPERTY(int childIndexB READ childIndexB)
0042     Q_PROPERTY(qreal friction READ getFriction WRITE setFriction)
0043     Q_PROPERTY(qreal restitution READ getRestitution WRITE setRestitution)
0044     Q_PROPERTY(qreal tangentSpeed READ getTangentSpeed WRITE setTangentSpeed)
0045 
0046 public:
0047     Box2DContact(b2Contact *contact = 0);
0048     void setContact(b2Contact *contact);
0049 
0050     Q_INVOKABLE bool isTouching();
0051     Q_INVOKABLE void resetFriction();
0052     Q_INVOKABLE void resetRestitution();
0053 
0054 protected:
0055     b2Contact *mContact;
0056 
0057     bool isEnabled() const;
0058     void setEnabled(bool enabled);
0059 
0060     Box2DFixture *fixtureA() const;
0061     Box2DFixture *fixtureB() const;
0062 
0063     int childIndexA() const;
0064     int childIndexB() const;
0065 
0066     qreal getFriction() const;
0067     void setFriction(qreal friction);
0068 
0069     qreal getRestitution() const;
0070     void setRestitution(qreal restitution);
0071 
0072     qreal getTangentSpeed() const;
0073     void setTangentSpeed(qreal speed);
0074 };
0075 
0076 #endif // BOX2DCONTACT_H