mirror of
https://github.com/LNH-team/pico-launcher.git
synced 2026-06-02 17:16:57 +02:00
Initial commit
This commit is contained in:
29
arm9/source/core/math/SinTable.h
Normal file
29
arm9/source/core/math/SinTable.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
#include <cmath>
|
||||
#include "fixed.h"
|
||||
|
||||
template<int N>
|
||||
class SinTable
|
||||
{
|
||||
struct sin_cos_t
|
||||
{
|
||||
fix16<14> sin = 0;
|
||||
fix16<14> cos = 0;
|
||||
};
|
||||
|
||||
sin_cos_t _table[N];
|
||||
|
||||
public:
|
||||
constexpr SinTable()
|
||||
: _table()
|
||||
{
|
||||
for (auto i = 0; i < N; i++)
|
||||
_table[i] = { sin(i * 2 * M_PI / N), cos(i * 2 * M_PI / N) };
|
||||
}
|
||||
|
||||
constexpr fix16<14> Sin(u16 angle) const { return _table[(angle * N) >> 16].sin; }
|
||||
constexpr fix16<14> Cos(u16 angle) const { return _table[(angle * N) >> 16].cos; }
|
||||
constexpr const sin_cos_t& SinCos(u16 angle) const { return _table[(angle * N) >> 16]; }
|
||||
};
|
||||
|
||||
constexpr SinTable<4096> gSinTable = SinTable<4096>();
|
||||
Reference in New Issue
Block a user