VectorMathNode.hx 830 B

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