1 /*
2 * box2draycast.h
3 * Copyright (c) 2014 Moukhlynin Ruslan <ruslan@khvmntk.ru>
4 *
5 * This file is part of the Box2D QML plugin.
6 *
7 * This software is provided 'as-is', without any express or implied warranty.
8 * In no event will the authors be held liable for any damages arising from
9 * the use of this software.
10 *
11 * Permission is granted to anyone to use this software for any purpose,
12 * including commercial applications, and to alter it and redistribute it
13 * freely, subject to the following restrictions:
14 *
15 * 1. The origin of this software must not be misrepresented; you must not
16 * claim that you wrote the original software. If you use this software in
17 * a product, an acknowledgment in the product documentation would be
18 * appreciated but is not required.
19 *
20 * 2. Altered source versions must be plainly marked as such, and must not be
21 * misrepresented as being the original software.
22 *
23 * 3. This notice may not be removed or altered from any source distribution.
24 */
25
26 #ifndef BOX2DRAYCAST_H
27 #define BOX2DRAYCAST_H
28
29 #include <QObject>
30 #include <QPointF>
31
32 #include <Box2D.h>
33
34 class Box2DFixture;
35
36 class Box2DRayCast : public QObject, public b2RayCastCallback
37 {
38 Q_OBJECT
39
40 Q_PROPERTY(float maxFraction READ maxFraction WRITE setMaxFraction)
41
42 public:
43 Box2DRayCast(QObject *parent = 0);
44
45 float32 ReportFixture(b2Fixture *fixture,
46 const b2Vec2 &point,
47 const b2Vec2 &normal,
48 float32 fraction);
49
50 float maxFraction() const;
51 void setMaxFraction(float maxFraction);
52
53 signals:
54 void fixtureReported(Box2DFixture *fixture,
55 const QPointF &point,
56 const QPointF &normal,
57 qreal fraction);
58
59 private:
60 float mMaxFraction;
61 };
62
maxFraction()63 inline float Box2DRayCast::maxFraction() const
64 {
65 return mMaxFraction;
66 }
67
setMaxFraction(float maxFraction)68 inline void Box2DRayCast::setMaxFraction(float maxFraction)
69 {
70 mMaxFraction = maxFraction;
71 }
72
73 #endif // BOX2DRAYCAST_H
74