mirror of
https://github.com/NoelFB/blah.git
synced 2025-09-13 13:24:26 +08:00
cleaned up Calc header, renamed numerics folder to math
This commit is contained in:
@ -4,7 +4,7 @@
|
||||
#include <blah/graphics/mesh.h>
|
||||
#include <blah/graphics/shader.h>
|
||||
#include <blah/graphics/material.h>
|
||||
#include <blah/numerics/calc.h>
|
||||
#include <blah/math/calc.h>
|
||||
#include <blah/app.h>
|
||||
#include "../internal/renderer.h"
|
||||
#include <cmath>
|
||||
@ -54,10 +54,10 @@ namespace
|
||||
*_i++ = (u32)m_vertices.size() + 3; \
|
||||
Vertex* _v = m_vertices.expand(4); \
|
||||
if (integerize) { \
|
||||
MAKE_VERTEX(_v, m_matrix, px0, py0, tx0, ty0, col0, mult, fill, wash, std::round); _v++; \
|
||||
MAKE_VERTEX(_v, m_matrix, px1, py1, tx1, ty1, col1, mult, fill, wash, std::round); _v++; \
|
||||
MAKE_VERTEX(_v, m_matrix, px2, py2, tx2, ty2, col2, mult, fill, wash, std::round); _v++; \
|
||||
MAKE_VERTEX(_v, m_matrix, px3, py3, tx3, ty3, col3, mult, fill, wash, std::round); \
|
||||
MAKE_VERTEX(_v, m_matrix, px0, py0, tx0, ty0, col0, mult, fill, wash, Calc::floor); _v++; \
|
||||
MAKE_VERTEX(_v, m_matrix, px1, py1, tx1, ty1, col1, mult, fill, wash, Calc::floor); _v++; \
|
||||
MAKE_VERTEX(_v, m_matrix, px2, py2, tx2, ty2, col2, mult, fill, wash, Calc::floor); _v++; \
|
||||
MAKE_VERTEX(_v, m_matrix, px3, py3, tx3, ty3, col3, mult, fill, wash, Calc::floor); \
|
||||
} else { \
|
||||
MAKE_VERTEX(_v, m_matrix, px0, py0, tx0, ty0, col0, mult, fill, wash, float); _v++; \
|
||||
MAKE_VERTEX(_v, m_matrix, px1, py1, tx1, ty1, col1, mult, fill, wash, float); _v++; \
|
||||
@ -75,9 +75,9 @@ namespace
|
||||
*_i++ = (u32)m_vertices.size() + 2; \
|
||||
Vertex* _v = m_vertices.expand(3); \
|
||||
if (integerize) { \
|
||||
MAKE_VERTEX(_v, m_matrix, px0, py0, tx0, ty0, col0, mult, fill, wash, std::floor); _v++; \
|
||||
MAKE_VERTEX(_v, m_matrix, px1, py1, tx1, ty1, col1, mult, fill, wash, std::floor); _v++; \
|
||||
MAKE_VERTEX(_v, m_matrix, px2, py2, tx2, ty2, col2, mult, fill, wash, std::floor); \
|
||||
MAKE_VERTEX(_v, m_matrix, px0, py0, tx0, ty0, col0, mult, fill, wash, Calc::floor); _v++; \
|
||||
MAKE_VERTEX(_v, m_matrix, px1, py1, tx1, ty1, col1, mult, fill, wash, Calc::floor); _v++; \
|
||||
MAKE_VERTEX(_v, m_matrix, px2, py2, tx2, ty2, col2, mult, fill, wash, Calc::floor); \
|
||||
} else { \
|
||||
MAKE_VERTEX(_v, m_matrix, px0, py0, tx0, ty0, col0, mult, fill, wash, float); _v++; \
|
||||
MAKE_VERTEX(_v, m_matrix, px1, py1, tx1, ty1, col1, mult, fill, wash, float); _v++; \
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include <blah/graphics/subtexture.h>
|
||||
#include <blah/numerics/calc.h>
|
||||
#include <blah/math/calc.h>
|
||||
|
||||
using namespace Blah;
|
||||
|
||||
|
@ -5,7 +5,9 @@ using namespace Blah;
|
||||
|
||||
TargetRef Target::create(int width, int height)
|
||||
{
|
||||
return create(width, height, { TextureFormat::RGBA });
|
||||
AttachmentFormats formats;
|
||||
formats.push_back(TextureFormat::RGBA);
|
||||
return create(width, height, formats);
|
||||
}
|
||||
|
||||
TargetRef Target::create(int width, int height, const AttachmentFormats& textures)
|
||||
|
@ -2,7 +2,7 @@
|
||||
#include <blah/streams/filestream.h>
|
||||
#include <blah/filesystem.h>
|
||||
#include <blah/common.h>
|
||||
#include <blah/numerics/calc.h>
|
||||
#include <blah/math/calc.h>
|
||||
|
||||
#define STBI_NO_STDIO
|
||||
#define STBI_ONLY_ZLIB
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include <blah/images/font.h>
|
||||
#include <blah/streams/filestream.h>
|
||||
#include <blah/numerics/calc.h>
|
||||
#include <blah/math/calc.h>
|
||||
#include <blah/common.h>
|
||||
|
||||
using namespace Blah;
|
||||
|
@ -2,7 +2,7 @@
|
||||
#include <blah/app.h>
|
||||
#include <blah/time.h>
|
||||
#include <blah/common.h>
|
||||
#include <blah/numerics/calc.h>
|
||||
#include <blah/math/calc.h>
|
||||
#include "internal/input.h"
|
||||
#include "internal/platform.h"
|
||||
#include <blah/graphics/target.h>
|
||||
|
@ -6,7 +6,7 @@
|
||||
#include <blah/graphics/shader.h>
|
||||
#include <blah/graphics/mesh.h>
|
||||
#include <blah/graphics/material.h>
|
||||
#include <blah/numerics/color.h>
|
||||
#include <blah/math/color.h>
|
||||
|
||||
#define BLAH_ASSERT_RENDERER() BLAH_ASSERT(Renderer::instance, "Renderer has not been created")
|
||||
|
||||
|
@ -1,115 +0,0 @@
|
||||
#include <blah/numerics/calc.h>
|
||||
#include <blah/numerics/spatial.h>
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
|
||||
using namespace Blah;
|
||||
|
||||
float Calc::approach(float t, float target, float delta)
|
||||
{
|
||||
return t < target ? min(t + delta, target) : max(t - delta, target);
|
||||
}
|
||||
|
||||
float Calc::map(float t, float old_min, float old_max, float new_min, float new_max)
|
||||
{
|
||||
return new_min + ((t - old_min) / (old_max - old_min)) * (new_max - new_min);
|
||||
}
|
||||
|
||||
float Calc::clamped_map(float t, float old_min, float old_max, float new_min, float new_max)
|
||||
{
|
||||
return map(Calc::clamp(t, old_min, old_max), old_min, old_max, new_min, new_max);
|
||||
}
|
||||
|
||||
int Calc::sign(int x)
|
||||
{
|
||||
return (x < 0 ? -1 : (x > 0 ? 1 : 0));
|
||||
}
|
||||
|
||||
float Calc::sign(float x)
|
||||
{
|
||||
return (x < 0 ? -1.0f : (x > 0 ? 1.0f : 0.0f));
|
||||
}
|
||||
|
||||
int Calc::abs(int x)
|
||||
{
|
||||
return x < 0 ? -x : x;
|
||||
}
|
||||
|
||||
float Calc::abs(float x)
|
||||
{
|
||||
return x < 0 ? -x : x;
|
||||
}
|
||||
|
||||
float Calc::round(float x)
|
||||
{
|
||||
return roundf(x);
|
||||
}
|
||||
|
||||
float Calc::floor(float x)
|
||||
{
|
||||
return floorf(x);
|
||||
}
|
||||
|
||||
float Calc::ceiling(float x)
|
||||
{
|
||||
return ceilf(x);
|
||||
}
|
||||
|
||||
float Calc::mod(float x, float m)
|
||||
{
|
||||
return x - (int)(x / m) * m;
|
||||
}
|
||||
|
||||
float Calc::sin(float x)
|
||||
{
|
||||
return sinf(x);
|
||||
}
|
||||
|
||||
float Calc::cos(float x)
|
||||
{
|
||||
return cosf(x);
|
||||
}
|
||||
|
||||
float Calc::tan(float x)
|
||||
{
|
||||
return tanf(x);
|
||||
}
|
||||
|
||||
float Calc::atan2(float y, float x)
|
||||
{
|
||||
return atan2f(y, x);
|
||||
}
|
||||
|
||||
float Calc::pow(float x, float n)
|
||||
{
|
||||
return powf(x, n);
|
||||
}
|
||||
|
||||
float Calc::sqrt(float x)
|
||||
{
|
||||
return sqrtf(x);
|
||||
}
|
||||
|
||||
float Calc::snap(float val, float interval)
|
||||
{
|
||||
if (val > 0)
|
||||
return ((int)((val + interval / 2) / interval)) * interval;
|
||||
else
|
||||
return ((int)((val - interval / 2) / interval)) * interval;
|
||||
}
|
||||
|
||||
float Calc::angle_diff(float radians_a, float radians_b)
|
||||
{
|
||||
return mod((radians_b - radians_a) + PI, TAU) - PI;
|
||||
}
|
||||
|
||||
float Calc::angle_lerp(float radians_a, float radians_b, float p)
|
||||
{
|
||||
const auto shortest_angle = mod(mod(radians_b - radians_a, TAU) + (TAU + PI), TAU) - PI;
|
||||
return radians_a + mod(shortest_angle * p, TAU);
|
||||
}
|
||||
|
||||
float Calc::lerp(float a, float b, float t)
|
||||
{
|
||||
return a + (b - a) * t;
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
#include <blah/numerics/color.h>
|
||||
|
||||
using namespace Blah;
|
||||
|
||||
String Color::to_hex_rgba() const
|
||||
{
|
||||
static const char* hex = "0123456789ABCDEF";
|
||||
|
||||
String str = "00000000";
|
||||
str[0] = hex[(r & 0xF0) >> 4];
|
||||
str[1] = hex[(r & 0x0F) >> 0];
|
||||
str[2] = hex[(g & 0xF0) >> 4];
|
||||
str[3] = hex[(g & 0x0F) >> 0];
|
||||
str[4] = hex[(b & 0xF0) >> 4];
|
||||
str[5] = hex[(b & 0x0F) >> 0];
|
||||
str[6] = hex[(a & 0xF0) >> 4];
|
||||
str[7] = hex[(a & 0x0F) >> 0];
|
||||
return str;
|
||||
}
|
||||
|
||||
String Color::to_hex_rgb() const
|
||||
{
|
||||
static const char* hex = "0123456789ABCDEF";
|
||||
|
||||
String str = "000000";
|
||||
str[0] = hex[(r & 0xF0) >> 4];
|
||||
str[1] = hex[(r & 0x0F) >> 0];
|
||||
str[2] = hex[(g & 0xF0) >> 4];
|
||||
str[3] = hex[(g & 0x0F) >> 0];
|
||||
str[4] = hex[(b & 0xF0) >> 4];
|
||||
str[5] = hex[(b & 0x0F) >> 0];
|
||||
return str;
|
||||
}
|
||||
|
||||
const Color Color::transparent = Color(0, 0, 0, 0);
|
||||
const Color Color::white = Color(255, 255, 255, 255);
|
||||
const Color Color::black = Color(0, 0, 0, 255);
|
||||
const Color Color::red = Color(255, 0, 0, 255);
|
||||
const Color Color::green = Color(0, 255, 0, 255);
|
||||
const Color Color::blue = Color(0, 0, 255, 255);
|
||||
const Color Color::yellow = Color(255, 255, 0, 255);
|
||||
const Color Color::purple = Color(255, 0, 255, 255);
|
||||
const Color Color::teal = Color(0, 255, 255, 255);
|
Reference in New Issue
Block a user