Untitled Game engine no.5  1.0
Public Types | Static Public Member Functions | List of all members
Engine::Physics Struct Reference

#include <Physics.hpp>

Public Types

enum  CollisionType { D2, D3 }
 

Static Public Member Functions

static std::vector< CollisionPointRaycast (const Scene &scene, glm::vec3 pos, glm::vec3 dir, float maxDistance=FLT_MAX)
 
static CollisionPoint RaycastClosest (const Scene &scene, glm::vec3 pos, glm::vec3 dir, float maxDistance=FLT_MAX)
 
static CollisionPoint GJK_EPA (const Shape &colliderA, const Shape &colliderB, CollisionType type=D3)
 Combination Gilbert-Johnson-Keerthi Expanding-Polytope-Algorithm TODO: (not fully memory optimized)
 
static CollisionPoint EPA2 (Simplex &simplex, const Shape &shapeA, const Shape &shapeB)
 Expanding Polytope Algorithm Implementation Calculates the separation normal from a colliding GJK simplex. Assumes that the input simplex contains a collision. More...
 
static bool GJK (const Shape &colliderA, const Shape &colliderB, Simplex &simplex, CollisionType type)
 Gilbert-Johnson-Keerthi collision detection algorithm https://blog.winter.dev/2020/gjk-algorithm/ improved from. More...
 
static bool NextSimplex (Simplex &simplex, glm::vec3 &direction, CollisionType type)
 
static bool Line (Simplex &simplex, glm::vec3 &direction)
 
static bool Triangle (Simplex &simplex, glm::vec3 &direction)
 
static bool Tetrahedron (Simplex &simplex, glm::vec3 &direction)
 
static void Update (Scene &scene)
 
static void simulateSystem (Scene &scene, float dt)
 Simulate the scene elements by a delta t Partially Implements Extended Position Based Dynamics. More...
 
static CollisionPoint processJoint (const Ref< Joint > &joint, const Ref< PhysicsEntity > &pe1, const Ref< PhysicsEntity > &pe2)
 
static void processJoints (const std::vector< Ref< Joint >> &joints, float h)
 
static void processCollisions (std::vector< Ref< PhysicsEntity >> &elements, float h, CollisionType type=D3)
 Generate collision data and solve it. More...
 
static void applyManifold (CollisionPoint cp, Ref< PhysicsEntity > &e1, Ref< PhysicsEntity > &e2, float h)
 
static std::vector< Ref< Joint > > CollectJoints (const Scene &scene)
 
static std::vector< Ref< PhysicsEntity > > CollectBodiesAndParticles (Scene &scene)
 
static std::vector< Ref< PhysicsEntity > > Collect2DElements (Scene &scene)
 
static Support furthestDiff (const Shape &shapeA, const Shape &shapeB, const glm::vec3 &norm, Support &support)
 
static void Barycentric (const glm::vec3 &p, const glm::vec3 &a, const glm::vec3 &b, const glm::vec3 &c, float &u, float &v, float &w)
 

Detailed Description

XPBD GJK EPA style physics engine (enjoy :) ).

Member Enumeration Documentation

◆ CollisionType

Enumeration for indexing 3D or 2D physics interactions.

Member Function Documentation

◆ applyManifold()

static void Engine::Physics::applyManifold ( CollisionPoint  cp,
Ref< PhysicsEntity > &  e1,
Ref< PhysicsEntity > &  e2,
float  h 
)
inlinestatic

Process delta x and delta q data from joints or collisions.

Parameters
cpdelta data
e1physics entity 1
e2physics entitiy 2
hdelta t

◆ Barycentric()

static void Engine::Physics::Barycentric ( const glm::vec3 &  p,
const glm::vec3 &  a,
const glm::vec3 &  b,
const glm::vec3 &  c,
float &  u,
float &  v,
float &  w 
)
inlinestatic

Calculate barycentric coordinates.

lovingly adapted from https://gamedev.stackexchange.com/questions/23743/whats-the-most-efficient-way-to-find-barycentric-coordinates

Inputs are the collision point the face vertexes and the outputs are the triangle coordinates (u, v, w).

Parameters
p
a
b
c
u
v
w

◆ Collect2DElements()

static std::vector<Ref<PhysicsEntity> > Engine::Physics::Collect2DElements ( Scene scene)
inlinestatic

