VectorMathNode.hx 837 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package arm.logicnode;
  2. import armory.logicnode.LogicNode;
  3. import armory.logicnode.LogicTree;
  4. import iron.math.Vec4;
  5. @:keep
  6. class VectorMathNode extends LogicNode {
  7. public var property0:String;
  8. var v = new Vec4();
  9. public function new(tree:LogicTree) {
  10. super(tree);
  11. }
  12. override function get(from:Int):Dynamic {
  13. var v1:Vec4 = inputs[0].get();
  14. var v2:Vec4 = inputs[1].get();
  15. v.setFrom(v1);
  16. var f = 0.0;
  17. switch (property0) {
  18. case "Add":
  19. v.add(v2);
  20. case "Subtract":
  21. v.sub(v2);
  22. case "Average":
  23. v.add(v2);
  24. v.x *= 0.5;
  25. v.y *= 0.5;
  26. v.z *= 0.5;
  27. case "Dot Product":
  28. f = v.dot(v2);
  29. v.set(f, f, f);
  30. case "Cross Product":
  31. v.cross(v2);
  32. case "Normalize":
  33. v.normalize();
  34. case "Multiply":
  35. v.x *= v2.x;
  36. v.y *= v2.y;
  37. v.z *= v2.z;
  38. }
  39. if (from == 0) return v;
  40. else return f;
  41. }
  42. }