mirror of
https://github.com/cyberarm/i-mic-fps.git
synced 2025-12-15 15:42:35 +00:00
88 lines
1.6 KiB
Ruby
88 lines
1.6 KiB
Ruby
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)
|
|
Vector.new(
|
|
@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)
|
|
Vector.new(
|
|
@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)
|
|
Vector.new(
|
|
@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)
|
|
Vector.new(
|
|
@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 |