OxMVector2 Class
Represents a position or direction in 2D space. The OxMVector2 class supports a range of mathematical operators for more natural expressions ( + - * / ) that can be used both with 2D vectors and scalars. The class also provides methods to perform these calculations in-place to reduce object overhead.
Constructors
Expand All | Collapse All
-
OxMVector2
Default constructor, sets the vector to (0,0). -
OxMVector2 ( vx As Double, vy As Double )
Set the vector using two Double values. -
OxMVector2 ( v As OxMVector2 )
Set the vector to a copy of the passed vector.
Properties
Methods
Expand All | Collapse All
-
Add ( n As Double )
-
Add ( v As OxMVector2 )
Adds the passed vector to this vector, storing the result. This is equivalent to:
self = self + v
-
Angle ( v As OxMVector2 ) As Double
Returns the angle in radians between the passed vector and this vector. -
CloseEnough ( v As OxMVector2, within As Double = 0.01 ) As Boolean
Compares this vector with the passed vector and returns True if all the components fall within the requested tolerance (default 0.01). -
Copy ( v As OxMVector2 )
Sets this vector to a copy of the passed vector. -
Distance ( v As OxMVector2 ) As Double
Returns the distance between the passed vector and this vector. -
DistanceSquared ( v As OxMVector2 ) As Double
Returns the squared distance between the passed vector and this vector. This is faster to compute than Distance as it avoids calling Sqrt, but the result is typically only useful when being compared to other squared values. -
Divide ( n As Double )
-
Divide ( v As OxMVector2 )
Divides this vector by the passed vector, storing the result. This is equivalent to:
self = self / v
-
DotProduct ( v As OxMVector2 ) As Double
Returns the dot product of this vector and the passed vector. -
Equals ( v As OxMVector2 ) As Boolean
Returns True if the vector has the exact same value as the passed vector.
Note: This is not generally useful due to floating point errors, however it can be handy to compare a vector's current state with a previously stored state. -
Equals ( v As OxMVector2, decimalplaces As UInt32 ) As Boolean
Rounds the vector components to the requested decimal places (decimalplaces = 1 is tenths, 2 is hundredths, etc.) and returns True if the rounded vectors have the exact same value.
Note: This can be a fairly CPU-intensive comparison. The CloseEnough method provides a similar result with much less work. -
Length As Double
Returns the length (or magnitude) of the vector. -
LengthSquared As Double
Returns the squared length (or magnitude) of the vector. This is faster to compute than Length as it avoids calling Sqrt, but the result is typically only useful when being compared to other squared values. -
Multiply ( n As Double )
-
Multiply ( v As OxMVector2 )
Multiplies the passed vector to this vector, storing the result. This is equivalent to:
self = self * v
-
Normalize
Scales the vector to unit length (1.0). -
Rotate ( angle As Double )
Rotate this vector by the passed angle (in radians). -
SetRotate ( vx As Double, vy As Double, angle As Double )
Rotate a vector defined by two Double values by the angle (in radians) defined by a third Double and store the result in this vector. -
SetRotate ( v As OxMVector2, angle As Double )
Rotate the vector passed by the angle (in radians) passed and store the result in this vector. -
SetToDifference ( v1 As OxMVector2, v2 As OxMVector2 )
Subtracts v1 from v2 and stores the result in this vector. This is equivalent to:
self = v1 - v2
-
SetToProduct ( v1 As OxMVector2, v2 As OxMVector2 )
Multiplies v1 by v2 and stores the result in this vector. This is equivalent to:
self = v1 * v2
-
SetToQuotient ( v1 As OxMVector2, v2 As OxMVector2 )
Divides v1 by v2 and stores the result in this vector. This is equivalent to:
self = v1 / v2
-
SetToSum ( v1 As OxMVector2, v2 As OxMVector2 )
Adds v1 with v2 and stores the result in this vector. This is equivalent to:
self = v1 + v2
-
SetVector ( vx As Double, vy As Double )
Set the vector using two Double values. -
Subtract ( n As Double )
-
Subtract ( v As OxMVector2 )
Subtracts the passed vector from this vector, storing the result. This is equivalent to:
self = self - v