1 /*
2 * box2draycast.cpp
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 #include "box2draycast.h"
27
28 #include "box2dbody.h"
29 #include "box2dfixture.h"
30 #include "box2dworld.h"
31
Box2DRayCast(QObject * parent)32 Box2DRayCast::Box2DRayCast(QObject *parent) :
33 QObject(parent),
34 mMaxFraction(-1.0f)
35 {
36 }
37
ReportFixture(b2Fixture * fixture,const b2Vec2 & point,const b2Vec2 & normal,float32 fraction)38 float32 Box2DRayCast::ReportFixture(b2Fixture *fixture,
39 const b2Vec2 &point,
40 const b2Vec2 &normal,
41 float32 fraction)
42 {
43 mMaxFraction = -1.0f;
44
45 Box2DFixture *box2dFixture = toBox2DFixture(fixture);
46 Box2DWorld *world = box2dFixture->getBody()->world();
47
48 emit fixtureReported(box2dFixture,
49 world->toPixels(point),
50 world->toPixels(normal),
51 fraction);
52
53 return mMaxFraction;
54 }
55