RoboidControl-cpp/Vector3.h
2022-01-07 16:15:16 +01:00

106 lines
2.5 KiB
C++

#ifndef VECTOR_H
#define VECTOR_H
#pragma once
struct Quaternion;
extern "C" {
typedef struct Vec3 {
float x;
float y;
float z;
} Vec3;
void CopyVec3(const Vec3& v1, Vec3& v2);
}
/// <summary>
/// A 3-dimensional vector
/// </summary>
struct Vector3 : Vec3 {
public:
/// <summary>
/// Create a new 3-dimensinal zero vector
/// </summary>
Vector3();
/// <summary>
/// Create a new 3-dimensional vector
/// </summary>
/// <param name="x">x axis value</param>
/// <param name="y">y axis value</param>
/// <param name="z">z axis value</param>
Vector3(float x, float y, float z);
/// <summary>
/// Create a vector from C-style Vec3
/// </summary>
/// <param name="v">The C-style Vec</param>
Vector3(Vec3 v);
~Vector3();
/// <summary>
/// A vector with zero for all axis
/// </summary>
const static Vector3 zero;
/// <summary>
/// A vector with values (1, 0, 0)
/// </summary>
const static Vector3 right;
/// <summary>
/// A vector3 with values (-1, 0, 0)
/// </summary>
const static Vector3 left;
/// <summary>
/// A vector with values (0, 1, 0)
/// </summary>
const static Vector3 up;
/// <summary>
/// A vector with values (0, -1, 0)
/// </summary>
const static Vector3 down;
/// <summary>
/// A vector with values (0, 0, 1)
/// </summary>
const static Vector3 forward;
/// <summary>
/// A vector with values (0, 0, -1)
/// </summary>
const static Vector3 back;
static float Magnitude(const Vector3& a);
float magnitude() const;
static float SqrMagnitude(const Vector3& a);
float sqrMagnitude() const;
static Vector3 Normalize(Vector3 v);
Vector3 normalized() const;
Vector3 operator -();
Vector3 operator -(const Vector3& p2) const;
Vector3 operator +(const Vector3& t1) const;
static Vector3 Scale(const Vector3& p1, const Vector3& p2);
Vector3 operator *(float f) const;
Vector3 operator /(const float& d);
static float Dot(const Vector3& v1, const Vector3& v2);
bool operator ==(const Vector3& v);
static float Distance(const Vector3& p1, const Vector3& p2);
static Vector3 Cross(const Vector3& v1, const Vector3& v2);
// Projects a vector onto another vector.
static Vector3 Project(Vector3 vector, Vector3 onNormal);
// Projects a vector onto a plane defined by a normal orthogonal to the plane.
static Vector3 ProjectOnPlane(Vector3 vector, Vector3 planeNormal);
static float Angle(Vector3 from, Vector3 to);
static float SignedAngle(Vector3 from, Vector3 to, Vector3 axis);
};
void Vec3_Constructor(Vec3* v, float _x, float _y, float _z);
#endif