Skyline Lua API
Version 1.0
Lua Script Reference for Skyline Game Engine.
|
#include <LUA_API_Vector2.h>
Public Member Functions | |
float | dotProduct (float vec1_X, float vec1_Y, float vec2_X, float vec2_Y) |
Calculates the dot (scalar) product of this vector with another. More... | |
float | angle (float vec1_X, float vec1_Y, float vec2_X, float vec2_Y) |
Gets the angle between 2 vectors. More... | |
float | angleTo (float vec1_X, float vec1_Y, float vec2_X, float vec2_Y) |
Gets the oriented angle between 2 vectors. More... | |
float | crossProduct (float vec1_X, float vec1_Y, float vec2_X, float vec2_Y) |
Calculates the 2 dimensional cross-product of 2 vectors, which results in a single floating point value which is 2 times the area of the triangle. More... | |
float | distance (float vec1_X, float vec1_Y, float vec2_X, float vec2_Y) |
Returns the distance to another vector. More... | |
float2 | midPoint (float vec1_X, float vec1_Y, float vec2_X, float vec2_Y) |
Returns a vector at a point half way between this and the passed in vector. More... | |
float | normalise (float vec1_X, float vec1_Y) |
Normalises the vector. More... | |
float2 | normalisedCopy (float vec1_X, float vec1_Y) |
As normalise, except that this vector is unaffected and the normalised vector is returned as a copy. More... | |
float | length (float vec1_X, float vec1_Y) |
Returns the length (magnitude) of the vector. More... | |
int | isNAN (float vec1_X, float vec1_Y) |
Check whether this vector contains valid values. More... | |
int | isZeroLength (float vec1_X, float vec1_Y) |
Returns true if this vector is zero length. More... | |
float2 | perpendicular (float vec1_X, float vec1_Y) |
Generates a vector perpendicular to this vector (eg an 'up' vector). More... | |
float2 | randomDeviant (float vec1_X, float vec1_Y, float randomAngle) |
Generates a new random vector which deviates from this vector by a given angle in a random direction. More... | |
float2 | reflect (float vec1_X, float vec1_Y, float vec2_X, float vec2_Y) |
Calculates a reflection vector to the plane with the given normal . More... | |
float | squaredDistance (float vec1_X, float vec1_Y, float vec2_X, float vec2_Y) |
Returns the square of the distance to another vector. More... | |
float | squaredLength (float vec1_X, float vec1_Y) |
Returns the square of the length(magnitude) of the vector. More... | |
This area covers vector2 functions. Use as vector2.function(); This is a utility class that gives you access to many easy functions for vector mathmatics. For more information on how these functions can be used please visit the User Manual - https://home.aurasoft-skyline.co.uk
Example Cross Product of 2 vectors:
Lua = crossProduct = newType.vec3( vector2.crossProduct(vec1X, vec1Y, vec1Z, vec2X, vec2Y, vec2Z ) );
this is essentially doing :
c++ = Vector2 return = vec1.crossProduct(vec2);
all functions that take in vec1 are the primary vector to do an operation on.
float vector2::angle | ( | float | vec1_X, |
float | vec1_Y, | ||
float | vec2_X, | ||
float | vec2_Y | ||
) |
Gets the angle between 2 vectors.
Vectors do not have to be unit-length but must represent directions.
vec1_X | : This is the X Axis of the vector which you are going to use an operation on. |
vec1_Y | : This is the Y Axis of the vector which you are going to use an operation on. |
vec2_X | : This is the X Axis of the vector which will be used for the operation. |
vec2_Y | : This is the Y Axis of the vector which will be used for the operation. |
float vector2::angleTo | ( | float | vec1_X, |
float | vec1_Y, | ||
float | vec2_X, | ||
float | vec2_Y | ||
) |
Gets the oriented angle between 2 vectors.
Vectors do not have to be unit-length but must represent directions. The angle is comprised between 0 and 2 PI.
vec1_X | : This is the X Axis of the vector which you are going to use an operation on. |
vec1_Y | : This is the Y Axis of the vector which you are going to use an operation on. |
vec2_X | : This is the X Axis of the vector which will be used for the operation. |
vec2_Y | : This is the Y Axis of the vector which will be used for the operation. |
float vector2::crossProduct | ( | float | vec1_X, |
float | vec1_Y, | ||
float | vec2_X, | ||
float | vec2_Y | ||
) |
Calculates the 2 dimensional cross-product of 2 vectors, which results in a single floating point value which is 2 times the area of the triangle.
vec1_X | : This is the X Axis of the vector which you are going to use an operation on. |
vec1_Y | : This is the Y Axis of the vector which you are going to use an operation on. |
vec2_X | : This is the X Axis of the vector which will be used for the operation. |
vec2_Y | : This is the Y Axis of the vector which will be used for the operation. |
float vector2::distance | ( | float | vec1_X, |
float | vec1_Y, | ||
float | vec2_X, | ||
float | vec2_Y | ||
) |
Returns the distance to another vector.
vec1_X | : This is the X Axis of the vector which you are going to use an operation on. |
vec1_Y | : This is the Y Axis of the vector which you are going to use an operation on. |
vec2_X | : This is the X Axis of the vector which will be compared against. |
vec2_Y | : This is the Y Axis of the vector which will be compared against. |
float vector2::dotProduct | ( | float | vec1_X, |
float | vec1_Y, | ||
float | vec2_X, | ||
float | vec2_Y | ||
) |
Calculates the dot (scalar) product of this vector with another.
The dot product can be used to calculate the angle between 2 vectors. If both are unit vectors, the dot product is the cosine of the angle; otherwise the dot product must be divided by the product of the lengths of both vectors to get the cosine of the angle. This result can further be used to calculate the distance of a point from a plane.
vec1_X | : This is the X Axis of the vector which you are going to use an operation on. |
vec1_Y | : This is the Y Axis of the vector which you are going to use an operation on. |
vec2_X | : This is the X Axis of the vector which will be used for the operation. |
vec2_Y | : This is the Y Axis of the vector which will be used for the operation. |
int vector2::isNAN | ( | float | vec1_X, |
float | vec1_Y | ||
) |
Check whether this vector contains valid values.
vec1_X | : This is the X Axis of the vector which you are going to use an operation on. |
vec1_Y | : This is the Y Axis of the vector which you are going to use an operation on. |
int vector2::isZeroLength | ( | float | vec1_X, |
float | vec1_Y | ||
) |
Returns true if this vector is zero length.
vec1_X | : This is the X Axis of the vector which you are going to use an operation on. |
vec1_Y | : This is the Y Axis of the vector which you are going to use an operation on. |
float vector2::length | ( | float | vec1_X, |
float | vec1_Y | ||
) |
Returns the length (magnitude) of the vector.
vec1_X | : This is the X Axis of the vector which you are going to use an operation on. |
vec1_Y | : This is the Y Axis of the vector which you are going to use an operation on. |
float2 vector2::midPoint | ( | float | vec1_X, |
float | vec1_Y, | ||
float | vec2_X, | ||
float | vec2_Y | ||
) |
Returns a vector at a point half way between this and the passed in vector.
vec1_X | : This is the X Axis of the vector which you are going to use an operation on. |
vec1_Y | : This is the Y Axis of the vector which you are going to use an operation on. |
vec2_X | : This is the X Axis of the vector which will be used for the operation. |
vec2_Y | : This is the Y Axis of the vector which will be used for the operation. |
float vector2::normalise | ( | float | vec1_X, |
float | vec1_Y | ||
) |
Normalises the vector.
This method normalises the vector such that it's length / magnitude is 1. The result is called a unit vector.
vec1_X | : This is the X Axis of the vector which you are going to use an operation on. |
vec1_Y | : This is the Y Axis of the vector which you are going to use an operation on. |
float2 vector2::normalisedCopy | ( | float | vec1_X, |
float | vec1_Y | ||
) |
As normalise, except that this vector is unaffected and the normalised vector is returned as a copy.
vec1_X | : This is the X Axis of the vector which you are going to use an operation on. |
vec1_Y | : This is the Y Axis of the vector which you are going to use an operation on. |
float2 vector2::perpendicular | ( | float | vec1_X, |
float | vec1_Y | ||
) |
Generates a vector perpendicular to this vector (eg an 'up' vector).
This method will return a vector which is perpendicular to vector 1. There are an infinite number of possibilities but this method will guarantee to generate one of them.
vec1_X | : This is the X Axis of the vector which you are going to use an operation on. |
vec1_Y | : This is the Y Axis of the vector which you are going to use an operation on. |
float2 vector2::randomDeviant | ( | float | vec1_X, |
float | vec1_Y, | ||
float | randomAngle | ||
) |
Generates a new random vector which deviates from this vector by a given angle in a random direction.
This method assumes that the random number generator has already been seeded appropriately.
vec1_X | : This is the X Axis of the vector which you are going to use an operation on. |
vec1_Y | : This is the Y Axis of the vector which you are going to use an operation on. |
angleDeg | : The angle at which to deviate |
float2 vector2::reflect | ( | float | vec1_X, |
float | vec1_Y, | ||
float | vec2_X, | ||
float | vec2_Y | ||
) |
Calculates a reflection vector to the plane with the given normal .
NB assumes 'this' is pointing AWAY FROM the plane, invert if it is not.
vec1_X | : This is the X Axis of the vector which you are going to use an operation on. |
vec1_Y | : This is the Y Axis of the vector which you are going to use an operation on. |
vec2_X | : This is the X Axis of the normal to reflect on. |
vec2_Y | : This is the Y Axis of the normal to reflect on. |
float vector2::squaredDistance | ( | float | vec1_X, |
float | vec1_Y, | ||
float | vec2_X, | ||
float | vec2_Y | ||
) |
Returns the square of the distance to another vector.
This method is for efficiency - calculating the actual distance to another vector requires a square root, which is expensive in terms of the operations required. This method returns the square of the distance to another vector, i.e. the same as the distance but before the square root is taken. Use this if you want to find the longest / shortest distance without incurring the square root.
vec1_X | : This is the X Axis of the vector which you are going to use an operation on. |
vec1_Y | : This is the Y Axis of the vector which you are going to use an operation on. |
vec2_X | : This is the X Axis of the vector which will be compared against. |
vec2_Y | : This is the Y Axis of the vector which will be compared against. |
float vector2::squaredLength | ( | float | vec1_X, |
float | vec1_Y | ||
) |
Returns the square of the length(magnitude) of the vector.
This method is for efficiency - calculating the actual length of a vector requires a square root, which is expensive in terms of the operations required. This method returns the square of the length of the vector, i.e. the same as the length but before the square root is taken. Use this if you want to find the longest / shortest vector without incurring the square root.
vec1_X | : This is the X Axis of the vector which you are going to use an operation on. |
vec1_Y | : This is the Y Axis of the vector which you are going to use an operation on. |