Class: Quake::Math::Vec3
- Inherits:
-
Data
- Object
- Data
- Quake::Math::Vec3
- Defined in:
- lib/quake/math/vec3.rb
Constant Summary collapse
- ORIGIN =
Vec3.new(0.0, 0.0, 0.0).freeze
Instance Attribute Summary collapse
-
#x ⇒ Object
readonly
Returns the value of attribute x.
-
#y ⇒ Object
readonly
Returns the value of attribute y.
-
#z ⇒ Object
readonly
Returns the value of attribute z.
Instance Method Summary collapse
- #*(scalar) ⇒ Object
- #+(other) ⇒ Object
- #-(other) ⇒ Object
- #-@ ⇒ Object
- #cross(other) ⇒ Object
- #dot(other) ⇒ Object
- #length ⇒ Object
- #normalize ⇒ Object
- #to_a ⇒ Object
Instance Attribute Details
#x ⇒ Object (readonly)
Returns the value of attribute x
5 6 7 |
# File 'lib/quake/math/vec3.rb', line 5 def x @x end |
#y ⇒ Object (readonly)
Returns the value of attribute y
5 6 7 |
# File 'lib/quake/math/vec3.rb', line 5 def y @y end |
#z ⇒ Object (readonly)
Returns the value of attribute 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 |
#length ⇒ Object
21 |
# File 'lib/quake/math/vec3.rb', line 21 def length = ::Math.sqrt(x * x + y * y + z * z) |
#normalize ⇒ Object
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_a ⇒ Object
29 |
# File 'lib/quake/math/vec3.rb', line 29 def to_a = [x, y, z] |