class FMOD::Core::Vector

Structure describing a point in 3D space.

Public Class Methods

new(*args) click to toggle source

@overload initialize(address)

@param address [Pointer, Integer, String, nil] The address in memory
  where the structure will be created from. If no address is given,
  new memory will be allocated.

@overload initialize(x, y, z)

@param x [Float] The X coordinate in 3D space.
@param y [Float] The Y coordinate in 3D space.
@param z [Float] The Z coordinate in 3D space.
Calls superclass method FMOD::Core::Structure::new
# 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
one() click to toggle source

@return [Vector] a new {Vector} with all values set to 1.0.

# File lib/fmod/core/vector.rb, line 16
def self.one
  new(1.0, 1.0, 1.0)
end
zero() click to toggle source

@return [Vector] a new {Vector} with all values set to 0.0.

# File lib/fmod/core/vector.rb, line 10
def self.zero
  new(0.0, 0.0, 0.0)
end

Public Instance Methods

set(x, y, z) click to toggle source

Helper function to set the {#x}, {#y}, and {#z} values simultaneously.

@param x [Float] The X coordinate in 3D space. @param y [Float] The Y coordinate in 3D space. @param z [Float] The Z coordinate in 3D space.

@return [self]

# 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() click to toggle source

@return [Array(Float, Float, Float)] the result of interpreting the

vector as an Array.
# File lib/fmod/core/vector.rb, line 67
def to_a
  @members.map { |sym| self[sym] }
end
to_h() click to toggle source

@return [Hash<Symbol, Float>] the result of interpreting the vector as a

Hash.
# File lib/fmod/core/vector.rb, line 74
def to_h
  { x: self[:x], y: self[:y], z: self[:z] }
end