3D Maths Library Documentation - Vinessa/VinessaAIEProgramming GitHub Wiki
Welcome to the documentation for the 3D Maths Library, created as student work in AIE's Programming for games program.
Disclaimer I am absolutely horrid at math. While I have tested the functions in this math library, the control many of these tests are based on are the results of me using my own paper and pencil skills to determine what the result the function should return to be considered "correct". At this point I am unable to guarantee the performance of this library in all situations. There are better math libraries out there and unless you yearn to live dangerously I cannot recommend you use it and won't be held responsible for any catastrophes that may occur when used. I'm still learning. Good Luck! *End Disclaimer
////Vector2////
Contructors
Vector2
Takes two floats, one for X and one for Y. To implement this as a variable you could simply: "Vector2 NAMEOFVECTOR2( XValue, YValue);" You can also say "Vector2 NAMEOFVECTOR2;" The default constructor will assign a value of 0 to the X and Y values. There is also a standard Destructor.
Overloaded Operators
+Vector2
Adds one Vector2 to another Vector2. To implement, simply: NAMEOFVECTOR2a + NAMEOFVECTOR2b, or NAMEOFVECTOR2A.+(NAMEOFVECTOR2B)
+Scaler
Adds a scaler to a Vector2. To implement, simply: NAMEOFVECTOR2a + SCALERNAME.
-Vector2
Subtracts one Vector2 from another Vector2. To implement, simply: NAMEOFVECTOR2a - NAMEOFVECTOR2b.
-Scaler
Subtracts a scaler from a Vector2. To implement, simply: NAMEOFVECTOR2a - SCALERNAME.
*Scaler
Multiplies a Vector2 by a scaler. To implement, simply: NAMEOFVECTOR2a * SCALERNAME.
/Scaler
Divides a Vector2 by a scaler. To implement, simply: NAMEOFVECTOR2a / SCALERNAME.
+=Vector2
Compares two different Vector2's to see if either are greater than or equal to each other.
-=Vector2
Compares two different Vector2's to see if either are less than than or equal to each other.
==Vector2
Compares two different Vector2's to see if either are equal to each other.
Member functions
GetMagnitude2D()
Returns the magnitude of the parent vector2 that calls it as a float. Example usage "VECTOR2NAME.GetMagnitude();" Will return the Magnitude of VECTOR2NAME.
Normalize()
After checking to be sure the magnitude of the parent vector that calls it is not 0, by calling GetMagnitude(), it normalizes the parent vector that calls it, returning nothing. Example usage: "VECTOR2NAME.Normalize();"
EulerAngle()
Takes another Vector2 as an argument. Returns the Euler angle between the parent vector2 and the argument vector2 as a float. Example usage: "VECTOR2NAME.Eulerangle(OTHERVECTOR2NAME);"
GetDotProduct2D()
Takes another Vector2 as an argument. Returns the DotProduct between the parent vector2 and the argument vector2 as a float. Example usage: "VECTOR2NAME.DotProduct(OTHERVECTOR2NAME);"
GetNormal()
Creates a temporary vector that is the normalized version of the vector that calls the function and returns it. Does not alter the parent vector. Example usage: "VECTOR2NAME.GetNormal();
CrossProduct()
As this is a vector2 this is not a true cross product. Some people like to use this hacky version anyway. Assumes that the Z value is 0 and returns a float instead of a Vector2.
LinearInterpolation()
Takes a vector2 as the destination from the parent Vector2 and a float to represent the amount of time. Returns a new vector2 representing the location of the point on a path between the two vectors over that much time. Example usage: "STARTVECTORNAME.LinearInterpolation(DESTINATIONVECTORNAME, 10.4);"
GetX()
Returns the current X value of the Vector2 that calls it as a float. Example: "VECTOR2NAME.GetX();"
SetX()
Takes a float as an argument and sets it as the current X value of the Vector that calls it. Example usage: "VECTOR2NAME.SetX(12);" - Would set the X value of VECTOR2NAME to 12.
GetY()
Returns the current Y value of the Vector2 that calls it as a float. Example: "VECTOR2NAME.GetY();"
SetY()
Takes a float as an argument and sets it as the current Y value of the Vector that calls it. Example usage: "VECTOR2NAME.SetY(11.1);" - Would set the Y value of VECTOR2NAME to 11.1.
////Vector3/////////////
Contructors
Vector3
Takes three floats, one for X,one for Y and one for Z. To implement this as a variable you could simply: "Vector3 NAMEOFVECTOR3( XValue, YValue, ZValue);" You can also say "Vector3 NAMEOFVECTOR3;" The default constructor will assign a value of 0 to the X,Y and Z values. There is also a standard Destructor.
Overloaded Operators
+Vector3
Adds one Vector3 to another Vector3. To implement, simply: NAMEOFVECTOR3a + NAMEOFVECTOR3b.
+Scaler
Adds a scaler to a Vector3. To implement, simply: NAMEOFVECTOR3a + SCALERNAME.
-Vector3
Subtracts one Vector3 from another Vector3. To implement, simply: NAMEOFVECTOR3a - NAMEOFVECTOR3b.
-Scaler
Subtracts a scaler from a Vector3. To implement, simply: NAMEOFVECTOR3a - SCALERNAME.
*Scaler
Multiplies a Vector3 by a scaler. To implement, simply: NAMEOFVECTOR3a * SCALERNAME.
/Scaler
Divides a Vector3 by a scaler. To implement, simply: NAMEOFVECTOR3a / SCALERNAME.
+=Vector3
Compares two different Vector3 to see if either are greater than or equal to each other.
-=Vector3
Compares two different Vector3's to see if either are less than than or equal to each other.
==Vector3
Compares two different Vector3's to see if either are equal to each other.
Member functions
GetMagnitude3D()
Returns the magnitude of the parent vector3 that calls it as a float. Example usage "VECTOR3NAME.GetMagnitude();" Will return the Magnitude of VECTOR3NAME.
Normalize()
After checking to be sure the magnitude of the parent vector that calls it is not 0, by calling GetMagnitude3D(), it normalizes the parent vector that calls it, returning nothing. Example usage: "VECTOR3NAME.Normalize();"
EulerAngle()
Takes another Vector3 as an argument. Returns the Euler angle between the parent vector3 and the argument vector3 as a float. Example usage: "VECTOR3NAME.Eulerangle(OTHERVECTOR3NAME);"
GetDotProduct3D()
Takes another Vector3 as an argument. Returns the DotProduct between the parent vector3 and the argument vector3 as a float. Example usage: "VECTOR3NAME.DotProduct(OTHERVECTOR3NAME);"
GetNormal()
Creates a temporary vector that is the normalized version of the vector that calls the function and returns it. Does not alter the parent vector. Example usage: "VECTOR3NAME.GetNormal();
CrossProduct()
Takes a vector3 as an argument. Returns the Cross Product of this Vector3 and one other Vector 3 as a Vector3. Example usage: "VECTOR3NAME.CrossProduct(OTHERVECTOR3NAME);"
LinearInterpolation()
Takes a vector3 as the destination from the parent Vector3 and a float to represent the amount of time. Returns a new vector3 representing the location of the point on a path between the two vectors over that much time. Example usage: "STARTVECTORNAME.LinearInterpolation(DESTINATIONVECTORNAME, 10.4);"
GetX()
Returns the current X value of the Vector3 that calls it as a float. Example: "VECTOR3NAME.GetX();"
SetX()
Takes a float as an argument and sets it as the current X value of the Vector that calls it. Example usage: "VECTOR3NAME.SetX(12);" - Would set the X value of VECTOR3NAME to 12.
GetY()
Returns the current Y value of the Vector3 that calls it as a float. Example: "VECTOR3NAME.GetY();"
SetY()
Takes a float as an argument and sets it as the current Y value of the Vector that calls it. Example usage: "VECTOR3NAME.SetY(11.1);" - Would set the Y value of VECTOR3NAME to 11.1.
GetZ()
Returns the current Z value of the Vector3 that calls it as a float. Example: "VECTOR3NAME.GetY();"
SetZ()
Takes a float as an argument and sets it as the current Z value of the Vector that calls it. Example usage: "VECTOR3NAME.SetY(11.1);" - Would set the Z value of VECTOR3NAME to 11.1.
////Vector4//////////////
Constructors
Vector4
Takes four floats, one for X (Red) ,one for Y (Green) , one for Z (Blue) and one for A(Alpha). To implement this as a variable you could simply: "Vector4 NAMEOFVECTOR4( XREDValue, YGREENValue, ZBLUEValue, AALPHAVALUE);" You can also say "Vector4 NAMEOFVECTOR3;" The default constructor will assign a value of 0 to the XRED,YGREEN,ZBLUE AND AALPHA values. There is also a standard Destructor.
Overloaded Operators
+Vector4
Adds one Vector4 to another Vector4. To implement, simply: NAMEOFVECTOR4a + NAMEOFVECTOR4b.
+Scaler
Adds a scaler to a Vector4. To implement, simply: NAMEOFVECTOR4a + SCALERNAME.
-Vector4
Subtracts one Vector4 from another Vector4. To implement, simply: NAMEOFVECTOR4a - NAMEOFVECTOR4b.
-Scaler
Subtracts a scaler from a Vector4. To implement, simply: NAMEOFVECTOR4a - SCALERNAME.
*Scaler
Multiplies a Vector4 by a scaler. To implement, simply: NAMEOFVECTOR4a * SCALERNAME.
/Scaler
Divides a Vector4 by a scaler. To implement, simply: NAMEOFVECTOR4a / SCALERNAME.
+=Vector4
Compares two different Vector4 to see if either are greater than or equal to each other.
-=Vector4
Compares two different Vector4's to see if either are less than than or equal to each other.
==Vector4
Compares two different Vector4's to see if either are equal to each other.
Member Functions
GetMagnitude4D()
Returns the magnitude of the parent vector4 that calls it as a float. Example usage "VECTOR4NAME.GetMagnitude();" Will return the Magnitude of VECTOR4NAME.
Normalize()
After checking to be sure the magnitude of the parent vector that calls it is not 0, by calling GetMagnitude4D(), it normalizes the parent vector that calls it, returning nothing. Example usage: "VECTOR4NAME.Normalize();"
GetNormal()
Creates a temporary vector4 that is the normalized version of the vector4 that calls the function and returns it. Does not alter the parent vector4. Example usage: "VECTOR4NAME.GetNormal();
ConvertHexidecimaltoRGB()
Takes in a hexidecimal color value as an unsigned int and converts it to a Vector4 and an R,G,B and AlphaValue (Red is X, Green is Y, Blue is Z and Alpha is A)returns this Vector4. NOTE: Hex Value must have this 0x infront of it to correctly function. Does not alter the Vector4 that calls it. Example usage: "VECTOR4NAME.ConvertHexidecimaltoRGB(0xff1234)"
GetXRed()
Returns XRed value of a Vector4 as a float. Example usage: "VECTOR4NAME.GetXRED();"
GetYGreen()
Returns YGreen value of a Vector4 as a float. Example usage: "VECTOR4NAME.GetYGreen();"
GetZBlue()
Returns ZBlue value of a Vector4 as a float. Example usage: "VECTOR4NAME.GetZBlue();"
GetAAlpha()
Returns AAlpha value of a Vector4 as a float. Example usage: "VECTOR4NAME.GetAAlpha();"
SetXRed()
Takes a float as an argument and assigns that value as the current XRED value of the Vector that calls it. Example usage: "VECTOR4NAME.SetXRED(12.1)" will set the XRED value of VECTOR4NAME to 12.1.
SetYGreen()
Takes a float as an argument and assigns that value as the current YGreen value of the Vector that calls it. Example usage: "VECTOR4NAME.SetYGreen(21.5)" will set the YGreen value of VECTOR4NAME to 21.5.
SetZBlue()
Takes a float as an argument and assigns that value as the current ZBlue value of the Vector that calls it. Example usage: "VECTOR4NAME.SetZBlue(10)" will set the ZBlue value of VECTOR4NAME to 10.
SetAAlpha()
Takes a float as an argument and assigns that value as the current AAlpha value of the Vector that calls it. Example usage: "VECTOR4NAME.SetAAlpha(1)" will set the AAlpha value of VECTOR4NAME to 1.
////Matrix3/////////////
Constructors
Matrix3
Takes 9 floats in this order: A1, B1, C1, A2, B2, C2, A3, B3, C3. Which are then applied to a 3x3 Matrix as follows:
--A---B---C
1[A1][B1][C1]
2[A2][B2][C2]
3[A3][B3][C3]
Member Functions
Scale()
Takes the value that you would like the to scale the Matrix in both the X and The Y as floats. Creates and returns a new Matrix3 that can be used to scale another matrix.
Create Rotation()
Takes floats (in DEGREES) the value that you would like the to rotate the Matrix in both the X and The Y. Converts these values from degrees to Radians. Creates and returns a new Matrix3 that can be used to rotate another matrix.
Transform Point
Takes in a Vector3 as the Start, a Vector3 as a destination, a Vector3 XYZ, floats representing rotation degrees in X and Y, floats representing scalers for the X and the Y. Transforms the point you fed it (XYZ). Returns nothing.
Transform Vector
Takes in a Vector3 as the Start, a Vector3 as a destination, floats representing rotation degrees in X and Y, floats representing scalers for the X and the Y. Transforms a Vector.
Matrix Multiplication
* Matrix3
Multiplies a Matrix3 by another Matrix3. Example usage "MATRIX3A * MATRIXB"
* Scaler
Multiplies a Matrix3 by a Scaler. Example usage "MATRIX3A * SCALERNAME"
////Matrix4////////////
Constructors
Matrix4
Takes 16 floats in this order: A1, B1, C1, D1, A2, B2, C2, D2, A3, B3, C3, D3, A4, B4, C4, D4. Which are then applied to a 3x3 Matrix as follows: ###---A---B----C---D
1[A1][B1][C1][D1]
2[A2][B2][C2][D2]
3[A3][B3][C3][D3]
4[A4][B4][C4][D4]
Member Functions
CreateOrthographicProjection() Takes a which plane you would like to project to as an argument (XY, XZ OR YZ). Depending on your selection, returns appropriate Matrix4.
CreateScaleMatrix()
Takes in three floats representing the value that you would like to scale the matrix in the X, Y AND Z. Returns a new matrix that can be used to rotate another matrix in all three axis. If you would like to only Scale in one or two axis, enter a value of 1 for the axis you would like to leave untouched. Example usage " MATRIX4NAME.CreateScaleMatrix(2,2,1);"
CreateRotationMatrix()
Takes in three floats representing the value that you would like to rotate the matrix in the X, Y AND Z. Creates 3 separate Matrix4's and multiplies them together to create and return a new Matrix4 that can be used to rotate another matrix in all three axis. If you would like to only rotate in one or two axis, enter a value of 0 for the axis you would like to leave untouched. Example usage: "MATRIX4NAME.CreateRotationMatrix(2,2,0);"
Transform Point
Takes in a Vector3 as the Start, a Vector3 as a destination, a Vector3 XYZ, floats representing rotation degrees in X and Y, floats representing scalers for the X and the Y. Transforms the point you fed it (XYZ). Returns nothing.
Transform Vector
Takes in a Vector3 as the Start, a Vector3 as a destination, floats representing rotation degrees in X and Y, floats representing scalers for the X and the Y. Transforms a Vector. Returns nothing.
Matrix Multiplication
* Matrix4
Multiplies a Matrix4 by another Matrix3. Example usage "MATRIX4A * MATRIX4B"
* Scaler
Multiplies a Matrix4 by a Scaler. Example usage "MATRIX4A * SCALERNAME"
////Common Math Functionality/////
Member Functions
TestPower2()
Takes in an int as an argument, checks to see if it is a power of 2. If not, uses Bit Shifts to shift it to the nearest value that is power of 2. Returns nothing.
ConvertDegreesToRadians()
Takes in a float as an argument, representing the number of degrees you would like converted to Radians for use. Returns a new float that is the Rads value of the number entered in argument.
LinearInterpolationScaler()
Takes three floats. Start, Destination and time. Returns a Float.