moving more stuff around
This commit is contained in:
315
src/game/Gen.cpp
315
src/game/Gen.cpp
@@ -49,4 +49,319 @@ namespace Gen
|
||||
res.Y += rhs.Y;
|
||||
return res;
|
||||
}
|
||||
|
||||
// Vec4
|
||||
Vec4& operator+=(Vec4& lhs, const Vec4& rhs)
|
||||
{
|
||||
lhs.x += rhs.x;
|
||||
lhs.y += rhs.y;
|
||||
lhs.z += rhs.z;
|
||||
lhs.w += rhs.w;
|
||||
return lhs;
|
||||
}
|
||||
Vec4 operator+(const Vec4& lhs, const Vec4& rhs)
|
||||
{
|
||||
Vec4 out = lhs;
|
||||
return out += rhs;
|
||||
}
|
||||
Vec4& operator+=(Vec4& lhs, float rhs)
|
||||
{
|
||||
lhs.x += rhs;
|
||||
lhs.y += rhs;
|
||||
lhs.z += rhs;
|
||||
lhs.w += rhs;
|
||||
return lhs;
|
||||
}
|
||||
Vec4 operator+(Vec4& lhs, float rhs)
|
||||
{
|
||||
Vec4 out = lhs;
|
||||
return out += rhs;
|
||||
}
|
||||
|
||||
Vec4& operator-=(Vec4& lhs, const Vec4& rhs)
|
||||
{
|
||||
lhs.x -= rhs.x;
|
||||
lhs.y -= rhs.y;
|
||||
lhs.z -= rhs.z;
|
||||
lhs.w -= rhs.w;
|
||||
return lhs;
|
||||
}
|
||||
Vec4 operator-(const Vec4& lhs, const Vec4& rhs)
|
||||
{
|
||||
Vec4 out = lhs;
|
||||
return out -= rhs;
|
||||
}
|
||||
Vec4& operator-=(Vec4& lhs, float rhs)
|
||||
{
|
||||
lhs.x -= rhs;
|
||||
lhs.y -= rhs;
|
||||
lhs.z -= rhs;
|
||||
lhs.w -= rhs;
|
||||
return lhs;
|
||||
}
|
||||
Vec4 operator-(const Vec4& lhs, float rhs)
|
||||
{
|
||||
Vec4 out = lhs;
|
||||
return out -= rhs;
|
||||
}
|
||||
|
||||
Vec4& operator*=(Vec4& lhs, float rhs)
|
||||
{
|
||||
lhs.x *= rhs;
|
||||
lhs.y *= rhs;
|
||||
lhs.z *= rhs;
|
||||
lhs.w *= rhs;
|
||||
return lhs;
|
||||
}
|
||||
Vec4 operator*(const Vec4& lhs, float rhs)
|
||||
{
|
||||
Vec4 out = lhs;
|
||||
return out *= rhs;
|
||||
}
|
||||
|
||||
Vec4& operator/=(Vec4& lhs, float rhs)
|
||||
{
|
||||
lhs.x /= rhs;
|
||||
lhs.y /= rhs;
|
||||
lhs.z /= rhs;
|
||||
lhs.w /= rhs;
|
||||
return lhs;
|
||||
}
|
||||
Vec4 operator/(const Vec4& lhs, float rhs)
|
||||
{
|
||||
Vec4 out = lhs;
|
||||
return out /= rhs;
|
||||
}
|
||||
|
||||
// Vec3
|
||||
Vec3& operator+=(Vec3& lhs, const Vec3& rhs)
|
||||
{
|
||||
lhs.x += rhs.x;
|
||||
lhs.y += rhs.y;
|
||||
lhs.z += rhs.z;
|
||||
return lhs;
|
||||
}
|
||||
Vec3 operator+(const Vec3& lhs, const Vec3& rhs)
|
||||
{
|
||||
Vec3 out = lhs;
|
||||
return out += rhs;
|
||||
}
|
||||
Vec3& operator+=(Vec3& lhs, float rhs)
|
||||
{
|
||||
lhs.x += rhs;
|
||||
lhs.y += rhs;
|
||||
lhs.z += rhs;
|
||||
return lhs;
|
||||
}
|
||||
Vec3 operator+(Vec3& lhs, float rhs)
|
||||
{
|
||||
Vec3 out = lhs;
|
||||
return out += rhs;
|
||||
}
|
||||
|
||||
Vec3& operator-=(Vec3& lhs, const Vec3& rhs)
|
||||
{
|
||||
lhs.x -= rhs.x;
|
||||
lhs.y -= rhs.y;
|
||||
lhs.z -= rhs.z;
|
||||
return lhs;
|
||||
}
|
||||
Vec3 operator-(const Vec3& lhs, const Vec3& rhs)
|
||||
{
|
||||
Vec3 out = lhs;
|
||||
return out -= rhs;
|
||||
}
|
||||
Vec3& operator-=(Vec3& lhs, float rhs)
|
||||
{
|
||||
lhs.x -= rhs;
|
||||
lhs.y -= rhs;
|
||||
lhs.z -= rhs;
|
||||
return lhs;
|
||||
}
|
||||
Vec3 operator-(const Vec3& lhs, float rhs)
|
||||
{
|
||||
Vec3 out = lhs;
|
||||
return out -= rhs;
|
||||
}
|
||||
|
||||
Vec3& operator*=(Vec3& lhs, float rhs)
|
||||
{
|
||||
lhs.x *= rhs;
|
||||
lhs.y *= rhs;
|
||||
lhs.z *= rhs;
|
||||
return lhs;
|
||||
}
|
||||
Vec3 operator*(const Vec3& lhs, float rhs)
|
||||
{
|
||||
Vec3 out = lhs;
|
||||
return out *= rhs;
|
||||
}
|
||||
|
||||
Vec3& operator/=(Vec3& lhs, float rhs)
|
||||
{
|
||||
lhs.x /= rhs;
|
||||
lhs.y /= rhs;
|
||||
lhs.z /= rhs;
|
||||
return lhs;
|
||||
}
|
||||
Vec3 operator/(const Vec3& lhs, float rhs)
|
||||
{
|
||||
Vec3 out = lhs;
|
||||
return out /= rhs;
|
||||
}
|
||||
|
||||
// Vec2
|
||||
Vec2& operator+=(Vec2& lhs, const Vec2& rhs)
|
||||
{
|
||||
lhs.x += rhs.x;
|
||||
lhs.y += rhs.y;
|
||||
return lhs;
|
||||
}
|
||||
Vec2 operator+(const Vec2& lhs, const Vec2& rhs)
|
||||
{
|
||||
Vec2 out = lhs;
|
||||
return out += rhs;
|
||||
}
|
||||
Vec2& operator+=(Vec2& lhs, float rhs)
|
||||
{
|
||||
lhs.x += rhs;
|
||||
lhs.y += rhs;
|
||||
return lhs;
|
||||
}
|
||||
Vec2 operator+(Vec2& lhs, float rhs)
|
||||
{
|
||||
Vec2 out = lhs;
|
||||
return out += rhs;
|
||||
}
|
||||
|
||||
Vec2& operator-=(Vec2& lhs, const Vec2& rhs)
|
||||
{
|
||||
lhs.x -= rhs.x;
|
||||
lhs.y -= rhs.y;
|
||||
return lhs;
|
||||
}
|
||||
Vec2 operator-(const Vec2& lhs, const Vec2& rhs)
|
||||
{
|
||||
Vec2 out = lhs;
|
||||
return out -= rhs;
|
||||
}
|
||||
Vec2& operator-=(Vec2& lhs, float rhs)
|
||||
{
|
||||
lhs.x -= rhs;
|
||||
lhs.y -= rhs;
|
||||
return lhs;
|
||||
}
|
||||
Vec2 operator-(const Vec2& lhs, float rhs)
|
||||
{
|
||||
Vec2 out = lhs;
|
||||
return out -= rhs;
|
||||
}
|
||||
|
||||
Vec2& operator*=(Vec2& lhs, float rhs)
|
||||
{
|
||||
lhs.x *= rhs;
|
||||
lhs.y *= rhs;
|
||||
return lhs;
|
||||
}
|
||||
Vec2 operator*(const Vec2& lhs, float rhs)
|
||||
{
|
||||
Vec2 out = lhs;
|
||||
return out *= rhs;
|
||||
}
|
||||
|
||||
Vec2& operator/=(Vec2& lhs, float rhs)
|
||||
{
|
||||
lhs.x /= rhs;
|
||||
lhs.y /= rhs;
|
||||
return lhs;
|
||||
}
|
||||
Vec2 operator/(const Vec2& lhs, float rhs)
|
||||
{
|
||||
Vec2 out = lhs;
|
||||
return out /= rhs;
|
||||
}
|
||||
|
||||
Mat4 Inverse(const Mat4& mat)
|
||||
{
|
||||
Mat4 result;
|
||||
bx::mtxInverse(result.M, &mat.M[0]);
|
||||
return result;
|
||||
}
|
||||
Mat4 Transpose(const Mat4& mat)
|
||||
{
|
||||
Mat4 result;
|
||||
bx::mtxTranspose(result.M, &mat.M[0]);
|
||||
return result;
|
||||
}
|
||||
Vec4 Mul(const Mat4& mat, const Vec4& vec)
|
||||
{
|
||||
Vec4 out;
|
||||
bx::vec4MulMtx(&out.x, &vec.x, &mat.M[0]);
|
||||
return out;
|
||||
}
|
||||
|
||||
float Magnitude(const Vec4& vec)
|
||||
{
|
||||
return bx::sqrt(vec.x * vec.x + vec.y * vec.y + vec.z * vec.z + vec.w * vec.w);
|
||||
}
|
||||
float Magnitude(const Vec3& vec)
|
||||
{
|
||||
return bx::sqrt(vec.x * vec.x + vec.y * vec.y + vec.z * vec.z);
|
||||
}
|
||||
float Magnitude(const Vec2& vec)
|
||||
{
|
||||
return bx::sqrt(vec.x * vec.x + vec.y * vec.y);
|
||||
}
|
||||
|
||||
Vec4 Normalized(const Vec4& vec)
|
||||
{
|
||||
Vec4 res = vec;
|
||||
return res /= Magnitude(vec);
|
||||
}
|
||||
Vec3 Normalized(const Vec3& vec)
|
||||
{
|
||||
Vec3 res = vec;
|
||||
return res /= Magnitude(vec);
|
||||
}
|
||||
Vec2 Normalized(const Vec2& vec)
|
||||
{
|
||||
Vec2 res = vec;
|
||||
return res /= Magnitude(vec);
|
||||
}
|
||||
|
||||
float DotProduct(Vec3 a, Vec3 b)
|
||||
{
|
||||
return a.x * b.x + a.y * b.y + a.z * b.z;
|
||||
}
|
||||
Vec3 CrossProduct(Vec3 a, Vec3 b)
|
||||
{
|
||||
float x = a.y * b.z - a.z * b.y;
|
||||
float y = a.z * b.x - a.x * b.z;
|
||||
float z = a.x * b.y - a.y * b.x;
|
||||
return {x, y, z};
|
||||
}
|
||||
Vec3 CrossProductFromPlane(Vec3 a, Vec3 b, Vec3 c)
|
||||
{
|
||||
// TODO: normalize might not be necessary
|
||||
Vec3 lineA = Normalized(b - a);
|
||||
Vec3 lineB = Normalized(c - a);
|
||||
return CrossProduct(lineA, lineB);
|
||||
}
|
||||
bool RayPlaneIntersect(Vec3 l1, Vec3 l2, Vec3 p1, Vec3 p2, Vec3 p3, Vec3& out)
|
||||
{
|
||||
// thanks to Paul Bourke and Bryan Hanson
|
||||
// l1,l2 constitute the line. P1,P2,P3 constitute the plane
|
||||
out = {};
|
||||
Vec3 N = CrossProductFromPlane(p1, p2, p3); // N is the normal of the plane
|
||||
float n = DotProduct(N, Vec3{p3.x - l1.x, p3.y - l1.y, p3.z - l1.z});
|
||||
Vec3 LbMinusLa = Vec3{l2.x - l1.x, l2.y - l1.y, l2.z - l1.z};
|
||||
float d = DotProduct(N, LbMinusLa);
|
||||
if (d == 0) return false; // Line is parallel to or in the plane
|
||||
float u = n / d;
|
||||
if ((u >= 0.0) && (u <= 1.0))
|
||||
{ // Plane is between the two points
|
||||
} // can be used for checking but does not influence the outcome
|
||||
out = Vec3{l1.x + u * LbMinusLa.x, l1.y + u * LbMinusLa.y, l1.z + u * LbMinusLa.z};
|
||||
return true;
|
||||
}
|
||||
} // namespace Gen
|
||||
|
||||
@@ -12,4 +12,69 @@ namespace Gen
|
||||
|
||||
PuzPos operator+=(PuzPos lhs, const PuzPos& rhs);
|
||||
PuzPos operator+(PuzPos lhs, const PuzPos& rhs);
|
||||
|
||||
Vec4& operator+=(Vec4& lhs, const Vec4& rhs);
|
||||
Vec4 operator+(const Vec4& lhs, const Vec4& rhs);
|
||||
Vec4& operator+=(Vec4& lhs, float rhs);
|
||||
Vec4 operator+(Vec4& lhs, float rhs);
|
||||
|
||||
Vec4& operator-=(Vec4& lhs, const Vec4& rhs);
|
||||
Vec4 operator-(const Vec4& lhs, const Vec4& rhs);
|
||||
Vec4& operator-=(Vec4& lhs, float rhs);
|
||||
Vec4 operator-(const Vec4& lhs, float rhs);
|
||||
|
||||
Vec4& operator*=(Vec4& lhs, float rhs);
|
||||
Vec4 operator*(const Vec4& lhs, float rhs);
|
||||
|
||||
Vec4& operator/=(Vec4& lhs, float rhs);
|
||||
Vec4 operator/(const Vec4& lhs, float rhs);
|
||||
|
||||
Vec3& operator+=(Vec3& lhs, const Vec3& rhs);
|
||||
Vec3 operator+(const Vec3& lhs, const Vec3& rhs);
|
||||
Vec3& operator+=(Vec3& lhs, float rhs);
|
||||
Vec3 operator+(Vec3& lhs, float rhs);
|
||||
|
||||
Vec3& operator-=(Vec3& lhs, const Vec3& rhs);
|
||||
Vec3 operator-(const Vec3& lhs, const Vec3& rhs);
|
||||
Vec3& operator-=(Vec3& lhs, float rhs);
|
||||
Vec3 operator-(const Vec3& lhs, float rhs);
|
||||
|
||||
Vec3& operator*=(Vec3& lhs, float rhs);
|
||||
Vec3 operator*(const Vec3& lhs, float rhs);
|
||||
|
||||
Vec3& operator/=(Vec3& lhs, float rhs);
|
||||
Vec3 operator/(const Vec3& lhs, float rhs);
|
||||
|
||||
Vec2& operator+=(Vec2& lhs, const Vec2& rhs);
|
||||
Vec2 operator+(const Vec2& lhs, const Vec2& rhs);
|
||||
Vec2& operator+=(Vec2& lhs, float rhs);
|
||||
Vec2 operator+(Vec2& lhs, float rhs);
|
||||
|
||||
Vec2& operator-=(Vec2& lhs, const Vec2& rhs);
|
||||
Vec2 operator-(const Vec2& lhs, const Vec2& rhs);
|
||||
Vec2& operator-=(Vec2& lhs, float rhs);
|
||||
Vec2 operator-(const Vec2& lhs, float rhs);
|
||||
|
||||
Vec2& operator*=(Vec2& lhs, float rhs);
|
||||
Vec2 operator*(const Vec2& lhs, float rhs);
|
||||
|
||||
Vec2& operator/=(Vec2& lhs, float rhs);
|
||||
Vec2 operator/(const Vec2& lhs, float rhs);
|
||||
|
||||
float Magnitude(const Vec4& vec);
|
||||
float Magnitude(const Vec3& vec);
|
||||
float Magnitude(const Vec2& vec);
|
||||
|
||||
Vec4 Normalized(const Vec4& vec);
|
||||
Vec3 Normalized(const Vec3& vec);
|
||||
Vec2 Normalized(const Vec2& vec);
|
||||
|
||||
Mat4 Inverse(const Mat4& mat);
|
||||
Mat4 Transpose(const Mat4& mat);
|
||||
Vec4 Mul(const Mat4& mat, const Vec4& vec);
|
||||
|
||||
float DotProduct(Vec3 a, Vec3 b);
|
||||
Vec3 CrossProduct(Vec3 a, Vec3 b);
|
||||
Vec3 CrossProductFromPlane(Vec3 a, Vec3 b, Vec3 c);
|
||||
bool RayPlaneIntersect(Vec3 l1, Vec3 l2, Vec3 p1, Vec3 p2, Vec3 p3, Vec3& out);
|
||||
} // namespace Gen
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#include "../engine/Shared.h"
|
||||
#include "Gen.h"
|
||||
#include "Global.h"
|
||||
#include "Instance.h"
|
||||
|
||||
#include "bx/bx.h"
|
||||
#include "bx/math.h"
|
||||
#include <cassert>
|
||||
@@ -162,318 +164,3 @@ Vec3 Transform::GetPosition()
|
||||
{
|
||||
return {Position.x, Position.y, Position.z};
|
||||
}
|
||||
|
||||
// Vec4
|
||||
Vec4& operator+=(Vec4& lhs, const Vec4& rhs)
|
||||
{
|
||||
lhs.x += rhs.x;
|
||||
lhs.y += rhs.y;
|
||||
lhs.z += rhs.z;
|
||||
lhs.w += rhs.w;
|
||||
return lhs;
|
||||
}
|
||||
Vec4 operator+(const Vec4& lhs, const Vec4& rhs)
|
||||
{
|
||||
Vec4 out = lhs;
|
||||
return out += rhs;
|
||||
}
|
||||
Vec4& operator+=(Vec4& lhs, float rhs)
|
||||
{
|
||||
lhs.x += rhs;
|
||||
lhs.y += rhs;
|
||||
lhs.z += rhs;
|
||||
lhs.w += rhs;
|
||||
return lhs;
|
||||
}
|
||||
Vec4 operator+(Vec4& lhs, float rhs)
|
||||
{
|
||||
Vec4 out = lhs;
|
||||
return out += rhs;
|
||||
}
|
||||
|
||||
Vec4& operator-=(Vec4& lhs, const Vec4& rhs)
|
||||
{
|
||||
lhs.x -= rhs.x;
|
||||
lhs.y -= rhs.y;
|
||||
lhs.z -= rhs.z;
|
||||
lhs.w -= rhs.w;
|
||||
return lhs;
|
||||
}
|
||||
Vec4 operator-(const Vec4& lhs, const Vec4& rhs)
|
||||
{
|
||||
Vec4 out = lhs;
|
||||
return out -= rhs;
|
||||
}
|
||||
Vec4& operator-=(Vec4& lhs, float rhs)
|
||||
{
|
||||
lhs.x -= rhs;
|
||||
lhs.y -= rhs;
|
||||
lhs.z -= rhs;
|
||||
lhs.w -= rhs;
|
||||
return lhs;
|
||||
}
|
||||
Vec4 operator-(const Vec4& lhs, float rhs)
|
||||
{
|
||||
Vec4 out = lhs;
|
||||
return out -= rhs;
|
||||
}
|
||||
|
||||
Vec4& operator*=(Vec4& lhs, float rhs)
|
||||
{
|
||||
lhs.x *= rhs;
|
||||
lhs.y *= rhs;
|
||||
lhs.z *= rhs;
|
||||
lhs.w *= rhs;
|
||||
return lhs;
|
||||
}
|
||||
Vec4 operator*(const Vec4& lhs, float rhs)
|
||||
{
|
||||
Vec4 out = lhs;
|
||||
return out *= rhs;
|
||||
}
|
||||
|
||||
Vec4& operator/=(Vec4& lhs, float rhs)
|
||||
{
|
||||
lhs.x /= rhs;
|
||||
lhs.y /= rhs;
|
||||
lhs.z /= rhs;
|
||||
lhs.w /= rhs;
|
||||
return lhs;
|
||||
}
|
||||
Vec4 operator/(const Vec4& lhs, float rhs)
|
||||
{
|
||||
Vec4 out = lhs;
|
||||
return out /= rhs;
|
||||
}
|
||||
|
||||
// Vec3
|
||||
Vec3& operator+=(Vec3& lhs, const Vec3& rhs)
|
||||
{
|
||||
lhs.x += rhs.x;
|
||||
lhs.y += rhs.y;
|
||||
lhs.z += rhs.z;
|
||||
return lhs;
|
||||
}
|
||||
Vec3 operator+(const Vec3& lhs, const Vec3& rhs)
|
||||
{
|
||||
Vec3 out = lhs;
|
||||
return out += rhs;
|
||||
}
|
||||
Vec3& operator+=(Vec3& lhs, float rhs)
|
||||
{
|
||||
lhs.x += rhs;
|
||||
lhs.y += rhs;
|
||||
lhs.z += rhs;
|
||||
return lhs;
|
||||
}
|
||||
Vec3 operator+(Vec3& lhs, float rhs)
|
||||
{
|
||||
Vec3 out = lhs;
|
||||
return out += rhs;
|
||||
}
|
||||
|
||||
Vec3& operator-=(Vec3& lhs, const Vec3& rhs)
|
||||
{
|
||||
lhs.x -= rhs.x;
|
||||
lhs.y -= rhs.y;
|
||||
lhs.z -= rhs.z;
|
||||
return lhs;
|
||||
}
|
||||
Vec3 operator-(const Vec3& lhs, const Vec3& rhs)
|
||||
{
|
||||
Vec3 out = lhs;
|
||||
return out -= rhs;
|
||||
}
|
||||
Vec3& operator-=(Vec3& lhs, float rhs)
|
||||
{
|
||||
lhs.x -= rhs;
|
||||
lhs.y -= rhs;
|
||||
lhs.z -= rhs;
|
||||
return lhs;
|
||||
}
|
||||
Vec3 operator-(const Vec3& lhs, float rhs)
|
||||
{
|
||||
Vec3 out = lhs;
|
||||
return out -= rhs;
|
||||
}
|
||||
|
||||
Vec3& operator*=(Vec3& lhs, float rhs)
|
||||
{
|
||||
lhs.x *= rhs;
|
||||
lhs.y *= rhs;
|
||||
lhs.z *= rhs;
|
||||
return lhs;
|
||||
}
|
||||
Vec3 operator*(const Vec3& lhs, float rhs)
|
||||
{
|
||||
Vec3 out = lhs;
|
||||
return out *= rhs;
|
||||
}
|
||||
|
||||
Vec3& operator/=(Vec3& lhs, float rhs)
|
||||
{
|
||||
lhs.x /= rhs;
|
||||
lhs.y /= rhs;
|
||||
lhs.z /= rhs;
|
||||
return lhs;
|
||||
}
|
||||
Vec3 operator/(const Vec3& lhs, float rhs)
|
||||
{
|
||||
Vec3 out = lhs;
|
||||
return out /= rhs;
|
||||
}
|
||||
|
||||
// Vec2
|
||||
Vec2& operator+=(Vec2& lhs, const Vec2& rhs)
|
||||
{
|
||||
lhs.x += rhs.x;
|
||||
lhs.y += rhs.y;
|
||||
return lhs;
|
||||
}
|
||||
Vec2 operator+(const Vec2& lhs, const Vec2& rhs)
|
||||
{
|
||||
Vec2 out = lhs;
|
||||
return out += rhs;
|
||||
}
|
||||
Vec2& operator+=(Vec2& lhs, float rhs)
|
||||
{
|
||||
lhs.x += rhs;
|
||||
lhs.y += rhs;
|
||||
return lhs;
|
||||
}
|
||||
Vec2 operator+(Vec2& lhs, float rhs)
|
||||
{
|
||||
Vec2 out = lhs;
|
||||
return out += rhs;
|
||||
}
|
||||
|
||||
Vec2& operator-=(Vec2& lhs, const Vec2& rhs)
|
||||
{
|
||||
lhs.x -= rhs.x;
|
||||
lhs.y -= rhs.y;
|
||||
return lhs;
|
||||
}
|
||||
Vec2 operator-(const Vec2& lhs, const Vec2& rhs)
|
||||
{
|
||||
Vec2 out = lhs;
|
||||
return out -= rhs;
|
||||
}
|
||||
Vec2& operator-=(Vec2& lhs, float rhs)
|
||||
{
|
||||
lhs.x -= rhs;
|
||||
lhs.y -= rhs;
|
||||
return lhs;
|
||||
}
|
||||
Vec2 operator-(const Vec2& lhs, float rhs)
|
||||
{
|
||||
Vec2 out = lhs;
|
||||
return out -= rhs;
|
||||
}
|
||||
|
||||
Vec2& operator*=(Vec2& lhs, float rhs)
|
||||
{
|
||||
lhs.x *= rhs;
|
||||
lhs.y *= rhs;
|
||||
return lhs;
|
||||
}
|
||||
Vec2 operator*(const Vec2& lhs, float rhs)
|
||||
{
|
||||
Vec2 out = lhs;
|
||||
return out *= rhs;
|
||||
}
|
||||
|
||||
Vec2& operator/=(Vec2& lhs, float rhs)
|
||||
{
|
||||
lhs.x /= rhs;
|
||||
lhs.y /= rhs;
|
||||
return lhs;
|
||||
}
|
||||
Vec2 operator/(const Vec2& lhs, float rhs)
|
||||
{
|
||||
Vec2 out = lhs;
|
||||
return out /= rhs;
|
||||
}
|
||||
|
||||
Mat4 Inverse(const Mat4& mat)
|
||||
{
|
||||
Mat4 result;
|
||||
bx::mtxInverse(result.M, &mat.M[0]);
|
||||
return result;
|
||||
}
|
||||
Mat4 Transpose(const Mat4& mat)
|
||||
{
|
||||
Mat4 result;
|
||||
bx::mtxTranspose(result.M, &mat.M[0]);
|
||||
return result;
|
||||
}
|
||||
Vec4 Mul(const Mat4& mat, const Vec4& vec)
|
||||
{
|
||||
Vec4 out;
|
||||
bx::vec4MulMtx(&out.x, &vec.x, &mat.M[0]);
|
||||
return out;
|
||||
}
|
||||
|
||||
float Magnitude(const Vec4& vec)
|
||||
{
|
||||
return bx::sqrt(vec.x * vec.x + vec.y * vec.y + vec.z * vec.z + vec.w * vec.w);
|
||||
}
|
||||
float Magnitude(const Vec3& vec)
|
||||
{
|
||||
return bx::sqrt(vec.x * vec.x + vec.y * vec.y + vec.z * vec.z);
|
||||
}
|
||||
float Magnitude(const Vec2& vec)
|
||||
{
|
||||
return bx::sqrt(vec.x * vec.x + vec.y * vec.y);
|
||||
}
|
||||
|
||||
Vec4 Normalized(const Vec4& vec)
|
||||
{
|
||||
Vec4 res = vec;
|
||||
return res /= Magnitude(vec);
|
||||
}
|
||||
Vec3 Normalized(const Vec3& vec)
|
||||
{
|
||||
Vec3 res = vec;
|
||||
return res /= Magnitude(vec);
|
||||
}
|
||||
Vec2 Normalized(const Vec2& vec)
|
||||
{
|
||||
Vec2 res = vec;
|
||||
return res /= Magnitude(vec);
|
||||
}
|
||||
|
||||
float DotProduct(Vec3 a, Vec3 b)
|
||||
{
|
||||
return a.x * b.x + a.y * b.y + a.z * b.z;
|
||||
}
|
||||
Vec3 CrossProduct(Vec3 a, Vec3 b)
|
||||
{
|
||||
float x = a.y * b.z - a.z * b.y;
|
||||
float y = a.z * b.x - a.x * b.z;
|
||||
float z = a.x * b.y - a.y * b.x;
|
||||
return {x, y, z};
|
||||
}
|
||||
Vec3 CrossProductFromPlane(Vec3 a, Vec3 b, Vec3 c)
|
||||
{
|
||||
// TODO: normalize might not be necessary
|
||||
Vec3 lineA = Normalized(b - a);
|
||||
Vec3 lineB = Normalized(c - a);
|
||||
return CrossProduct(lineA, lineB);
|
||||
}
|
||||
bool RayPlaneIntersect(Vec3 l1, Vec3 l2, Vec3 p1, Vec3 p2, Vec3 p3, Vec3& out)
|
||||
{
|
||||
// thanks to Paul Bourke and Bryan Hanson
|
||||
// l1,l2 constitute the line. P1,P2,P3 constitute the plane
|
||||
out = {};
|
||||
Vec3 N = CrossProductFromPlane(p1, p2, p3); // N is the normal of the plane
|
||||
float n = DotProduct(N, Vec3{p3.x - l1.x, p3.y - l1.y, p3.z - l1.z});
|
||||
Vec3 LbMinusLa = Vec3{l2.x - l1.x, l2.y - l1.y, l2.z - l1.z};
|
||||
float d = DotProduct(N, LbMinusLa);
|
||||
if (d == 0) return false; // Line is parallel to or in the plane
|
||||
float u = n / d;
|
||||
if ((u >= 0.0) && (u <= 1.0))
|
||||
{ // Plane is between the two points
|
||||
} // can be used for checking but does not influence the outcome
|
||||
out = Vec3{l1.x + u * LbMinusLa.x, l1.y + u * LbMinusLa.y, l1.z + u * LbMinusLa.z};
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -24,19 +24,6 @@ inline bool GetFlag(int32_t in, int32_t flags)
|
||||
return (in & flags) > 0;
|
||||
}
|
||||
|
||||
namespace Gen
|
||||
{
|
||||
bool IsValid(const AssetHandle& h);
|
||||
bool IsValid(const ModelHandle& h);
|
||||
bool IsValid(const TextureHandle& h);
|
||||
|
||||
bool operator==(const AssetHandle& lhs, const AssetHandle& rhs);
|
||||
bool operator==(const ModelHandle& lhs, const ModelHandle& rhs);
|
||||
|
||||
PuzPos operator+=(PuzPos lhs, const PuzPos& rhs);
|
||||
PuzPos operator+(PuzPos lhs, const PuzPos& rhs);
|
||||
} // namespace Gen
|
||||
|
||||
struct Transform
|
||||
{
|
||||
Gen::Mat4 M;
|
||||
@@ -64,71 +51,6 @@ struct Transform
|
||||
void UpdateMatrixForCam();
|
||||
};
|
||||
|
||||
Gen::Vec4& operator+=(Gen::Vec4& lhs, const Gen::Vec4& rhs);
|
||||
Gen::Vec4 operator+(const Gen::Vec4& lhs, const Gen::Vec4& rhs);
|
||||
Gen::Vec4& operator+=(Gen::Vec4& lhs, float rhs);
|
||||
Gen::Vec4 operator+(Gen::Vec4& lhs, float rhs);
|
||||
|
||||
Gen::Vec4& operator-=(Gen::Vec4& lhs, const Gen::Vec4& rhs);
|
||||
Gen::Vec4 operator-(const Gen::Vec4& lhs, const Gen::Vec4& rhs);
|
||||
Gen::Vec4& operator-=(Gen::Vec4& lhs, float rhs);
|
||||
Gen::Vec4 operator-(const Gen::Vec4& lhs, float rhs);
|
||||
|
||||
Gen::Vec4& operator*=(Gen::Vec4& lhs, float rhs);
|
||||
Gen::Vec4 operator*(const Gen::Vec4& lhs, float rhs);
|
||||
|
||||
Gen::Vec4& operator/=(Gen::Vec4& lhs, float rhs);
|
||||
Gen::Vec4 operator/(const Gen::Vec4& lhs, float rhs);
|
||||
|
||||
Gen::Vec3& operator+=(Gen::Vec3& lhs, const Gen::Vec3& rhs);
|
||||
Gen::Vec3 operator+(const Gen::Vec3& lhs, const Gen::Vec3& rhs);
|
||||
Gen::Vec3& operator+=(Gen::Vec3& lhs, float rhs);
|
||||
Gen::Vec3 operator+(Gen::Vec3& lhs, float rhs);
|
||||
|
||||
Gen::Vec3& operator-=(Gen::Vec3& lhs, const Gen::Vec3& rhs);
|
||||
Gen::Vec3 operator-(const Gen::Vec3& lhs, const Gen::Vec3& rhs);
|
||||
Gen::Vec3& operator-=(Gen::Vec3& lhs, float rhs);
|
||||
Gen::Vec3 operator-(const Gen::Vec3& lhs, float rhs);
|
||||
|
||||
Gen::Vec3& operator*=(Gen::Vec3& lhs, float rhs);
|
||||
Gen::Vec3 operator*(const Gen::Vec3& lhs, float rhs);
|
||||
|
||||
Gen::Vec3& operator/=(Gen::Vec3& lhs, float rhs);
|
||||
Gen::Vec3 operator/(const Gen::Vec3& lhs, float rhs);
|
||||
|
||||
Gen::Vec2& operator+=(Gen::Vec2& lhs, const Gen::Vec2& rhs);
|
||||
Gen::Vec2 operator+(const Gen::Vec2& lhs, const Gen::Vec2& rhs);
|
||||
Gen::Vec2& operator+=(Gen::Vec2& lhs, float rhs);
|
||||
Gen::Vec2 operator+(Gen::Vec2& lhs, float rhs);
|
||||
|
||||
Gen::Vec2& operator-=(Gen::Vec2& lhs, const Gen::Vec2& rhs);
|
||||
Gen::Vec2 operator-(const Gen::Vec2& lhs, const Gen::Vec2& rhs);
|
||||
Gen::Vec2& operator-=(Gen::Vec2& lhs, float rhs);
|
||||
Gen::Vec2 operator-(const Gen::Vec2& lhs, float rhs);
|
||||
|
||||
Gen::Vec2& operator*=(Gen::Vec2& lhs, float rhs);
|
||||
Gen::Vec2 operator*(const Gen::Vec2& lhs, float rhs);
|
||||
|
||||
Gen::Vec2& operator/=(Gen::Vec2& lhs, float rhs);
|
||||
Gen::Vec2 operator/(const Gen::Vec2& lhs, float rhs);
|
||||
|
||||
float Magnitude(const Gen::Vec4& vec);
|
||||
float Magnitude(const Gen::Vec3& vec);
|
||||
float Magnitude(const Gen::Vec2& vec);
|
||||
|
||||
Gen::Vec4 Normalized(const Gen::Vec4& vec);
|
||||
Gen::Vec3 Normalized(const Gen::Vec3& vec);
|
||||
Gen::Vec2 Normalized(const Gen::Vec2& vec);
|
||||
|
||||
Gen::Mat4 Inverse(const Gen::Mat4& mat);
|
||||
Gen::Mat4 Transpose(const Gen::Mat4& mat);
|
||||
Gen::Vec4 Mul(const Gen::Mat4& mat, const Gen::Vec4& vec);
|
||||
|
||||
float DotProduct(Gen::Vec3 a, Gen::Vec3 b);
|
||||
Gen::Vec3 CrossProduct(Gen::Vec3 a, Gen::Vec3 b);
|
||||
Gen::Vec3 CrossProductFromPlane(Gen::Vec3 a, Gen::Vec3 b, Gen::Vec3 c);
|
||||
bool RayPlaneIntersect(Gen::Vec3 l1, Gen::Vec3 l2, Gen::Vec3 p1, Gen::Vec3 p2, Gen::Vec3 p3, Gen::Vec3& out);
|
||||
|
||||
struct SharedData;
|
||||
|
||||
namespace Game
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "../gen/Def.h"
|
||||
#include "Gen.h"
|
||||
#include "Global.h"
|
||||
#include "Instance.h"
|
||||
#include "Log.h"
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#include "Gen.h"
|
||||
#include "Global.h"
|
||||
#include "Instance.h"
|
||||
#include "Mesh.h"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "../Global.h"
|
||||
#include "../Gen.h"
|
||||
#include "../Log.h"
|
||||
#include "Dither.h"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user