physics: rigid body drive API (force/impulse/torque/velocity)
PhysicsWorld facade methods addressed by entity bits via body records: AddForce/AddImpulse/AddTorque (dynamic bodies only, auto-wake), Set/ GetLinearVelocity/SetAngularVelocity (dynamic + kinematic). Inspector RigidBody block gains impulse debug controls for manual response tests. Transient by design — nothing serialized.
This commit is contained in:
@@ -75,6 +75,19 @@ namespace Engine {
|
||||
bool RayCast(const glm::vec3& origin, const glm::vec3& dir,
|
||||
f32 maxDist, RayHit& outHit) const;
|
||||
|
||||
// ---- 刚体驱动(游戏逻辑/编辑器调试;按实体位模式寻址)----
|
||||
// Jolt 力在每步模拟后清零:游戏逻辑每帧持续施加 = 正确用法;
|
||||
// 冲量一次性改变动量(自动唤醒休眠体);速度直写会打断自然
|
||||
// 模拟(Unity 同语义)。body 不存在或类型不符时静默忽略:
|
||||
// 力/扭矩/冲量仅动态体,速度直写动态+运动学体
|
||||
void AddForce(u32 entityBits, const glm::vec3& force);
|
||||
void AddImpulse(u32 entityBits, const glm::vec3& impulse);
|
||||
void AddTorque(u32 entityBits, const glm::vec3& torque);
|
||||
void SetLinearVelocity(u32 entityBits, const glm::vec3& velocity);
|
||||
void SetAngularVelocity(u32 entityBits, const glm::vec3& angularVelocity);
|
||||
// 无 body / 静态体返回零向量
|
||||
glm::vec3 GetLinearVelocity(u32 entityBits) const;
|
||||
|
||||
private:
|
||||
// 创建时缓存的参数(变更检测 → 重建 body)
|
||||
struct BodyRecord {
|
||||
@@ -104,6 +117,7 @@ namespace Engine {
|
||||
ECS::RigidBodyComponent& rb,
|
||||
ECS::TransformComponent& tr);
|
||||
void RemoveBody(u32 entityBits);
|
||||
const BodyRecord* FindRecord(u32 entityBits) const; // 刚体驱动寻址
|
||||
void QueueEvent(CollisionEvent&& ev); // 回调线程 append(多线程并发,加锁)
|
||||
bool TryBitsByBodyId(const JPH::BodyID& id, u32& outBits) const;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user