armory/Sources/armory/logicnode/LookAtNode.hx

43 lines
753 B
Haxe
Raw Normal View History

2018-06-14 15:24:28 +02:00
package armory.logicnode;
import iron.math.Vec4;
2018-06-14 22:50:11 +02:00
import iron.math.Quat;
2018-06-14 15:24:28 +02:00
class LookAtNode extends LogicNode {
2019-12-19 23:54:08 +01:00
public var property0: String;
2018-06-14 15:24:28 +02:00
var v1 = new Vec4();
var v2 = new Vec4();
2018-06-14 22:50:11 +02:00
var q = new Quat();
2018-06-14 15:24:28 +02:00
2019-12-19 23:54:08 +01:00
public function new(tree: LogicTree) {
2018-06-14 15:24:28 +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();
2018-06-14 15:24:28 +02:00
if (vfrom == null || vto == null) return null;
switch (property0) {
case "X":
v1.set(1, 0, 0);
case "-X":
v1.set(-1, 0, 0);
case "Y":
v1.set(0, 1, 0);
case "-Y":
v1.set(0, -1, 0);
case "Z":
v1.set(0, 0, 1);
case "-Z":
v1.set(0, 0, -1);
}
2018-06-14 15:24:28 +02:00
v2.setFrom(vto).sub(vfrom).normalize();
q.fromTo(v1, v2);
return q;
2018-06-14 15:24:28 +02:00
}
}