Class: FMOD::Core::Vector

Inherits:
Structure
  • Object
show all
Defined in:
lib/fmod/core/vector.rb

Overview

Structure describing a point in 3D space.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Structure

#inspect, #names, #values

Constructor Details

#initialize(address) ⇒ Vector #initialize(x, y, z) ⇒ Vector

Returns a new instance of Vector.

Overloads:

  • #initialize(address) ⇒ Vector

    Parameters:

    • 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.

  • #initialize(x, y, z) ⇒ Vector

    Parameters:

    • x (Float)

      The X coordinate in 3D space.

    • y (Float)

      The Y coordinate in 3D space.

    • z (Float)

      The Z coordinate in 3D space.



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

#xFloat

Returns the X coordinate in 3D space.

Returns:

  • (Float)

    the X coordinate in 3D space.



# File 'lib/fmod/core/vector.rb', line 37

#yFloat

Returns the Y coordinate in 3D space.

Returns:

  • (Float)

    the Y coordinate in 3D space.



# File 'lib/fmod/core/vector.rb', line 40

#zFloat

Returns the Z coordinate in 3D space.

Returns:

  • (Float)

    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

.oneVector

Returns a new FMOD::Core::Vector with all values set to 1.0.

Returns:



16
17
18
# File 'lib/fmod/core/vector.rb', line 16

def self.one
  new(1.0, 1.0, 1.0)
end

.zeroVector

Returns a new FMOD::Core::Vector with all values set to 0.0.

Returns:



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

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

Parameters:

  • x (Float)

    The X coordinate in 3D space.

  • y (Float)

    The Y coordinate in 3D space.

  • z (Float)

    The Z coordinate in 3D space.

Returns:

  • (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_aArray(Float, Float, Float)

Returns the result of interpreting the vector as an Array.

Returns:

  • (Array(Float, Float, Float))

    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_hHash<Symbol, Float>

Returns the result of interpreting the vector as a Hash.

Returns:

  • (Hash<Symbol, Float>)

    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