Physics optional

This commit is contained in:
2025-07-12 17:26:23 +02:00
parent 9dd12a55bf
commit 602dd870df
5 changed files with 66 additions and 23 deletions

View File

@@ -1,4 +1,4 @@
PHYSX_TEST :: false; PHYSX_DEFAULT_SHAPE_FLAGS :: cast(u8)(PhysX.PxShapeFlags.Visualization | PhysX.PxShapeFlags.SceneQueryShape | PhysX.PxShapeFlags.SimulationShape);
PHYSX_DEFAULT_SHAPE_FLAGS :: cast(u8)(PhysX.PxShapeFlags.Visualization | PhysX.PxShapeFlags.SceneQueryShape | PhysX.PxShapeFlags.SimulationShape);
PhysX_Handle :: #type, distinct u32;
@@ -116,6 +116,38 @@ post_physx_sync :: (game_scene: *Scene) {
}
}
add_physx_sphere :: (entity: *Entity, radius: float) -> PhysX_Handle {
geo := PhysX.PxSphereGeometry_new(radius);
transform := PhysX.PxTransform_new(*entity.transform.position);
actor := PhysX.PxPhysics_createRigidDynamic(physics, *transform);
//PhysX.PxRigidDynamic_setRigidDynamicLockFlag(actor, xx PhysX.PxRigidDynamicLockFlags.LockAngularX, true);
//PhysX.PxRigidDynamic_setRigidDynamicLockFlag(actor, xx PhysX.PxRigidDynamicLockFlags.LockAngularY, true);
//PhysX.PxRigidDynamic_setRigidDynamicLockFlag(actor, xx PhysX.PxRigidDynamicLockFlags.LockAngularZ, true);
material := PhysX.PxPhysics_createMaterial(physics, 0.1, 0.1, 0.5);
//PhysX.PxMaterial_setRestitutionCombineMode(material,1); // Turn off restitution no matter the other material
shape := PhysX.PxPhysics_createShape(physics, *geo, material, false, PHYSX_DEFAULT_SHAPE_FLAGS);
PhysX.PxRigidActor_attachShape(actor, shape);
PhysX.PxRigidBodyExt_updateMassAndInertia(actor, 0.1, null, false);
PhysX.PxScene_addActor(entity.scene.physx_scene.scene, actor, null);
PhysX.PxShape_release(shape);
PhysX.PxBase_release(material);
physics_actor : PhysX_Actor;
physics_actor.type = .DYNAMIC;
physics_actor.sync_rotation_from_physx = true;
physics_actor.dynamic = actor;
entity.physx_handle = parray_add(*entity.scene.physx_scene.actors, physics_actor);
return entity.physx_handle;
}
add_physx_capsule :: (entity: *Entity, half_height: float, radius: float) -> PhysX_Handle {
geo := PhysX.PxCapsuleGeometry_new(radius, half_height-radius);
@@ -145,8 +177,7 @@ add_physx_capsule :: (entity: *Entity, half_height: float, radius: float) -> Phy
PhysX.PxScene_addActor(entity.scene.physx_scene.scene, actor, null);
PhysX.PxShape_release(shape);
// @Incomplete
//PhysX.PxMaterial_release(material);
PhysX.PxBase_release(material);
physics_actor : PhysX_Actor;
physics_actor.type = .DYNAMIC;