#include "Vector3D.h" Vector3D::Vector3D(float x, float y, float z) { _vector.x = x; _vector.y = y; _vector.z = z; } Vector3D::Vector3D(XMFLOAT3 vertexA, XMFLOAT3 vertexB) { _vector.x = vertexB.x - vertexA.x; _vector.y = vertexB.y - vertexA.y; _vector.z = vertexB.z - vertexA.z; } Vector3D::Vector3D(const Vector3D& other) { Copy(other); } Vector3D::~Vector3D() { } XMFLOAT3 Vector3D::Get() const { return _vector; } const void Vector3D::Normalize() { float length = (float) sqrt((_vector.x * _vector.x) + (_vector.y + _vector.y) + (_vector.z * _vector.z)); if (length != 0) { _vector.x /= length; _vector.y /= length; _vector.z /= length; } } float Vector3D::DotProduct(const Vector3D v1, const Vector3D v2) { return v1.Get().x * v2.Get().x + v1.Get().y * v2.Get().y + v1.Get().z * v2.Get().z; } float Vector3D::Length(const Vector3D v1, const Vector3D v2) { return (float)sqrt(pow((v1.Get().x - v2.Get().x), 2) + pow((v1.Get().y - v2.Get().y), 2) + pow((v1.Get().z - v2.Get().z), 2)); } Vector3D Vector3D::CrossProduct(Vector3D v1, Vector3D v2) { // v1.GetY() * v2.GetZ() - v1.GetZ() * v2.GetY() float crossedX = v1.Get().y * v2.Get().z - v1.Get().z * v2.Get().y; // v1.GetZ() * v2.GetX() - v1.GetX() * v2.GetZ() float crossedY = v1.Get().z * v2.Get().x - v1.Get().x * v2.Get().z; // v1.GetX() * v2.GetY() - v1.GetY() * v2.GetX() float crossedZ = v1.Get().x * v2.Get().y - v1.Get().y * v2.Get().x; return Vector3D(crossedX, crossedY, crossedZ); } Vector3D& Vector3D::operator= (const Vector3D& rhs) { if (this != &rhs) { Copy(rhs); } return *this; } const Vector3D Vector3D::operator+ (const Vector3D& rhs) const { return Vector3D(_vector.x + rhs.Get().x, _vector.y + rhs.Get().y, _vector.z + rhs.Get().z); } Vector3D& Vector3D::operator+= (const Vector3D& rhs) { _vector.x += rhs.Get().x; _vector.y += rhs.Get().y; _vector.z += rhs.Get().z; return *this; } const Vector3D Vector3D::operator/ (const float rhs) const { return Vector3D(_vector.x / rhs, _vector.y / rhs, _vector.z / rhs); } const Vector3D Vector3D::operator/ (const int rhs) const { return Vector3D(_vector.x / rhs, _vector.y / rhs, _vector.z / rhs); } void Vector3D::Copy(const Vector3D& other) { _vector.x = other.Get().x; _vector.y = other.Get().y; _vector.z = other.Get().z; }