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

0001 /*
0002  * box2draycast.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 BOX2DRAYCAST_H
0027 #define BOX2DRAYCAST_H
0028 
0029 #include <QObject>
0030 #include <QPointF>
0031 
0032 #include <Box2D.h>
0033 
0034 class Box2DFixture;
0035 
0036 class Box2DRayCast : public QObject, public b2RayCastCallback
0037 {
0038     Q_OBJECT
0039 
0040     Q_PROPERTY(float maxFraction READ maxFraction WRITE setMaxFraction)
0041 
0042 public:
0043     Box2DRayCast(QObject *parent = 0);
0044 
0045     float32 ReportFixture(b2Fixture *fixture,
0046                           const b2Vec2 &point,
0047                           const b2Vec2 &normal,
0048                           float32 fraction);
0049 
0050     float maxFraction() const;
0051     void setMaxFraction(float maxFraction);
0052 
0053 signals:
0054     void fixtureReported(Box2DFixture *fixture,
0055                          const QPointF &point,
0056                          const QPointF &normal,
0057                          qreal fraction);
0058 
0059 private:
0060     float mMaxFraction;
0061 };
0062 
0063 inline float Box2DRayCast::maxFraction() const
0064 {
0065     return mMaxFraction;
0066 }
0067 
0068 inline void Box2DRayCast::setMaxFraction(float maxFraction)
0069 {
0070     mMaxFraction = maxFraction;
0071 }
0072 
0073 #endif // BOX2DRAYCAST_H