forked from LeenkxTeam/LNXSDK
Update leenkx/Sources/leenkx/trait/physics/bullet/DebugDrawHelper.hx
This commit is contained in:
parent
1944fc97b8
commit
07d98639f2
@ -49,9 +49,10 @@ class DebugDrawHelper {
|
||||
final fromScreenSpace = worldToScreenFast(new Vec4(from.x(), from.y(), from.z(), 1.0));
|
||||
final toScreenSpace = worldToScreenFast(new Vec4(to.x(), to.y(), to.z(), 1.0));
|
||||
|
||||
// For now don't draw lines if any point is outside of clip space z,
|
||||
// investigate how to clamp lines to clip space borders
|
||||
if (fromScreenSpace.w == 1 && toScreenSpace.w == 1) {
|
||||
// If at least one point is within the Z clip space (w==1), attempt to draw.
|
||||
// Note: This is not full clipping, line may still go off screen sides.
|
||||
if (fromScreenSpace.w == 1 || toScreenSpace.w == 1) {
|
||||
lines.push({
|
||||
fromX: fromScreenSpace.x,
|
||||
fromY: fromScreenSpace.y,
|
||||
@ -62,6 +63,25 @@ class DebugDrawHelper {
|
||||
}
|
||||
}
|
||||
|
||||
// Draws raycast in its own function because
|
||||
// something is conflicting with the btVector3 and JS pointer wrapping
|
||||
public function drawRayCast(fx:FastFloat, fy:FastFloat, fz:FastFloat, tx:FastFloat, ty:FastFloat, tz:FastFloat, r:FastFloat, g:FastFloat, b:FastFloat) {
|
||||
final fromScreenSpace = worldToScreenFast(new Vec4(fx, fy, fz, 1.0));
|
||||
final toScreenSpace = worldToScreenFast(new Vec4(tx, ty, tz, 1.0));
|
||||
|
||||
// TO DO: May still go off screen sides.
|
||||
if (fromScreenSpace.w == 1 || toScreenSpace.w == 1) {
|
||||
final color = kha.Color.fromFloats(r, g, b, 1.0);
|
||||
lines.push({
|
||||
fromX: fromScreenSpace.x,
|
||||
fromY: fromScreenSpace.y,
|
||||
toX: toScreenSpace.x,
|
||||
toY: toScreenSpace.y,
|
||||
color: color
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public function drawContactPoint(pointOnB: Vector3, normalOnB: Vector3, distance: kha.FastFloat, lifeTime: Int, color: Vector3) {
|
||||
#if js
|
||||
pointOnB = js.Syntax.code("Ammo.wrapPointer({0}, Ammo.btVector3)", pointOnB);
|
||||
@ -106,7 +126,7 @@ class DebugDrawHelper {
|
||||
x: contactPointScreenSpace.x,
|
||||
y: contactPointScreenSpace.y,
|
||||
color: color,
|
||||
text: Std.string(lifeTime), // lifeTime: number of frames the contact point existed
|
||||
text: Std.string(lifeTime),
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -159,8 +179,7 @@ class DebugDrawHelper {
|
||||
// will cause Bullet to call the btIDebugDraw callbacks), but this way
|
||||
// we can ensure that--within a frame--the function will not be called
|
||||
// before some user-specific physics update, which would result in a
|
||||
// one-frame drawing delay... Ideally we would ensure that debugDrawWorld()
|
||||
// is called when all other (late) update callbacks are already executed...
|
||||
// one-frame drawing delay...
|
||||
physicsWorld.world.debugDrawWorld();
|
||||
|
||||
g.opacity = 1.0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user