NoJobEngine
2.0.7
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsSystem.h
Go to the documentation of this file.
1
6
#pragma once
7
8
#include <cstdint>
9
#include <memory>
10
#include <optional>
11
#include <unordered_map>
12
#include <vector>
13
14
#include <glm/glm.hpp>
15
16
namespace
NoJob
17
{
18
class
Scene
;
19
class
Entity
;
20
21
struct
RaycastHit
22
{
23
std::uint64_t
EntityID
= 0;
24
glm::vec3
Point
{ 0.0f };
25
glm::vec3
Normal
{ 0.0f, 1.0f, 0.0f };
26
float
Distance
= 0.0f;
27
};
28
29
struct
TriggerEvent
30
{
31
enum class
Type
{ Enter, Exit };
32
Type
EventType
=
Type::Enter
;
33
std::uint64_t
TriggerEntityID
= 0;
34
std::uint64_t
OtherEntityID
= 0;
35
};
36
37
class
PhysicsSystem
38
{
39
public
:
40
PhysicsSystem
();
41
~PhysicsSystem
();
42
43
PhysicsSystem
(
const
PhysicsSystem
&) =
delete
;
44
PhysicsSystem
&
operator=
(
const
PhysicsSystem
&) =
delete
;
45
46
void
Start
(
Scene
& scene);
47
void
Stop
();
48
void
Update
(
float
deltaTime);
49
bool
IsRunning
()
const
{
return
m_Running; }
50
51
bool
AddForce
(std::uint64_t entityID,
const
glm::vec3& force);
52
bool
AddImpulse
(std::uint64_t entityID,
const
glm::vec3& impulse);
53
bool
SetLinearVelocity
(std::uint64_t entityID,
const
glm::vec3& velocity);
54
glm::vec3
GetLinearVelocity
(std::uint64_t entityID)
const
;
55
56
std::optional<RaycastHit>
Raycast
(
57
const
glm::vec3& origin,
58
const
glm::vec3& direction,
59
float
maxDistance = 1000.0f)
const
;
60
61
const
std::vector<TriggerEvent>&
GetTriggerEvents
()
const
62
{
63
return
m_TriggerEvents;
64
}
65
// Returns true when a physical obstacle exists
66
// between two world-space positions.
67
//
68
// The observer and target entities are excluded.
69
bool
HasObstacleBetween
(
70
const
glm::vec3& origin,
71
const
glm::vec3& destination,
72
std::uint64_t observerID,
73
std::uint64_t targetID
74
)
const
;
75
76
private
:
77
struct
Implementation;
78
std::unique_ptr<Implementation> m_Impl;
79
Scene
* m_Scene =
nullptr
;
80
bool
m_Running =
false
;
81
std::vector<TriggerEvent> m_TriggerEvents;
82
83
void
CreateBodies();
84
void
SyncTransformsFromPhysics();
85
};
86
}
NoJob::Entity
Definition
Entity.h:16
NoJob::PhysicsSystem::operator=
PhysicsSystem & operator=(const PhysicsSystem &)=delete
NoJob::PhysicsSystem::IsRunning
bool IsRunning() const
Definition
PhysicsSystem.h:49
NoJob::PhysicsSystem::PhysicsSystem
PhysicsSystem(const PhysicsSystem &)=delete
NoJob::PhysicsSystem::Raycast
std::optional< RaycastHit > Raycast(const glm::vec3 &origin, const glm::vec3 &direction, float maxDistance=1000.0f) const
Definition
PhysicsSystem.cpp:528
NoJob::PhysicsSystem::AddForce
bool AddForce(std::uint64_t entityID, const glm::vec3 &force)
Definition
PhysicsSystem.cpp:478
NoJob::PhysicsSystem::SetLinearVelocity
bool SetLinearVelocity(std::uint64_t entityID, const glm::vec3 &velocity)
Definition
PhysicsSystem.cpp:504
NoJob::PhysicsSystem::GetTriggerEvents
const std::vector< TriggerEvent > & GetTriggerEvents() const
Definition
PhysicsSystem.h:61
NoJob::PhysicsSystem::Stop
void Stop()
Definition
PhysicsSystem.cpp:288
NoJob::PhysicsSystem::PhysicsSystem
PhysicsSystem()
Definition
PhysicsSystem.cpp:237
NoJob::PhysicsSystem::Update
void Update(float deltaTime)
Definition
PhysicsSystem.cpp:421
NoJob::PhysicsSystem::AddImpulse
bool AddImpulse(std::uint64_t entityID, const glm::vec3 &impulse)
Definition
PhysicsSystem.cpp:491
NoJob::PhysicsSystem::Start
void Start(Scene &scene)
Definition
PhysicsSystem.cpp:253
NoJob::PhysicsSystem::GetLinearVelocity
glm::vec3 GetLinearVelocity(std::uint64_t entityID) const
Definition
PhysicsSystem.cpp:517
NoJob::PhysicsSystem::HasObstacleBetween
bool HasObstacleBetween(const glm::vec3 &origin, const glm::vec3 &destination, std::uint64_t observerID, std::uint64_t targetID) const
Definition
PhysicsSystem.cpp:561
NoJob::Scene
Definition
Scene.h:31
NoJob
Definition
BTActionNode.h:13
NoJob::RaycastHit
Definition
PhysicsSystem.h:22
NoJob::RaycastHit::Normal
glm::vec3 Normal
Definition
PhysicsSystem.h:25
NoJob::RaycastHit::Point
glm::vec3 Point
Definition
PhysicsSystem.h:24
NoJob::RaycastHit::EntityID
std::uint64_t EntityID
Definition
PhysicsSystem.h:23
NoJob::RaycastHit::Distance
float Distance
Definition
PhysicsSystem.h:26
NoJob::TriggerEvent
Definition
PhysicsSystem.h:30
NoJob::TriggerEvent::Type
Type
Definition
PhysicsSystem.h:31
NoJob::TriggerEvent::Type::Enter
@ Enter
Definition
PhysicsSystem.h:31
NoJob::TriggerEvent::OtherEntityID
std::uint64_t OtherEntityID
Definition
PhysicsSystem.h:34
NoJob::TriggerEvent::TriggerEntityID
std::uint64_t TriggerEntityID
Definition
PhysicsSystem.h:33
NoJob::TriggerEvent::EventType
Type EventType
Definition
PhysicsSystem.h:32
Engine
Physics
PhysicsSystem.h
Generated by
1.18.0