Nebula
Loading...
Searching...
No Matches
physicsinterface.h
Go to the documentation of this file.
1#pragma once
2//------------------------------------------------------------------------------
10#include "ids/id.h"
11#include "timing/time.h"
12#include "util/delegate.h"
13#include "util/set.h"
14#include "util/arraystack.h"
15#include "util/stringatom.h"
16#include "math/mat4.h"
17#include "math/transform.h"
19#include "flat/physics/material.h"
20
21#include <functional>
22#include "PxPhysicsAPI.h"
23
24//------------------------------------------------------------------------------
25
26namespace Physics
27{
28
33
35{
36 Static,
39};
40
42{
43 physx::PxMaterial * material;
45 uint64_t serialId;
46 float density;
47};
48
49struct ActorId
50{
52 ActorId() : id(Ids::InvalidId32) {}
53 ActorId(uint32_t i) : id(i) {}
54};
55
57{
59 ConstraintId() : id(Ids::InvalidId32) {}
60 ConstraintId(uint32_t i) : id(i) {}
61};
62
64{
66 AggregateId() : id(Ids::InvalidId32) {}
67 AggregateId(uint32_t i) : id(i) {}
68};
69
70struct Actor
71{
72 physx::PxActor* actor;
75 uint64_t userData;
76#ifdef NEBULA_DEBUG
77 Util::String debugName;
78#endif
79};
80
82{
85 physx::PxJoint* joint;
86 uint64_t userData;
87};
88
96
97using UpdateFunctionType = void (*) (const Actor&);
98
109
111
114struct Scene
115{
116 physx::PxFoundation *foundation;
117 physx::PxPhysics *physics;
118 physx::PxScene *scene;
119 physx::PxControllerManager *controllerManager;
120 physx::PxDefaultCpuDispatcher *dispatcher;
124 bool isSimulating = false;
127};
128
130void Setup();
132void ShutDown();
133
135void Update(Timing::Time delta);
136
138void BeginSimulating(Timing::Time delta, IndexT scene);
139void EndSimulating(IndexT scene);
140
142void FlushSimulation(IndexT scene);
143
147void DestroyScene(IndexT scene);
148
151
152
154void SetActiveActorCallback(UpdateFunctionType callback, IndexT sceneId = 0);
156void SetEventCallback(EventCallbackType callback, IndexT sceneId = 0);
157
158
160void RenderDebug();
161
163void SetOnSleepCallback(Util::Delegate<void(ActorId* id, SizeT num)> const& callback);
165void SetOnWakeCallback(Util::Delegate<void(ActorId* id, SizeT num)> const& callback);
166
168IndexT SetPhysicsMaterial(Util::StringAtom name, float staticFriction, float dynamicFriction, float restition, float density);
175
177ActorId CreateActorInstance(Physics::ActorResourceId id, Math::transform const& trans, Physics::ActorType type, uint64_t userData, IndexT scene = 0);
180}
181//------------------------------------------------------------------------------
Simple transform using position, quaternion, and scale.
Definition transform.h:18
Nebula's dynamic array class.
Definition array.h:60
Nebula delegate class, allows to store a function, method or lambda call into a C++ object for later ...
Definition delegate.h:39
A collection of unique values with quick lookup.
Definition set.h:34
A StringAtom.
Definition stringatom.h:22
This simple Id pool implements a set of free and used consecutive integers.
Definition id.h:135
uint32_t Id32
Definition id.h:138
Diverse functions for manipulating physics actors.
Definition actorcontext.cc:18
Physics::Scene & GetScene(IndexT idx)
Definition physicsinterface.cc:173
void FlushSimulation(IndexT scene)
this will block until simulation has ended for cleanups e.g.
Definition physicsinterface.cc:350
ActorType
Definition physicsinterface.h:35
@ Dynamic
Definition physicsinterface.h:38
@ Kinematic
Definition shapes.h:18
@ Static
Definition shapes.h:17
void RenderDebug()
render a debug visualization of the level
Definition physicsinterface.cc:200
SizeT GetNrMaterials()
Definition physicsinterface.cc:300
void ShutDown()
close the physics subsystem
Definition physicsinterface.cc:86
void SetEventCallback(EventCallbackType callback, IndexT sceneId)
Definition physicsinterface.cc:182
Physics::Material & GetMaterial(IndexT idx)
Definition physicsinterface.cc:228
ActorId CreateActorInstance(Physics::ActorResourceId id, Math::transform const &trans, Physics::ActorType type, uint64_t userData, IndexT scene)
Definition physicsinterface.cc:359
void Setup()
initialize the physics subsystem and create a default scene
Definition physicsinterface.cc:62
void SetOnSleepCallback(Util::Delegate< void(ActorId *id, SizeT num)> const &callback)
Definition physicsinterface.cc:241
void EndSimulating(IndexT scene)
Definition physicsinterface.cc:341
void DestroyActorInstance(Physics::ActorId id)
Definition physicsinterface.cc:368
void DestroyScene(IndexT sceneId)
Definition physicsinterface.cc:140
void SetActiveActorCallback(UpdateFunctionType callback, IndexT sceneId)
Definition physicsinterface.cc:191
void(*)(const Actor &) UpdateFunctionType
Definition physicsinterface.h:97
void SetOnWakeCallback(Util::Delegate< void(ActorId *id, SizeT num)> const &callback)
Definition physicsinterface.cc:250
void BeginSimulating(Timing::Time delta, IndexT scene)
explicit calls to simulate and fetch results. Do not mix with Update!
Definition physicsinterface.cc:328
void Update(Timing::Time delta)
perform sync simulation step(s)
Definition physicsinterface.cc:315
IndexT SetPhysicsMaterial(Util::StringAtom name, float staticFriction, float dynamicFriction, float restitution, float density)
Definition physicsinterface.cc:259
IndexT CreateScene()
Definition physicsinterface.cc:95
IndexT LookupMaterial(Util::StringAtom name)
Definition physicsinterface.cc:291
void(*)(const Util::Array< ContactEvent > &) EventCallbackType
Definition physicsinterface.h:110
double Time
the time datatype
Definition time.h:18
#define RESOURCE_ID_TYPE(type)
Definition resourceid.h:41
Represents a 3D point in space.
Definition point.h:22
A vector is a 3D direction in space.
Definition vector.h:22
Definition physicsinterface.h:71
physx::PxActor * actor
Definition physicsinterface.h:72
ActorResourceId res
Definition physicsinterface.h:74
uint64_t userData
Definition physicsinterface.h:75
ActorId id
Definition physicsinterface.h:73
Definition physicsinterface.h:50
ActorId()
Definition physicsinterface.h:52
ActorId(uint32_t i)
Definition physicsinterface.h:53
Ids::Id32 id
Definition physicsinterface.h:51
Definition physicsinterface.h:29
Definition physicsinterface.h:90
AggregateResourceId res
Definition physicsinterface.h:92
AggregateId id
Definition physicsinterface.h:91
Util::Array< ActorId > actors
Definition physicsinterface.h:93
Util::Array< ConstraintId > constraints
Definition physicsinterface.h:94
Definition physicsinterface.h:64
AggregateId()
Definition physicsinterface.h:66
AggregateId(uint32_t i)
Definition physicsinterface.h:67
Ids::Id32 id
Definition physicsinterface.h:65
Definition physicsinterface.h:30
Definition physicsinterface.h:82
ConstraintId id
Definition physicsinterface.h:83
Ids::Id32 res
Definition physicsinterface.h:84
uint64_t userData
Definition physicsinterface.h:86
physx::PxJoint * joint
Definition physicsinterface.h:85
Definition physicsinterface.h:57
Ids::Id32 id
Definition physicsinterface.h:58
ConstraintId(uint32_t i)
Definition physicsinterface.h:60
ConstraintId()
Definition physicsinterface.h:59
Definition physicsinterface.h:32
Definition physicsinterface.h:100
Math::vector normal
Definition physicsinterface.h:105
ActorId actor1
Definition physicsinterface.h:102
ActorId actor0
Definition physicsinterface.h:101
float separation
Definition physicsinterface.h:107
Math::vector impulse
Definition physicsinterface.h:106
Math::point position
Definition physicsinterface.h:104
Definition physicsinterface.h:42
Util::StringAtom name
Definition physicsinterface.h:44
physx::PxMaterial * material
Definition physicsinterface.h:43
uint64_t serialId
Definition physicsinterface.h:45
float density
Definition physicsinterface.h:46
Definition physicsinterface.h:31
physx scene classes, foundation and physics are duplicated here for convenience instead of static get...
Definition physicsinterface.h:115
Util::Set< Ids::Id32 > modifiedActors
Definition physicsinterface.h:126
Timing::Time time
Definition physicsinterface.h:123
physx::PxFoundation * foundation
Definition physicsinterface.h:116
UpdateFunctionType updateFunction
Definition physicsinterface.h:121
physx::PxPhysics * physics
Definition physicsinterface.h:117
EventCallbackType eventCallback
Definition physicsinterface.h:122
bool isSimulating
Definition physicsinterface.h:124
physx::PxDefaultCpuDispatcher * dispatcher
Definition physicsinterface.h:120
Util::Array< Physics::ContactEvent > eventBuffer
Definition physicsinterface.h:125
physx::PxScene * scene
Definition physicsinterface.h:118
physx::PxControllerManager * controllerManager
Definition physicsinterface.h:119
Nebula's universal string class.
Definition string.h:50
Typedefs for the Timing subsystem.
int SizeT
Definition types.h:49
int IndexT
Definition types.h:48