Generate a list of 2D PhysicsEntity from the scene.

Parameters
scenereference
Returns
list of PhysicsEntity

◆ CollectBodiesAndParticles()

static std::vector<Ref<PhysicsEntity> > Engine::Physics::CollectBodiesAndParticles ( Scene scene)
inlinestatic

Generate a list of PhysicsEntity from the scene.

Parameters
scenereference
Returns
list of PhysicsEntity

◆ CollectJoints()

static std::vector<Ref<Joint> > Engine::Physics::CollectJoints ( const Scene scene)
inlinestatic

Collect joint Components from the Scene.

Parameters
scenescene reference.
Returns
list of Joints

◆ EPA2()

static CollisionPoint Engine::Physics::EPA2 ( Simplex simplex,
const Shape shapeA,
const Shape shapeB 
)
inlinestatic

Expanding Polytope Algorithm Implementation Calculates the separation normal from a colliding GJK simplex. Assumes that the input simplex contains a collision.

lovingly adapted from https://github.com/kevinmoran/GJK/blob/master/GJK.h

Parameters
simplexoutput from running GJK
shapeAshape definition for object A
shapeBshape definition for object B
Returns
struct containing collision data (always returns a collision normal)

◆ furthestDiff()

static Support Engine::Physics::furthestDiff ( const Shape shapeA,
const Shape shapeB,
const glm::vec3 &  norm,
Support support 
)
inlinestatic

Find the difference vector between the two furthest vertex points in the two shapes along the normal.

Parameters
shapeA
shapeB
norm
supportstorage for the support points
Returns
the support point

◆ GJK()

static bool Engine::Physics::GJK ( const Shape colliderA,
const Shape colliderB,
Simplex simplex,
CollisionType  type 
)
inlinestatic

Gilbert-Johnson-Keerthi collision detection algorithm https://blog.winter.dev/2020/gjk-algorithm/ improved from.

Parameters
colliderAshape definition for object A
colliderBshape definition for object B
simplexstorage for simplex data
Returns
true if a there is a collision, false otherwise.

◆ processCollisions()

static void Engine::Physics::processCollisions ( std::vector< Ref< PhysicsEntity >> &  elements,
float  h,
CollisionType  type = D3 
)
inlinestatic

Generate collision data and solve it.

Using GKJ and EPA produce collision normals and then solve them using XPBD.

Parameters
elementslist of physics elements
hdelta t
typetype of collisions to produce (for 2D the physics are not calculated)

◆ processJoint()

static CollisionPoint Engine::Physics::processJoint ( const Ref< Joint > &  joint,
const Ref< PhysicsEntity > &  pe1,
const Ref< PhysicsEntity > &  pe2 
)
inlinestatic

Process a Joint structure using physics entity data.

Parameters
joint
pe1
pe2
Returns
A collision point representing any deltas to solve.

◆ processJoints()

static void Engine::Physics::processJoints ( const std::vector< Ref< Joint >> &  joints,
float  h 
)
inlinestatic

Generate Joint collision interactions.

Parameters
jointslist of joints
hdelta t

◆ Raycast()

static std::vector<CollisionPoint> Engine::Physics::Raycast ( const Scene scene,
glm::vec3  pos,
glm::vec3  dir,
float  maxDistance = FLT_MAX 
)
inlinestatic

Unimplemented raycasting function. TODO: Implement and test

Parameters
scene
pos
dir
maxDistance
Returns

◆ RaycastClosest()

static CollisionPoint Engine::Physics::RaycastClosest ( const Scene scene,
glm::vec3  pos,
glm::vec3  dir,
float  maxDistance = FLT_MAX 
)
inlinestatic

Another unimplemented Raycasting function. TODO: Implement and test

Parameters
scene
pos
dir
maxDistance
Returns

◆ simulateSystem()

static void Engine::Physics::simulateSystem ( Scene scene,
float  dt 
)
inlinestatic

Simulate the scene elements by a delta t Partially Implements Extended Position Based Dynamics.

Collects PhysicsEntities from the scene. Calculates their interactions. Produces delta values. And updates the corresponding scene components.

Parameters
scenescene reference
dttime delta

◆ Update()

static void Engine::Physics::Update ( Scene scene)
inlinestatic

Update the physics parameters of the scene.

Parameters
scene

The documentation for this struct was generated from the following file: