VEX Engine
Retro looking game engine made in vulkan mostly because i wanted to understand it better.
Loading...
Searching...
No Matches
vex::PhysicsComponent Struct Reference

Structure representing a physics component. More...

#include <PhysicsSystem.hpp>

Public Member Functions

 PhysicsComponent ()=default
 — Constructors —
 PhysicsComponent (ShapeType s)
void addCollisionEnterBinding (std::function< void(vex::Entity, vex::Entity, const CollisionHit &)> callback)
 Binds a callback for collision enter events.
void addCollisionStayBinding (std::function< void(vex::Entity, vex::Entity, const CollisionHit &)> callback)
 Binds a callback for collision stay events.
void addCollisionExitBinding (std::function< void(vex::Entity, vex::Entity)> callback)
 Binds a callback for collision exit events.

Static Public Member Functions

static PhysicsComponent Box (glm::vec3 halfExtents={0.5f, 0.5f, 0.5f}, BodyType bodyType=BodyType::STATIC, float mass=1.0f, float friction=0.5f, float bounce=0.1f)
 Creates a box-shaped physics component.
static PhysicsComponent RoundedBox (glm::vec3 halfExtents, float radius=0.05f, BodyType bodyType=BodyType::DYNAMIC, float mass=1.0f, float friction=0.5f, float bounce=0.1f)
 Creates a rounded box.
static PhysicsComponent Sphere (float radius=0.5f, BodyType bodyType=BodyType::STATIC, float mass=1.0f, float friction=0.5f, float bounce=0.1f)
 Creates a sphere-shaped physics component.
static PhysicsComponent Capsule (float radius=0.5f, float height=1.0f, BodyType bodyType=BodyType::STATIC, float mass=1.0f, float friction=0.5f, float bounce=0.1f)
 Creates a capsule-shaped physics component.
static PhysicsComponent Cylinder (float radius=0.5f, float height=1.0f, BodyType bodyType=BodyType::STATIC, float mass=1.0f, float friction=0.5f, float bounce=0.1f)
 Creates a cylinder-shaped physics component.
static PhysicsComponent ConvexHull (std::vector< JPH::Vec3 > points, BodyType bodyType=BodyType::STATIC, float mass=1.0f, float friction=0.5f, float bounce=0.1f)
 Creates a convex hull-shaped physics component.
static PhysicsComponent Mesh (MeshComponent &mesh, BodyType bodyType=BodyType::STATIC, float mass=1.0f, float friction=0.5f, float bounce=0.1f)
 Creates a mesh-shaped physics component.

Public Attributes

ShapeType shape = ShapeType::BOX
BodyType bodyType = BodyType::STATIC
float mass = 1.0f
float friction = 0.5f
float bounce = 0.1f
uint8_t objectLayer = 0
JPH::BodyID bodyId = JPH::BodyID(JPH::BodyID::cInvalidBodyID)
float linearDamping = 0.05f
float angularDamping = 0.05f
bool isSensor = false
bool allowSleeping = true
bool debugDraw = true
glm::vec3 boxHalfExtents = {0.5f, 0.5f, 0.5f}
float roundedRadius = 0.05f
float sphereRadius = 0.5f
float capsuleRadius = 0.5f
float capsuleHeight = 1.0f
float cylinderRadius = 0.5f
float cylinderHeight = 1.0f
std::vector< JPH::Vec3 > convexPoints
std::vector< glm::vec3 > meshVertices
std::vector< uint32_t > meshIndices
std::function< void(vex::Entity self, vex::Entity other, const CollisionHit &hit)> onCollisionEnter
std::function< void(vex::Entity self, vex::Entity other, const CollisionHit &hit)> onCollisionStay
std::function< void(vex::Entity self, vex::Entity other)> onCollisionExit

Detailed Description

Structure representing a physics component.

Definition at line 100 of file PhysicsSystem.hpp.

Constructor & Destructor Documentation

◆ PhysicsComponent()

vex::PhysicsComponent::PhysicsComponent ( ShapeType s)
inlineexplicit

Definition at line 137 of file PhysicsSystem.hpp.

Member Function Documentation

◆ addCollisionEnterBinding()

void vex::PhysicsComponent::addCollisionEnterBinding ( std::function< void(vex::Entity, vex::Entity, const CollisionHit &)> callback)
inline

Binds a callback for collision enter events.

Parameters
std::function<void(vex::Entity,vex::Entity,constCollisionHit&)> callback The callback function to bind.

Definition at line 281 of file PhysicsSystem.hpp.

◆ addCollisionExitBinding()

void vex::PhysicsComponent::addCollisionExitBinding ( std::function< void(vex::Entity, vex::Entity)> callback)
inline

