Class: SFML::Vector3
- Inherits:
-
Object
- Object
- SFML::Vector3
- Defined in:
- lib/sfml/system/vector3.rb
Overview
3D vector with float components. Mirrors Vector2’s surface.
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.
Class Method Summary collapse
Instance Method Summary collapse
- #*(scalar) ⇒ Object
- #+(other) ⇒ Object
- #-(other) ⇒ Object
- #-@ ⇒ Object
- #/(scalar) ⇒ Object
- #==(other) ⇒ Object (also: #eql?)
- #cross(other) ⇒ Object
- #deconstruct ⇒ Object
- #deconstruct_keys(_keys) ⇒ Object
- #dot(other) ⇒ Object
- #hash ⇒ Object
-
#initialize(x = 0, y = 0, z = 0) ⇒ Vector3
constructor
A new instance of Vector3.
- #length ⇒ Object
- #length_sq ⇒ Object
- #normalize ⇒ Object
- #to_a ⇒ Object
- #to_h ⇒ Object
-
#to_native_f ⇒ Object
:nodoc:.
- #to_s ⇒ Object (also: #inspect)
Constructor Details
#initialize(x = 0, y = 0, z = 0) ⇒ Vector3
Returns a new instance of Vector3.
9 10 11 12 13 14 |
# File 'lib/sfml/system/vector3.rb', line 9 def initialize(x = 0, y = 0, z = 0) @x = x @y = y @z = z freeze end |
Instance Attribute Details
#x ⇒ Object (readonly)
Returns the value of attribute x.
4 5 6 |
# File 'lib/sfml/system/vector3.rb', line 4 def x @x end |
#y ⇒ Object (readonly)
Returns the value of attribute y.
4 5 6 |
# File 'lib/sfml/system/vector3.rb', line 4 def y @y end |
#z ⇒ Object (readonly)
Returns the value of attribute z.
4 5 6 |
# File 'lib/sfml/system/vector3.rb', line 4 def z @z end |
Class Method Details
.[](x, y, z) ⇒ Object
6 |
# File 'lib/sfml/system/vector3.rb', line 6 def self.[](x, y, z) = new(x, y, z) |
.from_native(struct) ⇒ Object
:nodoc:
55 56 57 |
# File 'lib/sfml/system/vector3.rb', line 55 def self.from_native(struct) # :nodoc: new(struct[:x], struct[:y], struct[:z]) end |
.zero ⇒ Object
7 |
# File 'lib/sfml/system/vector3.rb', line 7 def self.zero = new(0, 0, 0) |
Instance Method Details
#*(scalar) ⇒ Object
18 |
# File 'lib/sfml/system/vector3.rb', line 18 def *(scalar) = Vector3.new(@x * scalar, @y * scalar, @z * scalar) |
#+(other) ⇒ Object
16 |
# File 'lib/sfml/system/vector3.rb', line 16 def +(other) = Vector3.new(@x + other.x, @y + other.y, @z + other.z) |
#-(other) ⇒ Object
17 |
# File 'lib/sfml/system/vector3.rb', line 17 def -(other) = Vector3.new(@x - other.x, @y - other.y, @z - other.z) |
#/(scalar) ⇒ Object
19 |
# File 'lib/sfml/system/vector3.rb', line 19 def /(scalar) = Vector3.new(@x / scalar.to_f, @y / scalar.to_f, @z / scalar.to_f) |
#==(other) ⇒ Object Also known as: eql?
22 23 24 |
# File 'lib/sfml/system/vector3.rb', line 22 def ==(other) other.is_a?(Vector3) && @x == other.x && @y == other.y && @z == other.z end |
#cross(other) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/sfml/system/vector3.rb', line 39 def cross(other) Vector3.new( (@y * other.z) - (@z * other.y), (@z * other.x) - (@x * other.z), (@x * other.y) - (@y * other.x) ) end |
#deconstruct ⇒ Object
49 |
# File 'lib/sfml/system/vector3.rb', line 49 def deconstruct = [@x, @y, @z] |
#deconstruct_keys(_keys) ⇒ Object
50 |
# File 'lib/sfml/system/vector3.rb', line 50 def deconstruct_keys(_keys) = { x: @x, y: @y, z: @z } |
#dot(other) ⇒ Object
37 |
# File 'lib/sfml/system/vector3.rb', line 37 def dot(other) = (@x * other.x) + (@y * other.y) + (@z * other.z) |
#hash ⇒ Object
26 |
# File 'lib/sfml/system/vector3.rb', line 26 def hash = [@x, @y, @z].hash |
#length ⇒ Object
28 |
# File 'lib/sfml/system/vector3.rb', line 28 def length = Math.sqrt(length_sq) |
#length_sq ⇒ Object
29 |
# File 'lib/sfml/system/vector3.rb', line 29 def length_sq = (@x * @x) + (@y * @y) + (@z * @z) |
#normalize ⇒ Object
31 32 33 34 35 |
# File 'lib/sfml/system/vector3.rb', line 31 def normalize len = length return Vector3.zero if len.zero? self / len end |
#to_a ⇒ Object
47 |
# File 'lib/sfml/system/vector3.rb', line 47 def to_a = [@x, @y, @z] |
#to_h ⇒ Object
48 |
# File 'lib/sfml/system/vector3.rb', line 48 def to_h = { x: @x, y: @y, z: @z } |
#to_native_f ⇒ Object
:nodoc:
59 60 61 |
# File 'lib/sfml/system/vector3.rb', line 59 def to_native_f # :nodoc: C::System::Vector3f.new.tap { |v| v[:x] = @x; v[:y] = @y; v[:z] = @z } end |
#to_s ⇒ Object Also known as: inspect
52 |
# File 'lib/sfml/system/vector3.rb', line 52 def to_s = "Vector3(#{@x}, #{@y}, #{@z})" |