Nebula
Loading...
Searching...
No Matches
actorcontext.h
Go to the documentation of this file.
1#pragma once
2//------------------------------------------------------------------------------
9//------------------------------------------------------------------------------
10
11#include "physicsinterface.h"
13#include "math/vector.h"
14#include "math/plane.h"
15#include "math/mat4.h"
16#include "util/tupleutility.h"
17#include "math/transform.h"
18
19namespace Physics
20{
21
23{
24 ShapeHandle() : shape(nullptr) {}
25 explicit ShapeHandle(physx::PxShape* inShape) : shape(inShape) {}
26 bool IsValid() const { return shape != nullptr; }
27 bool operator==(const ShapeHandle& other) { return shape == other.shape; }
28 physx::PxShape* shape;
29};
30
31class PhysxState;
32class StreamActorPool;
33
35{
36public:
39 static ActorId CreateBox(Math::vector const& extends, IndexT material, ActorType type, Math::mat4 const & transform, IndexT scene = 0);
41 static ActorId CreateSphere(float radius, IndexT material, ActorType type, Math::mat4 const & transform, IndexT scene = 0);
43 static ActorId CreatePlane(Math::plane const& plane, IndexT material, IndexT scene = 0);
45 static ActorId CreateCapsule(float radius, float halfHeight, IndexT material, ActorType type, Math::mat4 const & transform, IndexT scene = 0);
49 static ActorId CreateConvexHull(float* vertices, int numVertices, IndexT material, ActorType type, Math::mat4 const& transform, IndexT scene = 0);
50
52 static Actor& GetActor(ActorId id);
54 static void SetTransform(ActorId id, Math::mat4 const & transform);
58 static void SetPositionOrientation(ActorId id, Math::vec3 const& position, Math::quat const& orientation);
60 static void GetPositionOrientation(ActorId id, Math::vec3& position, Math::quat& orientation);
61
63 static void SetLinearVelocity(ActorId id, Math::vector speed);
66
68 static void SetAngularVelocity(ActorId id, Math::vector speed);
71
73 static void ApplyImpulseAtPos(ActorId id, const Math::vector& impulse, const Math::point& pos);
74
76 static void SetCollisionFeedback(ActorId id, CollisionFeedback feedback);
77
78 // shape stuff
79 enum { DefaultShapeAlloc = 16 };
81 static SizeT GetShapeCount(ActorId id);
82 static void GetShapes(ActorId id, ShapeArrayType& shapes);
83
85 static void SetShapeTransform(const ShapeHandle& shape, const Math::transform& transform);
86
87
89 static ActorId CreateActor(const BodyDescription& desc);
91 static void UpdateBody(ActorId id, const BodyDescription& desc);
92
94 static ShapeId AddShape(ActorId actor, const ColliderDescription& desc);
96 static bool UpdateShape(ShapeId shape, const ColliderDescription& desc);
98 static void RemoveShape(ShapeId shape);
99
101 static Shape& GetShape(ShapeId id);
103 static bool IsValidShape(ShapeId id);
104
106 static physx::PxRigidActor* GetPxActor(ActorId id);
108 static physx::PxRigidDynamic* GetPxDynamic(ActorId id);
109
110 static bool IsValid(ActorId id);
111
113 static void DiscardActor(ActorId id);
114
115 friend class PhysxState;
116 friend class StreamActorPool;
117private:
123 static ActorId AllocateActorId(physx::PxRigidActor* pxActor);
125 static ActorId AllocateActorId(physx::PxRigidActor* pxActor, ActorResourceId res);
127 static ShapeId AllocateShapeId(physx::PxShape* pxShape, ActorId actor, uint64_t geometryHash, uint64_t userData);
128};
129
131{
132public:
134
135 friend class PhysxState;
136 friend class StreamActorPool;
137private:
143 static void DiscardAggregate(AggregateId id);
144};
145
146//------------------------------------------------------------------------------
149inline bool
151{
152 return ActorContext::actorPool.IsValid(id.id);
153}
154
155//------------------------------------------------------------------------------
158inline bool
160{
161 return ActorContext::shapePool.IsValid(id.id);
162}
163
164}
Provides a system for creating array friendly id numbers with reuse and generations.
Definition idgenerationpool.h:43
Simple transform using position, quaternion, and scale.
Definition transform.h:18
Definition actorcontext.h:35
static void DiscardActor(ActorId id)
destroy an actor and the shapes it owns
Definition actorcontext.cc:363
static void SetCollisionFeedback(ActorId id, CollisionFeedback feedback)
modify collision callback handling
Definition actorcontext.cc:714
static Shape & GetShape(ShapeId id)
Definition actorcontext.cc:931
static ActorId CreateActor(const BodyDescription &desc)
Create a body from plain data. Shapes are added separately with AddShape.
Definition actorcontext.cc:743
static ActorId CreateCapsule(float radius, float halfHeight, IndexT material, ActorType type, Math::mat4 const &transform, IndexT scene=0)
Definition actorcontext.cc:434
static void ApplyImpulseAtPos(ActorId id, const Math::vector &impulse, const Math::point &pos)
apply a global impulse vector at the next time step at a global position
Definition actorcontext.cc:627
static ActorId CreateBox(Math::vector const &extends, IndexT material, ActorType type, Math::mat4 const &transform, IndexT scene=0)
helper functions for creating shapes
Definition actorcontext.cc:392
static ShapeId AllocateShapeId(physx::PxShape *pxShape, ActorId actor, uint64_t geometryHash, uint64_t userData)
Definition actorcontext.cc:297
static ActorId CreatePlane(Math::plane const &plane, IndexT material, IndexT scene=0)
Definition actorcontext.cc:498
static void GetPositionOrientation(ActorId id, Math::vec3 &position, Math::quat &orientation)
Definition actorcontext.cc:575
static Math::vector GetLinearVelocity(ActorId id)
Definition actorcontext.cc:597
Util::StackArray< ShapeHandle, DefaultShapeAlloc > ShapeArrayType
Definition actorcontext.h:80
static Ids::IdGenerationPool actorPool
Definition actorcontext.h:119
static Util::Array< Shape > shapes
Definition actorcontext.h:120
static physx::PxRigidDynamic * GetPxDynamic(ActorId id)
shortcut for getting the pxactor object
Definition actorcontext.cc:648
static Util::Array< Actor > actors
Definition actorcontext.h:118
static ActorId AllocateActorId(physx::PxRigidActor *pxActor, ActorResourceId res)
static Actor & GetActor(ActorId id)
Definition actorcontext.cc:520
static bool UpdateShape(ShapeId shape, const ColliderDescription &desc)
apply a description onto an existing shape. The geometry is rebuilt if the shape parameters changed
Definition actorcontext.cc:834
static void SetPositionOrientation(ActorId id, Math::vec3 const &position, Math::quat const &orientation)
Definition actorcontext.cc:557
static void UpdateBody(ActorId id, const BodyDescription &desc)
apply the body properties of the description onto an existing actor
Definition actorcontext.cc:759
static ActorId CreateConvexHull(float *vertices, int numVertices, IndexT material, ActorType type, Math::mat4 const &transform, IndexT scene=0)
Create a convex hull/mesh from vertex buffer.
Definition actorcontext.cc:454
static void RemoveShape(ShapeId shape)
detach and release a shape from its actor
Definition actorcontext.cc:898
static void GetShapes(ActorId id, ShapeArrayType &shapes)
Definition actorcontext.cc:674
static Ids::IdGenerationPool shapePool
Definition actorcontext.h:121
static Math::mat4 GetTransform(ActorId id)
Definition actorcontext.cc:547
static void SetShapeTransform(const ShapeHandle &shape, const Math::transform &transform)
Definition actorcontext.cc:703
static ShapeId AddShape(ActorId actor, const ColliderDescription &desc)
add a shape to an actor
Definition actorcontext.cc:809
static ActorId AllocateActorId(physx::PxRigidActor *pxActor)
static bool IsValid(ActorId id)
Definition actorcontext.h:150
static bool IsValidShape(ShapeId id)
Definition actorcontext.h:159
static Math::transform GetShapeTransform(const ShapeHandle &shape)
Definition actorcontext.cc:694
static void SetTransform(ActorId id, Math::mat4 const &transform)
Definition actorcontext.cc:529
static void SetAngularVelocity(ActorId id, Math::vector speed)
Definition actorcontext.cc:607
@ DefaultShapeAlloc
Definition actorcontext.h:79
friend class PhysxState
Definition actorcontext.h:115
static ActorId CreateSphere(float radius, IndexT material, ActorType type, Math::mat4 const &transform, IndexT scene=0)
Definition actorcontext.cc:413
static void SetLinearVelocity(ActorId id, Math::vector speed)
Definition actorcontext.cc:587
static Math::vector GetAngularVelocity(ActorId id)
Definition actorcontext.cc:617
static SizeT GetShapeCount(ActorId id)
Definition actorcontext.cc:658
static physx::PxRigidActor * GetPxActor(ActorId id)
shortcut for getting the pxactor object
Definition actorcontext.cc:638
friend class StreamActorPool
Definition actorcontext.h:116
Definition actorcontext.h:131
static AggregateId AllocateAggregateId(AggregateResourceId res)
Definition actorcontext.cc:940
static Ids::IdGenerationPool aggPool
Definition actorcontext.h:139
static Aggregate & GetAggregate(AggregateId id)
Definition actorcontext.cc:961
static void DiscardAggregate(AggregateId id)
Definition actorcontext.cc:972
static Util::Array< Aggregate > aggregates
Definition actorcontext.h:138
friend class PhysxState
Definition actorcontext.h:135
friend class StreamActorPool
Definition actorcontext.h:136
Definition physxstate.h:22
Definition streamactorpool.h:66
Nebula's dynamic array class.
Definition array.h:61
Diverse functions for manipulating physics actors.
Definition actorcontext.cc:22
ActorType
Definition physicsinterface.h:38
Array< TYPE, STACK_SIZE > StackArray
Definition array.h:2051
A 4x4 single point precision float matrix.
Definition mat4.h:55
A mathematical plane represented by a normal and a distance from origin.
Definition plane.h:23
Represents a 3D point in space.
Definition point.h:22
A quaternion is usually used to represent an orientation in 3D space.
Definition quat.h:30
A 3D vector.
Definition vec3.h:37
A vector is a 3D direction in space.
Definition vector.h:22
Definition physicsinterface.h:99
Definition physicsinterface.h:63
Definition physicsinterface.h:32
Definition physicsinterface.h:150
Definition physicsinterface.h:84
Definition physicsinterface.h:33
A physics body description.
Definition physicsinterface.h:264
A collider description / create info.
Definition physicsinterface.h:234
Definition actorcontext.h:23
ShapeHandle(physx::PxShape *inShape)
Definition actorcontext.h:25
bool IsValid() const
Definition actorcontext.h:26
ShapeHandle()
Definition actorcontext.h:24
bool operator==(const ShapeHandle &other)
Definition actorcontext.h:27
physx::PxShape * shape
Definition actorcontext.h:28
Definition physicsinterface.h:116
Definition physicsinterface.h:91
int SizeT
Definition types.h:50
int IndexT
Definition types.h:49