Class: FMOD::Core::Vector
- Defined in:
- lib/fmod/core/vector.rb
Overview
Structure describing a point in 3D space.
Instance Attribute Summary collapse
-
#x ⇒ Float
The X coordinate in 3D space.
-
#y ⇒ Float
The Y coordinate in 3D space.
-
#z ⇒ Float
The Z coordinate in 3D space.
Class Method Summary collapse
-
.one ⇒ Vector
A new Vector with all values set to 1.0.
-
.zero ⇒ Vector
A new Vector with all values set to 0.0.
Instance Method Summary collapse
-
#initialize(*args) ⇒ Vector
constructor
A new instance of Vector.
- #set(x, y, z) ⇒ self
-
#to_a ⇒ Array(Float, Float, Float)
The result of interpreting the vector as an Array.
-
#to_h ⇒ Hash<Symbol, Float>
The result of interpreting the vector as a Hash.
Methods inherited from Structure
Constructor Details
#initialize(address) ⇒ Vector #initialize(x, y, z) ⇒ Vector
Returns a new instance of Vector.
29 30 31 32 33 34 35 |
# File 'lib/fmod/core/vector.rb', line 29 def initialize(*args) address = args[0] if args.size <= 1 members = [:x, :y, :z] types = Array.new(3, TYPE_FLOAT) super(address, types, members) set(*args) if args.size == 3 end |
Instance Attribute Details
#x ⇒ Float
Returns the X coordinate in 3D space.
|
# File 'lib/fmod/core/vector.rb', line 37
|
#y ⇒ Float
Returns the Y coordinate in 3D space.
|
# File 'lib/fmod/core/vector.rb', line 40
|
#z ⇒ Float
Returns the Z coordinate in 3D space.
46 47 48 49 |
# File 'lib/fmod/core/vector.rb', line 46 [:x, :y, :z].each do |symbol| define_method(symbol) { self[symbol] } define_method("#{symbol}=") { |value| self[symbol] = value.to_f } end |
Class Method Details
.one ⇒ Vector
Returns a new FMOD::Core::Vector with all values set to 1.0.
16 17 18 |
# File 'lib/fmod/core/vector.rb', line 16 def self.one new(1.0, 1.0, 1.0) end |
.zero ⇒ Vector
Returns a new FMOD::Core::Vector with all values set to 0.0.
10 11 12 |
# File 'lib/fmod/core/vector.rb', line 10 def self.zero new(0.0, 0.0, 0.0) end |
Instance Method Details
#set(x, y, z) ⇒ self
59 60 61 62 |
# File 'lib/fmod/core/vector.rb', line 59 def set(x, y, z) self[:x], self[:y], self[:z] = x, y, z self end |
#to_a ⇒ Array(Float, Float, Float)
Returns the result of interpreting the vector as an Array.
67 68 69 |
# File 'lib/fmod/core/vector.rb', line 67 def to_a @members.map { |sym| self[sym] } end |
#to_h ⇒ Hash<Symbol, Float>
Returns the result of interpreting the vector as a Hash.
74 75 76 |
# File 'lib/fmod/core/vector.rb', line 74 def to_h { x: self[:x], y: self[:y], z: self[:z] } end |