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
|
#ifndef Vector3D_H
#define Vector3D_H
#include <cmath>
#include <iostream>
using namespace std;
class Vector3D
{
public:
void set4DVector(float theX, float theY, float theZ, float theW)
{
vecX = theX;
vecY = theY;
vecZ = theZ;
vecW = theW;
}
// Returns the X value as a float
float getX()
{
return vecX;
}
// Returns the Y value as a float
float getY()
{
return vecY;
}
// Returns the Z value as a float
float getZ()
{
return vecZ;
}
// Returns the W value as a float
float getW()
{
return vecW;
}
float dotProduct(Vector3D a, Vector3D b) // *
{
return ((a.getX() * b.getX()) + (a.getY() * b.getY()) + (a.getZ() * b.getZ()) + (a.getW() * b.getW()));
}
void* translation(Vector3D a[], float theX, float theY, float theZ, float theW, int vert)
{
Vector3D * t;
t = new Vector3D [3];
t[0].set4DVector(1, 0, 0, theX);
t[1].set4DVector(0, 1, 0, theY);
t[2].set4DVector(0, 0, 1, theZ);
t[3].set4DVector(0, 0, 0, 1);
float newX= 1 , newY = 1, newZ = 1;
int verticies = vert;
Vector3D* result; // resulting vector returns to stack
result = new Vector3D[verticies];
for (int i = 0; i < verticies; i++)
{
newX = newX + (t[0].dotProduct(t[0], a[i]));
newY = newY + (t[1].dotProduct(t[1], a[i]));
newZ = newZ + (t[2].dotProduct(t[2], a[i]));
}
for (int i = 0; i < verticies; i++)
{
result[i].set4DVector(a[i].getX() + newX,a[i].getY() + newY, a[i].getZ() + newZ, 1 );
}
return result;
}
private:
float vecX, vecY, vecZ, vecW; // the different X, Y, and Z coordinates of the Vector.
float tempDivideTop; // top value in any division
float tempDivideBottom; // bottom value used to catch divide by 0 error
};
#endif
|