You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
1.5 KiB
68 lines
1.5 KiB
#pragma once
|
|
#define _USE_MATH_DEFINES
|
|
#include <memory.h>
|
|
#include <cstdlib>
|
|
#include <cstdio>
|
|
#include <cmath>
|
|
#include <cfloat>
|
|
#include <vector>
|
|
#include <unordered_map>
|
|
#include <unordered_set>
|
|
|
|
typedef float scalar_t; // Scalar value,
|
|
|
|
typedef struct Vec3 // Vector or Position
|
|
{
|
|
scalar_t x; // horizontal
|
|
scalar_t y; // horizontal
|
|
scalar_t z; // vertical
|
|
|
|
Vec3() : x(0), y(0), z(0) { }
|
|
Vec3(float x, float y, float z) : x(x), y(y), z(z) { }
|
|
|
|
Vec3 operator+(const Vec3& other) const
|
|
{
|
|
return Vec3(x + other.x, y + other.y, z + other.z);
|
|
}
|
|
|
|
Vec3 operator-(const Vec3& other) const
|
|
{
|
|
return Vec3(x - other.x, y - other.y, z - other.z);
|
|
}
|
|
|
|
Vec3 operator*(float mul) const
|
|
{
|
|
return Vec3(x * mul, y * mul, z * mul);
|
|
}
|
|
|
|
Vec3 operator/(float div) const
|
|
{
|
|
return Vec3(x / div, y / div, z / div);
|
|
}
|
|
|
|
Vec3 operator-() const
|
|
{
|
|
return Vec3(-x, -y, -z);
|
|
}
|
|
|
|
float magnitude() const
|
|
{
|
|
return sqrtf(x * x + y * y + z * z);
|
|
}
|
|
|
|
Vec3 normalized() const
|
|
{
|
|
float invMag = 1.0f / magnitude();
|
|
return Vec3(x * invMag, y * invMag, z * invMag);
|
|
}
|
|
|
|
float dotProduct(const Vec3 &other) const
|
|
{
|
|
return x * other.x + y * other.y + z * other.z;
|
|
}
|
|
|
|
Vec3 crossProduct(const Vec3 &other) const
|
|
{
|
|
return Vec3(y * other.z - z * other.y, z * other.x - x * other.z, x * other.y - y * other.x);
|
|
}
|
|
} vec3_t;
|