This commit is contained in:
2026-05-06 17:52:45 -07:00
parent 9fc3f35125
commit 1463c23334
402 changed files with 3758 additions and 0 deletions

View File

@ -0,0 +1,4 @@
- Keyboard `L/R` Rotate cone
- Mouse `L` Raycast in cone direction
https://github.com/leenkx3d/leenkx/wiki/physics#raycast

View File

@ -0,0 +1,52 @@
package lnx;
import leenkx.trait.physics.PhysicsWorld;
class RayCastTrait extends iron.Trait {
var q = new iron.math.Quat();
public function new() {
super();
var mouse = iron.system.Input.getMouse();
var keyboard = iron.system.Input.getKeyboard();
notifyOnUpdate(function() {
if (mouse.down()) {
var physics = PhysicsWorld.active;
// Start from cone location
var from = object.transform.world.getLoc();
// Cast ray in the direction cone points to
var to = object.transform.look();
// 1000 units long
to.mult(1000);
// End position
to.add(from);
var hit = physics.rayCast(from, to);
var rb = (hit != null) ? hit.rb : null;
var info = '';
if( rb != null ) info += ' ${rb.object.name}';
trace(info);
}
if (keyboard.down("left")) {
q.fromEuler(0, 0, 0.1);
object.transform.rot.mult(q);
object.transform.buildMatrix();
}
if (keyboard.down("right")) {
q.fromEuler(0, 0, -0.1);
object.transform.rot.mult(q);
object.transform.buildMatrix();
}
});
}
}

Binary file not shown.