Files
Graphics-Rasterizer/Vector3D.cpp
IDunnoDev 773507b4ab Week7 [09/11] - [11/11]
Added Backface Culling Methods to the Model Class
Added Depth, Normal and Culled Flag Variables to the Polygon3D Class
Added Vector3D Class
Added - operator to the Vertex Class
Cleaned up Code, Adding Void to Params etc
2021-12-11 14:48:46 +00:00

78 lines
1.2 KiB
C++

#include "Vector3D.h"
Vector3D::Vector3D()
{
SetX(1);
SetY(1);
SetZ(1);
}
Vector3D::Vector3D(float x, float y, float z)
{
SetX(x);
SetY(y);
SetZ(z);
}
Vector3D::Vector3D(const Vector3D& other)
{
Copy(other);
}
Vector3D::~Vector3D()
{
}
// Accessors
float Vector3D::GetX() const
{
return _x;
}
void Vector3D::SetX(const float x)
{
_x = x;
}
float Vector3D::GetY() const
{
return _y;
}
void Vector3D::SetY(const float y)
{
_y = y;
}
float Vector3D::GetZ() const
{
return _z;
}
void Vector3D::SetZ(const float z)
{
_z = z;
}
float Vector3D::DotProduct(const Vector3D v1, const Vector3D v2)
{
return ((v1.GetX() * v2.GetX()) + (v1.GetY() * v2.GetY()) + (v1.GetZ() * v2.GetZ()));
}
Vector3D Vector3D::CrossProduct(const Vector3D v1, const Vector3D v2)
{
return Vector3D((v1.GetY() * v2.GetZ()) - (v1.GetZ() * v2.GetY()), (v1.GetZ() * v2.GetX()) - (v1.GetX() * v2.GetZ()), (v1.GetX() * v2.GetY()) - (v1.GetY() * v2.GetX()));
}
const Vector3D Vector3D::operator+ (const Vector3D& rhs) const
{
return Vector3D(_x + rhs.GetX(), _y + rhs.GetY(), _z + rhs.GetZ());
}
void Vector3D::Copy(const Vector3D& other)
{
_x = other.GetX();
_y = other.GetY();
_z = other.GetZ();
}