armory/Sources/armory/logicnode/CastPhysicsRayNode.hx

46 lines
1.1 KiB
Haxe
Raw Normal View History

2017-04-08 20:05:35 +02:00
package armory.logicnode;
2017-11-20 15:16:52 +01:00
import iron.math.Vec4;
2017-04-08 20:05:35 +02:00
class CastPhysicsRayNode extends LogicNode {
var v = new Vec4();
2019-12-19 23:54:08 +01:00
public function new(tree: LogicTree) {
2017-04-08 20:05:35 +02:00
super(tree);
}
2019-12-19 23:54:08 +01:00
override function get(from: Int): Dynamic {
var vfrom: Vec4 = inputs[0].get();
var vto: Vec4 = inputs[1].get();
var mask: Int = inputs[2].get();
2017-04-08 20:05:35 +02:00
2018-06-14 14:52:05 +02:00
if (vfrom == null || vto == null) return null;
2017-04-08 20:05:35 +02:00
#if arm_physics
2017-09-30 00:32:06 +02:00
var physics = armory.trait.physics.PhysicsWorld.active;
2019-09-05 22:21:31 +02:00
var hit = physics.rayCast(vfrom, vto, 1, mask);
var rb = (hit != null) ? hit.rb : null;
2017-07-14 14:18:38 +02:00
if (from == 0) { // Object
if (rb != null) return rb.object;
}
else if (from == 1) { // Hit
2019-12-19 23:54:08 +01:00
var hitPointWorld: Vec4 = rb != null ? physics.hitPointWorld : null;
if (hitPointWorld != null) {
v.set(hitPointWorld.x, hitPointWorld.y, hitPointWorld.z, 1);
return v;
}
2019-12-19 23:54:08 +01:00
}
else { // Normal
var hitNormalWorld: Vec4 = rb != null ? physics.hitNormalWorld : null;
if (hitNormalWorld != null) {
v.set(hitNormalWorld.x, hitNormalWorld.y, hitNormalWorld.z, 0);
return v;
}
2017-04-08 20:05:35 +02:00
}
#end
return null;
}
}