The Vector2 object.
Most functions in Novashell take a Vector2 instead of an x and y separately.
vPos = Vector2(5,5);
vPos = vPos + (vPos*2);
LogMsg("Hey, vPos is " .. tostring(vPos) .. " and the length is " .. vPos:Length());
//Output is "Hey, vPos is X:15.00 Y: 15.00 and the length is 21.21320343076"
vPos.x = vPos.x/1.54; //let's only modify the x coordinate
LogMsg("My god, vPos.x is " .. vPos.x);
//Output is "My god, vPos.x is 9.7402601242065"
//Let's turn it into a unit vector
vPos.Normalize();
If you use tostring() to show a Vector2, it is formatted and truncated to two decimal points for display. Internally it’s still double accuracy, like all all Lua numbers.
| Local Variables | |
| x | The x coordinate. |
| y | The y coordinate. |
| Initialization | |
| Vector2 | |
| Vector2(Vector2) | |
| Vector2(x,y) | |
| Member Functions | |
| Length | |
| Normalize | |
| Dot | |
| Cross | |
| Operators | |
| Assignment Operator | =Vector2 |
| Addition Operator | +Vector2 |
| Subtraction Operator | -Vector2 |
| Multiply Operator | *number |
| Division Operator | *number |
| Equality Operator | ==Vector2 |
| Inequality Operator | !=Vector2 |
+Vector2
vPos = vPos + Vector2(1,1); //add 1 to x and y in the vPos vector
-Vector2
vPos = vPos - Vector2(1,0); //remove 1 from vPos's x coordinate
*number
vPos = Vector(1,2);
vPos = vPos * 10; //vPos.x is now 10, vPos.y is now 20.
*number
vPos = Vector(1,0);
vPos = vPos /2; //vPos.x is now 0.5, vPos.y is still 0 of course.
==Vector2
if (vPos == vYourPos) then LogMsg("They are the same"); end;!=Vector2
if (vPos != vYourPos) then LogMsg("By jove, these are different"); end;The Rect object. Holds only whole integer numbers, no decimal points allowed.
| Local Variables | |
| left | The left coordinate. |
| top | The top coordinate. |
| right | The right coordinate. |
| bottom | The bottom coordinate. |
| Initialization | |
| Rect | |
| Rect(Rect) | |
| Rect(left,top,right,bottom) | |
| Member Functions | |
| GetWidth | |
| GetHeight | |
| IsOverlapped | |
| IsInside | |
| CalculateUnion | |
| CalculateCombined | |
| Operators | |
| Addition Operator | +Rect |
| Subtraction Operator | -Rect |
Rect(number left, number top, number right, number bottom)
A Rect can be initialized with four numbers.
Rect CalculateCombined(Rect rectB)
A Rect of the area required to enclose both the original and passed in rectangle.
The Rectf object. This version supports fractions and decimal points.
| Local Variables | |
| left | The left coordinate. |
| top | The top coordinate. |
| right | The right coordinate. |
| bottom | The bottom coordinate. |
| Initialization | |
| Rectf | |
| Rectf(Rectf) | |
| Rectf(left,top,right,bottom) | |
| Member Functions | |
| GetWidth | |
| GetHeight | |
| IsOverlapped | |
| IsInside | |
| CalculateUnion | |
| CalculateCombined | |
| Operators | |
| Addition Operator | +Rectf |
| Subtraction Operator | -Rectf |
Rectf(number left, number top, number right, number bottom)
A Rectf can be initialized with four numbers.
Rectf CalculateCombined(Rectf rectB)
A Rectf of the area required to enclose both the original and passed in rectangle.