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