armory/Sources/armory/logicnode/QuaternionNode.hx
niacdoial 17daabeb29 Improved quaternion and angle handling in logic nodes (+2bugfixes)
- Made so all nodes outputting a quaternion object also output it as a XYZ (vector) + W (float) combination
- Modernized the interface of the "Action/Rotate Object" node, to align on the newer "Action/Set Rotation" node interface  ("Action/Rotate Object Along Axis" is now depreciated, but still usable)
- Fixed a blender-side-only bug with the "Logic/Switch" node (...which technically could have lead to a compile-time problem if exploited the right way)
- Fixed a bug on the "Action/Set Rotation" node: now, quaternion input is automatically normalized in order to avoid accidental scaling
- Added a "Value/Separate Quaternion" node
- Made so the names of some sockets change in the "Set Rotation" and "Rotate Object" nodes, so they adapt to those nodes' input types.
  (Same thing with "Value/Vector From Transform"'s output type)
2020-08-30 15:50:06 +02:00

48 lines
1 KiB
Haxe

package armory.logicnode;
import iron.math.Quat;
import iron.math.Vec4;
class QuaternionNode extends LogicNode {
var value = new Quat();
public function new(tree: LogicTree, x: Null<Float> = null, y: Null<Float> = null, z: Null<Float> = null, w: Null<Float> = null) {
super(tree);
if (x != null) {
addInput(new FloatNode(tree, x), 0);
addInput(new FloatNode(tree, y), 0);
addInput(new FloatNode(tree, z), 0);
addInput(new FloatNode(tree, w), 0);
}
}
override function get(from: Int): Dynamic {
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;
}
}
override function set(value: Dynamic) {
this.value = value;
}
}