-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRaycast2d.hpp
59 lines (44 loc) · 1.33 KB
/
Raycast2d.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#pragma once
#include "../../Core/Core.hpp"
namespace alce
{
class Raycast2D : public Component
{
public:
Raycast2D();
void Init();
void Update();
void DebugRender();
float length = 5.0f;
Vector2 direction = Vector2(0.0f, -1.0f);
private:
friend class GameObject;
B2WorldPtr world = nullptr;
ContactListenerPtr contactListener;
class RaycastCallback : public b2RayCastCallback
{
public:
bool hit = false;
b2Fixture* fixture = nullptr;
b2Vec2 point;
b2Vec2 normal;
GameObject* owner;
GameObject* currentImpact = nullptr;
float ReportFixture(b2Fixture* f, const b2Vec2& p, const b2Vec2& n, float fraction) override
{
GameObject* other = static_cast<GameObject*>(f->GetBody()->attachedObject);
owner->OnImpact(other);
other->OnImpact(owner);
hit = true;
fixture = f;
point = p;
normal = n;
currentImpact = other;
return fraction;
}
};
RaycastCallback callback;
GameObject* previousImpact = nullptr;
};
typedef std::shared_ptr<Raycast2D> Raycast2DPtr;
}