armory/Sources/armory/logicnode/GetRotationNode.hx

45 lines
978 B
Haxe
Raw Normal View History

2017-04-14 20:38:50 +02:00
package armory.logicnode;
2017-11-20 15:16:52 +01:00
import iron.object.Object;
import iron.math.Quat;
import iron.math.Vec3;
2017-04-14 20:38:50 +02:00
2017-05-13 11:04:39 +02:00
class GetRotationNode extends LogicNode {
2017-04-14 20:38:50 +02:00
public function new(tree:LogicTree) {
super(tree);
}
override function get(from:Int):Dynamic {
2019-09-27 21:51:30 +02:00
var object:Object = inputs[0].get();
if (object == null)
return null;
var rot = object.transform.rot;
2019-09-27 21:35:26 +02:00
switch (from) {
2019-11-12 11:15:09 +01:00
case 0:
2019-09-27 21:35:26 +02:00
// euler angles
return object.transform.rot.getEuler();
2019-11-12 11:15:09 +01:00
case 1:
2019-09-27 21:35:26 +02:00
// vector
var sqrtW = Math.sqrt(1 - (rot.w * rot.w));
if (sqrtW == 0)
return new Vec3(0, 0, 1);
return new Vec3(rot.x / sqrtW, rot.y / sqrtW, rot.z / sqrtW);
2019-11-12 11:15:09 +01:00
case 2:
2019-09-27 21:51:30 +02:00
// angle radians
var angle = 2 * Math.acos(rot.w);
return angle;
2019-11-12 11:15:09 +01:00
case 3:
2019-09-27 21:51:30 +02:00
// angle degrees
var angle = 2 * Math.acos(rot.w);
return angle * (180 / Math.PI);
2019-11-12 11:15:09 +01:00
case 4:
2019-09-27 21:51:30 +02:00
//quaternion xyz
return new Vec3(rot.x, rot.y, rot.z);
2019-11-12 11:15:09 +01:00
case 5:
2019-09-27 21:51:30 +02:00
//quaternion w
2019-09-27 21:35:26 +02:00
return rot.w;
}
return null;
2017-04-14 20:38:50 +02:00
}
}