armory/Sources/armory/logicnode/VectorFromTransformNode.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

56 lines
987 B
Haxe

package armory.logicnode;
import iron.math.Quat;
import iron.math.Mat4;
import iron.math.Vec4;
class VectorFromTransformNode extends LogicNode {
public var property0: String;
public function new(tree: LogicTree) {
super(tree);
}
override function get(from: Int): Dynamic {
var m: Mat4 = inputs[0].get();
if (m == null) return null;
switch(from) {
case 0:
switch (property0) {
case "Up":
return m.up();
case "Right":
return m.right();
case "Look":
return m.look();
case "Quaternion":
var q = new Quat();
q.fromMat(m);
return q.normalize();
}
case 1:
if (property0 == "Quaternion") {
var q = new Quat();
q.fromMat(m);
q.normalize();
var v = new Vec4();
v.x = q.x; v.y = q.y; v.z = q.z;
v.w = 0; //prevent vector translation
return v;
}
case 2:
if (property0 == "Quaternion") {
var q = new Quat();
q.fromMat(m);
q.normalize();
return q.w;
}
}
return null;
}
}