mirror of https://github.com/AxioDL/zeus.git
Humungous refactor
This commit is contained in:
parent
cd28979d0a
commit
a76d43d5df
|
@ -2,15 +2,15 @@ cmake_minimum_required(VERSION 3.0)
|
||||||
project(zeus)
|
project(zeus)
|
||||||
|
|
||||||
if (NOT DEFINED ATHENA_INCLUDE_DIR)
|
if (NOT DEFINED ATHENA_INCLUDE_DIR)
|
||||||
set(ATHENA_INCLUDE_DIR ../Athena/include)
|
set(ATHENA_INCLUDE_DIR ../athena/include)
|
||||||
endif()
|
endif()
|
||||||
include_directories(include ${ATHENA_INCLUDE_DIR})
|
include_directories(include ${ATHENA_INCLUDE_DIR})
|
||||||
|
|
||||||
if(NOT WIN32)
|
if(NOT MSVC)
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.1 -msse4.2 -std=c++14")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.1 -msse4.2 -std=c++14")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_library(Math
|
add_library(zeus
|
||||||
src/CVector3f.cpp
|
src/CVector3f.cpp
|
||||||
src/Math.cpp
|
src/Math.cpp
|
||||||
src/CQuaternion.cpp
|
src/CQuaternion.cpp
|
||||||
|
@ -25,32 +25,32 @@ add_library(Math
|
||||||
src/CMatrix4f.cpp
|
src/CMatrix4f.cpp
|
||||||
src/CAABox.cpp
|
src/CAABox.cpp
|
||||||
|
|
||||||
include/Math.hpp
|
include/zeus/Math.hpp
|
||||||
include/CQuaternion.hpp
|
include/zeus/CQuaternion.hpp
|
||||||
include/CMatrix3f.hpp
|
include/zeus/CMatrix3f.hpp
|
||||||
include/CProjection.hpp
|
include/zeus/CProjection.hpp
|
||||||
include/CAxisAngle.hpp
|
include/zeus/CAxisAngle.hpp
|
||||||
include/CRelAngle.hpp
|
include/zeus/CRelAngle.hpp
|
||||||
include/CPlane.hpp
|
include/zeus/CPlane.hpp
|
||||||
include/CTransform.hpp
|
include/zeus/CTransform.hpp
|
||||||
include/CColor.hpp
|
include/zeus/CColor.hpp
|
||||||
include/Global.hpp
|
include/zeus/Global.hpp
|
||||||
include/MathLib.hpp
|
include/zeus/zeus.hpp
|
||||||
include/TVectorUnion.hpp
|
include/zeus/TVectorUnion.hpp
|
||||||
include/CVector2i.hpp
|
include/zeus/CVector2i.hpp
|
||||||
include/CVector2f.hpp
|
include/zeus/CVector2f.hpp
|
||||||
include/CVector3f.hpp
|
include/zeus/CVector3f.hpp
|
||||||
include/CVector3d.hpp
|
include/zeus/CVector3d.hpp
|
||||||
include/CVector4f.hpp
|
include/zeus/CVector4f.hpp
|
||||||
include/CRectangle.hpp
|
include/zeus/CRectangle.hpp
|
||||||
include/CMatrix4f.hpp
|
include/zeus/CMatrix4f.hpp
|
||||||
include/CFrustum.hpp
|
include/zeus/CFrustum.hpp
|
||||||
include/CAABox.hpp
|
include/zeus/CAABox.hpp
|
||||||
include/COBBox.hpp
|
include/zeus/COBBox.hpp
|
||||||
include/CLine.hpp
|
include/zeus/CLine.hpp
|
||||||
include/CSphere.hpp
|
include/zeus/CSphere.hpp
|
||||||
include/CUnitVector.hpp
|
include/zeus/CUnitVector.hpp
|
||||||
include/CMRay.hpp)
|
include/zeus/CMRay.hpp)
|
||||||
|
|
||||||
add_subdirectory(test)
|
add_subdirectory(test)
|
||||||
|
|
||||||
|
|
115
include/Math.hpp
115
include/Math.hpp
|
@ -1,115 +0,0 @@
|
||||||
#ifndef MATH_HPP
|
|
||||||
#define MATH_HPP
|
|
||||||
|
|
||||||
#undef min
|
|
||||||
#undef max
|
|
||||||
#ifndef NOMINMAX
|
|
||||||
#define NOMINMAX 1
|
|
||||||
#endif
|
|
||||||
#ifndef _USE_MATH_DEFINES
|
|
||||||
#define _USE_MATH_DEFINES 1
|
|
||||||
#endif
|
|
||||||
#include <math.h>
|
|
||||||
#include <algorithm>
|
|
||||||
|
|
||||||
namespace Zeus
|
|
||||||
{
|
|
||||||
struct CPUInfo
|
|
||||||
{
|
|
||||||
const char cpuBrand [48] = {0};
|
|
||||||
const char cpuVendor[32] = {0};
|
|
||||||
const bool isIntel = false;
|
|
||||||
const bool SSE1 = false;
|
|
||||||
const bool SSE2 = false;
|
|
||||||
const bool SSE3 = false;
|
|
||||||
const bool SSSE3 = false;
|
|
||||||
const bool SSE41 = false;
|
|
||||||
const bool SSE42 = false;
|
|
||||||
const bool SSE4a = false;
|
|
||||||
const bool AESNI = false;
|
|
||||||
};
|
|
||||||
/**
|
|
||||||
* Detects CPU capabilities and returns true if SSE4.1 or SSE4.2 is available
|
|
||||||
*/
|
|
||||||
void detectCPU();
|
|
||||||
const CPUInfo& cpuFeatures();
|
|
||||||
class CVector3f;
|
|
||||||
class CTransform;
|
|
||||||
namespace Math
|
|
||||||
{
|
|
||||||
template<typename T>
|
|
||||||
inline T min(T a, T b) { return a < b ? a : b; }
|
|
||||||
template<typename T>
|
|
||||||
inline T max(T a, T b) { return a > b ? a : b; }
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
inline T clamp(T a, T val, T b) {return max<T>(a, min<T>(b, val));}
|
|
||||||
inline float radToDeg(float rad) {return rad * 180.f / M_PI;}
|
|
||||||
inline float degToRad(float deg) {return deg * M_PI / 180;}
|
|
||||||
|
|
||||||
extern const CVector3f kRadToDegVec;
|
|
||||||
extern const CVector3f kDegToRadVec;
|
|
||||||
CVector3f radToDeg(const CVector3f& rad);
|
|
||||||
CVector3f degToRad(const CVector3f& deg);
|
|
||||||
|
|
||||||
extern const CVector3f kUpVec;
|
|
||||||
CTransform lookAt(const CVector3f& pos, const CVector3f& lookPos, const CVector3f& up=kUpVec);
|
|
||||||
CVector3f baryToWorld(const CVector3f& p0, const CVector3f& p1, const CVector3f& p2, const CVector3f& bary);
|
|
||||||
|
|
||||||
CVector3f getBezierPoint(const CVector3f& a, const CVector3f& b,
|
|
||||||
const CVector3f& c, const CVector3f& d, float t);
|
|
||||||
float getCatmullRomSplinePoint(float a, float b,
|
|
||||||
float c, float d, float t);
|
|
||||||
CVector3f getCatmullRomSplinePoint(const CVector3f& a, const CVector3f& b,
|
|
||||||
const CVector3f& c, const CVector3f& d, float t);
|
|
||||||
CVector3f getRoundCatmullRomSplinePoint(const CVector3f& a, const CVector3f& b,
|
|
||||||
const CVector3f& c, const CVector3f& d, float t);
|
|
||||||
|
|
||||||
inline float slowCosineR(float val) { return float(cos(val)); }
|
|
||||||
inline float slowSineR(float val) { return float(sin(val)); }
|
|
||||||
inline float slowTangentR(float val) { return float(tan(val)); }
|
|
||||||
inline float arcSineR(float val) { return float(asin(val)); }
|
|
||||||
inline float arcTangentR(float val) { return float(atan(val)); }
|
|
||||||
inline float arcCosineR(float val) { return float(acos(val)); }
|
|
||||||
inline float powF(float a, float b) { return float(exp(b * log(a))); }
|
|
||||||
inline float floorF(float val) { return float(floor(val)); }
|
|
||||||
inline float ceilingF(float val)
|
|
||||||
{
|
|
||||||
float tmp = floorF(val);
|
|
||||||
return (tmp == val ? tmp : tmp + 1.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Since round(double) doesn't exist in some <cmath> implementations
|
|
||||||
// we'll define our own
|
|
||||||
inline double round(double val) { return (val < 0.0 ? ceilingF(val - 0.5) : floorF(val + 0.5)); }
|
|
||||||
inline double powD(float a, float b) { return exp(b * log(a)); }
|
|
||||||
|
|
||||||
double sqrtD(double val);
|
|
||||||
inline double invSqrtD(double val) { return 1.0 / sqrtD(val); }
|
|
||||||
inline float invSqrtF(float val) { return float(1.0 / sqrtD(val)); }
|
|
||||||
inline float sqrtF(float val) { return float(sqrtD(val)); }
|
|
||||||
float fastArcCosR(float val);
|
|
||||||
float fastCosR(float val);
|
|
||||||
float fastSinR(float val);
|
|
||||||
int floorPowerOfTwo(int x);
|
|
||||||
int ceilingPowerOfTwo(int x);
|
|
||||||
|
|
||||||
template <class T>
|
|
||||||
inline int PopCount(T x)
|
|
||||||
{
|
|
||||||
using U = std::make_unsigned_t<std::conditional_t<std::is_enum<T>::value, std::underlying_type_t<T>, T>>;
|
|
||||||
U cx = U(x);
|
|
||||||
const U m1 = U(0x5555555555555555); //binary: 0101...
|
|
||||||
const U m2 = U(0x3333333333333333); //binary: 00110011..
|
|
||||||
const U m4 = U(0x0f0f0f0f0f0f0f0f); //binary: 4 zeros, 4 ones ...
|
|
||||||
const U h01 = U(0x0101010101010101); //the sum of 256 to the power of 0,1,2,3...
|
|
||||||
|
|
||||||
cx -= (cx >> 1) & m1; //put count of each 2 bits into those 2 bits
|
|
||||||
cx = (cx & m2) + ((cx >> 2) & m2); //put count of each 4 bits into those 4 bits
|
|
||||||
cx = (cx + (cx >> 4)) & m4; //put count of each 8 bits into those 8 bits
|
|
||||||
return (cx * h01) >> ((sizeof(U)-1)*8); //returns left 8 bits of x + (x<<8) + (x<<16) + (x<<24) + ...
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // MATH_HPP
|
|
|
@ -1,27 +0,0 @@
|
||||||
#ifndef __MATHLIB_HPP
|
|
||||||
#define __MATHLIB_HPP
|
|
||||||
|
|
||||||
#include "CAxisAngle.hpp"
|
|
||||||
#include "CRelAngle.hpp"
|
|
||||||
#include "CMatrix3f.hpp"
|
|
||||||
#include "CMatrix4f.hpp"
|
|
||||||
#include "CProjection.hpp"
|
|
||||||
#include "CTransform.hpp"
|
|
||||||
#include "CQuaternion.hpp"
|
|
||||||
#include "CVector2f.hpp"
|
|
||||||
#include "CVector3f.hpp"
|
|
||||||
#include "CVector3d.hpp"
|
|
||||||
#include "CVector4f.hpp"
|
|
||||||
#include "CUnitVector.hpp"
|
|
||||||
#include "CRectangle.hpp"
|
|
||||||
#include "CPlane.hpp"
|
|
||||||
#include "CLine.hpp"
|
|
||||||
#include "CAABox.hpp"
|
|
||||||
#include "COBBox.hpp"
|
|
||||||
#include "CSphere.hpp"
|
|
||||||
#include "CFrustum.hpp"
|
|
||||||
#include "CColor.hpp"
|
|
||||||
#include "Global.hpp"
|
|
||||||
#include "Math.hpp"
|
|
||||||
|
|
||||||
#endif // __MATHLIB_HPP
|
|
|
@ -1,18 +1,18 @@
|
||||||
#ifndef CAABOX_HPP
|
#ifndef CAABOX_HPP
|
||||||
#define CAABOX_HPP
|
#define CAABOX_HPP
|
||||||
|
|
||||||
#include "CVector3f.hpp"
|
#include "zeus/CVector3f.hpp"
|
||||||
#include "CUnitVector.hpp"
|
#include "CUnitVector.hpp"
|
||||||
#include "CTransform.hpp"
|
#include "zeus/CTransform.hpp"
|
||||||
#include "CPlane.hpp"
|
#include "zeus/CPlane.hpp"
|
||||||
#include "CLine.hpp"
|
#include "CLine.hpp"
|
||||||
#include "CSphere.hpp"
|
#include "CSphere.hpp"
|
||||||
#include "Math.hpp"
|
#include "zeus/Math.hpp"
|
||||||
#if ZE_ATHENA_TYPES
|
#if ZE_ATHENA_TYPES
|
||||||
#include <Athena/IStreamReader.hpp>
|
#include <athena/IStreamReader.hpp>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace Zeus
|
namespace zeus
|
||||||
{
|
{
|
||||||
class alignas(16) CAABox
|
class alignas(16) CAABox
|
||||||
{
|
{
|
||||||
|
@ -62,9 +62,9 @@ public:
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
#if ZE_ATHENA_TYPES
|
#if ZE_ATHENA_TYPES
|
||||||
CAABox(Athena::io::IStreamReader& in) {readBoundingBox(in);}
|
CAABox(athena::io::IStreamReader& in) {readBoundingBox(in);}
|
||||||
|
|
||||||
inline void readBoundingBox(Athena::io::IStreamReader& in)
|
inline void readBoundingBox(athena::io::IStreamReader& in)
|
||||||
{
|
{
|
||||||
m_min = CVector3f(in);
|
m_min = CVector3f(in);
|
||||||
m_max = CVector3f(in);
|
m_max = CVector3f(in);
|
||||||
|
@ -93,7 +93,7 @@ public:
|
||||||
|
|
||||||
float distanceFromPoint(const CVector3f &other) const
|
float distanceFromPoint(const CVector3f &other) const
|
||||||
{
|
{
|
||||||
return Math::sqrtF(distanceFromPointSquared(other));
|
return sqrtF(distanceFromPointSquared(other));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool intersects(const CAABox& other) const
|
inline bool intersects(const CAABox& other) const
|
||||||
|
@ -283,9 +283,9 @@ public:
|
||||||
inline CVector3f clampToBox(const CVector3f& vec)
|
inline CVector3f clampToBox(const CVector3f& vec)
|
||||||
{
|
{
|
||||||
CVector3f ret = vec;
|
CVector3f ret = vec;
|
||||||
Math::clamp(m_min.x, ret.x, m_max.x);
|
clamp(m_min.x, ret.x, m_max.x);
|
||||||
Math::clamp(m_min.y, ret.y, m_max.y);
|
clamp(m_min.y, ret.y, m_max.y);
|
||||||
Math::clamp(m_min.z, ret.z, m_max.z);
|
clamp(m_min.z, ret.z, m_max.z);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,10 +2,10 @@
|
||||||
#define CAXISANGLE_H
|
#define CAXISANGLE_H
|
||||||
|
|
||||||
#include "Global.hpp"
|
#include "Global.hpp"
|
||||||
#include "CVector3f.hpp"
|
#include "zeus/CVector3f.hpp"
|
||||||
#include "CUnitVector.hpp"
|
#include "CUnitVector.hpp"
|
||||||
|
|
||||||
namespace Zeus
|
namespace zeus
|
||||||
{
|
{
|
||||||
struct alignas(16) CAxisAngle : CVector3f
|
struct alignas(16) CAxisAngle : CVector3f
|
||||||
{
|
{
|
|
@ -2,10 +2,10 @@
|
||||||
#define CCOLOR_HPP
|
#define CCOLOR_HPP
|
||||||
|
|
||||||
#include "Global.hpp"
|
#include "Global.hpp"
|
||||||
#include "Math.hpp"
|
#include "zeus/Math.hpp"
|
||||||
#include "TVectorUnion.hpp"
|
#include "TVectorUnion.hpp"
|
||||||
#if ZE_ATHENA_TYPES
|
#if ZE_ATHENA_TYPES
|
||||||
#include <Athena/FileReader.hpp>
|
#include <athena/FileReader.hpp>
|
||||||
#endif
|
#endif
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@
|
||||||
#define COLOR(rgba) rgba
|
#define COLOR(rgba) rgba
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace Zeus
|
namespace zeus
|
||||||
{
|
{
|
||||||
typedef uint8_t Comp8;
|
typedef uint8_t Comp8;
|
||||||
typedef uint32_t Comp32;
|
typedef uint32_t Comp32;
|
||||||
|
@ -57,7 +57,7 @@ public:
|
||||||
CColor(float rgb, float a = 1.0) { splat(rgb, a); }
|
CColor(float rgb, float a = 1.0) { splat(rgb, a); }
|
||||||
CColor(float r, float g, float b, float a = 1.0f) {v[0] = r; v[1] = g; v[2] = b; v[3] = a; }
|
CColor(float r, float g, float b, float a = 1.0f) {v[0] = r; v[1] = g; v[2] = b; v[3] = a; }
|
||||||
#if ZE_ATHENA_TYPES
|
#if ZE_ATHENA_TYPES
|
||||||
CColor(Athena::io::IStreamReader& reader) {readRGBA(reader);}
|
CColor(athena::io::IStreamReader& reader) {readRGBA(reader);}
|
||||||
CColor(const atVec4f& vec)
|
CColor(const atVec4f& vec)
|
||||||
#if __SSE__ || __GEKKO_PS__
|
#if __SSE__ || __GEKKO_PS__
|
||||||
: mVec128(vec.mVec128){}
|
: mVec128(vec.mVec128){}
|
||||||
|
@ -75,14 +75,14 @@ public:
|
||||||
CColor& operator=(const CVector4f& other);
|
CColor& operator=(const CVector4f& other);
|
||||||
|
|
||||||
#if ZE_ATHENA_TYPES
|
#if ZE_ATHENA_TYPES
|
||||||
inline void readRGBA(Athena::io::IStreamReader& reader)
|
inline void readRGBA(athena::io::IStreamReader& reader)
|
||||||
{
|
{
|
||||||
r = reader.readFloat();
|
r = reader.readFloat();
|
||||||
g = reader.readFloat();
|
g = reader.readFloat();
|
||||||
b = reader.readFloat();
|
b = reader.readFloat();
|
||||||
a = reader.readFloat();
|
a = reader.readFloat();
|
||||||
}
|
}
|
||||||
inline void readBGRA(Athena::io::IStreamReader& reader)
|
inline void readBGRA(athena::io::IStreamReader& reader)
|
||||||
{
|
{
|
||||||
b = reader.readFloat();
|
b = reader.readFloat();
|
||||||
g = reader.readFloat();
|
g = reader.readFloat();
|
||||||
|
@ -232,7 +232,7 @@ public:
|
||||||
}
|
}
|
||||||
inline float magnitude() const
|
inline float magnitude() const
|
||||||
{
|
{
|
||||||
return sqrtf(magSquared());
|
return std::sqrt(magSquared());
|
||||||
}
|
}
|
||||||
static inline CColor lerp(const CColor& a, const CColor& b, float t)
|
static inline CColor lerp(const CColor& a, const CColor& b, float t)
|
||||||
{
|
{
|
||||||
|
@ -320,7 +320,7 @@ public:
|
||||||
void toHSL(float& h, float& s, float& l);
|
void toHSL(float& h, float& s, float& l);
|
||||||
|
|
||||||
CColor toGrayscale()
|
CColor toGrayscale()
|
||||||
{ return {Math::sqrtF((r * r + g * g + b * b) / 3), a}; }
|
{ return {sqrtF((r * r + g * g + b * b) / 3), a}; }
|
||||||
};
|
};
|
||||||
|
|
||||||
static inline CColor operator+(float lhs, const CColor& rhs)
|
static inline CColor operator+(float lhs, const CColor& rhs)
|
|
@ -1,10 +1,10 @@
|
||||||
#ifndef CFRUSTUM_HPP
|
#ifndef CFRUSTUM_HPP
|
||||||
#define CFRUSTUM_HPP
|
#define CFRUSTUM_HPP
|
||||||
|
|
||||||
#include "CPlane.hpp"
|
#include "zeus/CPlane.hpp"
|
||||||
#include "CAABox.hpp"
|
#include "zeus/CAABox.hpp"
|
||||||
|
|
||||||
namespace Zeus
|
namespace zeus
|
||||||
{
|
{
|
||||||
class CFrustum
|
class CFrustum
|
||||||
{
|
{
|
|
@ -2,10 +2,10 @@
|
||||||
#define CLINE_HPP
|
#define CLINE_HPP
|
||||||
|
|
||||||
#include "Global.hpp"
|
#include "Global.hpp"
|
||||||
#include "CVector3f.hpp"
|
#include "zeus/CVector3f.hpp"
|
||||||
#include "CUnitVector.hpp"
|
#include "CUnitVector.hpp"
|
||||||
|
|
||||||
namespace Zeus
|
namespace zeus
|
||||||
{
|
{
|
||||||
class alignas(16) CLine
|
class alignas(16) CLine
|
||||||
{
|
{
|
|
@ -1,10 +1,10 @@
|
||||||
#ifndef CMRAY_HPP
|
#ifndef CMRAY_HPP
|
||||||
#define CMRAY_HPP
|
#define CMRAY_HPP
|
||||||
#include "CVector3f.hpp"
|
#include "zeus/CVector3f.hpp"
|
||||||
#include "CTransform.hpp"
|
#include "zeus/CTransform.hpp"
|
||||||
#include "Math.hpp"
|
#include "zeus/Math.hpp"
|
||||||
|
|
||||||
namespace Zeus
|
namespace zeus
|
||||||
{
|
{
|
||||||
struct alignas(16) CMRay
|
struct alignas(16) CMRay
|
||||||
{
|
{
|
|
@ -2,12 +2,12 @@
|
||||||
#define CMATRIX3F_HPP
|
#define CMATRIX3F_HPP
|
||||||
|
|
||||||
#include "Global.hpp"
|
#include "Global.hpp"
|
||||||
#include "CVector3f.hpp"
|
#include "zeus/CVector3f.hpp"
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* Column-major matrix class */
|
/* Column-major matrix class */
|
||||||
namespace Zeus
|
namespace zeus
|
||||||
{
|
{
|
||||||
class CQuaternion;
|
class CQuaternion;
|
||||||
class alignas(16) CMatrix3f
|
class alignas(16) CMatrix3f
|
|
@ -1,10 +1,10 @@
|
||||||
#ifndef CMATRIX4F
|
#ifndef CMATRIX4F
|
||||||
#define CMATRIX4F
|
#define CMATRIX4F
|
||||||
#include "CMatrix3f.hpp"
|
#include "zeus/CMatrix3f.hpp"
|
||||||
#include "CVector4f.hpp"
|
#include "zeus/CVector4f.hpp"
|
||||||
#include "CVector3f.hpp"
|
#include "zeus/CVector3f.hpp"
|
||||||
|
|
||||||
namespace Zeus
|
namespace zeus
|
||||||
{
|
{
|
||||||
class alignas(16) CMatrix4f
|
class alignas(16) CMatrix4f
|
||||||
{
|
{
|
|
@ -1,11 +1,11 @@
|
||||||
#ifndef COBBOX_HPP
|
#ifndef COBBOX_HPP
|
||||||
#define COBBOX_HPP
|
#define COBBOX_HPP
|
||||||
|
|
||||||
#include "CTransform.hpp"
|
#include "zeus/CTransform.hpp"
|
||||||
#include "CVector3f.hpp"
|
#include "zeus/CVector3f.hpp"
|
||||||
#include "CAABox.hpp"
|
#include "zeus/CAABox.hpp"
|
||||||
|
|
||||||
namespace Zeus
|
namespace zeus
|
||||||
{
|
{
|
||||||
class alignas(16) COBBox
|
class alignas(16) COBBox
|
||||||
{
|
{
|
|
@ -2,10 +2,10 @@
|
||||||
#define CPLANE_HPP
|
#define CPLANE_HPP
|
||||||
|
|
||||||
#include "Global.hpp"
|
#include "Global.hpp"
|
||||||
#include "CVector3f.hpp"
|
#include "zeus/CVector3f.hpp"
|
||||||
#include "Math.hpp"
|
#include "zeus/Math.hpp"
|
||||||
|
|
||||||
namespace Zeus
|
namespace zeus
|
||||||
{
|
{
|
||||||
class alignas(16) CPlane
|
class alignas(16) CPlane
|
||||||
{
|
{
|
||||||
|
@ -36,7 +36,7 @@ public:
|
||||||
{
|
{
|
||||||
float mag = ((b.z - a.z) * (((b.x - a.x) * ((b.y - a.y) * vec.y)) + vec.x)) + vec.z;
|
float mag = ((b.z - a.z) * (((b.x - a.x) * ((b.y - a.y) * vec.y)) + vec.x)) + vec.z;
|
||||||
float dis = (-(vec.y - d)) / mag;
|
float dis = (-(vec.y - d)) / mag;
|
||||||
return Math::clamp(0.0f, dis, 1.0f);
|
return clamp(0.0f, dis, 1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void normalize()
|
inline void normalize()
|
|
@ -2,12 +2,12 @@
|
||||||
#define CPROJECTION_HPP
|
#define CPROJECTION_HPP
|
||||||
|
|
||||||
#include "Global.hpp"
|
#include "Global.hpp"
|
||||||
#include "CMatrix4f.hpp"
|
#include "zeus/CMatrix4f.hpp"
|
||||||
#include <stdio.h>
|
#include <cstdlib>
|
||||||
|
#include <cstdio>
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
#define _USE_MATH_DEFINES 1
|
namespace zeus
|
||||||
#include <math.h>
|
|
||||||
namespace Zeus
|
|
||||||
{
|
{
|
||||||
enum class EProjType
|
enum class EProjType
|
||||||
{
|
{
|
||||||
|
@ -25,7 +25,7 @@ struct SProjOrtho
|
||||||
struct SProjPersp
|
struct SProjPersp
|
||||||
{
|
{
|
||||||
float m_fov, m_aspect, m_near, m_far;
|
float m_fov, m_aspect, m_near, m_far;
|
||||||
SProjPersp(float p_fov=55.0f * M_PI / 180.0f, float p_aspect=1.0f, float p_near=0.1f, float p_far=4096.f) :
|
SProjPersp(float p_fov=degToRad(55.0f), float p_aspect=1.0f, float p_near=0.1f, float p_far=4096.f) :
|
||||||
m_fov(p_fov), m_aspect(p_aspect), m_near(p_near), m_far(p_far) {}
|
m_fov(p_fov), m_aspect(p_aspect), m_near(p_near), m_far(p_far) {}
|
||||||
};
|
};
|
||||||
extern const SProjOrtho kOrthoIdentity;
|
extern const SProjOrtho kOrthoIdentity;
|
||||||
|
@ -67,8 +67,8 @@ public:
|
||||||
{
|
{
|
||||||
if (m_projType != EProjType::Orthographic)
|
if (m_projType != EProjType::Orthographic)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "attempted to access orthographic structure of non-ortho projection");
|
std::fprintf(stderr, "attempted to access orthographic structure of non-ortho projection");
|
||||||
abort();
|
std::abort();
|
||||||
}
|
}
|
||||||
return m_ortho;
|
return m_ortho;
|
||||||
}
|
}
|
||||||
|
@ -76,8 +76,8 @@ public:
|
||||||
{
|
{
|
||||||
if (m_projType != EProjType::Perspective)
|
if (m_projType != EProjType::Perspective)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "attempted to access perspective structure of non-persp projection");
|
std::fprintf(stderr, "attempted to access perspective structure of non-persp projection");
|
||||||
abort();
|
std::abort();
|
||||||
}
|
}
|
||||||
return m_persp;
|
return m_persp;
|
||||||
}
|
}
|
|
@ -3,14 +3,14 @@
|
||||||
|
|
||||||
#include "Global.hpp"
|
#include "Global.hpp"
|
||||||
#include "CAxisAngle.hpp"
|
#include "CAxisAngle.hpp"
|
||||||
#include "CVector3f.hpp"
|
#include "zeus/CVector3f.hpp"
|
||||||
#include "CVector4f.hpp"
|
#include "zeus/CVector4f.hpp"
|
||||||
#include <math.h>
|
#include "zeus/Math.hpp"
|
||||||
#if ZE_ATHENA_TYPES
|
#if ZE_ATHENA_TYPES
|
||||||
#include <Athena/IStreamReader.hpp>
|
#include <athena/IStreamReader.hpp>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace Zeus
|
namespace zeus
|
||||||
{
|
{
|
||||||
class alignas(16) CQuaternion
|
class alignas(16) CQuaternion
|
||||||
{
|
{
|
||||||
|
@ -25,7 +25,7 @@ public:
|
||||||
CQuaternion(float x, float y, float z) { fromVector3f(CVector3f(x, y, z)); }
|
CQuaternion(float x, float y, float z) { fromVector3f(CVector3f(x, y, z)); }
|
||||||
CQuaternion(float r, const CVector3f& vec) : v(vec){ this->r = r;}
|
CQuaternion(float r, const CVector3f& vec) : v(vec){ this->r = r;}
|
||||||
#if ZE_ATHENA_TYPES
|
#if ZE_ATHENA_TYPES
|
||||||
CQuaternion(Athena::io::IStreamReader& input) { r = input.readFloat(); v = CVector3f(input);}
|
CQuaternion(athena::io::IStreamReader& input) { r = input.readFloat(); v = CVector3f(input);}
|
||||||
CQuaternion(const atVec4f& vec)
|
CQuaternion(const atVec4f& vec)
|
||||||
{
|
{
|
||||||
#if __SSE__
|
#if __SSE__
|
||||||
|
@ -99,7 +99,7 @@ public:
|
||||||
*/
|
*/
|
||||||
static inline CQuaternion fromAxisAngle(const CVector3f& axis, float angle)
|
static inline CQuaternion fromAxisAngle(const CVector3f& axis, float angle)
|
||||||
{
|
{
|
||||||
return CQuaternion(cosf(angle/2), axis*sinf(angle/2));
|
return CQuaternion(std::cos(angle / 2.f), axis * std::sin(angle / 2.f));
|
||||||
}
|
}
|
||||||
|
|
||||||
void rotateX(float angle) { *this *= fromAxisAngle({1.0f, 0.0f, 0.0f}, angle); }
|
void rotateX(float angle) { *this *= fromAxisAngle({1.0f, 0.0f, 0.0f}, angle); }
|
||||||
|
@ -129,17 +129,17 @@ public:
|
||||||
|
|
||||||
inline float roll() const
|
inline float roll() const
|
||||||
{
|
{
|
||||||
return atan2f(2.0 * (v.x * v.y + r * v.z), r * r + v.x * v.x - v.y * v.y - v.z * v.z);
|
return std::atan2(2.f * (v.x * v.y + r * v.z), r * r + v.x * v.x - v.y * v.y - v.z * v.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline float pitch() const
|
inline float pitch() const
|
||||||
{
|
{
|
||||||
return atan2f(2.0 * (v.y * v.z + r * v.x), r * r - v.x * v.x - v.y * v.y + v.z * v.z);
|
return std::atan2(2.f * (v.y * v.z + r * v.x), r * r - v.x * v.x - v.y * v.y + v.z * v.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline float yaw() const
|
inline float yaw() const
|
||||||
{
|
{
|
||||||
return asinf(-2.0 * (v.x * v.z - r * v.y));
|
return std::asin(-2.f * (v.x * v.z - r * v.y));
|
||||||
}
|
}
|
||||||
|
|
||||||
union
|
union
|
|
@ -1,8 +1,8 @@
|
||||||
#ifndef CRECTANGLE_HPP
|
#ifndef CRECTANGLE_HPP
|
||||||
#define CRECTANGLE_HPP
|
#define CRECTANGLE_HPP
|
||||||
#include "CVector2f.hpp"
|
#include "zeus/CVector2f.hpp"
|
||||||
|
|
||||||
namespace Zeus
|
namespace zeus
|
||||||
{
|
{
|
||||||
class CRectangle
|
class CRectangle
|
||||||
{
|
{
|
|
@ -1,10 +1,10 @@
|
||||||
#ifndef CRELANGLE_HPP
|
#ifndef CRELANGLE_HPP
|
||||||
#define CRELANGLE_HPP
|
#define CRELANGLE_HPP
|
||||||
|
|
||||||
#include "CVector3f.hpp"
|
#include "zeus/CVector3f.hpp"
|
||||||
#include "Math.hpp"
|
#include "zeus/Math.hpp"
|
||||||
|
|
||||||
namespace Zeus
|
namespace zeus
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @brief The CRelAngle class represents relative angles in radians
|
* @brief The CRelAngle class represents relative angles in radians
|
||||||
|
@ -18,9 +18,9 @@ public:
|
||||||
*/
|
*/
|
||||||
CRelAngle(const CVector3f& angles)
|
CRelAngle(const CVector3f& angles)
|
||||||
{
|
{
|
||||||
x = Math::degToRad(angles.x);
|
x = degToRad(angles.x);
|
||||||
y = Math::degToRad(angles.y);
|
y = degToRad(angles.y);
|
||||||
z = Math::degToRad(angles.z);
|
z = degToRad(angles.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
CRelAngle(float x, float y, float z)
|
CRelAngle(float x, float y, float z)
|
|
@ -1,9 +1,9 @@
|
||||||
#ifndef CSPHERE_HPP
|
#ifndef CSPHERE_HPP
|
||||||
#define CSPHERE_HPP
|
#define CSPHERE_HPP
|
||||||
|
|
||||||
#include "CVector3f.hpp"
|
#include "zeus/CVector3f.hpp"
|
||||||
|
|
||||||
namespace Zeus
|
namespace zeus
|
||||||
{
|
{
|
||||||
class alignas(16) CSphere
|
class alignas(16) CSphere
|
||||||
{
|
{
|
|
@ -2,12 +2,12 @@
|
||||||
#define CTRANSFORM_HPP
|
#define CTRANSFORM_HPP
|
||||||
|
|
||||||
#include "Global.hpp"
|
#include "Global.hpp"
|
||||||
#include "CMatrix3f.hpp"
|
#include "zeus/CMatrix3f.hpp"
|
||||||
#include "CMatrix4f.hpp"
|
#include "zeus/CMatrix4f.hpp"
|
||||||
#include "CVector3f.hpp"
|
#include "zeus/CVector3f.hpp"
|
||||||
#include "CQuaternion.hpp"
|
#include "zeus/CQuaternion.hpp"
|
||||||
|
|
||||||
namespace Zeus
|
namespace zeus
|
||||||
{
|
{
|
||||||
class alignas(16) CTransform
|
class alignas(16) CTransform
|
||||||
{
|
{
|
||||||
|
@ -69,8 +69,8 @@ public:
|
||||||
|
|
||||||
static inline CTransform RotateX(float theta)
|
static inline CTransform RotateX(float theta)
|
||||||
{
|
{
|
||||||
float sinT = sinf(theta);
|
float sinT = std::sin(theta);
|
||||||
float cosT = cosf(theta);
|
float cosT = std::cos(theta);
|
||||||
return CTransform(CMatrix3f(TVectorUnion{1.f, 0.f, 0.f, 0.f},
|
return CTransform(CMatrix3f(TVectorUnion{1.f, 0.f, 0.f, 0.f},
|
||||||
TVectorUnion{0.f, cosT, sinT, 0.f},
|
TVectorUnion{0.f, cosT, sinT, 0.f},
|
||||||
TVectorUnion{0.f, -sinT, cosT, 0.f}));
|
TVectorUnion{0.f, -sinT, cosT, 0.f}));
|
||||||
|
@ -78,8 +78,8 @@ public:
|
||||||
|
|
||||||
static inline CTransform RotateY(float theta)
|
static inline CTransform RotateY(float theta)
|
||||||
{
|
{
|
||||||
float sinT = sinf(theta);
|
float sinT = std::sin(theta);
|
||||||
float cosT = cosf(theta);
|
float cosT = std::cos(theta);
|
||||||
return CTransform(CMatrix3f(TVectorUnion{cosT, 0.f, -sinT, 0.f},
|
return CTransform(CMatrix3f(TVectorUnion{cosT, 0.f, -sinT, 0.f},
|
||||||
TVectorUnion{0.f, 1.f, 0.f, 0.f},
|
TVectorUnion{0.f, 1.f, 0.f, 0.f},
|
||||||
TVectorUnion{sinT, 0.f, cosT, 0.f}));
|
TVectorUnion{sinT, 0.f, cosT, 0.f}));
|
||||||
|
@ -87,8 +87,8 @@ public:
|
||||||
|
|
||||||
static inline CTransform RotateZ(float theta)
|
static inline CTransform RotateZ(float theta)
|
||||||
{
|
{
|
||||||
float sinT = sinf(theta);
|
float sinT = std::sin(theta);
|
||||||
float cosT = cosf(theta);
|
float cosT = std::cos(theta);
|
||||||
return CTransform(CMatrix3f(TVectorUnion{cosT, sinT, 0.f, 0.f},
|
return CTransform(CMatrix3f(TVectorUnion{cosT, sinT, 0.f, 0.f},
|
||||||
TVectorUnion{-sinT, cosT, 0.f, 0.f},
|
TVectorUnion{-sinT, cosT, 0.f, 0.f},
|
||||||
TVectorUnion{0.f, 0.f, 1.f, 0.f}));
|
TVectorUnion{0.f, 0.f, 1.f, 0.f}));
|
||||||
|
@ -96,12 +96,12 @@ public:
|
||||||
|
|
||||||
inline void rotateLocalX(float theta)
|
inline void rotateLocalX(float theta)
|
||||||
{
|
{
|
||||||
float sinT = sinf(theta);
|
float sinT = std::sin(theta);
|
||||||
float cosT = cosf(theta);
|
float cosT = std::cos(theta);
|
||||||
|
|
||||||
Zeus::CVector3f b2 = m_basis[2] * sinT;
|
zeus::CVector3f b2 = m_basis[2] * sinT;
|
||||||
Zeus::CVector3f b1 = m_basis[1] * sinT;
|
zeus::CVector3f b1 = m_basis[1] * sinT;
|
||||||
Zeus::CVector3f cosV(cosT);
|
zeus::CVector3f cosV(cosT);
|
||||||
|
|
||||||
m_basis[1] *= cosV;
|
m_basis[1] *= cosV;
|
||||||
m_basis[2] *= cosV;
|
m_basis[2] *= cosV;
|
||||||
|
@ -112,12 +112,12 @@ public:
|
||||||
|
|
||||||
inline void rotateLocalY(float theta)
|
inline void rotateLocalY(float theta)
|
||||||
{
|
{
|
||||||
float sinT = sinf(theta);
|
float sinT = std::sin(theta);
|
||||||
float cosT = cosf(theta);
|
float cosT = std::cos(theta);
|
||||||
|
|
||||||
Zeus::CVector3f b0 = m_basis[0] * sinT;
|
zeus::CVector3f b0 = m_basis[0] * sinT;
|
||||||
Zeus::CVector3f b2 = m_basis[2] * sinT;
|
zeus::CVector3f b2 = m_basis[2] * sinT;
|
||||||
Zeus::CVector3f cosV(cosT);
|
zeus::CVector3f cosV(cosT);
|
||||||
|
|
||||||
m_basis[0] *= cosV;
|
m_basis[0] *= cosV;
|
||||||
m_basis[2] *= cosV;
|
m_basis[2] *= cosV;
|
||||||
|
@ -128,12 +128,12 @@ public:
|
||||||
|
|
||||||
inline void rotateLocalZ(float theta)
|
inline void rotateLocalZ(float theta)
|
||||||
{
|
{
|
||||||
float sinT = sinf(theta);
|
float sinT = std::sin(theta);
|
||||||
float cosT = cosf(theta);
|
float cosT = std::cos(theta);
|
||||||
|
|
||||||
Zeus::CVector3f b0 = m_basis[0] * sinT;
|
zeus::CVector3f b0 = m_basis[0] * sinT;
|
||||||
Zeus::CVector3f b1 = m_basis[1] * sinT;
|
zeus::CVector3f b1 = m_basis[1] * sinT;
|
||||||
Zeus::CVector3f cosV(cosT);
|
zeus::CVector3f cosV(cosT);
|
||||||
|
|
||||||
m_basis[0] *= cosV;
|
m_basis[0] *= cosV;
|
||||||
m_basis[1] *= cosV;
|
m_basis[1] *= cosV;
|
||||||
|
@ -225,6 +225,7 @@ static inline CTransform CTransformFromScaleVector(const CVector3f& scale)
|
||||||
CTransform CTransformFromEditorEuler(const CVector3f& eulerVec);
|
CTransform CTransformFromEditorEuler(const CVector3f& eulerVec);
|
||||||
CTransform CTransformFromEditorEulers(const CVector3f& eulerVec, const CVector3f& origin);
|
CTransform CTransformFromEditorEulers(const CVector3f& eulerVec, const CVector3f& origin);
|
||||||
CTransform CTransformFromAxisAngle(const CVector3f& axis, float angle);
|
CTransform CTransformFromAxisAngle(const CVector3f& axis, float angle);
|
||||||
|
CTransform lookAt(const CVector3f& pos, const CVector3f& lookPos, const CVector3f& up=kUpVec);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // CTRANSFORM_HPP
|
#endif // CTRANSFORM_HPP
|
|
@ -1,9 +1,9 @@
|
||||||
#ifndef CUNITVECTOR_HPP
|
#ifndef CUNITVECTOR_HPP
|
||||||
#define CUNITVECTOR_HPP
|
#define CUNITVECTOR_HPP
|
||||||
|
|
||||||
#include "CVector3f.hpp"
|
#include "zeus/CVector3f.hpp"
|
||||||
|
|
||||||
namespace Zeus
|
namespace zeus
|
||||||
{
|
{
|
||||||
class alignas(16) CUnitVector3f : public CVector3f
|
class alignas(16) CUnitVector3f : public CVector3f
|
||||||
{
|
{
|
|
@ -2,17 +2,17 @@
|
||||||
#define CVECTOR2f_HPP
|
#define CVECTOR2f_HPP
|
||||||
|
|
||||||
#include "Global.hpp"
|
#include "Global.hpp"
|
||||||
#include "Math.hpp"
|
#include "zeus/Math.hpp"
|
||||||
#include "TVectorUnion.hpp"
|
#include "TVectorUnion.hpp"
|
||||||
|
|
||||||
#if ZE_ATHENA_TYPES
|
#if ZE_ATHENA_TYPES
|
||||||
#include <Athena/IStreamReader.hpp>
|
#include <athena/IStreamReader.hpp>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <math.h>
|
#include "zeus/Math.hpp"
|
||||||
#include <assert.h>
|
#include <cassert>
|
||||||
|
|
||||||
namespace Zeus
|
namespace zeus
|
||||||
{
|
{
|
||||||
class alignas(16) CVector2f
|
class alignas(16) CVector2f
|
||||||
{
|
{
|
||||||
|
@ -68,7 +68,7 @@ public:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void read(Athena::io::IStreamReader& input)
|
void read(athena::io::IStreamReader& input)
|
||||||
{
|
{
|
||||||
x = input.readFloat();
|
x = input.readFloat();
|
||||||
y = input.readFloat();
|
y = input.readFloat();
|
||||||
|
@ -76,12 +76,12 @@ public:
|
||||||
v[3] = 0.0f;
|
v[3] = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
CVector2f(Athena::io::IStreamReader& input)
|
CVector2f(athena::io::IStreamReader& input)
|
||||||
{ read(input); }
|
{ read(input); }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
CVector2f(float xy) {splat(xy);}
|
CVector2f(float xy) {splat(xy);}
|
||||||
void assign(float x, float y) {v[0] = x; v[1] = y; v[2] = 0; v[3] = 0.0;}
|
void assign(float x, float y) {v[0] = x; v[1] = y; v[2] = 0; v[3] = 0.0f;}
|
||||||
CVector2f(float x, float y) {assign(x, y);}
|
CVector2f(float x, float y) {assign(x, y);}
|
||||||
|
|
||||||
inline bool operator ==(const CVector2f& rhs) const
|
inline bool operator ==(const CVector2f& rhs) const
|
||||||
|
@ -172,7 +172,7 @@ public:
|
||||||
inline CVector2f operator+(float val) const
|
inline CVector2f operator+(float val) const
|
||||||
{
|
{
|
||||||
#if __SSE__
|
#if __SSE__
|
||||||
TVectorUnion splat = {{val, val, 0.0, 0.0}};
|
TVectorUnion splat = {{val, val, 0.0f, 0.0f}};
|
||||||
return CVector2f(_mm_add_ps(mVec128, splat.mVec128));
|
return CVector2f(_mm_add_ps(mVec128, splat.mVec128));
|
||||||
#else
|
#else
|
||||||
return CVector2f(x + val, y + val);
|
return CVector2f(x + val, y + val);
|
||||||
|
@ -181,7 +181,7 @@ public:
|
||||||
inline CVector2f operator-(float val) const
|
inline CVector2f operator-(float val) const
|
||||||
{
|
{
|
||||||
#if __SSE__
|
#if __SSE__
|
||||||
TVectorUnion splat = {{val, val, 0.0, 0.0}};
|
TVectorUnion splat = {{val, val, 0.0f, 0.0f}};
|
||||||
return CVector2f(_mm_sub_ps(mVec128, splat.mVec128));
|
return CVector2f(_mm_sub_ps(mVec128, splat.mVec128));
|
||||||
#else
|
#else
|
||||||
return CVector2f(x - val, y - val);
|
return CVector2f(x - val, y - val);
|
||||||
|
@ -190,7 +190,7 @@ public:
|
||||||
inline CVector2f operator*(float val) const
|
inline CVector2f operator*(float val) const
|
||||||
{
|
{
|
||||||
#if __SSE__
|
#if __SSE__
|
||||||
TVectorUnion splat = {{val, val, 0.0, 0.0}};
|
TVectorUnion splat = {{val, val, 0.0f, 0.0f}};
|
||||||
return CVector2f(_mm_mul_ps(mVec128, splat.mVec128));
|
return CVector2f(_mm_mul_ps(mVec128, splat.mVec128));
|
||||||
#else
|
#else
|
||||||
return CVector2f(x * val, y * val);
|
return CVector2f(x * val, y * val);
|
||||||
|
@ -199,7 +199,7 @@ public:
|
||||||
inline CVector2f operator/(float val) const
|
inline CVector2f operator/(float val) const
|
||||||
{
|
{
|
||||||
#if __SSE__
|
#if __SSE__
|
||||||
TVectorUnion splat = {{val, val, val, 0.0}};
|
TVectorUnion splat = {{val, val, val, 0.0f}};
|
||||||
return CVector2f(_mm_div_ps(mVec128, splat.mVec128));
|
return CVector2f(_mm_div_ps(mVec128, splat.mVec128));
|
||||||
#else
|
#else
|
||||||
return CVector2f(x / val, y / val);
|
return CVector2f(x / val, y / val);
|
||||||
|
@ -251,7 +251,7 @@ public:
|
||||||
inline CVector2f normalized() const
|
inline CVector2f normalized() const
|
||||||
{
|
{
|
||||||
float mag = magnitude();
|
float mag = magnitude();
|
||||||
mag = 1.0 / mag;
|
mag = 1.0f / mag;
|
||||||
return *this * mag;
|
return *this * mag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -299,7 +299,7 @@ public:
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
inline float magnitude() const
|
inline float magnitude() const
|
||||||
{ return Math::sqrtF(magSquared()); }
|
{ return sqrtF(magSquared()); }
|
||||||
|
|
||||||
inline void zeroOut()
|
inline void zeroOut()
|
||||||
{
|
{
|
||||||
|
@ -335,7 +335,7 @@ public:
|
||||||
inline bool canBeNormalized() const
|
inline bool canBeNormalized() const
|
||||||
{
|
{
|
||||||
const float epsilon = 1.1920929e-7f;
|
const float epsilon = 1.1920929e-7f;
|
||||||
if (fabs(x) >= epsilon || fabs(y) >= epsilon)
|
if (std::fabs(x) >= epsilon || std::fabs(y) >= epsilon)
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -359,7 +359,7 @@ public:
|
||||||
static inline CVector2f operator+(float lhs, const CVector2f& rhs)
|
static inline CVector2f operator+(float lhs, const CVector2f& rhs)
|
||||||
{
|
{
|
||||||
#if __SSE__
|
#if __SSE__
|
||||||
TVectorUnion splat = {{lhs, lhs, 0.0, 0.0}};
|
TVectorUnion splat = {{lhs, lhs, 0.0f, 0.0f}};
|
||||||
return CVector2f(_mm_add_ps(splat.mVec128, rhs.mVec128));
|
return CVector2f(_mm_add_ps(splat.mVec128, rhs.mVec128));
|
||||||
#else
|
#else
|
||||||
return CVector2f(lhs + rhs.x, lhs + rhs.y);
|
return CVector2f(lhs + rhs.x, lhs + rhs.y);
|
||||||
|
@ -369,7 +369,7 @@ static inline CVector2f operator+(float lhs, const CVector2f& rhs)
|
||||||
static inline CVector2f operator-(float lhs, const CVector2f& rhs)
|
static inline CVector2f operator-(float lhs, const CVector2f& rhs)
|
||||||
{
|
{
|
||||||
#if __SSE__
|
#if __SSE__
|
||||||
TVectorUnion splat = {{lhs, lhs, 0.0, 0.0}};
|
TVectorUnion splat = {{lhs, lhs, 0.0f, 0.0f}};
|
||||||
return CVector2f(_mm_sub_ps(splat.mVec128, rhs.mVec128));
|
return CVector2f(_mm_sub_ps(splat.mVec128, rhs.mVec128));
|
||||||
#else
|
#else
|
||||||
return CVector2f(lhs - rhs.x, lhs - rhs.y);
|
return CVector2f(lhs - rhs.x, lhs - rhs.y);
|
||||||
|
@ -379,7 +379,7 @@ static inline CVector2f operator-(float lhs, const CVector2f& rhs)
|
||||||
static inline CVector2f operator*(float lhs, const CVector2f& rhs)
|
static inline CVector2f operator*(float lhs, const CVector2f& rhs)
|
||||||
{
|
{
|
||||||
#if __SSE__
|
#if __SSE__
|
||||||
TVectorUnion splat = {{lhs, lhs, 0.0, 0.0}};
|
TVectorUnion splat = {{lhs, lhs, 0.0f, 0.0f}};
|
||||||
return CVector2f(_mm_mul_ps(splat.mVec128, rhs.mVec128));
|
return CVector2f(_mm_mul_ps(splat.mVec128, rhs.mVec128));
|
||||||
#else
|
#else
|
||||||
return CVector2f(lhs * rhs.x, lhs * rhs.y);
|
return CVector2f(lhs * rhs.x, lhs * rhs.y);
|
||||||
|
@ -389,7 +389,7 @@ static inline CVector2f operator*(float lhs, const CVector2f& rhs)
|
||||||
static inline CVector2f operator/(float lhs, const CVector2f& rhs)
|
static inline CVector2f operator/(float lhs, const CVector2f& rhs)
|
||||||
{
|
{
|
||||||
#if __SSE__
|
#if __SSE__
|
||||||
TVectorUnion splat = {{lhs, lhs, 0.0, 0.0}};
|
TVectorUnion splat = {{lhs, lhs, 0.0f, 0.0f}};
|
||||||
return CVector2f(_mm_div_ps(splat.mVec128, rhs.mVec128));
|
return CVector2f(_mm_div_ps(splat.mVec128, rhs.mVec128));
|
||||||
#else
|
#else
|
||||||
return CVector2f(lhs / rhs.x, lhs / rhs.y);
|
return CVector2f(lhs / rhs.x, lhs / rhs.y);
|
|
@ -2,16 +2,13 @@
|
||||||
#define CVECTOR2i_HPP
|
#define CVECTOR2i_HPP
|
||||||
|
|
||||||
#include "Global.hpp"
|
#include "Global.hpp"
|
||||||
#include "Math.hpp"
|
#include "zeus/Math.hpp"
|
||||||
|
|
||||||
#if ZE_ATHENA_TYPES
|
#if ZE_ATHENA_TYPES
|
||||||
#include <Athena/IStreamReader.hpp>
|
#include <athena/IStreamReader.hpp>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <math.h>
|
namespace zeus
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
namespace Zeus
|
|
||||||
{
|
{
|
||||||
|
|
||||||
class CVector2i
|
class CVector2i
|
|
@ -2,11 +2,11 @@
|
||||||
#define CVECTOR3D_HPP
|
#define CVECTOR3D_HPP
|
||||||
|
|
||||||
#include "Global.hpp"
|
#include "Global.hpp"
|
||||||
#include "Math.hpp"
|
#include "zeus/Math.hpp"
|
||||||
#include "TVectorUnion.hpp"
|
#include "TVectorUnion.hpp"
|
||||||
#include "CVector3f.hpp"
|
#include "zeus/CVector3f.hpp"
|
||||||
|
|
||||||
namespace Zeus
|
namespace zeus
|
||||||
{
|
{
|
||||||
class alignas(16) CVector3d
|
class alignas(16) CVector3d
|
||||||
{
|
{
|
|
@ -2,17 +2,14 @@
|
||||||
#define CVECTOR3F_HPP
|
#define CVECTOR3F_HPP
|
||||||
|
|
||||||
#include "Global.hpp"
|
#include "Global.hpp"
|
||||||
#include "Math.hpp"
|
#include "zeus/Math.hpp"
|
||||||
#include "CVector2f.hpp"
|
#include "zeus/CVector2f.hpp"
|
||||||
#include "TVectorUnion.hpp"
|
#include "TVectorUnion.hpp"
|
||||||
#if ZE_ATHENA_TYPES
|
#if ZE_ATHENA_TYPES
|
||||||
#include <Athena/IStreamReader.hpp>
|
#include <athena/IStreamReader.hpp>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <math.h>
|
namespace zeus
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
namespace Zeus
|
|
||||||
{
|
{
|
||||||
class alignas(16) CVector3f
|
class alignas(16) CVector3f
|
||||||
{
|
{
|
||||||
|
@ -69,25 +66,25 @@ public:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void read(Athena::io::IStreamReader& input)
|
void read(athena::io::IStreamReader& input)
|
||||||
{
|
{
|
||||||
x = input.readFloat();
|
x = input.readFloat();
|
||||||
y = input.readFloat();
|
y = input.readFloat();
|
||||||
z = input.readFloat();
|
z = input.readFloat();
|
||||||
v[3] = 0.0f;
|
v[3] = 0.0f;
|
||||||
}
|
}
|
||||||
CVector3f(Athena::io::IStreamReader& input) {read(input);}
|
CVector3f(athena::io::IStreamReader& input) {read(input);}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
CVector3f(float xyz) {splat(xyz);}
|
CVector3f(float xyz) {splat(xyz);}
|
||||||
void assign(float x, float y, float z) {v[0] = x; v[1] = y; v[2] = z; v[3] = 0.0;}
|
void assign(float x, float y, float z) {v[0] = x; v[1] = y; v[2] = z; v[3] = 0.0f;}
|
||||||
CVector3f(float x, float y, float z) {assign(x, y, z);}
|
CVector3f(float x, float y, float z) {assign(x, y, z);}
|
||||||
|
|
||||||
CVector3f(const CVector2f& other)
|
CVector3f(const CVector2f& other)
|
||||||
{
|
{
|
||||||
x = other.x;
|
x = other.x;
|
||||||
y = other.y;
|
y = other.y;
|
||||||
z = 0.0;
|
z = 0.0f;
|
||||||
v[3] = 0.0f;
|
v[3] = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,7 +148,7 @@ public:
|
||||||
inline CVector3f operator+(float val) const
|
inline CVector3f operator+(float val) const
|
||||||
{
|
{
|
||||||
#if __SSE__
|
#if __SSE__
|
||||||
TVectorUnion splat = {{val, val, val, 0.0}};
|
TVectorUnion splat = {{val, val, val, 0.0f}};
|
||||||
return CVector3f(_mm_add_ps(mVec128, splat.mVec128));
|
return CVector3f(_mm_add_ps(mVec128, splat.mVec128));
|
||||||
#else
|
#else
|
||||||
return CVector3f(x + val, y + val, z + val);
|
return CVector3f(x + val, y + val, z + val);
|
||||||
|
@ -160,7 +157,7 @@ public:
|
||||||
inline CVector3f operator-(float val) const
|
inline CVector3f operator-(float val) const
|
||||||
{
|
{
|
||||||
#if __SSE__ || __GEKKO_PS__
|
#if __SSE__ || __GEKKO_PS__
|
||||||
TVectorUnion splat = {{val, val, val, 0.0}};
|
TVectorUnion splat = {{val, val, val, 0.0f}};
|
||||||
#endif
|
#endif
|
||||||
#if __SSE__
|
#if __SSE__
|
||||||
return CVector3f(_mm_sub_ps(mVec128, splat.mVec128));
|
return CVector3f(_mm_sub_ps(mVec128, splat.mVec128));
|
||||||
|
@ -173,7 +170,7 @@ public:
|
||||||
inline CVector3f operator*(float val) const
|
inline CVector3f operator*(float val) const
|
||||||
{
|
{
|
||||||
#if __SSE__ || __GEKKO_PS__
|
#if __SSE__ || __GEKKO_PS__
|
||||||
TVectorUnion splat = {{val, val, val, 0.0}};
|
TVectorUnion splat = {{val, val, val, 0.0f}};
|
||||||
#endif
|
#endif
|
||||||
#if __SSE__
|
#if __SSE__
|
||||||
return CVector3f(_mm_mul_ps(mVec128, splat.mVec128));
|
return CVector3f(_mm_mul_ps(mVec128, splat.mVec128));
|
||||||
|
@ -186,7 +183,7 @@ public:
|
||||||
inline CVector3f operator/(float val) const
|
inline CVector3f operator/(float val) const
|
||||||
{
|
{
|
||||||
#if __SSE__ || __GEKKO_PS__
|
#if __SSE__ || __GEKKO_PS__
|
||||||
TVectorUnion splat = {{val, val, val, 0.0}};
|
TVectorUnion splat = {{val, val, val, 0.0f}};
|
||||||
#endif
|
#endif
|
||||||
#if __SSE__
|
#if __SSE__
|
||||||
return CVector3f(_mm_div_ps(mVec128, splat.mVec128));
|
return CVector3f(_mm_div_ps(mVec128, splat.mVec128));
|
||||||
|
@ -285,7 +282,7 @@ public:
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
inline float magnitude() const
|
inline float magnitude() const
|
||||||
{ return Math::sqrtF(magSquared()); }
|
{ return sqrtF(magSquared()); }
|
||||||
|
|
||||||
inline void zeroOut()
|
inline void zeroOut()
|
||||||
{
|
{
|
||||||
|
@ -318,7 +315,7 @@ public:
|
||||||
inline bool canBeNormalized() const
|
inline bool canBeNormalized() const
|
||||||
{
|
{
|
||||||
const float epsilon = 1.1920929e-7f;
|
const float epsilon = 1.1920929e-7f;
|
||||||
if (fabs(x) >= epsilon || fabs(y) >= epsilon || fabs(z) >= epsilon)
|
if (std::fabs(x) >= epsilon || std::fabs(y) >= epsilon || std::fabs(z) >= epsilon)
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -338,7 +335,7 @@ public:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
length = sqrt(length);
|
length = std::sqrt(length);
|
||||||
float scalar = newLength / length;
|
float scalar = newLength / length;
|
||||||
*this *= scalar;
|
*this *= scalar;
|
||||||
}
|
}
|
||||||
|
@ -368,7 +365,7 @@ public:
|
||||||
static inline CVector3f operator+(float lhs, const CVector3f& rhs)
|
static inline CVector3f operator+(float lhs, const CVector3f& rhs)
|
||||||
{
|
{
|
||||||
#if __SSE__
|
#if __SSE__
|
||||||
TVectorUnion splat = {{lhs, lhs, lhs, 0.0}};
|
TVectorUnion splat = {{lhs, lhs, lhs, 0.0f}};
|
||||||
return CVector3f(_mm_add_ps(splat.mVec128, rhs.mVec128));
|
return CVector3f(_mm_add_ps(splat.mVec128, rhs.mVec128));
|
||||||
#else
|
#else
|
||||||
return CVector3f(lhs + rhs.x, lhs + rhs.y, lhs + rhs.z);
|
return CVector3f(lhs + rhs.x, lhs + rhs.y, lhs + rhs.z);
|
||||||
|
@ -378,7 +375,7 @@ static inline CVector3f operator+(float lhs, const CVector3f& rhs)
|
||||||
static inline CVector3f operator-(float lhs, const CVector3f& rhs)
|
static inline CVector3f operator-(float lhs, const CVector3f& rhs)
|
||||||
{
|
{
|
||||||
#if __SSE__
|
#if __SSE__
|
||||||
TVectorUnion splat = {{lhs, lhs, lhs, 0.0}};
|
TVectorUnion splat = {{lhs, lhs, lhs, 0.0f}};
|
||||||
return CVector3f(_mm_sub_ps(splat.mVec128, rhs.mVec128));
|
return CVector3f(_mm_sub_ps(splat.mVec128, rhs.mVec128));
|
||||||
#else
|
#else
|
||||||
return CVector3f(lhs - rhs.x, lhs - rhs.y, lhs - rhs.z);
|
return CVector3f(lhs - rhs.x, lhs - rhs.y, lhs - rhs.z);
|
||||||
|
@ -388,7 +385,7 @@ static inline CVector3f operator-(float lhs, const CVector3f& rhs)
|
||||||
static inline CVector3f operator*(float lhs, const CVector3f& rhs)
|
static inline CVector3f operator*(float lhs, const CVector3f& rhs)
|
||||||
{
|
{
|
||||||
#if __SSE__
|
#if __SSE__
|
||||||
TVectorUnion splat = {{lhs, lhs, lhs, 0.0}};
|
TVectorUnion splat = {{lhs, lhs, lhs, 0.0f}};
|
||||||
return CVector3f(_mm_mul_ps(splat.mVec128, rhs.mVec128));
|
return CVector3f(_mm_mul_ps(splat.mVec128, rhs.mVec128));
|
||||||
#else
|
#else
|
||||||
return CVector3f(lhs * rhs.x, lhs * rhs.y, lhs * rhs.z);
|
return CVector3f(lhs * rhs.x, lhs * rhs.y, lhs * rhs.z);
|
||||||
|
@ -398,12 +395,19 @@ static inline CVector3f operator*(float lhs, const CVector3f& rhs)
|
||||||
static inline CVector3f operator/(float lhs, const CVector3f& rhs)
|
static inline CVector3f operator/(float lhs, const CVector3f& rhs)
|
||||||
{
|
{
|
||||||
#if __SSE__
|
#if __SSE__
|
||||||
TVectorUnion splat = {{lhs, lhs, lhs, 0.0}};
|
TVectorUnion splat = {{lhs, lhs, lhs, 0.0f}};
|
||||||
return CVector3f(_mm_div_ps(splat.mVec128, rhs.mVec128));
|
return CVector3f(_mm_div_ps(splat.mVec128, rhs.mVec128));
|
||||||
#else
|
#else
|
||||||
return CVector3f(lhs / rhs.x, lhs / rhs.y, lhs / rhs.z);
|
return CVector3f(lhs / rhs.x, lhs / rhs.y, lhs / rhs.z);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern const CVector3f kUpVec;
|
||||||
|
extern const CVector3f kRadToDegVec;
|
||||||
|
extern const CVector3f kDegToRadVec;
|
||||||
|
inline CVector3f radToDeg(const CVector3f& rad) {return rad * kRadToDegVec;}
|
||||||
|
inline CVector3f degToRad(const CVector3f& deg) {return deg * kDegToRadVec;}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // CVECTOR3F_HPP
|
#endif // CVECTOR3F_HPP
|
|
@ -3,15 +3,15 @@
|
||||||
|
|
||||||
#include "Global.hpp"
|
#include "Global.hpp"
|
||||||
#include "TVectorUnion.hpp"
|
#include "TVectorUnion.hpp"
|
||||||
#include "CVector3f.hpp"
|
#include "zeus/CVector3f.hpp"
|
||||||
#if ZE_ATHENA_TYPES
|
#if ZE_ATHENA_TYPES
|
||||||
#include <Athena/IStreamReader.hpp>
|
#include <athena/IStreamReader.hpp>
|
||||||
#endif
|
#endif
|
||||||
#include <math.h>
|
#include "zeus/Math.hpp"
|
||||||
#include <float.h>
|
#include <cfloat>
|
||||||
#include <assert.h>
|
#include <cassert>
|
||||||
|
|
||||||
namespace Zeus
|
namespace zeus
|
||||||
{
|
{
|
||||||
class CColor;
|
class CColor;
|
||||||
class alignas(16) CVector4f
|
class alignas(16) CVector4f
|
||||||
|
@ -68,7 +68,7 @@ public:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void read(Athena::io::IStreamReader& input)
|
void read(athena::io::IStreamReader& input)
|
||||||
{
|
{
|
||||||
x = input.readFloat();
|
x = input.readFloat();
|
||||||
y = input.readFloat();
|
y = input.readFloat();
|
||||||
|
@ -76,7 +76,7 @@ public:
|
||||||
w = input.readFloat();
|
w = input.readFloat();
|
||||||
}
|
}
|
||||||
|
|
||||||
CVector4f(Athena::io::IStreamReader& input)
|
CVector4f(athena::io::IStreamReader& input)
|
||||||
{ read(input); }
|
{ read(input); }
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -330,7 +330,7 @@ public:
|
||||||
}
|
}
|
||||||
inline float magnitude() const
|
inline float magnitude() const
|
||||||
{
|
{
|
||||||
return sqrtf(magSquared());
|
return std::sqrt(magSquared());
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void zeroOut()
|
inline void zeroOut()
|
||||||
|
@ -364,7 +364,7 @@ public:
|
||||||
inline bool canBeNormalized() const
|
inline bool canBeNormalized() const
|
||||||
{
|
{
|
||||||
const float epsilon = 1.1920929e-7f;
|
const float epsilon = 1.1920929e-7f;
|
||||||
if (fabs(x) >= epsilon || fabs(y) >= epsilon || fabs(z) >= epsilon || fabs(w) >= epsilon)
|
if (std::fabs(x) >= epsilon || std::fabs(y) >= epsilon || std::fabs(z) >= epsilon || std::fabs(w) >= epsilon)
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
|
@ -0,0 +1,114 @@
|
||||||
|
#ifndef MATH_HPP
|
||||||
|
#define MATH_HPP
|
||||||
|
|
||||||
|
#undef min
|
||||||
|
#undef max
|
||||||
|
|
||||||
|
#undef M_PI
|
||||||
|
#define M_PI 3.14159265358979323846 /* pi */
|
||||||
|
#undef M_PI_2
|
||||||
|
#define M_PI_2 1.57079632679489661923 /* pi/2 */
|
||||||
|
#undef M_PI_4
|
||||||
|
#define M_PI_4 0.78539816339744830962 /* pi/4 */
|
||||||
|
#undef M_1_PI
|
||||||
|
#define M_1_PI 0.31830988618379067154 /* 1/pi */
|
||||||
|
#undef M_2_PI
|
||||||
|
#define M_2_PI 0.63661977236758134308 /* 2/pi */
|
||||||
|
#undef M_2_SQRTPI
|
||||||
|
#define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */
|
||||||
|
#undef M_SQRT2
|
||||||
|
#define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
|
||||||
|
#undef M_SQRT1_2
|
||||||
|
#define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
namespace zeus
|
||||||
|
{
|
||||||
|
struct CPUInfo
|
||||||
|
{
|
||||||
|
const char cpuBrand [48] = {0};
|
||||||
|
const char cpuVendor[32] = {0};
|
||||||
|
const bool isIntel = false;
|
||||||
|
const bool SSE1 = false;
|
||||||
|
const bool SSE2 = false;
|
||||||
|
const bool SSE3 = false;
|
||||||
|
const bool SSSE3 = false;
|
||||||
|
const bool SSE41 = false;
|
||||||
|
const bool SSE42 = false;
|
||||||
|
const bool SSE4a = false;
|
||||||
|
const bool AESNI = false;
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* Detects CPU capabilities and returns true if SSE4.1 or SSE4.2 is available
|
||||||
|
*/
|
||||||
|
void detectCPU();
|
||||||
|
const CPUInfo& cpuFeatures();
|
||||||
|
class CVector3f;
|
||||||
|
class CTransform;
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline T min(T a, T b) { return a < b ? a : b; }
|
||||||
|
template<typename T>
|
||||||
|
inline T max(T a, T b) { return a > b ? a : b; }
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline T clamp(T a, T val, T b) {return max<T>(a, min<T>(b, val));}
|
||||||
|
inline float radToDeg(float rad) {return rad * 180.f / M_PI;}
|
||||||
|
inline float degToRad(float deg) {return deg * M_PI / 180.f;}
|
||||||
|
inline double radToDeg(double rad) {return rad * 180.0 / M_PI;}
|
||||||
|
inline double degToRad(double deg) {return deg * M_PI / 180.0;}
|
||||||
|
|
||||||
|
CVector3f baryToWorld(const CVector3f& p0, const CVector3f& p1, const CVector3f& p2, const CVector3f& bary);
|
||||||
|
|
||||||
|
CVector3f getBezierPoint(const CVector3f& a, const CVector3f& b,
|
||||||
|
const CVector3f& c, const CVector3f& d, float t);
|
||||||
|
float getCatmullRomSplinePoint(float a, float b,
|
||||||
|
float c, float d, float t);
|
||||||
|
CVector3f getCatmullRomSplinePoint(const CVector3f& a, const CVector3f& b,
|
||||||
|
const CVector3f& c, const CVector3f& d, float t);
|
||||||
|
CVector3f getRoundCatmullRomSplinePoint(const CVector3f& a, const CVector3f& b,
|
||||||
|
const CVector3f& c, const CVector3f& d, float t);
|
||||||
|
|
||||||
|
inline float powF(float a, float b) { return std::pow(a, b); }
|
||||||
|
inline float floorF(float val) { return std::floor(val); }
|
||||||
|
inline float ceilingF(float val)
|
||||||
|
{
|
||||||
|
float tmp = std::floor(val);
|
||||||
|
return (tmp == val ? tmp : tmp + 1.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Since round(double) doesn't exist in some <cmath> implementations
|
||||||
|
// we'll define our own
|
||||||
|
inline double round(double val) { return (val < 0.0 ? ceilingF(val - 0.5) : floorF(val + 0.5)); }
|
||||||
|
inline double powD(float a, float b) { return std::exp(b * std::log(a)); }
|
||||||
|
|
||||||
|
double sqrtD(double val);
|
||||||
|
inline double invSqrtD(double val) { return 1.0 / sqrtD(val); }
|
||||||
|
inline float invSqrtF(float val) { return float(1.0 / sqrtD(val)); }
|
||||||
|
inline float sqrtF(float val) { return float(sqrtD(val)); }
|
||||||
|
float fastArcCosF(float val);
|
||||||
|
float fastCosF(float val);
|
||||||
|
float fastSinF(float val);
|
||||||
|
int floorPowerOfTwo(int x);
|
||||||
|
int ceilingPowerOfTwo(int x);
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
inline int PopCount(T x)
|
||||||
|
{
|
||||||
|
using U = std::make_unsigned_t<std::conditional_t<std::is_enum<T>::value, std::underlying_type_t<T>, T>>;
|
||||||
|
U cx = U(x);
|
||||||
|
const U m1 = U(0x5555555555555555); //binary: 0101...
|
||||||
|
const U m2 = U(0x3333333333333333); //binary: 00110011..
|
||||||
|
const U m4 = U(0x0f0f0f0f0f0f0f0f); //binary: 4 zeros, 4 ones ...
|
||||||
|
const U h01 = U(0x0101010101010101); //the sum of 256 to the power of 0,1,2,3...
|
||||||
|
|
||||||
|
cx -= (cx >> 1) & m1; //put count of each 2 bits into those 2 bits
|
||||||
|
cx = (cx & m2) + ((cx >> 2) & m2); //put count of each 4 bits into those 4 bits
|
||||||
|
cx = (cx + (cx >> 4)) & m4; //put count of each 8 bits into those 8 bits
|
||||||
|
return (cx * h01) >> ((sizeof(U)-1)*8); //returns left 8 bits of x + (x<<8) + (x<<16) + (x<<24) + ...
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // MATH_HPP
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef TVECTORUNION
|
#ifndef TVECTORUNION
|
||||||
#define TVECTORUNION
|
#define TVECTORUNION
|
||||||
|
|
||||||
namespace Zeus
|
namespace zeus
|
||||||
{
|
{
|
||||||
typedef union
|
typedef union
|
||||||
{
|
{
|
|
@ -0,0 +1,27 @@
|
||||||
|
#ifndef __MATHLIB_HPP
|
||||||
|
#define __MATHLIB_HPP
|
||||||
|
|
||||||
|
#include "CAxisAngle.hpp"
|
||||||
|
#include "CRelAngle.hpp"
|
||||||
|
#include "zeus/CMatrix3f.hpp"
|
||||||
|
#include "zeus/CMatrix4f.hpp"
|
||||||
|
#include "zeus/CProjection.hpp"
|
||||||
|
#include "zeus/CTransform.hpp"
|
||||||
|
#include "zeus/CQuaternion.hpp"
|
||||||
|
#include "zeus/CVector2f.hpp"
|
||||||
|
#include "zeus/CVector3f.hpp"
|
||||||
|
#include "CVector3d.hpp"
|
||||||
|
#include "zeus/CVector4f.hpp"
|
||||||
|
#include "CUnitVector.hpp"
|
||||||
|
#include "zeus/CRectangle.hpp"
|
||||||
|
#include "zeus/CPlane.hpp"
|
||||||
|
#include "CLine.hpp"
|
||||||
|
#include "zeus/CAABox.hpp"
|
||||||
|
#include "COBBox.hpp"
|
||||||
|
#include "CSphere.hpp"
|
||||||
|
#include "CFrustum.hpp"
|
||||||
|
#include "zeus/CColor.hpp"
|
||||||
|
#include "Global.hpp"
|
||||||
|
#include "zeus/Math.hpp"
|
||||||
|
|
||||||
|
#endif // __MATHLIB_HPP
|
|
@ -1,2 +1,2 @@
|
||||||
#include "CAABox.hpp"
|
#include "zeus/CAABox.hpp"
|
||||||
const Zeus::CAABox Zeus::CAABox::skInvertedBox = CAABox();
|
const zeus::CAABox zeus::CAABox::skInvertedBox = CAABox();
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#include "CColor.hpp"
|
#include "zeus/CColor.hpp"
|
||||||
#include "CVector4f.hpp"
|
#include "zeus/CVector4f.hpp"
|
||||||
|
|
||||||
namespace Zeus
|
namespace zeus
|
||||||
{
|
{
|
||||||
const CColor CColor::skRed (Comp32(0xFF0000FFul));
|
const CColor CColor::skRed (Comp32(0xFF0000FFul));
|
||||||
const CColor CColor::skBlack (Comp32(0x000000FFul));
|
const CColor CColor::skBlack (Comp32(0x000000FFul));
|
||||||
|
@ -68,8 +68,8 @@ void CColor::fromHSV(float h, float s, float v, float _a)
|
||||||
|
|
||||||
void CColor::toHSV(float &h, float &s, float &v) const
|
void CColor::toHSV(float &h, float &s, float &v) const
|
||||||
{
|
{
|
||||||
float min = Math::min(r, Math::min(g, b));
|
float min = std::min(r, std::min(g, b));
|
||||||
float max = Math::max(r, Math::max(g, b));
|
float max = std::max(r, std::max(g, b));
|
||||||
v = max;
|
v = max;
|
||||||
|
|
||||||
float delta = max - min;
|
float delta = max - min;
|
||||||
|
@ -106,8 +106,8 @@ void CColor::fromHSL(float h, float s, float l, float _a)
|
||||||
|
|
||||||
void CColor::toHSL(float &h, float &s, float &l)
|
void CColor::toHSL(float &h, float &s, float &l)
|
||||||
{
|
{
|
||||||
const float min = Math::min(r, Math::min(g, b));
|
const float min = std::min(r, std::min(g, b));
|
||||||
const float max = Math::max(r, Math::max(g, b));
|
const float max = std::max(r, std::max(g, b));
|
||||||
const float d = max - min;
|
const float d = max - min;
|
||||||
|
|
||||||
if (max == min)
|
if (max == min)
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
#include "CMatrix3f.hpp"
|
#include "zeus/CMatrix3f.hpp"
|
||||||
#include "CQuaternion.hpp"
|
#include "zeus/CQuaternion.hpp"
|
||||||
#include "Global.hpp"
|
#include "zeus/Global.hpp"
|
||||||
|
|
||||||
namespace Zeus
|
namespace zeus
|
||||||
{
|
{
|
||||||
const CMatrix3f CMatrix3f::skIdentityMatrix3f = CMatrix3f();
|
const CMatrix3f CMatrix3f::skIdentityMatrix3f = CMatrix3f();
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
#include "CMatrix4f.hpp"
|
#include "zeus/CMatrix4f.hpp"
|
||||||
|
|
||||||
const Zeus::CMatrix4f Zeus::CMatrix4f::skIdentityMatrix4f = CMatrix4f();
|
const zeus::CMatrix4f zeus::CMatrix4f::skIdentityMatrix4f = CMatrix4f();
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
#include "CPlane.hpp"
|
#include "zeus/CPlane.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
#include "CProjection.hpp"
|
#include "zeus/CProjection.hpp"
|
||||||
#include <math.h>
|
#include "zeus/Math.hpp"
|
||||||
#include <stdio.h>
|
#include <cassert>
|
||||||
|
|
||||||
namespace Zeus
|
namespace zeus
|
||||||
{
|
{
|
||||||
void CProjection::_updateCachedMatrix()
|
void CProjection::_updateCachedMatrix()
|
||||||
{
|
{
|
||||||
|
assert(m_projType == EProjType::Orthographic || m_projType == EProjType::Perspective);
|
||||||
if (m_projType == EProjType::Orthographic)
|
if (m_projType == EProjType::Orthographic)
|
||||||
{
|
{
|
||||||
float tmp;
|
float tmp;
|
||||||
|
@ -36,7 +37,7 @@ void CProjection::_updateCachedMatrix()
|
||||||
else if (m_projType == EProjType::Perspective)
|
else if (m_projType == EProjType::Perspective)
|
||||||
{
|
{
|
||||||
float cot,tmp;
|
float cot,tmp;
|
||||||
float t_fovy = tanf(m_persp.m_fov / 2.0);
|
float t_fovy = std::tan(m_persp.m_fov / 2.0f);
|
||||||
|
|
||||||
cot = 1.0f / t_fovy;
|
cot = 1.0f / t_fovy;
|
||||||
|
|
||||||
|
@ -61,11 +62,6 @@ void CProjection::_updateCachedMatrix()
|
||||||
m_mtx.m[2][3] = -1.0f;
|
m_mtx.m[2][3] = -1.0f;
|
||||||
m_mtx.m[3][3] = 0.0f;
|
m_mtx.m[3][3] = 0.0f;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
fprintf(stderr, "attempted to cache invalid projection type");
|
|
||||||
abort();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
#include "CQuaternion.hpp"
|
#include "zeus/CQuaternion.hpp"
|
||||||
#include <math.h>
|
#include "zeus/Math.hpp"
|
||||||
|
|
||||||
namespace Zeus
|
namespace zeus
|
||||||
{
|
{
|
||||||
void CQuaternion::fromVector3f(const CVector3f& vec)
|
void CQuaternion::fromVector3f(const CVector3f& vec)
|
||||||
{
|
{
|
||||||
float cosX = cosf(0.5 * vec.x);
|
float cosX = std::cos(0.5f * vec.x);
|
||||||
float cosY = cosf(0.5 * vec.y);
|
float cosY = std::cos(0.5f * vec.y);
|
||||||
float cosZ = cosf(0.5 * vec.z);
|
float cosZ = std::cos(0.5f * vec.z);
|
||||||
|
|
||||||
float sinX = sinf(0.5 * vec.x);
|
float sinX = std::sin(0.5f * vec.x);
|
||||||
float sinY = sinf(0.5 * vec.y);
|
float sinY = std::sin(0.5f * vec.y);
|
||||||
float sinZ = sinf(0.5 * vec.z);
|
float sinZ = std::sin(0.5f * vec.z);
|
||||||
|
|
||||||
r = cosZ * cosY * cosX + sinZ * sinY * sinX;
|
r = cosZ * cosY * cosX + sinZ * sinY * sinX;
|
||||||
v.x = cosZ * cosY * sinX - sinZ * sinY * cosX;
|
v.x = cosZ * cosY * sinX - sinZ * sinY * cosX;
|
||||||
|
@ -106,7 +106,7 @@ const CQuaternion& CQuaternion::operator/=(float scale)
|
||||||
|
|
||||||
float CQuaternion::magnitude() const
|
float CQuaternion::magnitude() const
|
||||||
{
|
{
|
||||||
return sqrt(magSquared());
|
return std::sqrt(magSquared());
|
||||||
}
|
}
|
||||||
|
|
||||||
float CQuaternion::magSquared() const
|
float CQuaternion::magSquared() const
|
||||||
|
@ -137,15 +137,15 @@ CQuaternion CQuaternion::inverse() const
|
||||||
CAxisAngle CQuaternion::toAxisAngle()
|
CAxisAngle CQuaternion::toAxisAngle()
|
||||||
{
|
{
|
||||||
// CAxisAngle ret;
|
// CAxisAngle ret;
|
||||||
// ret.angle = acosf(r);
|
// ret.angle = std::acos(r);
|
||||||
|
|
||||||
// float thetaInv = 1.0f/sinf(ret.angle);
|
// float thetaInv = 1.0f/std::sin(ret.angle);
|
||||||
|
|
||||||
// ret.axis.x = v.x * thetaInv;
|
// ret.axis.x = v.x * thetaInv;
|
||||||
// ret.axis.y = v.y * thetaInv;
|
// ret.axis.y = v.y * thetaInv;
|
||||||
// ret.axis.z = v.z * thetaInv;
|
// ret.axis.z = v.z * thetaInv;
|
||||||
|
|
||||||
// ret.angle *= 2;
|
// ret.angle *= 2.f;
|
||||||
|
|
||||||
// return ret;
|
// return ret;
|
||||||
return CAxisAngle();
|
return CAxisAngle();
|
||||||
|
@ -153,20 +153,20 @@ CAxisAngle CQuaternion::toAxisAngle()
|
||||||
|
|
||||||
CQuaternion CQuaternion::log() const
|
CQuaternion CQuaternion::log() const
|
||||||
{
|
{
|
||||||
float a = acosf(r);
|
float a = std::acos(r);
|
||||||
float sina = sinf(a);
|
float sina = std::sin(a);
|
||||||
CQuaternion ret;
|
CQuaternion ret;
|
||||||
|
|
||||||
ret.r = 0;
|
ret.r = 0.f;
|
||||||
|
|
||||||
if (sina > 0)
|
if (sina > 0.f)
|
||||||
{
|
{
|
||||||
ret.v.x = a * v.x / sina;
|
ret.v.x = a * v.x / sina;
|
||||||
ret.v.y = a * v.y / sina;
|
ret.v.y = a * v.y / sina;
|
||||||
ret.v.z = a * v.z / sina;
|
ret.v.z = a * v.z / sina;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
ret.v = CVector3f(0);
|
ret.v = CVector3f(0.f);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -174,19 +174,19 @@ CQuaternion CQuaternion::log() const
|
||||||
CQuaternion CQuaternion::exp() const
|
CQuaternion CQuaternion::exp() const
|
||||||
{
|
{
|
||||||
float a = (v.magnitude());
|
float a = (v.magnitude());
|
||||||
float sina = sinf(a);
|
float sina = std::sin(a);
|
||||||
float cosa = cos(a);
|
float cosa = std::cos(a);
|
||||||
CQuaternion ret;
|
CQuaternion ret;
|
||||||
|
|
||||||
ret.r = cosa;
|
ret.r = cosa;
|
||||||
if (a > 0)
|
if (a > 0.f)
|
||||||
{
|
{
|
||||||
ret.v.x = sina * v.x / a;
|
ret.v.x = sina * v.x / a;
|
||||||
ret.v.y = sina * v.y / a;
|
ret.v.y = sina * v.y / a;
|
||||||
ret.v.z = sina * v.z / a;
|
ret.v.z = sina * v.z / a;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
ret.v = CVector3f(0);
|
ret.v = CVector3f(0.f);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -215,18 +215,18 @@ CQuaternion CQuaternion::slerp(CQuaternion& a, CQuaternion& b, double t)
|
||||||
|
|
||||||
CQuaternion ret;
|
CQuaternion ret;
|
||||||
|
|
||||||
float mag = sqrtf(a.dot(a) * b.dot(b));
|
float mag = std::sqrt(a.dot(a) * b.dot(b));
|
||||||
|
|
||||||
float prod = a.dot(b) / mag;
|
float prod = a.dot(b) / mag;
|
||||||
|
|
||||||
if (fabsf(prod) < 1.0)
|
if (std::fabs(prod) < 1.0f)
|
||||||
{
|
{
|
||||||
const double sign = (prod < 0.0) ? -1.0 : 1.0;
|
const double sign = (prod < 0.0f) ? -1.0f : 1.0f;
|
||||||
|
|
||||||
const double theta = acos(sign * prod);
|
const double theta = std::acos(sign * prod);
|
||||||
const double s1 = sin (sign * t * theta);
|
const double s1 = std::sin(sign * t * theta);
|
||||||
const double d = 1.0 / sin(theta);
|
const double d = 1.0 / std::sin(theta);
|
||||||
const double s0 = sin((1.0 - t) * theta);
|
const double s0 = std::sin((1.0 - t) * theta);
|
||||||
|
|
||||||
ret.v.x = (float)(a.v.x * s0 + b.v.x * s1) * d;
|
ret.v.x = (float)(a.v.x * s0 + b.v.x * s1) * d;
|
||||||
ret.v.y = (float)(a.v.y * s0 + b.v.y * s1) * d;
|
ret.v.y = (float)(a.v.y * s0 + b.v.y * s1) * d;
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
#include "CRectangle.hpp"
|
#include "zeus/CRectangle.hpp"
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#include "CTransform.hpp"
|
#include "zeus/CTransform.hpp"
|
||||||
|
|
||||||
namespace Zeus
|
namespace zeus
|
||||||
{
|
{
|
||||||
CTransform CTransformFromEditorEuler(const CVector3f& eulerVec)
|
CTransform CTransformFromEditorEuler(const CVector3f& eulerVec)
|
||||||
{
|
{
|
||||||
|
@ -11,27 +11,27 @@ CTransform CTransformFromEditorEuler(const CVector3f& eulerVec)
|
||||||
tj = eulerVec[1];
|
tj = eulerVec[1];
|
||||||
th = eulerVec[2];
|
th = eulerVec[2];
|
||||||
|
|
||||||
ci = cos(ti);
|
ci = std::cos(ti);
|
||||||
cj = cos(tj);
|
cj = std::cos(tj);
|
||||||
ch = cos(th);
|
ch = std::cos(th);
|
||||||
si = sin(ti);
|
si = std::sin(ti);
|
||||||
sj = sin(tj);
|
sj = std::sin(tj);
|
||||||
sh = sin(th);
|
sh = std::sin(th);
|
||||||
|
|
||||||
cc = ci * ch;
|
cc = ci * ch;
|
||||||
cs = ci * sh;
|
cs = ci * sh;
|
||||||
sc = si * ch;
|
sc = si * ch;
|
||||||
ss = si * sh;
|
ss = si * sh;
|
||||||
|
|
||||||
result.m_basis.m[0][0] = (float)(cj * ch);
|
result.m_basis.m[0][0] = float(cj * ch);
|
||||||
result.m_basis.m[1][0] = (float)(sj * sc - cs);
|
result.m_basis.m[1][0] = float(sj * sc - cs);
|
||||||
result.m_basis.m[2][0] = (float)(sj * cc + ss);
|
result.m_basis.m[2][0] = float(sj * cc + ss);
|
||||||
result.m_basis.m[0][1] = (float)(cj * sh);
|
result.m_basis.m[0][1] = float(cj * sh);
|
||||||
result.m_basis.m[1][1] = (float)(sj * ss + cc);
|
result.m_basis.m[1][1] = float(sj * ss + cc);
|
||||||
result.m_basis.m[2][1] = (float)(sj * cs - sc);
|
result.m_basis.m[2][1] = float(sj * cs - sc);
|
||||||
result.m_basis.m[0][2] = (float)(-sj);
|
result.m_basis.m[0][2] = float(-sj);
|
||||||
result.m_basis.m[1][2] = (float)(cj * si);
|
result.m_basis.m[1][2] = float(cj * si);
|
||||||
result.m_basis.m[2][2] = (float)(cj * ci);
|
result.m_basis.m[2][2] = float(cj * ci);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -41,9 +41,9 @@ CTransform CTransformFromAxisAngle(const CVector3f& axis, float angle)
|
||||||
CTransform result;
|
CTransform result;
|
||||||
CVector3f axisN = axis.normalized();
|
CVector3f axisN = axis.normalized();
|
||||||
|
|
||||||
float c = cosf(angle);
|
float c = std::cos(angle);
|
||||||
float s = sinf(angle);
|
float s = std::sin(angle);
|
||||||
float t = 1 - c;
|
float t = 1.f - c;
|
||||||
|
|
||||||
result.m_basis.m[0][0] = t * axisN.v[0] * axisN.v[0] + c;
|
result.m_basis.m[0][0] = t * axisN.v[0] * axisN.v[0] + c;
|
||||||
result.m_basis.m[1][0] = t * axisN.v[0] * axisN.v[1] - axisN.v[2] * s;
|
result.m_basis.m[1][0] = t * axisN.v[0] * axisN.v[1] - axisN.v[2] * s;
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
#include "CVector2f.hpp"
|
#include "zeus/CVector2f.hpp"
|
||||||
#include <memory.h>
|
#include <memory.h>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include "Math.hpp"
|
#include "zeus/Math.hpp"
|
||||||
|
|
||||||
namespace Zeus
|
namespace zeus
|
||||||
{
|
{
|
||||||
const CVector2f CVector2f::skOne = CVector2f(1.0);
|
const CVector2f CVector2f::skOne = CVector2f(1.0);
|
||||||
const CVector2f CVector2f::skNegOne = CVector2f(-1.0);
|
const CVector2f CVector2f::skNegOne = CVector2f(-1.0);
|
||||||
|
@ -19,7 +19,7 @@ float CVector2f::getAngleDiff(const CVector2f& a, const CVector2f& b)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
float dot = a.dot(b);
|
float dot = a.dot(b);
|
||||||
float theta = Math::arcCosineR(dot / (mag1 * mag2));
|
float theta = std::acos(dot / (mag1 * mag2));
|
||||||
return theta;
|
return theta;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,18 +32,18 @@ CVector2f CVector2f::slerp(const CVector2f& a, const CVector2f& b, float t)
|
||||||
|
|
||||||
CVector2f ret;
|
CVector2f ret;
|
||||||
|
|
||||||
float mag = sqrtf(a.dot(a) * b.dot(b));
|
float mag = std::sqrt(a.dot(a) * b.dot(b));
|
||||||
|
|
||||||
float prod = a.dot(b) / mag;
|
float prod = a.dot(b) / mag;
|
||||||
|
|
||||||
if (fabsf(prod) < 1.0)
|
if (std::fabs(prod) < 1.0f)
|
||||||
{
|
{
|
||||||
const double sign = (prod < 0.0) ? -1.0 : 1.0;
|
const double sign = (prod < 0.0f) ? -1.0f : 1.0f;
|
||||||
|
|
||||||
const double theta = acos(sign * prod);
|
const double theta = std::acos(sign * prod);
|
||||||
const double s1 = sin (sign * t * theta);
|
const double s1 = std::sin(sign * t * theta);
|
||||||
const double d = 1.0 / sin(theta);
|
const double d = 1.0 / std::sin(theta);
|
||||||
const double s0 = sin((1.0 - t) * theta);
|
const double s0 = std::sin((1.0f - t) * theta);
|
||||||
|
|
||||||
ret = (a * s0 + b * s1) * d;
|
ret = (a * s0 + b * s1) * d;
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -1,25 +1,29 @@
|
||||||
#include "CVector3f.hpp"
|
#include "zeus/CVector3f.hpp"
|
||||||
#include <memory.h>
|
#include <memory.h>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include "Math.hpp"
|
#include "zeus/Math.hpp"
|
||||||
|
|
||||||
namespace Zeus
|
namespace zeus
|
||||||
{
|
{
|
||||||
const CVector3f CVector3f::skOne = CVector3f(1.0);
|
const CVector3f CVector3f::skOne = CVector3f(1.0);
|
||||||
const CVector3f CVector3f::skNegOne = CVector3f(-1.0);
|
const CVector3f CVector3f::skNegOne = CVector3f(-1.0);
|
||||||
const CVector3f CVector3f::skZero;
|
const CVector3f CVector3f::skZero;
|
||||||
|
|
||||||
|
const CVector3f kUpVec(0.0, 0.0, 1.0);
|
||||||
|
const CVector3f kRadToDegVec(180.0f / M_PI);
|
||||||
|
const CVector3f kDegToRadVec(M_PI / 180.0f);
|
||||||
|
|
||||||
float CVector3f::getAngleDiff(const CVector3f& a, const CVector3f& b)
|
float CVector3f::getAngleDiff(const CVector3f& a, const CVector3f& b)
|
||||||
{
|
{
|
||||||
float mag1 = a.magnitude();
|
float mag1 = a.magnitude();
|
||||||
float mag2 = b.magnitude();
|
float mag2 = b.magnitude();
|
||||||
|
|
||||||
if (!mag1 || !mag2)
|
if (!mag1 || !mag2)
|
||||||
return 0;
|
return 0.f;
|
||||||
|
|
||||||
float dot = a.dot(b);
|
float dot = a.dot(b);
|
||||||
float theta = Math::arcCosineR(dot / (mag1 * mag2));
|
float theta = std::acos(dot / (mag1 * mag2));
|
||||||
return theta;
|
return theta;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,13 +36,13 @@ CVector3f CVector3f::slerp(const CVector3f& a, const CVector3f& b, float t)
|
||||||
|
|
||||||
CVector3f ret;
|
CVector3f ret;
|
||||||
|
|
||||||
float mag = sqrtf(a.dot(a) * b.dot(b));
|
float mag = std::sqrt(a.dot(a) * b.dot(b));
|
||||||
|
|
||||||
float prod = a.dot(b) / mag;
|
float prod = a.dot(b) / mag;
|
||||||
|
|
||||||
if (fabsf(prod) < 1.0)
|
if (std::fabs(prod) < 1.0f)
|
||||||
{
|
{
|
||||||
const double sign = (prod < 0.0) ? -1.0 : 1.0;
|
const double sign = (prod < 0.0f) ? -1.0f : 1.0f;
|
||||||
|
|
||||||
const double theta = acos(sign * prod);
|
const double theta = acos(sign * prod);
|
||||||
const double s1 = sin (sign * t * theta);
|
const double s1 = sin (sign * t * theta);
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
#include "CVector4f.hpp"
|
#include "zeus/CVector4f.hpp"
|
||||||
#include "CColor.hpp"
|
#include "zeus/CColor.hpp"
|
||||||
|
|
||||||
namespace Zeus
|
namespace zeus
|
||||||
{
|
{
|
||||||
CVector4f::CVector4f(const Zeus::CColor& other)
|
CVector4f::CVector4f(const zeus::CColor& other)
|
||||||
: x(other.r), y(other.g), z(other.b), w(other.a)
|
: x(other.r), y(other.g), z(other.b), w(other.a)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
38
src/Math.cpp
38
src/Math.cpp
|
@ -1,13 +1,13 @@
|
||||||
#include "Math.hpp"
|
#include "zeus/Math.hpp"
|
||||||
#include "CTransform.hpp"
|
#include "zeus/CTransform.hpp"
|
||||||
#include "CVector3f.hpp"
|
#include "zeus/CVector3f.hpp"
|
||||||
#if _WIN32
|
#if _WIN32
|
||||||
#include <intrin.h>
|
#include <intrin.h>
|
||||||
#else
|
#else
|
||||||
#include <cpuid.h>
|
#include <cpuid.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace Zeus
|
namespace zeus
|
||||||
{
|
{
|
||||||
|
|
||||||
static CPUInfo g_cpuFeatures;
|
static CPUInfo g_cpuFeatures;
|
||||||
|
@ -69,12 +69,6 @@ void detectCPU()
|
||||||
|
|
||||||
const CPUInfo& cpuFeatures() { return g_cpuFeatures; }
|
const CPUInfo& cpuFeatures() { return g_cpuFeatures; }
|
||||||
|
|
||||||
namespace Math
|
|
||||||
{
|
|
||||||
const CVector3f kUpVec(0.0, 0.0, 1.0);
|
|
||||||
const CVector3f kRadToDegVec(180.0f / M_PI);
|
|
||||||
const CVector3f kDegToRadVec(M_PI / 180.0f);
|
|
||||||
|
|
||||||
CTransform lookAt(const CVector3f& pos, const CVector3f& lookPos, const CVector3f& up)
|
CTransform lookAt(const CVector3f& pos, const CVector3f& lookPos, const CVector3f& up)
|
||||||
{
|
{
|
||||||
CVector3f vLook,vRight,vUp;
|
CVector3f vLook,vRight,vUp;
|
||||||
|
@ -158,18 +152,18 @@ double sqrtD(double val)
|
||||||
return q;
|
return q;
|
||||||
}
|
}
|
||||||
|
|
||||||
float fastArcCosR(float val)
|
float fastArcCosF(float val)
|
||||||
{
|
{
|
||||||
/* If we're not at a low enough value,
|
/* If we're not at a low enough value,
|
||||||
* the approximation below won't provide any benefit,
|
* the approximation below won't provide any benefit,
|
||||||
* and we simply fall back to the standard implementation
|
* and we simply fall back to the standard implementation
|
||||||
*/
|
*/
|
||||||
if (fabs(val) >= 0.925000011920929)
|
if (std::fabs(val) >= 0.925000011920929)
|
||||||
return float(acos(val));
|
return std::acos(val);
|
||||||
|
|
||||||
/* Fast Arc Cosine approximation using Taylor Polynomials
|
/* Fast Arc Cosine approximation using Taylor Polynomials
|
||||||
* while this implementation is fast, it's also not as accurate.
|
* while this implementation is fast, it's also not as accurate.
|
||||||
* This is a straight reimplementation of Retro's CMath::FastArcCosR
|
* This is a straight reimplementation of Retro's CFastArcCosR
|
||||||
* and as a result of the polynomials, it returns the inverse value,
|
* and as a result of the polynomials, it returns the inverse value,
|
||||||
* I'm not certain if this was intended originally, but we'll leave it
|
* I'm not certain if this was intended originally, but we'll leave it
|
||||||
* in order to be as accurate as possible.
|
* in order to be as accurate as possible.
|
||||||
|
@ -217,9 +211,9 @@ int ceilingPowerOfTwo(int x)
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
float fastCosR(float val)
|
float fastCosF(float val)
|
||||||
{
|
{
|
||||||
if (fabs(val) > M_PI)
|
if (std::fabs(val) > M_PI)
|
||||||
{
|
{
|
||||||
float rVal = float(uint32_t(val));
|
float rVal = float(uint32_t(val));
|
||||||
val = -((rVal * val) - 6.2831855);
|
val = -((rVal * val) - 6.2831855);
|
||||||
|
@ -240,9 +234,9 @@ float fastCosR(float val)
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
float fastSinR(float val)
|
float fastSinF(float val)
|
||||||
{
|
{
|
||||||
if (fabs(val) > M_PI)
|
if (std::fabs(val) > M_PI)
|
||||||
{
|
{
|
||||||
float rVal = float(uint32_t(val));
|
float rVal = float(uint32_t(val));
|
||||||
val = -((rVal * val) - 6.2831855);
|
val = -((rVal * val) - 6.2831855);
|
||||||
|
@ -319,16 +313,10 @@ CVector3f getRoundCatmullRomSplinePoint(const CVector3f& a, const CVector3f& b,
|
||||||
if (cVelocity.canBeNormalized())
|
if (cVelocity.canBeNormalized())
|
||||||
cVelocity.normalize();
|
cVelocity.normalize();
|
||||||
const float cbDistance = cb.magnitude();
|
const float cbDistance = cb.magnitude();
|
||||||
return getCatmullRomSplinePoint(b, c, bVelocity * cbDistance, cVelocity * cbDistance, t);
|
return zeus::getCatmullRomSplinePoint(b, c, bVelocity * cbDistance, cVelocity * cbDistance, t);
|
||||||
}
|
}
|
||||||
|
|
||||||
CVector3f baryToWorld(const CVector3f& p0, const CVector3f& p1, const CVector3f& p2, const CVector3f& bary)
|
CVector3f baryToWorld(const CVector3f& p0, const CVector3f& p1, const CVector3f& p2, const CVector3f& bary)
|
||||||
{ return bary.x * p0 + bary.y * p1 + bary.z * p2; }
|
{ return bary.x * p0 + bary.y * p1 + bary.z * p2; }
|
||||||
|
|
||||||
CVector3f radToDeg(const CVector3f& rad) {return rad * kRadToDegVec;}
|
|
||||||
|
|
||||||
CVector3f degToRad(const CVector3f& deg) {return deg * kDegToRadVec;}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,8 +3,5 @@ project(zeustest)
|
||||||
|
|
||||||
include_directories(../include)
|
include_directories(../include)
|
||||||
|
|
||||||
add_executable(zeustest
|
add_executable(zeustest main.cpp)
|
||||||
main.cpp)
|
target_link_libraries(zeustest zeus)
|
||||||
|
|
||||||
target_link_libraries(zeustest
|
|
||||||
Math)
|
|
||||||
|
|
|
@ -1,19 +1,19 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <MathLib.hpp>
|
#include <zeus/zeus.hpp>
|
||||||
|
|
||||||
// This is only for testing, do NOT do this normally
|
// This is only for testing, do NOT do this normally
|
||||||
using namespace Zeus;
|
using namespace zeus;
|
||||||
|
|
||||||
union Color
|
union Color
|
||||||
{
|
{
|
||||||
struct { Zeus::Comp8 r, g, b, a; };
|
struct { zeus::Comp8 r, g, b, a; };
|
||||||
Zeus::Comp32 rgba;
|
zeus::Comp32 rgba;
|
||||||
};
|
};
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
Zeus::detectCPU();
|
zeus::detectCPU();
|
||||||
assert(!CAABox({100, 100, 100}, {100, 100, 100}).invalid());
|
assert(!CAABox({100, 100, 100}, {100, 100, 100}).invalid());
|
||||||
assert(CAABox().invalid());
|
assert(CAABox().invalid());
|
||||||
CVector3f vec{320, 632162.f, 800.f};
|
CVector3f vec{320, 632162.f, 800.f};
|
||||||
|
@ -23,7 +23,7 @@ int main()
|
||||||
assert(!vec.normalized().canBeNormalized());
|
assert(!vec.normalized().canBeNormalized());
|
||||||
float blarg = 5.f;
|
float blarg = 5.f;
|
||||||
CVector3f t{100, 100, 200};
|
CVector3f t{100, 100, 200};
|
||||||
blarg = Math::clamp(0.f, blarg, 1.f);
|
blarg = clamp(0.f, blarg, 1.f);
|
||||||
CAABox test{{-100, -100, -100}, {100, 100, 100}};
|
CAABox test{{-100, -100, -100}, {100, 100, 100}};
|
||||||
CAABox test2{{-100, -100, -100}, {100, 100, 100}};
|
CAABox test2{{-100, -100, -100}, {100, 100, 100}};
|
||||||
CAABox test3{{-50, -50, -50}, {50, 50, 50}};
|
CAABox test3{{-50, -50, -50}, {50, 50, 50}};
|
||||||
|
@ -43,15 +43,15 @@ int main()
|
||||||
CSphere s2({1, 0, 0}, 1);
|
CSphere s2({1, 0, 0}, 1);
|
||||||
CSphere s3({3, 0, 0}, 1);
|
CSphere s3({3, 0, 0}, 1);
|
||||||
|
|
||||||
std::cout << Math::min(1, 3) << std::endl;
|
std::cout << min(1, 3) << std::endl;
|
||||||
std::cout << Math::min(2, 1) << std::endl;
|
std::cout << min(2, 1) << std::endl;
|
||||||
std::cout << Math::max(1, 3) << std::endl;
|
std::cout << max(1, 3) << std::endl;
|
||||||
std::cout << Math::max(2, 1) << std::endl;
|
std::cout << max(2, 1) << std::endl;
|
||||||
std::cout << Math::clamp(-50, 100, 50) << std::endl;
|
std::cout << clamp(-50, 100, 50) << std::endl;
|
||||||
std::cout << Math::clamp(-50, -100, 50) << std::endl;
|
std::cout << clamp(-50, -100, 50) << std::endl;
|
||||||
std::cout << Math::powF(6.66663489, 2) << std::endl;
|
std::cout << powF(6.66663489, 2) << std::endl;
|
||||||
std::cout << Math::invSqrtF(1) << std::endl;
|
std::cout << invSqrtF(1) << std::endl;
|
||||||
std::cout << Math::floorPowerOfTwo(256) << std::endl;
|
std::cout << floorPowerOfTwo(256) << std::endl;
|
||||||
std::cout << " Test 1 " << ( aabb.intersects(s1) ? "succeeded" : "failed" ) << std::endl;
|
std::cout << " Test 1 " << ( aabb.intersects(s1) ? "succeeded" : "failed" ) << std::endl;
|
||||||
std::cout << " Test 2 " << ( aabb.intersects(s2) ? "succeeded" : "failed" ) << std::endl;
|
std::cout << " Test 2 " << ( aabb.intersects(s2) ? "succeeded" : "failed" ) << std::endl;
|
||||||
std::cout << " Test 3 " << ( aabb.intersects(s3) ? "succeeded" : "failed" ) << std::endl;
|
std::cout << " Test 3 " << ( aabb.intersects(s3) ? "succeeded" : "failed" ) << std::endl;
|
||||||
|
|
Loading…
Reference in New Issue