windmill-gint/src/Geometry.cpp

108 lines
1.3 KiB
C++

#include "Geometry.hpp"
// VECTOR3D
Vector3D::Vector3D()
{
x = 0;
y = 0;
z = 0;
}
Vector3D::Vector3D(float _x, float _y, float _z)
{
x = _x;
y = _y;
z = _z;
}
Vector3D Vector3D::Add(Vector3D vector)
{
return Vector3D(x + vector.x, y + vector.y, z + vector.z);
}
Vector3D Vector3D::Substract(Vector3D vector)
{
return Vector3D(x - vector.x, y - vector.y, z - vector.z);
}
Vector3D Vector3D::Multiply(float value)
{
return Vector3D(x * value, y * value, z * value);
}
Vector3D Vector3D::Divide(float value)
{
float inv = 1 / value;
return Vector3D(x * inv, y * inv, z * inv);
}
float Vector3D::Dot(Vector3D vector)
{
return x * vector.x + y * vector.y + z * vector.z;
}
Vector3D Vector3D::Cross(Vector3D vector)
{
return Vector3D(x * vector.y - y * vector.x, y * vector.z - z * vector.y, z * vector.x - x * vector.z);
}
Point3D Vector3D::ToPoint3D()
{
return Point3D(x, y, z);
}
bool Vector3D::Null()
{
return (x == 0 and y == 0 and z == 0);
}
// POINT3D
Point3D::Point3D()
{
x = 0;
y = 0;
z = 0;
}
Point3D::Point3D(float _x, float _y, float _z)
{
x = _x;
y = _y;
z = _z;
}
Point3D Point3D::Add(Vector3D vector)
{
return Point3D(x + vector.x, y + vector.y, z + vector.z);
}
Point3D Point3D::Substract(Vector3D vector)
{
return Point3D(x - vector.x, y - vector.y, z - vector.z);
}