Binds a callback for collision exit events.

Parameters
std::function<void(vex::Entity,vex::Entity)>callback The callback function to bind.

Definition at line 293 of file PhysicsSystem.hpp.

◆ addCollisionStayBinding()

void vex::PhysicsComponent::addCollisionStayBinding ( std::function< void(vex::Entity, vex::Entity, const CollisionHit &)> callback)
inline

Binds a callback for collision stay events.

Parameters
std::function<void(vex::Entity,vex::Entity,constCollisionHit&)> callback The callback function to bind.

Definition at line 287 of file PhysicsSystem.hpp.

◆ Box()

PhysicsComponent vex::PhysicsComponent::Box ( glm::vec3 halfExtents = {0.5f, 0.5f, 0.5f},
BodyType bodyType = BodyType::STATIC,
float mass = 1.0f,
float friction = 0.5f,
float bounce = 0.1f )
inlinestatic

Creates a box-shaped physics component.

Parameters
glm::vec3halfExtents The half-extents of the box.
BodyTypebodyType The type of body (static, dynamic, kinematic).
floatmass The mass of the box.
floatfriction The friction coefficient of the box.
floatbounce The bounce coefficient of the box.

Definition at line 145 of file PhysicsSystem.hpp.

◆ Capsule()

PhysicsComponent vex::PhysicsComponent::Capsule ( float radius = 0.5f,
float height = 1.0f,
BodyType bodyType = BodyType::STATIC,
float mass = 1.0f,
float friction = 0.5f,
float bounce = 0.1f )
inlinestatic

Creates a capsule-shaped physics component.

Parameters
floatradius The radius of the capsule.
floatheight The height of the capsule.
BodyTypebodyType The type of body (static, dynamic, kinematic).
floatmass The mass of the capsule.
floatfriction The friction coefficient of the capsule.
floatbounce The bounce coefficient of the capsule.

Definition at line 199 of file PhysicsSystem.hpp.

◆ ConvexHull()

PhysicsComponent vex::PhysicsComponent::ConvexHull ( std::vector< JPH::Vec3 > points,
BodyType bodyType = BodyType::STATIC,
float mass = 1.0f,
float friction = 0.5f,
float bounce = 0.1f )
inlinestatic

Creates a convex hull-shaped physics component.

Parameters
std::vector<JPH::Vec3>points The points defining the convex hull.
BodyTypebodyType The type of body (static, dynamic, kinematic).
floatmass The mass of the convex hull.
floatfriction The friction coefficient of the convex hull.
floatbounce The bounce coefficient of the convex hull.

Definition at line 236 of file PhysicsSystem.hpp.

◆ Cylinder()

PhysicsComponent vex::PhysicsComponent::Cylinder ( float radius = 0.5f,
float height = 1.0f,
BodyType bodyType = BodyType::STATIC,
float mass = 1.0f,
float friction = 0.5f,
float bounce = 0.1f )
inlinestatic

Creates a cylinder-shaped physics component.

Parameters
floatradius The radius of the cylinder.
floatheight The height of the cylinder.
BodyTypebodyType The type of body (static, dynamic, kinematic).
floatmass The mass of the cylinder.
floatfriction The friction coefficient of the cylinder.
floatbounce The bounce coefficient of the cylinder.

Definition at line 218 of file PhysicsSystem.hpp.

◆ Mesh()

PhysicsComponent vex::PhysicsComponent::Mesh ( MeshComponent & mesh,
BodyType bodyType = BodyType::STATIC,
float mass = 1.0f,
float friction = 0.5f,
float bounce = 0.1f )
inlinestatic

Creates a mesh-shaped physics component.

Parameters
MeshComponent&mesh The mesh component to create the physics component from.
BodyTypebodyType The type of body (static, dynamic, kinematic).
floatmass The mass of the mesh.
floatfriction The friction coefficient of the mesh.
floatbounce The bounce coefficient of the mesh.

Definition at line 253 of file PhysicsSystem.hpp.

◆ RoundedBox()

PhysicsComponent vex::PhysicsComponent::RoundedBox ( glm::vec3 halfExtents,
float radius = 0.05f,
BodyType bodyType = BodyType::DYNAMIC,
float mass = 1.0f,
float friction = 0.5f,
float bounce = 0.1f )
inlinestatic

Creates a rounded box.

Parameters
glm::vec3halfExtents The half-extents of the rounded box.
floatradius The radius of the rounded corners.
BodyTypebodyType The type of body (static, dynamic, kinematic).
floatmass The mass of the rounded box.
floatfriction The friction coefficient of the rounded box.
floatbounce The bounce coefficient of the rounded box.

Definition at line 163 of file PhysicsSystem.hpp.

