Update leenkx/Sources/leenkx/trait/physics/bullet/PhysicsWorld.hx
This commit is contained in:
		| @ -71,7 +71,6 @@ class PhysicsWorld extends Trait { | ||||
| 	public var convexHitPointWorld = new Vec4(); | ||||
| 	public var convexHitNormalWorld = new Vec4(); | ||||
| 	var pairCache: Bool = false; | ||||
| 	public var drawRaycasts: Bool = false; | ||||
|  | ||||
| 	static var nullvec = true; | ||||
| 	static var vec1: bullet.Bt.Vector3 = null; | ||||
| @ -102,7 +101,7 @@ class PhysicsWorld extends Trait { | ||||
|  | ||||
|  | ||||
|  | ||||
| 	public function new(timeScale = 1.0, maxSteps = 10, solverIterations = 10, debugDrawMode: DebugDrawMode = NoDebug, drawRaycasts: Bool = false) { | ||||
| 	public function new(timeScale = 1.0, maxSteps = 10, solverIterations = 10, debugDrawMode: DebugDrawMode = NoDebug) { | ||||
| 		super(); | ||||
|  | ||||
| 		if (nullvec) { | ||||
| @ -121,7 +120,6 @@ class PhysicsWorld extends Trait { | ||||
| 		this.timeScale = timeScale; | ||||
| 		this.maxSteps = maxSteps; | ||||
| 		this.solverIterations = solverIterations; | ||||
| 		this.drawRaycasts = drawRaycasts; | ||||
|  | ||||
| 		// First scene | ||||
| 		if (active == null) { | ||||
| @ -408,14 +406,6 @@ class PhysicsWorld extends Trait { | ||||
| 		var worldDyn: bullet.Bt.DynamicsWorld = world; | ||||
| 		var worldCol: bullet.Bt.CollisionWorld = worldDyn; | ||||
|  | ||||
| 		if (this.drawRaycasts && this.debugDrawHelper != null) { | ||||
| 			this.debugDrawHelper.drawRayCast( | ||||
| 				rayFrom.x(), rayFrom.y(), rayFrom.z(),  | ||||
| 				rayTo.x(),   rayTo.y(),   rayTo.z(),    | ||||
| 				0.73, 0.341, 1.0  | ||||
| 			); | ||||
| 		} | ||||
|  | ||||
| 		worldCol.rayTest(rayFrom, rayTo, rayCallback); | ||||
| 		var rb: RigidBody = null; | ||||
| 		var hitInfo: Hit = null; | ||||
| @ -441,6 +431,16 @@ class PhysicsWorld extends Trait { | ||||
| 			#end | ||||
| 		} | ||||
|  | ||||
| 		if (getDebugDrawMode() & DrawRayCast != 0) { | ||||
| 			debugDrawHelper.rayCast({ | ||||
| 				from: from, | ||||
| 				to: to, | ||||
| 				hasHit: rc.hasHit(), | ||||
| 				hitPoint: hitPointWorld, | ||||
| 				hitNormal: hitNormalWorld | ||||
| 			}); | ||||
| 		} | ||||
|  | ||||
| 		#if js | ||||
| 		bullet.Bt.Ammo.destroy(rayCallback); | ||||
| 		#else | ||||
| @ -519,22 +519,14 @@ class PhysicsWorld extends Trait { | ||||
|  | ||||
| 	public function setDebugDrawMode(debugDrawMode: DebugDrawMode) { | ||||
| 		if (debugDrawHelper == null) { | ||||
| 			// Initialize if helper is null AND (standard debug mode is requested OR our custom raycast drawing is requested) | ||||
| 			if (debugDrawMode != NoDebug || this.drawRaycasts) { | ||||
| 				initDebugDrawing(); | ||||
| 			} | ||||
| 			else { | ||||
| 				// Helper is null and no debug drawing needed, so exit | ||||
| 			if (debugDrawMode == NoDebug) { | ||||
| 				return; | ||||
| 			} | ||||
| 			initDebugDrawing(debugDrawMode); | ||||
| 		} | ||||
|  | ||||
| 		// If we reached here, the helper is initialized (or was already) | ||||
| 		// Now set the standard Bullet debug mode on the actual drawer | ||||
| 		#if js | ||||
| 			// Ensure drawer exists before setting mode (might have just been initialized) | ||||
| 			var drawer = world.getDebugDrawer(); | ||||
| 			if (drawer != null) drawer.setDebugMode(debugDrawMode); | ||||
| 			world.getDebugDrawer().setDebugMode(debugDrawMode); | ||||
| 		#elseif hl | ||||
| 			hlDebugDrawer_setDebugMode(debugDrawMode); | ||||
| 		#end | ||||
| @ -554,8 +546,8 @@ class PhysicsWorld extends Trait { | ||||
| 		#end | ||||
| 	} | ||||
|  | ||||
| 	function initDebugDrawing() { | ||||
| 		debugDrawHelper = new DebugDrawHelper(this); | ||||
| 	function initDebugDrawing(debugDrawMode: DebugDrawMode) { | ||||
| 		debugDrawHelper = new DebugDrawHelper(this, debugDrawMode); | ||||
|  | ||||
| 		#if js | ||||
| 			final drawer = new bullet.Bt.DebugDrawer(); | ||||
| @ -691,6 +683,8 @@ enum abstract DebugDrawMode(Int) from Int to Int { | ||||
| 	 **/ | ||||
| 	var DrawFrames = 1 << 15; | ||||
|  | ||||
| 	var DrawRayCast = 1 << 16; | ||||
|  | ||||
| 	@:op(~A) public inline function bitwiseNegate(): DebugDrawMode { | ||||
| 		return ~this; | ||||
| 	} | ||||
|  | ||||
		Reference in New Issue
	
	Block a user