armory/Sources/armory/logicnode/QuaternionNode.hx

48 lines
1.1 KiB
Haxe
Raw Permalink 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.Quat;
import iron.math.Vec4;
2017-04-08 20:05:35 +02:00
class QuaternionNode extends LogicNode {
var value = new Quat();
2019-12-19 23:54:08 +01:00
public function new(tree: LogicTree, x: Null<Float> = null, y: Null<Float> = null, z: Null<Float> = null, w: Null<Float> = null) {
2017-04-08 20:05:35 +02:00
super(tree);
if (x != null) {
LogicNode.addLink(new FloatNode(tree, x), this, 0, 0);
LogicNode.addLink(new FloatNode(tree, y), this, 0, 1);
LogicNode.addLink(new FloatNode(tree, z), this, 0, 2);
LogicNode.addLink(new FloatNode(tree, w), this, 0, 3);
2017-04-08 20:05:35 +02:00
}
}
2019-12-19 23:54:08 +01:00
override function get(from: Int): Dynamic {
2017-04-08 20:05:35 +02:00
value.x = inputs[0].get();
value.y = inputs[1].get();
value.z = inputs[2].get();
value.w = inputs[3].get();
value.normalize();
switch (from){
case 0:
return value;
case 1:
var value1 = new Vec4();
value1.x = value.x;
value1.y = value.y;
value1.z = value.z;
value1.w = 0; // use 0 to avoid this vector being translated.
return value1;
case 2:
return value.w;
default:
return null;
}
2017-04-08 20:05:35 +02:00
}
2019-12-19 23:54:08 +01:00
override function set(value: Dynamic) {
2017-04-08 20:05:35 +02:00
this.value = value;
}
}