Kemena3D
Loading...
Searching...
No Matches
kemena::kPhysicsObject Class Reference

Represents a single rigid body or trigger volume inside the physics simulation. More...

#include <kphysicsobject.h>

Public Member Functions

 kPhysicsObject ()
 ~kPhysicsObject ()
void setPosition (const kVec3 &position)
 Teleports the body to a new world-space position.
void setRotation (const kQuat &rotation)
 Sets the body's world-space orientation.
kVec3 getPosition () const
 Returns the body's current world-space position.
kQuat getRotation () const
 Returns the body's current world-space orientation.
void setLinearVelocity (const kVec3 &velocity)
 Directly sets the linear velocity (m/s).
void setAngularVelocity (const kVec3 &velocity)
 Directly sets the angular velocity (rad/s).
kVec3 getLinearVelocity () const
 Returns the current linear velocity (m/s).
kVec3 getAngularVelocity () const
 Returns the current angular velocity (rad/s).
void applyForce (const kVec3 &force)
 Applies a continuous force (N) at the centre of mass this step.
void applyImpulse (const kVec3 &impulse)
 Applies an instantaneous impulse (kg·m/s) at the centre of mass.
void applyTorque (const kVec3 &torque)
 Applies a torque (N·m) for the current simulation step.
void setMass (float mass)
 Changes the body mass (kg). No-op for Static bodies.
void setFriction (float friction)
 Sets the coefficient of friction (0–1).
void setRestitution (float restitution)
 Sets the coefficient of restitution / bounciness (0–1).
void setLinearDamping (float damping)
 Sets the linear velocity drag coefficient (per second).
void setAngularDamping (float damping)
 Sets the angular velocity drag coefficient (per second).
void setGravityFactor (float factor)
 Scales the world gravity applied to this body.
bool isActive () const
 Returns true if the body is currently awake and being simulated.
kPhysicsObjectType getObjectType () const
 Returns the motion type (Dynamic / Static / Kinematic / Trigger).
kPhysicsShapeType getShapeType () const
 Returns the underlying collision shape type.
bool init (void *physicsSystem, const kPhysicsObjectDesc &desc)
 Initialises the body inside an existing Jolt PhysicsSystem.
void uninit ()
 Removes the body from the simulation and releases its resources.
uint32_t getBodyId () const
 Returns the internal Jolt body ID (cast from JPH::BodyID).

Detailed Description

Represents a single rigid body or trigger volume inside the physics simulation.

Instances must be created via kPhysicsManager::createObject() and destroyed with kPhysicsManager::destroyObject().

desc.shape.halfExtents = kVec3(1.f, 0.5f, 1.f);
desc.position = kVec3(0.f, 5.f, 0.f);
kPhysicsObject* box = physicsManager->createObject(desc);
box->applyImpulse(kVec3(0.f, 10.f, 0.f));
// Each frame:
physicsManager->update(deltaTime);
object->setPosition(box->getPosition());
kVec3 getPosition() const
Returns the body's current world-space position.
void applyImpulse(const kVec3 &impulse)
Applies an instantaneous impulse (kg·m/s) at the centre of mass.
@ Box
Axis-aligned box defined by half-extents.
Definition kphysicsobject.h:25
glm::vec3 kVec3
3-component float vector.
Definition kdatatype.h:33
@ Dynamic
Full rigid-body simulation (affected by forces and gravity).
Definition kphysicsobject.h:76
All parameters needed to create a kPhysicsObject.
Definition kphysicsobject.h:92
kVec3 position
Definition kphysicsobject.h:95
kPhysicsObjectType type
Definition kphysicsobject.h:94
kPhysicsShapeDesc shape
Definition kphysicsobject.h:93
kVec3 halfExtents
Box / Plane: per-axis half-extents (Plane uses x,z).
Definition kphysicsobject.h:59
kPhysicsShapeType type
Definition kphysicsobject.h:58

Constructor & Destructor Documentation

◆ kPhysicsObject()

kemena::kPhysicsObject::kPhysicsObject ( )

◆ ~kPhysicsObject()

