From 99827fce4472e45cc77a8135988bb4d52cd754fd Mon Sep 17 00:00:00 2001 From: Daniel Bross Date: Sat, 19 Jul 2025 23:59:46 +0200 Subject: [PATCH] Deleted unused PhysX procs. Fixed capsule --- core/entity.jai | 1 + physics/physx.jai | 123 ++-------------------------------------------- 2 files changed, 4 insertions(+), 120 deletions(-) diff --git a/core/entity.jai b/core/entity.jai index ce2775b..5b9f20f 100644 --- a/core/entity.jai +++ b/core/entity.jai @@ -77,6 +77,7 @@ MAX_CHILDREN :: 16; restitution: float; lock: Physics_Lock; + offset: Vector3; type: Collider_Type; union { diff --git a/physics/physx.jai b/physics/physx.jai index e0922e2..a42254a 100644 --- a/physics/physx.jai +++ b/physics/physx.jai @@ -154,6 +154,7 @@ post_physx_sync :: (game_scene: *Scene) { create_physx_actor :: (e: *Entity) { actor : *PhysX.PxRigidActor; transform : PhysX.PxTransform; + position := e.transform.position + e.physics.offset; if e.physics.type == .CAPSULE { angle := PI * 0.5; @@ -163,9 +164,9 @@ create_physx_actor :: (e: *Entity) { cos_half := cos(half_angle); rotation := Quaternion.{0, 0, sin(-PI * 0.25), cos(-PI * 0.25)}; - transform = PhysX.PxTransform_new(*e.transform.position, *rotation); + transform = PhysX.PxTransform_new(*position, *rotation); } else { - transform = PhysX.PxTransform_new(*e.transform.position, *e.transform.orientation); + transform = PhysX.PxTransform_new(*position, *e.transform.orientation); } if e.physics.dynamic { @@ -225,114 +226,6 @@ create_physx_actor :: (e: *Entity) { e.physics.enabled = true; } -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); - actor.userData = entity; - - 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); - - angle := PI * 0.5; - half_angle := angle * 0.5; - - sin_half := sin(half_angle); - cos_half := cos(half_angle); - - rotation := Quaternion.{0, 0, sin(-PI * 0.25), cos(-PI * 0.25)}; - - transform := PhysX.PxTransform_new(*entity.transform.position, *rotation); - - actor := PhysX.PxPhysics_createRigidDynamic(physics, *transform); - actor.userData = entity; - - 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.0, 0.0, 0.0); - - 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 = false; - physics_actor.dynamic = actor; - - entity.physx_handle = parray_add(*entity.scene.physx_scene.actors, physics_actor); - return entity.physics.physx_handle; -} - -add_physx_box :: (entity: *Entity, half_extent: Vector3, offset: Vector3 = .{}) -> PhysX_Handle { - shape := PhysX.PxPhysics_createShape(physics, PhysX.PxBoxGeometry_new(half_extent), material, false, PHYSX_DEFAULT_SHAPE_FLAGS); - pos := entity.transform.position + offset; - t := PhysX.PxTransform_new(*pos, *entity.transform.orientation); - - body := PhysX.PxPhysics_createRigidStatic(physics, *t); - body.userData = entity; - PhysX.PxRigidActor_attachShape(body, shape); - PhysX.PxScene_addActor(entity.scene.physx_scene.scene, body, null); - - PhysX.PxShape_release(shape); - - physics_actor : PhysX_Actor; - physics_actor.type = .STATIC; - physics_actor.static = body; - - entity.physx_handle = parray_add(*entity.scene.physx_scene.actors, physics_actor); - return entity.physics.physx_handle; - -} - -create_stack :: (scene: *PhysX.PxScene, t: PhysX.PxTransform, size: u32, half_extent: float) { - shape := PhysX.PxPhysics_createShape(physics, PhysX.PxBoxGeometry_new(half_extent, half_extent, half_extent), material, false, PHYSX_DEFAULT_SHAPE_FLAGS); - for i: 0..size-1 { - for j: 0..size-i-1 { - pos := Vector3.{cast(float)(j*2) - cast(float)(size-i), cast(float)(i*2+1), 0} * half_extent; - local_tm := PhysX.PxTransform_new(*pos); - - body := PhysX.PxPhysics_createRigidDynamic(physics, *PhysX.PxTransform_transform(*t, *local_tm)); - PhysX.PxRigidActor_attachShape(body, shape); - PhysX.PxRigidBodyExt_updateMassAndInertia(body, 10., null, false); - PhysX.PxScene_addActor(scene, body, null); - } - } - //shape->release(); -} - Hit :: struct { } @@ -344,16 +237,6 @@ physx_raycast :: (origin: Vector3, direction: Vector3, max_distance: float = 100 return has_hit, .{}; } -create_dynamic :: (scene: *PhysX.PxScene, t: PhysX.PxTransform, geometry: *PhysX.PxGeometry, velocity: Vector3 = .{}) -> *PhysX.PxRigidDynamic { - p := Vector3.{0,0,0}; - transform := PhysX.PxTransform_new(cast(s32)PhysX.PxIDENTITY.PxIdentity); - dynamic := PhysX.PxCreateDynamic(physics, *t, geometry, material, 10.0, *transform); - PhysX.PxRigidBody_setAngularDamping(dynamic, 0.5); - PhysX.PxRigidDynamic_setLinearVelocity(dynamic, *velocity, true); - PhysX.PxScene_addActor(scene, dynamic, null); - return dynamic; -} - PhysX :: #import "PhysX"; #scope_file