Class: Quake::Math::Vec3

Inherits:
Data
  • Object
show all
Defined in:
lib/quake/math/vec3.rb

Constant Summary collapse

ORIGIN =
Vec3.new(0.0, 0.0, 0.0).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#xObject (readonly)

Returns the value of attribute x

Returns:

  • (Object)

    the current value of x



5
6
7
# File 'lib/quake/math/vec3.rb', line 5

def x
  @x
end

#yObject (readonly)

Returns the value of attribute y

Returns:

  • (Object)

    the current value of y



5
6
7
# File 'lib/quake/math/vec3.rb', line 5

def y
  @y
end

#zObject (readonly)

Returns the value of attribute z

Returns:

  • (Object)

    the current value of z



5
6
7
# File 'lib/quake/math/vec3.rb', line 5

def z
  @z
end

Instance Method Details

#*(scalar) ⇒ Object



8
# File 'lib/quake/math/vec3.rb', line 8

def *(scalar) = Vec3.new(x * scalar, y * scalar, z * scalar)

#+(other) ⇒ Object



6
# File 'lib/quake/math/vec3.rb', line 6

def +(other) = Vec3.new(x + other.x, y + other.y, z + other.z)

#-(other) ⇒ Object



7
# File 'lib/quake/math/vec3.rb', line 7

def -(other) = Vec3.new(x - other.x, y - other.y, z - other.z)

#-@Object



9
# File 'lib/quake/math/vec3.rb', line 9

def -@ = Vec3.new(-x, -y, -z)

#cross(other) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/quake/math/vec3.rb', line 13

def cross(other)
  Vec3.new(
    y * other.z - z * other.y,
    z * other.x - x * other.z,
    x * other.y - y * other.x
  )
end

#dot(other) ⇒ Object



11
# File 'lib/quake/math/vec3.rb', line 11

def dot(other) = x * other.x + y * other.y + z * other.z

#lengthObject



21
# File 'lib/quake/math/vec3.rb', line 21

def length = ::Math.sqrt(x * x + y * y + z * z)

#normalizeObject



23
24
25
26
27
# File 'lib/quake/math/vec3.rb', line 23

def normalize
  l = length
  return self if l == 0.0
  Vec3.new(x / l, y / l, z / l)
end

#to_aObject



29
# File 'lib/quake/math/vec3.rb', line 29

def to_a = [x, y, z]