math.lua 499 B

1234567891011121314151617181920212223242526
  1. --extends the math and vector tables.
  2. --returns the sign of x. Who would have thought?
  3. math.sign = math.sign or function(x)
  4. if x < 0 then
  5. return -1
  6. elseif x > 0 then
  7. return 1
  8. else
  9. return 0
  10. end
  11. end
  12. if not vector then vector = {} end
  13. --returns a unit vector pointing the direction from a to b
  14. vector.aim = function(a, b)
  15. return vector.normalize(vector.subtract(b, a))
  16. end
  17. --returns the inner product of a and b
  18. vector.dot = function(a, b)
  19. return a.x * b.x + a.y * b.y + a.z * b.z
  20. end