mirror of
https://github.com/cyberarm/i-mic-fps.git
synced 2025-12-15 15:42:35 +00:00
Replaced Vertex struct with Vector class
This commit is contained in:
52
lib/math/vector.rb
Normal file
52
lib/math/vector.rb
Normal file
@@ -0,0 +1,52 @@
|
||||
class IMICFPS
|
||||
class Vector
|
||||
|
||||
attr_accessor :x, :y, :z, :weight
|
||||
def initialize(x = 0, y = 0, z = 0, weight = 0)
|
||||
@x, @y, @z, @weight = x, y, z, weight
|
||||
end
|
||||
|
||||
def ==(other)
|
||||
@x == other.x &&
|
||||
@y == other.y &&
|
||||
@z == other.z &&
|
||||
@weight == other.weight
|
||||
end
|
||||
|
||||
def +(other)
|
||||
@x += other.x
|
||||
@y += other.y
|
||||
@z += other.z
|
||||
@weight += other.weight
|
||||
end
|
||||
|
||||
def -(other)
|
||||
@x -= other.x
|
||||
@y -= other.y
|
||||
@z -= other.z
|
||||
@weight -= other.weight
|
||||
end
|
||||
|
||||
def *(other)
|
||||
@x *= other.x
|
||||
@y *= other.y
|
||||
@z *= other.z
|
||||
@weight *= other.weight
|
||||
end
|
||||
|
||||
def /(other)
|
||||
@x /= other.x
|
||||
@y /= other.y
|
||||
@z /= other.z
|
||||
@weight /= other.weight
|
||||
end
|
||||
|
||||
def to_a
|
||||
[@x, @y, @z, @weight]
|
||||
end
|
||||
|
||||
def to_s
|
||||
"X: #{@x}, Y: #{@y}, Z: #{@z}, Weight: #{@weight}"
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user