lib/cyberarm_engine/lib/vector.rb in cyberarm_engine-0.10.2 vs lib/cyberarm_engine/lib/vector.rb in cyberarm_engine-0.11.0
- old
+ new
@@ -1,7 +1,31 @@
module CyberarmEngine
class Vector
+ def self.up
+ Vector.new(0, 1, 0)
+ end
+
+ def self.down
+ Vector.new(0, -1, 0)
+ end
+
+ def self.left
+ Vector.new(-1, 0, 0)
+ end
+
+ def self.right
+ Vector.new(1, 0, 0)
+ end
+
+ def self.forward
+ Vector.new(0, 0, 1)
+ end
+
+ def self.backward
+ Vector.new(0, 0, -1)
+ end
+
def initialize(x = 0, y = 0, z = 0, weight = 0)
@x, @y, @z, @weight = x, y, z, weight
end
def x; @x; end
@@ -134,9 +158,13 @@
Vector.new(1.0 / @x, 1.0 / @y, 1.0 / @z)
end
def sum
@x + @y + @z
+ end
+
+ def lerp(other, factor)
+ (self - other) * factor.clamp(0.0, 1.0)
end
# 2D distance using X and Y
def distance(other)
Math.sqrt((@x-other.x)**2 + (@y-other.y)**2)
\ No newline at end of file