Toast Engine
Loading...
Searching...
No Matches
physics::Simulator Class Reference

Classes

struct  DebugDirtyBrick
struct  ConnectivityResult
struct  PhysicsStepProfile
 Counters and phase timings for one tick snapshotted at a safe point for a debug view to read. More...

Public Member Functions

 Simulator (const Simulator &)=delete
auto operator= (const Simulator &) -> Simulator &=delete
 Simulator (Simulator &&)=delete
auto operator= (Simulator &&) -> Simulator &=delete
void tick ()
void integrate (float dt)
auto createBody (const BodyDescriptor &descriptor) -> BodyID
void destroyBody (BodyID body)
auto valid (BodyID body) const -> bool
auto state (BodyID body) const -> std::optional< BodyState >
auto setTransform (BodyID body, const glm::vec3 &position, const glm::quat &rotation) -> bool
auto setLinearVelocity (BodyID body, const glm::vec3 &velocity) -> bool
void recordDamage (DamageCommand &&command)
void applyDamageCommands ()
void applyDamageCommand (const DamageCommand &c)
void damageArea (const AreaDamage &damage)
auto explode (const ExplosionDamage &explosion) -> uint32_t
auto shootVoxel (const glm::vec3 &origin, const glm::vec3 &direction, float max_distance, float energy_density, float fracture_radius, const std::optional< FragmentPush > &push=std::nullopt, Hardness max_hardness=k_hardest) -> bool
auto smashCapsule (const CapsuleShape &capsule, const glm::vec3 &position, const glm::quat &rotation, const glm::vec3 &sweep, const CapsuleSmash &smash) -> uint32_t
auto cutVoxel (const glm::vec3 &origin, const glm::vec3 &direction, float max_distance, float energy_density, float radius, float depth, Hardness max_hardness=k_hardest) -> uint32_t
auto runConnectivityAnalysis () -> std::vector< ConnectivityResult >
auto debugDirtyBricks () const -> std::span< const DebugDirtyBrick >
auto overlapCapsule (BodyID ignored, const CapsuleShape &capsule, const glm::vec3 &position, const glm::quat &rotation, float min_penetration, std::vector< QueryContact > &contacts) const -> bool
auto overlapSphere (const SphereShape &sphere, const glm::vec3 &position, float min_penetration, std::vector< QueryContact > &contacts) const -> bool
 Tests a world-space sphere against enabled physics shapes.
auto overlapAABB (const AABB &bounds) const -> bool
 Tests a world-space axis-aligned box against enabled physics shapes.
auto sweepCapsule (BodyID ignored, const CapsuleShape &capsule, const glm::quat &rotation, const glm::vec3 &from, const glm::vec3 &to, float skin, bool refine=true) const -> SweepHit
auto setCapsuleShape (BodyID body, const CapsuleShape &capsule) -> bool
 Resizes the capsule collider of a body.
void moveKinematicBody (BodyID id, const glm::vec3 &position, const glm::quat &rotation, const glm::vec3 &velocity)
void pushBody (BodyID id, const glm::vec3 &point, const glm::vec3 &direction, float speed, float max_impulse)
 Raises the velocity of a dynamic body along direction.
auto takeDebrisSpawns () -> std::vector< DebrisSpawn >

Static Public Member Functions

static auto raycast (glm::vec3 origin, glm::vec3 direction, float max_distance=-1.0f, BodyID ignored={}, uint32_t layers=k_all_layers) -> std::optional< RayHit >
static auto raymulticast (glm::vec3 origin, glm::vec3 direction, float max_distance=-1.0f, int max_hits=-1, BodyID ignored={}, uint32_t layers=k_all_layers) -> std::vector< RayHit >
static auto linecast (glm::vec3 from, glm::vec3 to, int max_hits=-1, BodyID ignored={}, uint32_t layers=k_all_layers) -> std::vector< RayHit >
static auto bodyFor (const toast::Node &node) -> BodyID
static auto stepProfile () -> const PhysicsStepProfile &
 The last tick profile is safe to read from another thread between ticks.
static void recordTickBurst (size_t steps, bool time_budget_reached)
 Stamps how many ticks the accumulator ran once it stops catching up for this frame.
static void recordInterpolationAlpha (double alpha)
 Leftover accumulator time as a fraction of one step for blending the last two poses.
static auto interpolationAlpha () -> float
static auto renderPoseDelta (BodyID id) -> glm::mat4
 World transform from the tick pose to the blended pose drawn this frame and identity unless dynamic and awake.
static auto renderPoseDelta (const toast::VoxelNode &node) -> glm::mat4
static auto renderPoseDeltaFor (const toast::Node &node) -> glm::mat4
 Delta of the dynamic body a node sits below and identity when it follows none.
static void syncRenderPoses ()
 Once per frame after the ticks so nodes below driven bodies match the tick pose the delta starts from.
static auto shapeWorldBounds (ShapeID shape) -> std::optional< AABB >
static auto nodeFor (BodyID body) -> toast::Box< toast::Node >
 Rigidbody or VoxelNode that owns body.
static void callTick ()
static void bindToThisThread () noexcept
static auto onSimulatorThread () noexcept -> bool
static auto pendingRequests () noexcept -> size_t
 How many requests from other threads are waiting for the simulator thread.
static void runPendingRequests ()
 Carries out the requests other threads made, on the simulator thread.
static void requestSleep (BodyID id)
 Puts a body to sleep or wakes it, from any thread.
static void requestWake (BodyID id)
static void registerRigidbody (Rigidbody &node)
static void unregisterRigidbody (Rigidbody &node)
static void registerVoxelNode (toast::VoxelNode &node)
static void unregisterVoxelNode (toast::VoxelNode &node)
static void registerTrigger (Trigger &node)
static void unregisterTrigger (Trigger &node)
static auto current () -> Simulator *
 Simulator running the current step, null outside a play session.
static auto voxelFragmentRecords () -> std::span< const VoxelRenderRecord >
static void setWind (const glm::vec3 &wind)
static auto wind () -> glm::vec3
static void resetWind ()
static auto tryGetVoxelData (VoxelDataID data) -> VoxelShapeData *
static auto tryGetVoxelDataConst (VoxelDataID data) -> const VoxelShapeData *

Friends

class Collider
class Rigidbody
class DynamicRigidbody
class toast::VoxelNode

Member Function Documentation

◆ raycast()

auto physics::Simulator::raycast ( glm::vec3 origin,
glm::vec3 direction,
float max_distance = -1.0f,
BodyID ignored = {},
uint32_t layers = k_all_layers ) -> std::optional< RayHit >
static
Parameters
layersOnly bodies including one of these layers are hit
Here is the caller graph for this function:

◆ sweepCapsule()

auto physics::Simulator::sweepCapsule ( BodyID ignored,
const CapsuleShape & capsule,
const glm::quat & rotation,
const glm::vec3 & from,
const glm::vec3 & to,
float skin,
bool refine = true ) const -> SweepHit
nodiscard

Moves a capsule until it would dig into something

Parameters
refinefalse stops at first iteration, only position is not accurate

The documentation for this class was generated from the following files:
  • engine/src/toast/physics/simulator.hpp
  • engine/src/toast/physics/raycast.cpp
  • engine/src/toast/physics/shape_query.cpp
  • engine/src/toast/physics/simulator.cpp