From 6d0caff6ea3b0439f82f56c0eefb32cc46721d8e Mon Sep 17 00:00:00 2001 From: capdevon Date: Thu, 16 Nov 2023 11:05:16 +0100 Subject: [PATCH] RaycastHit: fix clear() method --- .../java/com/capdevon/physx/RaycastHit.java | 37 ++++++++++--------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/game/src/main/java/com/capdevon/physx/RaycastHit.java b/game/src/main/java/com/capdevon/physx/RaycastHit.java index 0f74e53..b03e8f8 100644 --- a/game/src/main/java/com/capdevon/physx/RaycastHit.java +++ b/game/src/main/java/com/capdevon/physx/RaycastHit.java @@ -21,37 +21,38 @@ public class RaycastHit { public Vector3f normal; public Vector3f point; public float distance; - + public RaycastHit() { this.normal = new Vector3f(); - this.point = new Vector3f(); + this.point = new Vector3f(); } - + protected void set(Vector3f beginVec, Vector3f finalVec, PhysicsRayTestResult ray) { PhysicsCollisionObject pco = ray.getCollisionObject(); float hf = ray.getHitFraction(); - rigidBody = pco; - collider = pco.getCollisionShape(); - gameObject = GameObject.findGameObject(pco); - distance = finalVec.subtract(beginVec).length() * hf; - point.interpolateLocal(beginVec, finalVec, hf); + rigidBody = pco; + collider = pco.getCollisionShape(); + gameObject = GameObject.findGameObject(pco); ray.getHitNormalLocal(normal); + point.interpolateLocal(beginVec, finalVec, hf); + distance = beginVec.distance(point); } - + protected void set(Vector3f beginVec, Vector3f finalVec, PhysicsSweepTestResult tr) { PhysicsCollisionObject pco = tr.getCollisionObject(); - rigidBody = pco; - collider = pco.getCollisionShape(); - gameObject = GameObject.findGameObject(pco); - MyVector3f.lerp(tr.getHitFraction(), beginVec, finalVec, point); + rigidBody = pco; + collider = pco.getCollisionShape(); + gameObject = GameObject.findGameObject(pco); tr.getHitNormalLocal(normal); + MyVector3f.lerp(tr.getHitFraction(), beginVec, finalVec, point); distance = beginVec.distance(point); } - + public void clear() { rigidBody = null; + collider = null; gameObject = null; distance = Float.NaN; point.set(Vector3f.NAN); @@ -60,11 +61,11 @@ public void clear() { @Override public String toString() { - return "RaycastHit [rigidbody=" + toHexString(rigidBody) + return "RaycastHit [rigidbody=" + toHexString(rigidBody) + ", collider=" + toHexString(collider) - + ", gameObject=" + gameObject - + ", distance=" + distance - + ", normal=" + normal + + ", gameObject=" + gameObject + + ", distance=" + distance + + ", normal=" + normal + ", point=" + point + "]"; }