Engine
Frameworkcreatedbymeusableforthecreationofsimplegames.CurrentlysupportsOpenGL(Verysimple)andVulkan.
RaycastCallback.cpp
Go to the documentation of this file.
2 #include "Engine/engine.hpp"
3 
4 namespace Engine
5 {
7  {
8  }
9 
10  RayCastClosestCallback::RayCastClosestCallback(const CollisionLayer detectLayers) : hit(false), detectionLayers(detectLayers)
11  {
12  }
13 
14  float32 RayCastClosestCallback::ReportFixture(b2Fixture* fixture, const b2Vec2& point, const b2Vec2& normal, float32 fraction)
15  {
16  const bool isDetectable = uint16(detectionLayers) & fixture->GetFilterData().categoryBits;
17  if (isDetectable == false)
18  return 1.0f;
19 
20  // Record hit data
21  hit = true;
22  this->point = point;
23  this->normal = normal;
24 
25  // Record Hit Entity
26  const uint64_t entityID = uint64_t(fixture->GetUserData());
27  entity = Engine::GetEngine().lock()->GetEntitySystem().lock()->GetEntity(entityID);
28 
29  // BOX2D Comment - By returning the current fraction, we instruct the calling code to clip the ray and
30  // continue the ray-cast to the next fixture. WARNING: do not assume that fixtures
31  // are reported in order. However, by clipping, we can always get the closest fixture.
32  return fraction;
33  }
34 
36  {
37  }
38 
39  RayCastMultipleCallback::RayCastMultipleCallback(const CollisionLayer detectLayers) : detectionLayers(detectLayers), count(0)
40  {
41  }
42 
43  float32 RayCastMultipleCallback::ReportFixture(b2Fixture* fixture, const b2Vec2& point, const b2Vec2& normal, float32)
44  {
45  const bool isDetectable = uint16(detectionLayers) & fixture->GetFilterData().categoryBits;
46  if (isDetectable == false)
47  return 1.0f;
48 
49  b2Assert(count < MAX_COUNT);
50 
51  // Record hit data
52  points[count] = point;
53  normals[count] = normal;
54  ++count;
55 
56  if (count == MAX_COUNT)
57  {
58  // At this point the buffer is full.
59  // By returning 0, we instruct the calling code to terminate the ray-cast.
60  return 0.0f;
61  }
62 
63  // By returning 1, we instruct the caller to continue without clipping the ray.
64  return 1.0f;
65  }
66 } // namespace Engine
float32 ReportFixture(b2Fixture *fixture, const b2Vec2 &point, const b2Vec2 &normal, float32 fraction) override
Function used by Box2D to tell the Callback class that the ray has collided with a fixture...
float32 ReportFixture(b2Fixture *fixture, const b2Vec2 &point, const b2Vec2 &normal, float32) override
Function used by Box2D to tell the Callback class that the ray has collided with a fixture...
static eastl::weak_ptr< Engine > GetEngine() noexcept
This method allows you to get the instance of the Engine. This method will automatically initialize t...
Definition: engine.cpp:130
CollisionLayer
Bitmask Enum that allows for layered collision checking