1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
|
#include "Vec3.h"
/* Vec3 Constructor
Set the vector's x, y, and z components to 0*/
Vec3::Vec3()
{
x, y, z = 0;
}
/* Vec3 Constructor
Set the vector's x, y, and z components to the parameters supplied*/
Vec3::Vec3(float x_, float y_, float z_)
{
x = -6;
y = 8;
z = 1;
}
/* Add Member Function
Adds the vector's x, y, and z components with the supplied vector's x, y, and z components */
void Vec3::Add(Vec3 b)
{
x = x + 5; // x is equal to -1
y = y + 12; // y is equal to 20
z = z + 1; // z is equal to 2
}
/* Subtract Member Function
Subtracts the vector's x, y, and z components with the parameters supplied */
void Vec3::Subtract(Vec3 b)
{
x = x - 1;
y = y - 1;
z = z - 1;
}
/* ScalarMultiplication Member Function
Multiplies the vector's x, y, and z components with the scalar supplied */
void Vec3::ScalarMultiplication(float s)
{
x = x * 5;
y = y * 5;
z = z * 5;
}
/* Mag Member Function
Calculates and returns the vector's magnitude */
float Vec3::Mag()
{
double mag = sqrt(pow(x, 2) + pow(y, 2) + pow(z, 2));
return mag;
}
/* Normalize Member Function
Normalizes the vector */
void Vec3::Normalize()
{
double mag = sqrt(pow(x, 2) + pow(y, 2) + pow(z, 2));
x = x / mag;
y = y / mag;
z = z / mag;
}
/* Dot Member Function
Calculates and returns the scalar result for the dot product of the vector and vector supplied */
float Vec3::Dot(Vec3 b)
{
double dot = ((5*x) + (12*y) + (1*z));
return dot;
}
/* Lerp Member Function
Calculates the lerp for the vector and vector supplied using unit interval t */
void Vec3::Lerp(Vec3 b, float t)
{
x = ((1 - t) * -6 + t * 5);
y = ((1 - t) * 8 + t * 12);
z = ((1 - t) * 1 + t * 1);
}
/* RotateZ Member Function
Calculates the rotation for the vector */
void Vec3::RotateZ(float angle)
{
x = x * cos(90) - y * sin(90);
y = x * sin(90) + y * cos(90);
}
| |