Kemena3D
Loading...
Searching...
No Matches
kphysicsobject.h
Go to the documentation of this file.
1
5
6#ifndef KPHYSICSOBJECT_H
7#define KPHYSICSOBJECT_H
8
9#include "kexport.h"
10#include "kdatatype.h"
11
12#include <cstdint>
13#include <vector>
14
15namespace kemena
16{
17 // -------------------------------------------------------------------------
18 // Shape descriptor
19 // -------------------------------------------------------------------------
20
32
57 {
59 kVec3 halfExtents = kVec3(0.5f, 0.5f, 0.5f);
60 float radius = 0.5f;
61 float height = 1.0f;
62 kVec3 customScale = kVec3(1.0f, 1.0f, 1.0f);
63 std::vector<kVec3> meshVertices;
64 std::vector<uint32_t> meshIndices;
65 };
66
67 // -------------------------------------------------------------------------
68 // Object type (motion mode)
69 // -------------------------------------------------------------------------
70
81
82 // -------------------------------------------------------------------------
83 // Creation descriptor
84 // -------------------------------------------------------------------------
85
92 {
95 kVec3 position = kVec3(0.0f, 0.0f, 0.0f);
96 kQuat rotation = kQuat(1.0f, 0.0f, 0.0f, 0.0f);
97 float mass = 1.0f;
98 float friction = 0.5f;
99 float restitution = 0.0f;
100 float linearDamping = 0.05f;
101 float angularDamping = 0.05f;
102 float gravityFactor = 1.0f;
103 };
104
105 // -------------------------------------------------------------------------
106 // kPhysicsObject
107 // -------------------------------------------------------------------------
108
131 {
132 public:
135
136 // --- Transform -------------------------------------------------------
137
139 void setPosition(const kVec3 &position);
140
142 void setRotation(const kQuat &rotation);
143
146
149
150 // --- Velocity --------------------------------------------------------
151
153 void setLinearVelocity(const kVec3 &velocity);
154
156 void setAngularVelocity(const kVec3 &velocity);
157
160
163
164 // --- Forces ----------------------------------------------------------
165
170 void applyForce(const kVec3 &force);
171
176 void applyImpulse(const kVec3 &impulse);
177
182 void applyTorque(const kVec3 &torque);
183
184 // --- Properties ------------------------------------------------------
185
189 void setMass(float mass);
190
192 void setFriction(float friction);
193
195 void setRestitution(float restitution);
196
198 void setLinearDamping(float damping);
199
201 void setAngularDamping(float damping);
202
207 void setGravityFactor(float factor);
208
209 // --- State queries ---------------------------------------------------
210
212 bool isActive() const;
213
216
219
220 // --- Internal (kPhysicsManager only) ---------------------------------
221
229 bool init(void *physicsSystem, const kPhysicsObjectDesc &desc);
230
232 void uninit();
233
235 uint32_t getBodyId() const;
236
237 protected:
238 private:
239 struct Impl;
240 Impl *m_impl;
241 };
242
243} // namespace kemena
244
245#endif // KPHYSICSOBJECT_H
kPhysicsShapeType getShapeType() const
Returns the underlying collision shape type.
void setMass(float mass)
Changes the body mass (kg). No-op for Static bodies.
void setPosition(const kVec3 &position)
Teleports the body to a new world-space position.
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).
kQuat getRotation() const
Returns the body's current world-space orientation.
void setLinearVelocity(const kVec3 &velocity)
Directly sets the linear velocity (m/s).
void setAngularDamping(float damping)
Sets the angular velocity drag coefficient (per second).
kVec3 getPosition() const
Returns the body's current world-space position.
void setLinearDamping(float damping)
Sets the linear velocity drag coefficient (per second).
kVec3 getAngularVelocity() const
Returns the current angular velocity (rad/s).
void applyTorque(const kVec3 &torque)
Applies a torque (N·m) for the current simulation step.
void setAngularVelocity(const kVec3 &velocity)
Directly sets the angular velocity (rad/s).
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).
void setFriction(float friction)
Sets the coefficient of friction (0–1).
void setRestitution(float restitution)
Sets the coefficient of restitution / bounciness (0–1).
void applyForce(const kVec3 &force)
Applies a continuous force (N) at the centre of mass this step.
kVec3 getLinearVelocity() const
Returns the current linear velocity (m/s).
bool init(void *physicsSystem, const kPhysicsObjectDesc &desc)
Initialises the body inside an existing Jolt PhysicsSystem.
void setGravityFactor(float factor)
Scales the world gravity applied to this body.
void applyImpulse(const kVec3 &impulse)
Applies an instantaneous impulse (kg·m/s) at the centre of mass.
void setRotation(const kQuat &rotation)
Sets the body's world-space orientation.
Core type aliases, enumerations, structs, and utility functions used throughout the engine.
Symbol visibility / linkage macro for the Kemena3D library.
#define KEMENA3D_API
Definition kexport.h:35
Top-level Kemena3D engine namespace.
Definition kanimation.h:23
kPhysicsShapeType
Collision shape type.
Definition kphysicsobject.h:23
@ Plane
Infinite plane (object's local +Y); static-only (Jolt restriction).
Definition kphysicsobject.h:30
@ Cylinder
Cylinder defined by radius + total height.
Definition kphysicsobject.h:27
@ Box
Axis-aligned box defined by half-extents.
Definition kphysicsobject.h:25
@ ConvexHull
Convex hull of the object's mesh vertices; any motion type.
Definition kphysicsobject.h:28
@ Capsule
Capsule (cylinder + hemispherical end-caps) defined by radius + total height.
Definition kphysicsobject.h:26
@ Mesh
Triangle mesh from the object's mesh; static-only (Jolt restriction).
Definition kphysicsobject.h:29
@ Sphere
Uniform sphere defined by radius.
Definition kphysicsobject.h:24
glm::quat kQuat
Unit quaternion.
Definition kdatatype.h:40
glm::vec3 kVec3
3-component float vector.
Definition kdatatype.h:33
kPhysicsObjectType
Determines how the physics engine moves (or does not move) a body.
Definition kphysicsobject.h:75
@ Kinematic
Moved via setPosition / setVelocity; not affected by forces.
Definition kphysicsobject.h:78
@ Static
Immovable; used for world geometry and terrain.
Definition kphysicsobject.h:77
@ Dynamic
Full rigid-body simulation (affected by forces and gravity).
Definition kphysicsobject.h:76
@ Trigger
Detects overlaps but exerts no physical response.
Definition kphysicsobject.h:79
All parameters needed to create a kPhysicsObject.
Definition kphysicsobject.h:92
float angularDamping
Angular velocity drag per second.
Definition kphysicsobject.h:101
float linearDamping
Linear velocity drag per second.
Definition kphysicsobject.h:100
kVec3 position
Definition kphysicsobject.h:95
kPhysicsObjectType type
Definition kphysicsobject.h:94
kPhysicsShapeDesc shape
Definition kphysicsobject.h:93
float mass
kg; ignored for Static / Kinematic.
Definition kphysicsobject.h:97
float gravityFactor
Multiplier on world gravity (0 = gravity-free).
Definition kphysicsobject.h:102
float friction
0 = frictionless, 1 = high friction.
Definition kphysicsobject.h:98
float restitution
0 = inelastic, 1 = perfectly elastic.
Definition kphysicsobject.h:99
kQuat rotation
Identity quaternion.
Definition kphysicsobject.h:96
Parameters that fully describe a collision shape.
Definition kphysicsobject.h:57
std::vector< kVec3 > meshVertices
Mesh / ConvexHull source vertices.
Definition kphysicsobject.h:63
std::vector< uint32_t > meshIndices
Mesh source indices (triplets per triangle).
Definition kphysicsobject.h:64
kVec3 halfExtents
Box / Plane: per-axis half-extents (Plane uses x,z).
Definition kphysicsobject.h:59
kVec3 customScale
ConvexHull / Mesh per-axis scale.
Definition kphysicsobject.h:62
float height
Capsule / Cylinder total height.
Definition kphysicsobject.h:61
kPhysicsShapeType type
Definition kphysicsobject.h:58
float radius
Sphere / Capsule / Cylinder radius.
Definition kphysicsobject.h:60