Class: Vector2
- Inherits:
-
Object
- Object
- Vector2
- Defined in:
- mrb_doc/models/vector2.rb
Overview
A class used to hold an x and y value, will be translated when viewed through a Camera2D object.
Constant Summary collapse
- ZERO =
A Vector2 setup at 0, 0
Vector2.new(0, 0)
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#+(other) ⇒ Vector2
The addition operator is used for adding up two Vector2s.
-
#-(other) ⇒ Vector2
(also: #difference)
The addition operator is used for subtracting two Vector2s.
-
#==(other) ⇒ Boolean
The equality operator is used for checking if two Vector2s share the same position.
-
#initialize(x, y) ⇒ Vector2
constructor
Creates a new instance of Vector2.
-
#length ⇒ Numeric
Calculates the length of the Vector2.
-
#scale(scalar) ⇒ Vector2
Change the length of the Vector2.
-
#to_h ⇒ Hash
Return the object represented by a Hash.
Constructor Details
Instance Attribute Details
#x ⇒ Float
5 6 7 |
# File 'mrb_doc/models/vector2.rb', line 5 def x @x end |
#y ⇒ Float
5 6 7 |
# File 'mrb_doc/models/vector2.rb', line 5 def y @y end |
Instance Method Details
#+(other) ⇒ Vector2
The addition operator is used for adding up two Vector2s
42 43 44 45 46 47 48 |
# File 'mrb_doc/models/vector2.rb', line 42 def +(other) # src/mruby_integration/models/vector2.cpp Vector2.new( self.x + other.x, self.y + other.y ) end |
#-(other) ⇒ Vector2 Also known as: difference
The addition operator is used for subtracting two Vector2s
53 54 55 56 57 58 59 |
# File 'mrb_doc/models/vector2.rb', line 53 def -(other) # src/mruby_integration/models/vector2.cpp Vector2.new( self.x - other.x, self.y - other.y ) end |
#==(other) ⇒ Boolean
The equality operator is used for checking if two Vector2s share the same position.
33 34 35 36 37 |
# File 'mrb_doc/models/vector2.rb', line 33 def ==(other) # src/mruby_integration/models/vector2.cpp self.x == other.x && self.y == other.y end |
#length ⇒ Numeric
Calculates the length of the Vector2
76 77 78 79 |
# File 'mrb_doc/models/vector2.rb', line 76 def length # src/mruby_integration/models/vector2.cpp Math.sqrt(x**2 + y**2) end |
#scale(scalar) ⇒ Vector2
Change the length of the Vector2
66 67 68 69 70 71 72 |
# File 'mrb_doc/models/vector2.rb', line 66 def scale(scalar) # src/mruby_integration/models/vector2.cpp Vector2.new( self.x * scalar, self.y * scalar ) end |
#to_h ⇒ Hash
Return the object represented by a Hash
83 84 85 86 87 88 89 |
# File 'mrb_doc/models/vector2.rb', line 83 def to_h # src/mruby_integration/models/vector2.cpp { x: x, y: y, } end |