-
Notifications
You must be signed in to change notification settings - Fork 0
Vector
This section contains all functions relating to CP_Vector.
- CP_Vector_Set
- CP_Vector_Zero
- CP_Vector_Negate
- CP_Vector_Add
- CP_Vector_Subtract
- CP_Vector_Scale
- CP_Vector_Normalize
- CP_Vector_MatrixMultiply
- CP_Vector_Length
- CP_Vector_Distance
- CP_Vector_DotProduct
- CP_Vector_CrossProduct
- CP_Vector_Angle
Manually create a CP_Vector by inputting its two values.
CP_Vector CP_Vector_Set(float x, float y);
- x (float) - The x value you want in the vector.
- y (float) - The y value you want in the vector.
- CP_Vector - A vector with the given values.
void update()
{
CP_Vector random_v = CP_Vector_Set(CP_Random_RangeFloat(0, 50), CP_Random_RangeFloat(0, 50));
}
Creates a CP_Vector with both values being 0.
CP_Vector CP_Vector_Zero();
This function has no parameters.
- CP_Vector - A vector with the given values.
void update()
{
CP_Vector zero_v = CP_Vector_Zero();
}
Returns a vector with the negated values of a given CP_Vector
CP_Vector CP_Vector_Negate(CP_Vector v);
- v (CP_Vector) - The vector to negate the value in.
- CP_Vector - A vector with the negated values.
void update()
{
CP_Vector random_v = CP_Vector_Set(CP_Random_RangeFloat(0, 50), CP_Random_RangeFloat(0, 50));
CP_Vector negated_v = CP_Vector_Negate(random_v);
}
Adds together the values within two given CP_Vectors.
CP_Vector CP_Vector_Add(CP_Vector a, CP_Vector b);
- CP_Vector - The sum of the two vectors.
void update()
{
CP_Vector vec_a = CP_Vector_Set(1, 1);
CP_Vector vec_b = CP_Vector_Set(-1, 6);
CP_Vector sum_v = CP_Vector_Add(vec_a, vec_b); // Returns a vector with values (0, 7)
}
Subtracts the values within two given CP_Vectors.
CP_Vector CP_Vector_Subtract(CP_Vector a, CP_Vector b);
- a (CP_Vector) - The vector that will subtract b.
- b (CP_Vector) - The vector that will be subtracted from a.
- CP_Vector - The difference of the two vectors.
void update()
{
CP_Vector vec_a = CP_Vector_Set(1, 1);
CP_Vector vec_b = CP_Vector_Set(-1, 6);
CP_Vector sum_v = CP_Vector_Subtract(vec_a, vec_b); // Returns a vector with values (2, -5)
}
Returns a new CP_Vector that has the values of the given CP_Vector scaled by the given scalar.
CP_Vector CP_Vector_Scale(CP_Vector a, float scale);
- a (CP_Vector) - The vector to scale.
- scale (float) - The value to scale the vector by.
- CP_Vector - The scaled vector.
void update()
{
CP_Vector vec_a = CP_Vector_Set(1, 1);
CP_Vector sum_v = CP_Vector_Scale(vec_a, 4); // Returns a vector with values (4, 4)
}
Returns a new CP_Vector that is the normalized version of the given CP_Vector.
CP_Vector CP_Vector_Normalize(CP_Vector vec);
- vec (CP_Vector) - The vector to normalize.
- CP_Vector - The normalized vector.
void update()
{
CP_Vector vec_a = CP_Vector_Set(3, 4);
CP_Vector norm_v = CP_Vector_Normalize(vec_a); // Returns a vector with values (.6, .8)
}
Creates a CP_Vector by multiplying the given CP_Vector by the given CP_Matrix.
CP_Vector CP_Vector_MatrixMultiply(CP_Matrix matrix, CP_Vector vec);
- matrix (CP_Matrix) - The matrix to use in the multiplication.
- vec (CP_Vector) - The vector to use in the multiplication.
- CP_Vector - The vector created by matrix * vec.
void update()
{
CP_Vector vec_a = CP_Vector_Set(3, 4);
CP_Matrix matrix_a = CP_Matrix_Translate(CP_Vector_Set(10, 6));
CP_Vector norm_v = CP_Vector_MatrixMultiply(matrix_a, vec_a);
}
Calculates the length of a given CP_Vector.
float CP_Vector_Length(CP_Vector vec);
- vec (CP_Vector) - The vector to find the length of.
- float - the length of the given vector.
void update()
{
CP_Vector vec_a = CP_Vector_Set(3, 4);
float vec_length = CP_Vector_Length(vec_a); // returns 5
}
Calculates the distance between two given CP_Vectors.
float CP_Vector_Distance(CP_Vector a, CP_Vector b);
- a (CP_Vector) - The first point in the calculation.
- b (CP_Vector) - The second point in the calculation.
- float - The distance between the two given points.
void update()
{
CP_Vector vec_a = CP_Vector_Set(3, 4);
CP_Vector vec_b = CP_Vector_Set(0, 0);
float dist = CP_Vector_Distance(vec_a, vec_b); // returns 5
}
Calculates the dot product of two given CP_Vectors.
float CP_Vector_DotProduct(CP_Vector a, CP_Vector b);
- a (CP_Vector) - The first vector in the calculation.
- b (CP_Vector) - The second vector in the calculation.
- float - The dot product of the two given CP_Vectors.
void update()
{
CP_Vector vec_a = CP_Vector_Set(1, 0);
CP_Vector vec_b = CP_Vector_Set(0, 1);
float dist = CP_Vector_DotProduct(vec_a, vec_b); // returns 0 since a and b are perpendicular
}
Calculates the magnitude of the cross product of two given CP_Vectors.
float CP_Vector_CrossProduct(CP_Vector a, CP_Vector b);
- a (CP_Vector) - The first vector in the calculation.
- b (CP_Vector) - The second vector in the calculation.
- float - The length of the cross product of the two given CP_Vectors.
void update()
{
CP_Vector vec_a = CP_Vector_Set(1, 0);
CP_Vector vec_b = CP_Vector_Set(0, 1);
float crossPLength = CP_Vector_CrossProduct(vec_a, vec_b); // returns 1 since a x b = (0, 0, 1)
}
Calculates the angle between two given CP_Vectors.
float CP_Vector_Angle(CP_Vector a, CP_Vector b);
- a (CP_Vector) - The first vector in the calculation.
- b (CP_Vector) - The second vector in the calculation.
- float - The angle between the given CP_Vectors.
void update()
{
CP_Vector vec_a = CP_Vector_Set(1, 0);
CP_Vector vec_b = CP_Vector_Set(0, 1);
float crossPLength = CP_Vector_Angle(vec_a, vec_b); // returns 90
}