Created deg struct for better usage of degree
This commit is contained in:
parent
74a483da28
commit
d0aa1d43d2
|
@ -15,7 +15,7 @@ namespace GTETest {
|
||||||
Make::PageClut(Assets::Main::DoenerFishInfo.tim.get_clut_position()),
|
Make::PageClut(Assets::Main::DoenerFishInfo.tim.get_clut_position()),
|
||||||
GPU::Color24::Grey()
|
GPU::Color24::Grey()
|
||||||
));
|
));
|
||||||
static auto rotation = 0_DEG;
|
static auto rotation = 0.0_deg;
|
||||||
|
|
||||||
static void setup() {
|
static void setup() {
|
||||||
Shared::back_menu.reset();
|
Shared::back_menu.reset();
|
||||||
|
@ -35,7 +35,7 @@ namespace GTETest {
|
||||||
GTE::TRANSFERVECTOR::translated((Assets::Main::DoenerFishInfo.size.width/2), (Assets::Main::DoenerFishInfo.size.height/2))
|
GTE::TRANSFERVECTOR::translated((Assets::Main::DoenerFishInfo.size.width/2), (Assets::Main::DoenerFishInfo.size.height/2))
|
||||||
};
|
};
|
||||||
doener_fish.apply(matrix);
|
doener_fish.apply(matrix);
|
||||||
rotation += 5_DEG;
|
rotation += 5.0_deg;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "../GPU/gpu_types.hpp"
|
#include "../GPU/gpu_types.hpp"
|
||||||
#include "../../math.h"
|
#include "../../math.hpp"
|
||||||
|
|
||||||
namespace JabyEngine {
|
namespace JabyEngine {
|
||||||
namespace GTE {
|
namespace GTE {
|
||||||
|
@ -44,8 +44,9 @@ namespace JabyEngine {
|
||||||
{0, 0, 4096}
|
{0, 0, 4096}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} // TODO: replace int32_t with something weird for the DEG stuff??
|
}
|
||||||
static ROTMATRIX rotated(int32_t x, int32_t y, int32_t z);
|
|
||||||
|
static ROTMATRIX rotated(deg_t x = deg_t::zero(), deg_t y = deg_t::zero(), deg_t z = deg_t::zero());
|
||||||
};
|
};
|
||||||
|
|
||||||
struct TRANSFERVECTOR : public VECTOR {
|
struct TRANSFERVECTOR : public VECTOR {
|
||||||
|
@ -70,8 +71,8 @@ namespace JabyEngine {
|
||||||
return MATRIX{.rotation = ROTMATRIX::identity(), .transfer = TRANSFERVECTOR::translated(x, y, z)};
|
return MATRIX{.rotation = ROTMATRIX::identity(), .transfer = TRANSFERVECTOR::translated(x, y, z)};
|
||||||
}
|
}
|
||||||
|
|
||||||
static constexpr MATRIX rotated(int32_t x_deg = 0, int32_t y_deg = 0, int32_t z_deg = 0) {
|
static MATRIX rotated(deg_t x = deg_t::zero(), deg_t y = deg_t::zero(), deg_t z = deg_t::zero()) {
|
||||||
return MATRIX{.rotation = ROTMATRIX::rotated(x_deg, y_deg, z_deg), .transfer = TRANSFERVECTOR::identity()};
|
return MATRIX{.rotation = ROTMATRIX::rotated(x, y, z), .transfer = TRANSFERVECTOR::identity()};
|
||||||
}
|
}
|
||||||
|
|
||||||
static MATRIX comp(MATRIX new_matrix, const MATRIX& matrix) {
|
static MATRIX comp(MATRIX new_matrix, const MATRIX& matrix) {
|
||||||
|
@ -83,24 +84,5 @@ namespace JabyEngine {
|
||||||
GPU::Vertex& apply_to(GPU::Vertex& vertex) const;
|
GPU::Vertex& apply_to(GPU::Vertex& vertex) const;
|
||||||
GPU::Vertex apply_to(const GPU::Vertex& vertex) const;
|
GPU::Vertex apply_to(const GPU::Vertex& vertex) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
static constexpr auto one_degree = FULL_CIRCLE/360;
|
|
||||||
static constexpr auto one_tenth_degree = FULL_CIRCLE/3600;
|
|
||||||
|
|
||||||
static constexpr int16_t in_degree(int32_t degree) {
|
|
||||||
return degree*one_degree;
|
|
||||||
}
|
|
||||||
|
|
||||||
static constexpr int16_t in_degree10(int32_t degree) {
|
|
||||||
return degree*one_tenth_degree;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static constexpr unsigned long long operator""_DEG(unsigned long long degree) {
|
|
||||||
return GTE::in_degree(degree);
|
|
||||||
}
|
|
||||||
|
|
||||||
static constexpr unsigned long long operator""_DEG10(unsigned long long degree) {
|
|
||||||
return GTE::in_degree10(degree);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,10 +0,0 @@
|
||||||
#ifndef __MATH_H__
|
|
||||||
#define __MATH_H__
|
|
||||||
#include "stdint.h"
|
|
||||||
|
|
||||||
#define FULL_CIRCLE 32768
|
|
||||||
|
|
||||||
int32_t sin(int32_t value);
|
|
||||||
int32_t cos(int32_t value);
|
|
||||||
|
|
||||||
#endif // !__MATH_H__
|
|
|
@ -0,0 +1,57 @@
|
||||||
|
#pragma once
|
||||||
|
#include "stdint.h"
|
||||||
|
|
||||||
|
namespace math {
|
||||||
|
template<typename T>
|
||||||
|
struct raw_math {
|
||||||
|
constexpr T operator-() const {
|
||||||
|
return T{.raw = -(static_cast<const T&>(*this).raw)};
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr T operator+(const T& obj) const {
|
||||||
|
return T{.raw = static_cast<const T&>(*this).raw + obj.raw};
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr T operator-(const T& b) const {}
|
||||||
|
|
||||||
|
constexpr T& operator+=(const T& obj) {
|
||||||
|
static_cast<T&>(*this).raw += obj.raw;
|
||||||
|
return static_cast<T&>(*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr T& operator-=(const T& obj) {
|
||||||
|
static_cast<T&>(*this).raw -= obj.raw;
|
||||||
|
return static_cast<T&>(*this);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
struct deg_t : public math::raw_math<deg_t> {
|
||||||
|
static constexpr auto full_circle = 32768;
|
||||||
|
static constexpr auto one_degree = full_circle/360;
|
||||||
|
static constexpr auto one_tenth_degree = full_circle/3600;
|
||||||
|
|
||||||
|
int16_t raw;
|
||||||
|
|
||||||
|
static constexpr deg_t zero() {
|
||||||
|
return deg_t{.raw = 0};
|
||||||
|
}
|
||||||
|
|
||||||
|
static constexpr deg_t from_degree(int32_t deg) {
|
||||||
|
return deg_t{.raw = static_cast<int16_t>(deg*one_degree)};
|
||||||
|
}
|
||||||
|
|
||||||
|
static constexpr deg_t from_tenth_degree(int32_t deg10) {
|
||||||
|
return deg_t{.raw = static_cast<int16_t>(deg10*one_tenth_degree)};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
static constexpr deg_t operator""_deg(long double degree) {
|
||||||
|
return deg_t::from_tenth_degree((degree*10.0));
|
||||||
|
}
|
||||||
|
|
||||||
|
using sin_t = int32_t;
|
||||||
|
using cos_t = int32_t;
|
||||||
|
|
||||||
|
sin_t sin(deg_t value);
|
||||||
|
cos_t cos(deg_t value);
|
|
@ -1,7 +1,6 @@
|
||||||
#include <PSX/GTE/gte.hpp>
|
#include <PSX/GTE/gte.hpp>
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
int32_t sin(int32_t value) {
|
static int32_t hisin(int32_t value) {
|
||||||
static constexpr int32_t qN = 13;
|
static constexpr int32_t qN = 13;
|
||||||
static constexpr int32_t qA = 12;
|
static constexpr int32_t qA = 12;
|
||||||
static constexpr int32_t B = 19900;
|
static constexpr int32_t B = 19900;
|
||||||
|
@ -20,8 +19,12 @@ int32_t sin(int32_t value) {
|
||||||
return c >= 0 ? result : -result;
|
return c >= 0 ? result : -result;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t cos(int32_t value) {
|
sin_t sin(deg_t value) {
|
||||||
return sin(value + (FULL_CIRCLE/4));
|
return hisin(value.raw);
|
||||||
|
}
|
||||||
|
|
||||||
|
cos_t cos(deg_t value) {
|
||||||
|
return hisin(value.raw + (deg_t::full_circle/4));
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace JabyEngine {
|
namespace JabyEngine {
|
||||||
|
@ -31,7 +34,7 @@ namespace JabyEngine {
|
||||||
int16_t sin;
|
int16_t sin;
|
||||||
int16_t cos;
|
int16_t cos;
|
||||||
|
|
||||||
static SinCosPair create_for(int32_t value) {
|
static SinCosPair create_for(deg_t value) {
|
||||||
return SinCosPair{
|
return SinCosPair{
|
||||||
.sin = static_cast<int16_t>(::sin(value)),
|
.sin = static_cast<int16_t>(::sin(value)),
|
||||||
.cos = static_cast<int16_t>(::cos(value)),
|
.cos = static_cast<int16_t>(::cos(value)),
|
||||||
|
@ -96,7 +99,7 @@ namespace JabyEngine {
|
||||||
return matrix;
|
return matrix;
|
||||||
}
|
}
|
||||||
|
|
||||||
ROTMATRIX ROTMATRIX :: rotated(int32_t x, int32_t y, int32_t z) {
|
ROTMATRIX ROTMATRIX :: rotated(deg_t x, deg_t y, deg_t z) {
|
||||||
using namespace MatrixHelper;
|
using namespace MatrixHelper;
|
||||||
|
|
||||||
const auto sincos_x = SinCosPair::create_for(x);
|
const auto sincos_x = SinCosPair::create_for(x);
|
||||||
|
|
Loading…
Reference in New Issue