◆ Sphere()

PhysicsComponent vex::PhysicsComponent::Sphere ( float radius = 0.5f,
BodyType bodyType = BodyType::STATIC,
float mass = 1.0f,
float friction = 0.5f,
float bounce = 0.1f )
inlinestatic

Creates a sphere-shaped physics component.

Parameters
floatradius The radius of the sphere.
BodyTypebodyType The type of body (static, dynamic, kinematic).
floatmass The mass of the sphere.
floatfriction The friction coefficient of the sphere.
floatbounce The bounce coefficient of the sphere.

Definition at line 181 of file PhysicsSystem.hpp.

Member Data Documentation

◆ allowSleeping

bool vex::PhysicsComponent::allowSleeping = true

Definition at line 111 of file PhysicsSystem.hpp.

◆ angularDamping

float vex::PhysicsComponent::angularDamping = 0.05f

Definition at line 109 of file PhysicsSystem.hpp.

◆ bodyId

JPH::BodyID vex::PhysicsComponent::bodyId = JPH::BodyID(JPH::BodyID::cInvalidBodyID)

Definition at line 107 of file PhysicsSystem.hpp.

◆ bodyType

BodyType vex::PhysicsComponent::bodyType = BodyType::STATIC

Definition at line 102 of file PhysicsSystem.hpp.

◆ bounce

float vex::PhysicsComponent::bounce = 0.1f

Definition at line 105 of file PhysicsSystem.hpp.

◆ boxHalfExtents

glm::vec3 vex::PhysicsComponent::boxHalfExtents = {0.5f, 0.5f, 0.5f}

Definition at line 114 of file PhysicsSystem.hpp.

◆ capsuleHeight

float vex::PhysicsComponent::capsuleHeight = 1.0f

Definition at line 118 of file PhysicsSystem.hpp.

◆ capsuleRadius

float vex::PhysicsComponent::capsuleRadius = 0.5f

Definition at line 117 of file PhysicsSystem.hpp.

◆ convexPoints

std::vector<JPH::Vec3> vex::PhysicsComponent::convexPoints

Definition at line 121 of file PhysicsSystem.hpp.

◆ cylinderHeight

float vex::PhysicsComponent::cylinderHeight = 1.0f

Definition at line 120 of file PhysicsSystem.hpp.

◆ cylinderRadius

float vex::PhysicsComponent::cylinderRadius = 0.5f

Definition at line 119 of file PhysicsSystem.hpp.

◆ debugDraw

bool vex::PhysicsComponent::debugDraw = true

Definition at line 112 of file PhysicsSystem.hpp.

◆ friction

float vex::PhysicsComponent::friction = 0.5f

Definition at line 104 of file PhysicsSystem.hpp.

◆ isSensor

bool vex::PhysicsComponent::isSensor = false

Definition at line 110 of file PhysicsSystem.hpp.

◆ linearDamping

float vex::PhysicsComponent::linearDamping = 0.05f

Definition at line 108 of file PhysicsSystem.hpp.

◆ mass

float vex::PhysicsComponent::mass = 1.0f

Definition at line 103 of file PhysicsSystem.hpp.

◆ meshIndices

std::vector<uint32_t> vex::PhysicsComponent::meshIndices

Definition at line 123 of file PhysicsSystem.hpp.

◆ meshVertices

std::vector<glm::vec3> vex::PhysicsComponent::meshVertices

Definition at line 122 of file PhysicsSystem.hpp.

◆ objectLayer

uint8_t vex::PhysicsComponent::objectLayer = 0

Definition at line 106 of file PhysicsSystem.hpp.

◆ onCollisionEnter

std::function<void(vex::Entity self, vex::Entity other, const CollisionHit& hit)> vex::PhysicsComponent::onCollisionEnter

Definition at line 126 of file PhysicsSystem.hpp.

◆ onCollisionExit

std::function<void(vex::Entity self, vex::Entity other)> vex::PhysicsComponent::onCollisionExit

Definition at line 128 of file PhysicsSystem.hpp.

◆ onCollisionStay

std::function<void(vex::Entity self, vex::Entity other, const CollisionHit& hit)> vex::PhysicsComponent::onCollisionStay

Definition at line 127 of file PhysicsSystem.hpp.

◆ roundedRadius

float vex::PhysicsComponent::roundedRadius = 0.05f

Definition at line 115 of file PhysicsSystem.hpp.

◆ shape

ShapeType vex::PhysicsComponent::shape = ShapeType::BOX

Definition at line 101 of file PhysicsSystem.hpp.

◆ sphereRadius

float vex::PhysicsComponent::sphereRadius = 0.5f

Definition at line 116 of file PhysicsSystem.hpp.


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