kemena::kPhysicsObject::~kPhysicsObject ( )

Member Function Documentation

◆ applyForce()

void kemena::kPhysicsObject::applyForce ( const kVec3 & force)

Applies a continuous force (N) at the centre of mass this step.

Note
Has no effect on Static or Kinematic bodies.

◆ applyImpulse()

void kemena::kPhysicsObject::applyImpulse ( const kVec3 & impulse)

Applies an instantaneous impulse (kg·m/s) at the centre of mass.

Note
Has no effect on Static or Kinematic bodies.

◆ applyTorque()

void kemena::kPhysicsObject::applyTorque ( const kVec3 & torque)

Applies a torque (N·m) for the current simulation step.

Note
Has no effect on Static or Kinematic bodies.

◆ getAngularVelocity()

kVec3 kemena::kPhysicsObject::getAngularVelocity ( ) const

Returns the current angular velocity (rad/s).

◆ getBodyId()

uint32_t kemena::kPhysicsObject::getBodyId ( ) const

Returns the internal Jolt body ID (cast from JPH::BodyID).

◆ getLinearVelocity()

kVec3 kemena::kPhysicsObject::getLinearVelocity ( ) const

Returns the current linear velocity (m/s).

◆ getObjectType()

kPhysicsObjectType kemena::kPhysicsObject::getObjectType ( ) const

Returns the motion type (Dynamic / Static / Kinematic / Trigger).

◆ getPosition()

kVec3 kemena::kPhysicsObject::getPosition ( ) const

Returns the body's current world-space position.

◆ getRotation()

kQuat kemena::kPhysicsObject::getRotation ( ) const

Returns the body's current world-space orientation.

◆ getShapeType()

kPhysicsShapeType kemena::kPhysicsObject::getShapeType ( ) const

Returns the underlying collision shape type.

◆ init()

bool kemena::kPhysicsObject::init ( void * physicsSystem,
const kPhysicsObjectDesc & desc )

Initialises the body inside an existing Jolt PhysicsSystem.

Parameters
physicsSystemOpaque pointer to a JPH::PhysicsSystem owned by kPhysicsManager.
descFull creation parameters.
Returns
true on success.
Note
Not part of the public API — call kPhysicsManager::createObject() instead.

◆ isActive()

bool kemena::kPhysicsObject::isActive ( ) const

Returns true if the body is currently awake and being simulated.

◆ setAngularDamping()

void kemena::kPhysicsObject::setAngularDamping ( float damping)

Sets the angular velocity drag coefficient (per second).

◆ setAngularVelocity()

void kemena::kPhysicsObject::setAngularVelocity ( const kVec3 & velocity)

Directly sets the angular velocity (rad/s).

◆ setFriction()

void kemena::kPhysicsObject::setFriction ( float friction)

Sets the coefficient of friction (0–1).

◆ setGravityFactor()

void kemena::kPhysicsObject::setGravityFactor ( float factor)

Scales the world gravity applied to this body.

Parameters
factor0 = no gravity, 1 = full gravity (default), negative = anti-gravity.

◆ setLinearDamping()

void kemena::kPhysicsObject::setLinearDamping ( float damping)

Sets the linear velocity drag coefficient (per second).

◆ setLinearVelocity()

void kemena::kPhysicsObject::setLinearVelocity ( const kVec3 & velocity)

Directly sets the linear velocity (m/s).

◆ setMass()

void kemena::kPhysicsObject::setMass ( float mass)

Changes the body mass (kg). No-op for Static bodies.

◆ setPosition()

void kemena::kPhysicsObject::setPosition ( const kVec3 & position)

Teleports the body to a new world-space position.

◆ setRestitution()

void kemena::kPhysicsObject::setRestitution ( float restitution)

Sets the coefficient of restitution / bounciness (0–1).

◆ setRotation()

void kemena::kPhysicsObject::setRotation ( const kQuat & rotation)

Sets the body's world-space orientation.

◆ uninit()

void kemena::kPhysicsObject::uninit ( )

Removes the body from the simulation and releases its resources.


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