mirror of
https://github.com/NoelFB/blah.git
synced 2025-06-29 19:25:26 +08:00
large spatial / numerics refactor to allow double/integer vector types
This commit is contained in:
@ -29,19 +29,9 @@
|
||||
#include "blah/images/packer.h"
|
||||
|
||||
#include "blah/numerics/calc.h"
|
||||
#include "blah/numerics/circle.h"
|
||||
#include "blah/numerics/spatial.h"
|
||||
#include "blah/numerics/color.h"
|
||||
#include "blah/numerics/ease.h"
|
||||
#include "blah/numerics/line.h"
|
||||
#include "blah/numerics/mat3x2.h"
|
||||
#include "blah/numerics/mat4x4.h"
|
||||
#include "blah/numerics/point.h"
|
||||
#include "blah/numerics/quad.h"
|
||||
#include "blah/numerics/rect.h"
|
||||
#include "blah/numerics/rectI.h"
|
||||
#include "blah/numerics/vec2.h"
|
||||
#include "blah/numerics/vec3.h"
|
||||
#include "blah/numerics/vec4.h"
|
||||
|
||||
#include "blah/streams/bufferstream.h"
|
||||
#include "blah/streams/filestream.h"
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
#include <blah/common.h>
|
||||
#include <blah/numerics/point.h>
|
||||
#include <blah/numerics/spatial.h>
|
||||
|
||||
namespace Blah
|
||||
{
|
||||
|
@ -165,7 +165,7 @@ namespace Blah
|
||||
// clears and disposes the internal string buffer
|
||||
void dispose();
|
||||
|
||||
~Str()
|
||||
virtual ~Str()
|
||||
{
|
||||
if (m_buffer != nullptr && m_buffer != empty_buffer)
|
||||
delete[] m_buffer;
|
||||
@ -181,10 +181,10 @@ namespace Blah
|
||||
}
|
||||
|
||||
// returns a pointer to the heap buffer or to our stack allocation
|
||||
char* data() { return (m_buffer != nullptr ? m_buffer : ((char*)(this) + sizeof(Str))); }
|
||||
virtual char* data() { return m_buffer; }
|
||||
|
||||
// returns a pointer to the heap buffer or to our stack allocation
|
||||
const char* data() const { return (m_buffer != nullptr ? m_buffer : ((char*)(this) + sizeof(Str))); }
|
||||
virtual const char* data() const { return m_buffer; }
|
||||
|
||||
// assigns the contents of the string
|
||||
void set(const Str& str) { set(str.cstr(), str.cstr() + str.m_length); }
|
||||
@ -192,9 +192,10 @@ namespace Blah
|
||||
// assigns the contents of the string
|
||||
void set(const char* start, const char* end = nullptr);
|
||||
|
||||
char* m_buffer;
|
||||
|
||||
private:
|
||||
static char empty_buffer[1];
|
||||
char* m_buffer;
|
||||
int m_length;
|
||||
int m_capacity;
|
||||
int m_local_size;
|
||||
@ -221,6 +222,10 @@ namespace Blah
|
||||
StrOf& operator=(const Str& rhs) { set(rhs); return *this; }
|
||||
StrOf& operator=(const StrOf& rhs) { set(rhs); return *this; }
|
||||
|
||||
// either return stack or heap buffer depending on which is in-use
|
||||
char* data() override { return m_buffer != nullptr ? m_buffer : m_local_buffer; }
|
||||
const char* data() const override { return m_buffer != nullptr ? m_buffer : m_local_buffer; }
|
||||
|
||||
// creates a string from the format
|
||||
static StrOf fmt(const char* str, ...);
|
||||
};
|
||||
@ -251,6 +256,33 @@ namespace Blah
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
struct CaseInsenstiveStringHash
|
||||
{
|
||||
std::size_t operator()(const Blah::Str& key) const
|
||||
{
|
||||
std::size_t result = 2166136261U;
|
||||
|
||||
for (auto& it : key)
|
||||
{
|
||||
if (it >= 'A' && it <= 'Z')
|
||||
result ^= (static_cast<std::size_t>(it) - 'A' + 'a');
|
||||
else
|
||||
result ^= static_cast<std::size_t>(it);
|
||||
result *= 16777619U;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
struct CaseInsenstiveStringCompare
|
||||
{
|
||||
bool operator() (const Str& lhs, const Str& rhs) const
|
||||
{
|
||||
return lhs.length() == rhs.length() && lhs.starts_with(rhs, true);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
namespace std
|
||||
@ -264,7 +296,7 @@ namespace std
|
||||
|
||||
for (auto& it : key)
|
||||
{
|
||||
result ^= static_cast<size_t>(it);
|
||||
result ^= static_cast<std::size_t>(it);
|
||||
result *= 16777619U;
|
||||
}
|
||||
|
||||
@ -281,7 +313,7 @@ namespace std
|
||||
|
||||
for (auto& it : key)
|
||||
{
|
||||
result ^= static_cast<size_t>(it);
|
||||
result ^= static_cast<std::size_t>(it);
|
||||
result *= 16777619U;
|
||||
}
|
||||
|
||||
|
@ -104,7 +104,7 @@ namespace Blah
|
||||
template<typename ... Args>
|
||||
FilePath join(const FilePath& a, const FilePath& b, const Args&... args)
|
||||
{
|
||||
return join(a, join(b, std::forward<Args>(args)...));
|
||||
return join(a, join(b, args...));
|
||||
}
|
||||
}
|
||||
}
|
@ -1,9 +1,6 @@
|
||||
#pragma once
|
||||
#include <blah/containers/str.h>
|
||||
#include <blah/numerics/vec2.h>
|
||||
#include <blah/numerics/rect.h>
|
||||
#include <blah/numerics/mat3x2.h>
|
||||
#include <blah/numerics/mat4x4.h>
|
||||
#include <blah/numerics/spatial.h>
|
||||
#include <blah/numerics/color.h>
|
||||
#include <blah/graphics/subtexture.h>
|
||||
#include <blah/graphics/spritefont.h>
|
||||
@ -53,6 +50,10 @@ namespace Blah
|
||||
const char* sampler_uniform;
|
||||
const char* matrix_uniform;
|
||||
|
||||
// Snaps all drawing coordinates to integer values
|
||||
// This is useful for drawing Pixel Art stuff
|
||||
bool integerize = false;
|
||||
|
||||
// Default Sampler, set on clear
|
||||
TextureSampler default_sampler;
|
||||
|
||||
@ -63,23 +64,23 @@ namespace Blah
|
||||
|
||||
// Pushes a new matrix onto the stack, and uses it for transforming all drawing.
|
||||
// `absolute` means the matrix provided will not be transformed by the current stack.
|
||||
void push_matrix(const Mat3x2& matrix, bool absolute = false);
|
||||
void push_matrix(const Mat3x2f& matrix, bool absolute = false);
|
||||
|
||||
// Pops the matrix from the stack
|
||||
Mat3x2 pop_matrix();
|
||||
Mat3x2f pop_matrix();
|
||||
|
||||
// Gets the current matrix from the top of the stackKO
|
||||
Mat3x2 peek_matrix() const;
|
||||
Mat3x2f peek_matrix() const;
|
||||
|
||||
// Pushes a Scissor rectangle. Note this is not transformed by the matrix stack
|
||||
// or other scissors. Each push is screen-space.
|
||||
void push_scissor(const Rect& scissor);
|
||||
void push_scissor(const Rectf& scissor);
|
||||
|
||||
// Pops a Scissor rectangle from the stack
|
||||
Rect pop_scissor();
|
||||
Rectf pop_scissor();
|
||||
|
||||
// Gets the current Scissor rectangle from the top of the stack
|
||||
Rect peek_scissor() const;
|
||||
Rectf peek_scissor() const;
|
||||
|
||||
// Pushes a blend mode
|
||||
void push_blend(const BlendMode& blend);
|
||||
@ -130,7 +131,7 @@ namespace Blah
|
||||
void render(const TargetRef& target = App::backbuffer);
|
||||
|
||||
// Draws the batch to the given target, with the provided matrix
|
||||
void render(const TargetRef& target, const Mat4x4& matrix);
|
||||
void render(const TargetRef& target, const Mat4x4f& matrix);
|
||||
|
||||
// Clears the batch
|
||||
void clear();
|
||||
@ -138,60 +139,60 @@ namespace Blah
|
||||
// Clears and disposes all resources that the batch is using
|
||||
void dispose();
|
||||
|
||||
void line(const Vec2& from, const Vec2& to, float t, Color color);
|
||||
void line(const Vec2& from, const Vec2& to, float t, Color fromColor, Color toColor);
|
||||
void line(const Vec2f& from, const Vec2f& to, float t, Color color);
|
||||
void line(const Vec2f& from, const Vec2f& to, float t, Color fromColor, Color toColor);
|
||||
|
||||
void bezier_line(const Vec2& from, const Vec2& b, const Vec2& to, int steps, float t, Color color);
|
||||
void bezier_line(const Vec2& from, const Vec2& b, const Vec2& c, const Vec2& to, int steps, float t, Color color);
|
||||
void bezier_line(const Vec2f& from, const Vec2f& b, const Vec2f& to, int steps, float t, Color color);
|
||||
void bezier_line(const Vec2f& from, const Vec2f& b, const Vec2f& c, const Vec2f& to, int steps, float t, Color color);
|
||||
|
||||
void tri(const Vec2& pos0, const Vec2& pos1, const Vec2& pos2, Color color);
|
||||
void tri(const Vec2& pos0, const Vec2& pos1, const Vec2& pos2, Color col0, Color col1, Color col2);
|
||||
void tri(const Vec2& pos0, const Vec2& pos1, const Vec2& pos2, const Vec2& tex0, const Vec2& tex1, const Vec2& tex2, Color color);
|
||||
void tri(const Vec2& pos0, const Vec2& pos1, const Vec2& pos2, const Vec2& tex0, const Vec2& tex1, const Vec2& tex2, Color col0, Color col1, Color col2);
|
||||
void tri(const Vec2f& pos0, const Vec2f& pos1, const Vec2f& pos2, Color color);
|
||||
void tri(const Vec2f& pos0, const Vec2f& pos1, const Vec2f& pos2, Color col0, Color col1, Color col2);
|
||||
void tri(const Vec2f& pos0, const Vec2f& pos1, const Vec2f& pos2, const Vec2f& tex0, const Vec2f& tex1, const Vec2f& tex2, Color color);
|
||||
void tri(const Vec2f& pos0, const Vec2f& pos1, const Vec2f& pos2, const Vec2f& tex0, const Vec2f& tex1, const Vec2f& tex2, Color col0, Color col1, Color col2);
|
||||
|
||||
void tri_line(const Vec2& a, const Vec2& b, const Vec2& c, float t, Color color);
|
||||
void tri_line(const Vec2f& a, const Vec2f& b, const Vec2f& c, float t, Color color);
|
||||
|
||||
void rect(const Rect& rect, Color color);
|
||||
void rect_line(const Rect& rect, float t, Color color);
|
||||
void rect_rounded(const Rect& rect, float radius, int steps, Color color);
|
||||
void rect_rounded(const Rect& rect, float rtl, int rtl_steps, float rtr, int rtr_steps, float rbr, int rbr_steps, float rbl, int rbl_steps, Color color);
|
||||
void rect_rounded_line(const Rect& rect, float radius, int steps, float t, Color color);
|
||||
void rect_rounded_line(const Rect& rect, float rtl, int rtl_steps, float rtr, int rtr_steps, float rbr, int rbr_steps, float rbl, int rbl_steps, float t, Color color);
|
||||
void rect(const Rectf& rect, Color color);
|
||||
void rect_line(const Rectf& rect, float t, Color color);
|
||||
void rect_rounded(const Rectf& rect, float radius, int steps, Color color);
|
||||
void rect_rounded(const Rectf& rect, float rtl, int rtl_steps, float rtr, int rtr_steps, float rbr, int rbr_steps, float rbl, int rbl_steps, Color color);
|
||||
void rect_rounded_line(const Rectf& rect, float radius, int steps, float t, Color color);
|
||||
void rect_rounded_line(const Rectf& rect, float rtl, int rtl_steps, float rtr, int rtr_steps, float rbr, int rbr_steps, float rbl, int rbl_steps, float t, Color color);
|
||||
|
||||
void semi_circle(const Vec2& center, float start_radians, float end_radians, float radius, int steps, Color centerColor, Color edgeColor);
|
||||
void semi_circle(const Vec2& center, float start_radians, float end_radians, float radius, int steps, Color color);
|
||||
void semi_circle_line(const Vec2& center, float start_radians, float end_radians, float radius, int steps, float t, Color color);
|
||||
void semi_circle(const Vec2f& center, float start_radians, float end_radians, float radius, int steps, Color centerColor, Color edgeColor);
|
||||
void semi_circle(const Vec2f& center, float start_radians, float end_radians, float radius, int steps, Color color);
|
||||
void semi_circle_line(const Vec2f& center, float start_radians, float end_radians, float radius, int steps, float t, Color color);
|
||||
|
||||
void circle(const Vec2& center, float radius, int steps, Color color);
|
||||
void circle(const Vec2& center, float radius, int steps, Color center_color, Color outer_color);
|
||||
void circle_line(const Vec2& center, float radius, float t, int steps, Color color);
|
||||
void circle(const Vec2f& center, float radius, int steps, Color color);
|
||||
void circle(const Vec2f& center, float radius, int steps, Color center_color, Color outer_color);
|
||||
void circle_line(const Vec2f& center, float radius, float t, int steps, Color color);
|
||||
|
||||
void quad(const Vec2& pos0, const Vec2& pos1, const Vec2& pos2, const Vec2& pos3, Color color);
|
||||
void quad(const Vec2& pos0, const Vec2& pos1, const Vec2& pos2, const Vec2& pos3, Color col0, Color col1, Color col2, Color col3);
|
||||
void quad(const Vec2& pos0, const Vec2& pos1, const Vec2& pos2, const Vec2& pos3, const Vec2& tex0, const Vec2& tex1, const Vec2& tex2, const Vec2& tex3, Color color);
|
||||
void quad(const Vec2& pos0, const Vec2& pos1, const Vec2& pos2, const Vec2& pos3, const Vec2& tex0, const Vec2& tex1, const Vec2& tex2, const Vec2& tex3, Color col0, Color col1, Color col2, Color col3);
|
||||
void quad_line(const Vec2& a, const Vec2& b, const Vec2& c, const Vec2& d, float t, Color color);
|
||||
void quad(const Vec2f& pos0, const Vec2f& pos1, const Vec2f& pos2, const Vec2f& pos3, Color color);
|
||||
void quad(const Vec2f& pos0, const Vec2f& pos1, const Vec2f& pos2, const Vec2f& pos3, Color col0, Color col1, Color col2, Color col3);
|
||||
void quad(const Vec2f& pos0, const Vec2f& pos1, const Vec2f& pos2, const Vec2f& pos3, const Vec2f& tex0, const Vec2f& tex1, const Vec2f& tex2, const Vec2f& tex3, Color color);
|
||||
void quad(const Vec2f& pos0, const Vec2f& pos1, const Vec2f& pos2, const Vec2f& pos3, const Vec2f& tex0, const Vec2f& tex1, const Vec2f& tex2, const Vec2f& tex3, Color col0, Color col1, Color col2, Color col3);
|
||||
void quad_line(const Vec2f& a, const Vec2f& b, const Vec2f& c, const Vec2f& d, float t, Color color);
|
||||
|
||||
void arrow_head(const Vec2& point_pos, float radians, float side_len, Color color);
|
||||
void arrow_head(const Vec2& point_pos, const Vec2& from_pos, float side_len, Color color);
|
||||
void arrow_head(const Vec2f& point_pos, float radians, float side_len, Color color);
|
||||
void arrow_head(const Vec2f& point_pos, const Vec2f& from_pos, float side_len, Color color);
|
||||
|
||||
void tex(const TextureRef& texture, const Vec2& position = Vec2::zero, Color color = Color::white);
|
||||
void tex(const TextureRef& texture, const Vec2& position, const Vec2& origin, const Vec2& scale, float rotation, Color color);
|
||||
void tex(const TextureRef& texture, const Rect& clip, const Vec2& position, const Vec2& origin, const Vec2& scale, float rotation, Color color);
|
||||
void tex(const TextureRef& texture, const Vec2f& position = Vec2f::zero, Color color = Color::white);
|
||||
void tex(const TextureRef& texture, const Vec2f& position, const Vec2f& origin, const Vec2f& scale, float rotation, Color color);
|
||||
void tex(const TextureRef& texture, const Rectf& clip, const Vec2f& position, const Vec2f& origin, const Vec2f& scale, float rotation, Color color);
|
||||
|
||||
void tex(const Subtexture& subtexture, const Vec2& position = Vec2::zero, Color color = Color::white);
|
||||
void tex(const Subtexture& subtexture, const Vec2& pos, const Vec2& origin, const Vec2& scale, float rotation, Color color);
|
||||
void tex(const Subtexture& subtexture, const Rect& clip, const Vec2& pos, const Vec2& origin, const Vec2& scale, float rotation, Color color);
|
||||
void tex(const Subtexture& subtexture, const Vec2f& position = Vec2f::zero, Color color = Color::white);
|
||||
void tex(const Subtexture& subtexture, const Vec2f& pos, const Vec2f& origin, const Vec2f& scale, float rotation, Color color);
|
||||
void tex(const Subtexture& subtexture, const Rectf& clip, const Vec2f& pos, const Vec2f& origin, const Vec2f& scale, float rotation, Color color);
|
||||
|
||||
void str(const SpriteFont& font, const String& text, const Vec2& pos, Color color);
|
||||
void str(const SpriteFont& font, const String& text, const Vec2& pos, TextAlign align, float size, Color color);
|
||||
void str(const SpriteFont& font, const String& text, const Vec2f& pos, Color color);
|
||||
void str(const SpriteFont& font, const String& text, const Vec2f& pos, TextAlign align, float size, Color color);
|
||||
|
||||
private:
|
||||
|
||||
struct Vertex
|
||||
{
|
||||
Vec2 pos;
|
||||
Vec2 tex;
|
||||
Vec2f pos;
|
||||
Vec2f tex;
|
||||
Color col;
|
||||
|
||||
u8 mult;
|
||||
@ -210,7 +211,7 @@ namespace Blah
|
||||
TextureRef texture;
|
||||
TextureSampler sampler;
|
||||
bool flip_vertically;
|
||||
Rect scissor;
|
||||
Rectf scissor;
|
||||
|
||||
DrawBatch() :
|
||||
layer(0),
|
||||
@ -224,15 +225,15 @@ namespace Blah
|
||||
static ShaderRef m_default_shader;
|
||||
MaterialRef m_default_material;
|
||||
MeshRef m_mesh;
|
||||
Mat3x2 m_matrix;
|
||||
Mat3x2f m_matrix;
|
||||
ColorMode m_color_mode;
|
||||
u8 m_tex_mult;
|
||||
u8 m_tex_wash;
|
||||
DrawBatch m_batch;
|
||||
Vector<Vertex> m_vertices;
|
||||
Vector<u32> m_indices;
|
||||
Vector<Mat3x2> m_matrix_stack;
|
||||
Vector<Rect> m_scissor_stack;
|
||||
Vector<Mat3x2f> m_matrix_stack;
|
||||
Vector<Rectf> m_scissor_stack;
|
||||
Vector<BlendMode> m_blend_stack;
|
||||
Vector<MaterialRef> m_material_stack;
|
||||
Vector<ColorMode> m_color_mode_stack;
|
||||
@ -240,6 +241,6 @@ namespace Blah
|
||||
Vector<DrawBatch> m_batches;
|
||||
int m_batch_insert;
|
||||
|
||||
void render_single_batch(RenderPass& pass, const DrawBatch& b, const Mat4x4& matrix);
|
||||
void render_single_batch(RenderPass& pass, const DrawBatch& b, const Mat4x4f& matrix);
|
||||
};
|
||||
}
|
@ -4,6 +4,7 @@
|
||||
#include <blah/graphics/shader.h>
|
||||
#include <blah/graphics/sampler.h>
|
||||
#include <blah/containers/vector.h>
|
||||
#include <blah/numerics/spatial.h>
|
||||
|
||||
namespace Blah
|
||||
{
|
||||
@ -30,6 +31,9 @@ namespace Blah
|
||||
// If the Shader is invalid, it will return an invalid MaterialRef.
|
||||
static MaterialRef create(const ShaderRef& shader);
|
||||
|
||||
// Clones the material and returns a new one
|
||||
MaterialRef clone() const;
|
||||
|
||||
// Returns the Shader assigned to the Material.
|
||||
ShaderRef shader() const;
|
||||
|
||||
@ -62,6 +66,20 @@ namespace Blah
|
||||
// can be set.
|
||||
void set_value(const char* name, const float* value, i64 length);
|
||||
|
||||
// Shorthands to more easily assign uniform values
|
||||
void set_value(const char* name, float value);
|
||||
void set_value(const char* name, const Vec2f& value);
|
||||
void set_value(const char* name, const Vec3f& value);
|
||||
void set_value(const char* name, const Vec4f& value);
|
||||
void set_value(const char* name, const Mat3x2f& value);
|
||||
void set_value(const char* name, const Mat4x4f& value);
|
||||
void set_value(const char* name, const Vector<float>& value);
|
||||
void set_value(const char* name, const Vector<Vec2f>& value);
|
||||
void set_value(const char* name, const Vector<Vec3f>& value);
|
||||
void set_value(const char* name, const Vector<Vec4f>& value);
|
||||
void set_value(const char* name, const Vector<Mat3x2f>& value);
|
||||
void set_value(const char* name, const Vector<Mat4x4f>& value);
|
||||
|
||||
// Gets a pointer to the values of the given Uniform, or nullptr if it doesn't exist.
|
||||
const float* get_value(const char* name, i64* length = nullptr) const;
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
#include <blah/common.h>
|
||||
#include <blah/numerics/rect.h>
|
||||
#include <blah/numerics/spatial.h>
|
||||
#include <blah/containers/str.h>
|
||||
#include <blah/graphics/texture.h>
|
||||
#include <blah/graphics/target.h>
|
||||
@ -57,10 +57,10 @@ namespace Blah
|
||||
bool has_scissor;
|
||||
|
||||
// The viewport (only used if hasViewport is true)
|
||||
Rect viewport;
|
||||
Rectf viewport;
|
||||
|
||||
// The scissor rectangle (only used if hasScissor is true)
|
||||
Rect scissor;
|
||||
Rectf scissor;
|
||||
|
||||
// First index in the Mesh to draw from
|
||||
i64 index_start;
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include <blah/containers/str.h>
|
||||
#include <blah/containers/vector.h>
|
||||
#include <blah/graphics/subtexture.h>
|
||||
#include <blah/numerics/vec2.h>
|
||||
#include <blah/numerics/spatial.h>
|
||||
#include <blah/filesystem.h>
|
||||
#include <unordered_map>
|
||||
|
||||
@ -44,7 +44,7 @@ namespace Blah
|
||||
{
|
||||
Subtexture subtexture;
|
||||
float advance = 0;
|
||||
Vec2 offset;
|
||||
Vec2f offset;
|
||||
};
|
||||
|
||||
// SpriteFont name
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
#include <blah/graphics/texture.h>
|
||||
#include <blah/numerics/rect.h>
|
||||
#include <blah/numerics/spatial.h>
|
||||
|
||||
namespace Blah
|
||||
{
|
||||
@ -12,23 +12,23 @@ namespace Blah
|
||||
TextureRef texture;
|
||||
|
||||
// Source rectangle, in pixels
|
||||
Rect source;
|
||||
Rectf source;
|
||||
|
||||
// Frame rectangle, in pixels. This describes padding around the image.
|
||||
// This is useful for drawing images that have been trimmed. Ex. if the source
|
||||
// is 32,32, but the original image was 64,64, the frame could be -16,-16,64,64
|
||||
Rect frame;
|
||||
Rectf frame;
|
||||
|
||||
// `draw_coords` are automatically assigned through `update` method
|
||||
Vec2 draw_coords[4];
|
||||
Vec2f draw_coords[4];
|
||||
|
||||
// `tex_coords` are automatically assigned through the `update` method
|
||||
Vec2 tex_coords[4];
|
||||
Vec2f tex_coords[4];
|
||||
|
||||
Subtexture();
|
||||
Subtexture(const TextureRef& texture);
|
||||
Subtexture(const TextureRef& texture, Rect source);
|
||||
Subtexture(const TextureRef& texture, Rect source, Rect frame);
|
||||
Subtexture(const TextureRef& texture, Rectf source);
|
||||
Subtexture(const TextureRef& texture, Rectf source, Rectf frame);
|
||||
|
||||
// Returns the width of the image
|
||||
float width() const { return frame.w; }
|
||||
@ -40,9 +40,9 @@ namespace Blah
|
||||
void update();
|
||||
|
||||
// returns resulting source and frame rectangles based on the provided clip rectangle
|
||||
void crop_info(const Rect& clip, Rect* dest_source, Rect* dest_frame) const;
|
||||
void crop_info(const Rectf& clip, Rectf* dest_source, Rectf* dest_frame) const;
|
||||
|
||||
// returns a subtexture cropped to the provided rectangle
|
||||
Subtexture crop(const Rect& clip) const;
|
||||
Subtexture crop(const Rectf& clip) const;
|
||||
};
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
#include <blah/numerics/color.h>
|
||||
#include <blah/numerics/rectI.h>
|
||||
#include <blah/numerics/point.h>
|
||||
#include <blah/numerics/spatial.h>
|
||||
#include <blah/filesystem.h>
|
||||
|
||||
namespace Blah
|
||||
@ -45,7 +44,7 @@ namespace Blah
|
||||
|
||||
// sets the pixels at the provided rectangle to the given data
|
||||
// data must be at least rect.w * rect.h in size!
|
||||
void set_pixels(const RectI& rect, Color* data);
|
||||
void set_pixels(const Recti& rect, Color* data);
|
||||
|
||||
// saves the image to a png file
|
||||
bool save_png(const FilePath& file) const;
|
||||
@ -60,10 +59,10 @@ namespace Blah
|
||||
bool save_jpg(Stream& stream, int quality) const;
|
||||
|
||||
// gets the pixels from the given source rectangle
|
||||
void get_pixels(Color* dest, const Point& dest_pos, const Point& dest_size, RectI source_rect) const;
|
||||
void get_pixels(Color* dest, const Point& dest_pos, const Point& dest_size, Recti source_rect) const;
|
||||
|
||||
// gets a sub image from this image
|
||||
Image get_sub_image(const RectI& source_rect);
|
||||
Image get_sub_image(const Recti& source_rect);
|
||||
|
||||
private:
|
||||
|
||||
|
@ -1,8 +1,7 @@
|
||||
#pragma once
|
||||
#include <blah/images/image.h>
|
||||
#include <blah/numerics/color.h>
|
||||
#include <blah/numerics/rectI.h>
|
||||
#include <blah/numerics/point.h>
|
||||
#include <blah/numerics/spatial.h>
|
||||
#include <blah/containers/str.h>
|
||||
#include <blah/containers/vector.h>
|
||||
#include <blah/streams/bufferstream.h>
|
||||
@ -37,13 +36,13 @@ namespace Blah
|
||||
|
||||
// Packed frame rectangle.
|
||||
// This won't be set until after the packer has run.
|
||||
RectI frame;
|
||||
Recti frame;
|
||||
|
||||
// Packed position and size.
|
||||
// This won't be set until after the packer has run.
|
||||
RectI packed;
|
||||
Recti packed;
|
||||
|
||||
Entry(u64 id, const RectI& frame)
|
||||
Entry(u64 id, const Recti& frame)
|
||||
: memory_index(0)
|
||||
, id(id)
|
||||
, page(0)
|
||||
@ -83,7 +82,7 @@ namespace Blah
|
||||
void add(u64 id, const Image& bitmap);
|
||||
|
||||
// add a new entry
|
||||
void add(u64 id, const Image& bitmap, const RectI& source);
|
||||
void add(u64 id, const Image& bitmap, const Recti& source);
|
||||
|
||||
// add a new entry
|
||||
void add(u64 id, const FilePath& path);
|
||||
@ -104,13 +103,13 @@ namespace Blah
|
||||
struct Node
|
||||
{
|
||||
bool used;
|
||||
RectI rect;
|
||||
Recti rect;
|
||||
Node* right;
|
||||
Node* down;
|
||||
|
||||
Node();
|
||||
Node* Find(int w, int h);
|
||||
Node* Reset(const RectI& rect);
|
||||
Node* Reset(const Recti& rect);
|
||||
};
|
||||
|
||||
// whether the packer has any changes that require it to run again
|
||||
@ -123,6 +122,6 @@ namespace Blah
|
||||
Vector<Entry> m_entries;
|
||||
|
||||
// adds a new entry
|
||||
void add_entry(u64 id, int w, int h, const Color* pixels, const RectI& source);
|
||||
void add_entry(u64 id, int w, int h, const Color* pixels, const Recti& source);
|
||||
};
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <blah/common.h>
|
||||
#include <blah/numerics/vec2.h>
|
||||
#include <blah/numerics/spatial.h>
|
||||
#include <blah/containers/str.h>
|
||||
#include <blah/containers/stackvector.h>
|
||||
|
||||
@ -392,13 +392,13 @@ namespace Blah
|
||||
u64 timestamp[Input::max_mouse_buttons];
|
||||
|
||||
// mouse position in screen coordinates
|
||||
Vec2 screen_position;
|
||||
Vec2f screen_position;
|
||||
|
||||
// mouse position in pixel coordinates
|
||||
Vec2 draw_position;
|
||||
Vec2f draw_position;
|
||||
|
||||
// mouse position on the window
|
||||
Vec2 position;
|
||||
Vec2f position;
|
||||
|
||||
// mouse wheel value this frame
|
||||
Point wheel;
|
||||
@ -407,7 +407,7 @@ namespace Blah
|
||||
void on_press(MouseButton button);
|
||||
|
||||
// invokes a mouse movement
|
||||
void on_move(const Vec2& position, const Vec2& screen_position);
|
||||
void on_move(const Vec2f& position, const Vec2f& screen_position);
|
||||
|
||||
// invokes a key release
|
||||
void on_release(MouseButton button);
|
||||
@ -686,7 +686,7 @@ namespace Blah
|
||||
{}
|
||||
|
||||
// Current Value, -1 to 1
|
||||
Vec2 value() const;
|
||||
Vec2f value() const;
|
||||
|
||||
// Current value, either -1, 0, or 1
|
||||
Point sign() const;
|
||||
@ -735,14 +735,18 @@ namespace Blah
|
||||
// Input State for the previous frame
|
||||
extern InputState last_state;
|
||||
|
||||
// Key-Repeating intervals
|
||||
extern float repeat_delay;
|
||||
extern float repeat_interval;
|
||||
|
||||
// Gets the Mouse Position
|
||||
Vec2 mouse();
|
||||
Vec2f mouse();
|
||||
|
||||
// Gets the Draw Mouse Position (Mouse Position / Window Size * Draw Size)
|
||||
Vec2 mouse_draw();
|
||||
Vec2f mouse_draw();
|
||||
|
||||
// Gets the Mouse Position in Screen Coordinates
|
||||
Vec2 mouse_screen();
|
||||
Vec2f mouse_screen();
|
||||
|
||||
// Checks if the given Mouse Button is pressed
|
||||
bool pressed(MouseButton button);
|
||||
@ -765,6 +769,9 @@ namespace Blah
|
||||
// Checks if the keyboard key was released this frame
|
||||
bool released(Key key);
|
||||
|
||||
// Pressed or repeating on-interval
|
||||
bool repeating(Key key);
|
||||
|
||||
// Checks if the Left or Right Ctrl Key is down
|
||||
bool ctrl();
|
||||
|
||||
@ -780,6 +787,12 @@ namespace Blah
|
||||
// returns a string name of the button
|
||||
const char* name_of(Button button);
|
||||
|
||||
// gets the string contents of the clipboard
|
||||
const String& get_clipboard();
|
||||
|
||||
// sets the string contents of the clipboard
|
||||
void set_clipboard(const String& text);
|
||||
|
||||
// registers a new binding
|
||||
ButtonBindingRef register_binding(const ButtonBinding& binding);
|
||||
|
||||
|
@ -3,8 +3,6 @@
|
||||
|
||||
namespace Blah
|
||||
{
|
||||
struct Vec2;
|
||||
|
||||
namespace Calc
|
||||
{
|
||||
constexpr float PI = 3.141592653f;
|
||||
@ -14,20 +12,8 @@ namespace Blah
|
||||
constexpr float UP = PI / -2;
|
||||
constexpr float DOWN = PI / 2;
|
||||
|
||||
float rand_float(float min, float maxExc);
|
||||
|
||||
float rand_float(float maxExc);
|
||||
|
||||
int rand_int(int min, int maxExc);
|
||||
|
||||
int rand_int(int maxExc);
|
||||
|
||||
int rand_int();
|
||||
|
||||
float approach(float t, float target, float delta);
|
||||
|
||||
Vec2 approach(const Vec2& t, const Vec2& target, float delta);
|
||||
|
||||
float map(float t, float old_min, float old_max, float new_min, float new_max);
|
||||
|
||||
float clamped_map(float t, float old_min, float old_max, float new_min, float new_max);
|
||||
@ -40,8 +26,8 @@ namespace Blah
|
||||
|
||||
float abs(float x);
|
||||
|
||||
template<class T>
|
||||
T clamp(T value, T min, T max) { return value < min ? min : (value > max ? max : value); }
|
||||
template<class T, class TMin, class TMax>
|
||||
T clamp(T value, TMin min, TMax max) { return value < min ? static_cast<T>(min) : (value > max ? static_cast<T>(max) : value); }
|
||||
|
||||
template<class T>
|
||||
T min(T a, T b) { return (T)(a < b ? a : b); }
|
||||
|
@ -1,26 +0,0 @@
|
||||
#pragma once
|
||||
#include <blah/numerics/vec2.h>
|
||||
|
||||
namespace Blah
|
||||
{
|
||||
struct Circle
|
||||
{
|
||||
Vec2 center;
|
||||
float radius;
|
||||
|
||||
constexpr Circle()
|
||||
: center(), radius(0) {}
|
||||
|
||||
constexpr Circle(Vec2 center, float radius)
|
||||
: center(center), radius(radius) {}
|
||||
|
||||
constexpr Circle(float x, float y, float radius)
|
||||
: center(x, y), radius(radius) {}
|
||||
|
||||
constexpr void project(const Vec2& axis, float* min, float* max) const
|
||||
{
|
||||
*min = Vec2::dot(center - axis * radius, axis);
|
||||
*max = Vec2::dot(center + axis * radius, axis);
|
||||
}
|
||||
};
|
||||
}
|
@ -1,8 +1,7 @@
|
||||
#pragma once
|
||||
#include <blah/common.h>
|
||||
#include <blah/containers/str.h>
|
||||
#include <blah/numerics/vec3.h>
|
||||
#include <blah/numerics/vec4.h>
|
||||
#include <blah/numerics/spatial.h>
|
||||
|
||||
#define BLAH_HEX_VALUE(n) ((n >= '0' && n <= '9') ? (n - '0') : ((n >= 'A' && n <= 'F') ? (10 + n - 'A') : ((n >= 'a' && n <= 'f') ? (10 + n - 'a') : 0)))
|
||||
|
||||
@ -42,19 +41,19 @@ namespace Blah
|
||||
, b(b)
|
||||
, a(a) {}
|
||||
|
||||
constexpr Color(const Vec3& vec3)
|
||||
constexpr Color(const Vec3f& vec3)
|
||||
: r((int)(vec3.x * 255))
|
||||
, g((int)(vec3.y * 255))
|
||||
, b((int)(vec3.z * 255))
|
||||
, a((int)(255)) {}
|
||||
|
||||
constexpr Color(const Vec3& vec3, float alpha)
|
||||
constexpr Color(const Vec3f& vec3, float alpha)
|
||||
: r((int)(vec3.x* alpha * 255))
|
||||
, g((int)(vec3.y* alpha * 255))
|
||||
, b((int)(vec3.z* alpha * 255))
|
||||
, a((int)(alpha * 255)) {}
|
||||
|
||||
constexpr Color(const Vec4& vec4)
|
||||
constexpr Color(const Vec4f& vec4)
|
||||
: r((int)(vec4.x * 255))
|
||||
, g((int)(vec4.y * 255))
|
||||
, b((int)(vec4.z * 255))
|
||||
@ -99,15 +98,15 @@ namespace Blah
|
||||
String to_hex_rgb() const;
|
||||
|
||||
// Converts the Color to a Vec3 (RGB)
|
||||
constexpr Vec3 to_vec3() const
|
||||
constexpr Vec3f to_vec3() const
|
||||
{
|
||||
return Vec3(r / 255.0f, g / 255.0f, b / 255.0f);
|
||||
return Vec3f(r / 255.0f, g / 255.0f, b / 255.0f);
|
||||
}
|
||||
|
||||
// Converts the Color to a Vec4 (RGBA)
|
||||
constexpr Vec4 to_vec4() const
|
||||
constexpr Vec4f to_vec4() const
|
||||
{
|
||||
return Vec4(r / 255.0f, g / 255.0f, b / 255.0f, a / 255.0f);
|
||||
return Vec4f(r / 255.0f, g / 255.0f, b / 255.0f, a / 255.0f);
|
||||
}
|
||||
|
||||
// Convers the Color to a u32
|
||||
@ -120,6 +119,15 @@ namespace Blah
|
||||
(u32)a;
|
||||
}
|
||||
|
||||
// Convers the Color to a u32
|
||||
constexpr u32 to_rgb() const
|
||||
{
|
||||
return
|
||||
((u32)r << 16) |
|
||||
((u32)g << 8) |
|
||||
(u32)b;
|
||||
}
|
||||
|
||||
// Returns a RGBA Color representation of the integer value
|
||||
static constexpr Color from_rgba(u32 value)
|
||||
{
|
||||
@ -198,16 +206,6 @@ namespace Blah
|
||||
static const Color purple;
|
||||
static const Color teal;
|
||||
};
|
||||
|
||||
inline const Color Color::transparent = Color(0, 0, 0, 0);
|
||||
inline const Color Color::white = Color(255, 255, 255, 255);
|
||||
inline const Color Color::black = Color(0, 0, 0, 255);
|
||||
inline const Color Color::red = Color(255, 0, 0, 255);
|
||||
inline const Color Color::green = Color(0, 255, 0, 255);
|
||||
inline const Color Color::blue = Color(0, 0, 255, 255);
|
||||
inline const Color Color::yellow = Color(255, 255, 0, 255);
|
||||
inline const Color Color::purple = Color(255, 0, 255, 255);
|
||||
inline const Color Color::teal = Color(0, 255, 255, 255);
|
||||
}
|
||||
|
||||
#undef BLAH_HEX_VALUE
|
||||
|
@ -1,50 +0,0 @@
|
||||
#pragma once
|
||||
#include <blah/numerics/vec2.h>
|
||||
|
||||
namespace Blah
|
||||
{
|
||||
struct Rect;
|
||||
|
||||
struct Line
|
||||
{
|
||||
Vec2 a;
|
||||
Vec2 b;
|
||||
|
||||
constexpr Line()
|
||||
: a(), b() {}
|
||||
|
||||
constexpr Line(const Vec2& a, const Vec2& b)
|
||||
: a(a), b(b) {}
|
||||
|
||||
constexpr Line(float x0, float y0, float x1, float y1)
|
||||
: a(x0, y0), b(x1, y1) {}
|
||||
|
||||
Rect bounds() const;
|
||||
|
||||
Vec2 closest_point(const Vec2& pt) const;
|
||||
bool intersects(const Rect& rect) const;
|
||||
bool intersects(const Rect& rect, Vec2* out_intersection_point) const;
|
||||
bool intersects(const Line& line) const;
|
||||
bool intersects(const Line& line, Vec2* out_intersection_point) const;
|
||||
|
||||
constexpr void project(const Vec2& axis, float* min, float* max) const
|
||||
{
|
||||
float dot = a.x * axis.x + a.y * axis.y;
|
||||
*min = dot;
|
||||
*max = dot;
|
||||
dot = b.x * axis.x + b.y * axis.y;
|
||||
*min = dot < *min ? dot : *min;
|
||||
*max = dot > *max ? dot : *max;
|
||||
}
|
||||
|
||||
constexpr Line operator +(const Vec2& rhs) const
|
||||
{
|
||||
return Line(a + rhs, b + rhs);
|
||||
}
|
||||
|
||||
constexpr Line operator -(const Vec2& rhs) const
|
||||
{
|
||||
return Line(a - rhs, b - rhs);
|
||||
}
|
||||
};
|
||||
}
|
@ -1,133 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
namespace Blah
|
||||
{
|
||||
struct Vec2;
|
||||
|
||||
struct Mat3x2
|
||||
{
|
||||
float m11;
|
||||
float m12;
|
||||
float m21;
|
||||
float m22;
|
||||
float m31;
|
||||
float m32;
|
||||
|
||||
constexpr Mat3x2()
|
||||
: m11(0), m12(0), m21(0), m22(0), m31(0), m32(0) {}
|
||||
|
||||
constexpr Mat3x2(float m11, float m12, float m21, float m22, float m31, float m32)
|
||||
: m11(m11), m12(m12), m21(m21), m22(m22), m31(m31), m32(m32) {}
|
||||
|
||||
static const Mat3x2 identity;
|
||||
|
||||
constexpr Mat3x2 invert() const
|
||||
{
|
||||
auto det = (m11 * m22) - (m21 * m12);
|
||||
auto invDet = 1.0f / det;
|
||||
|
||||
return Mat3x2
|
||||
{
|
||||
m22 * invDet,
|
||||
-m12 * invDet,
|
||||
-m21 * invDet,
|
||||
m11 * invDet,
|
||||
(m21 * m32 - m31 * m22) * invDet,
|
||||
(m31 * m12 - m11 * m32) * invDet
|
||||
};
|
||||
}
|
||||
|
||||
float scaling_factor() const;
|
||||
|
||||
static Mat3x2 create_translation(const Vec2& position);
|
||||
|
||||
static constexpr Mat3x2 create_translation(float x, float y)
|
||||
{
|
||||
return Mat3x2(1, 0, 0, 1, x, y);
|
||||
}
|
||||
|
||||
static constexpr Mat3x2 create_scale(float scale)
|
||||
{
|
||||
return Mat3x2(scale, 0, 0, scale, 0, 0);
|
||||
}
|
||||
|
||||
static Mat3x2 create_scale(float x, float y)
|
||||
{
|
||||
return Mat3x2(x, 0, 0, y, 0, 0);
|
||||
}
|
||||
|
||||
static Mat3x2 create_scale(const Vec2& scale);
|
||||
static Mat3x2 create_scale(float scale, const Vec2& center_point);
|
||||
static Mat3x2 create_scale(const Vec2& scale, const Vec2& center_point);
|
||||
static Mat3x2 create_scale(float scale_x, float scale_y, const Vec2& center_point);
|
||||
|
||||
static Mat3x2 create_rotation(float radians);
|
||||
|
||||
static Mat3x2 create_transform(const Vec2& position, const Vec2& origin, const Vec2& scale, float rotation);
|
||||
|
||||
static constexpr Mat3x2 add(const Mat3x2& a, const Mat3x2& b)
|
||||
{
|
||||
return Mat3x2(
|
||||
a.m11 + b.m11,
|
||||
a.m12 + b.m12,
|
||||
a.m21 + b.m21,
|
||||
a.m22 + b.m22,
|
||||
a.m31 + b.m31,
|
||||
a.m32 + b.m32);
|
||||
}
|
||||
|
||||
static constexpr Mat3x2 subtract(const Mat3x2& a, const Mat3x2& b)
|
||||
{
|
||||
return Mat3x2(
|
||||
a.m11 - b.m11,
|
||||
a.m12 - b.m12,
|
||||
a.m21 - b.m21,
|
||||
a.m22 - b.m22,
|
||||
a.m31 - b.m31,
|
||||
a.m32 - b.m32);
|
||||
}
|
||||
|
||||
static constexpr Mat3x2 multiply(const Mat3x2& a, const Mat3x2& b)
|
||||
{
|
||||
return Mat3x2(a.m11 * b.m11 + a.m12 * b.m21,
|
||||
a.m11 * b.m12 + a.m12 * b.m22,
|
||||
a.m21 * b.m11 + a.m22 * b.m21,
|
||||
a.m21 * b.m12 + a.m22 * b.m22,
|
||||
a.m31 * b.m11 + a.m32 * b.m21 + b.m31,
|
||||
a.m31 * b.m12 + a.m32 * b.m22 + b.m32);
|
||||
}
|
||||
|
||||
constexpr Mat3x2 operator *(const Mat3x2& rhs) const
|
||||
{
|
||||
return multiply(*this, rhs);
|
||||
}
|
||||
|
||||
constexpr Mat3x2 operator +(const Mat3x2& rhs) const
|
||||
{
|
||||
return add(*this, rhs);
|
||||
}
|
||||
|
||||
constexpr Mat3x2 operator -(const Mat3x2& rhs) const
|
||||
{
|
||||
return subtract(*this, rhs);
|
||||
}
|
||||
|
||||
constexpr Mat3x2& operator *=(const Mat3x2& rhs)
|
||||
{
|
||||
*this = multiply(*this, rhs);
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr bool operator==(const Mat3x2& rhs)
|
||||
{
|
||||
return m11 == rhs.m11 && m12 == rhs.m12 && m21 == rhs.m21 && m22 == rhs.m22 && m31 == rhs.m31 && m32 == rhs.m32;
|
||||
}
|
||||
|
||||
constexpr bool operator!=(const Mat3x2& rhs)
|
||||
{
|
||||
return m11 != rhs.m11 || m12 != rhs.m12 || m21 != rhs.m21 || m22 != rhs.m22 || m31 != rhs.m31 || m32 != rhs.m32;
|
||||
}
|
||||
};
|
||||
|
||||
inline const Mat3x2 Mat3x2::identity = Mat3x2(1, 0, 0, 1, 0, 0);
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
#pragma once
|
||||
#include "vec3.h"
|
||||
|
||||
namespace Blah
|
||||
{
|
||||
struct Mat4x4
|
||||
{
|
||||
float m11;
|
||||
float m12;
|
||||
float m13;
|
||||
float m14;
|
||||
|
||||
float m21;
|
||||
float m22;
|
||||
float m23;
|
||||
float m24;
|
||||
|
||||
float m31;
|
||||
float m32;
|
||||
float m33;
|
||||
float m34;
|
||||
|
||||
float m41;
|
||||
float m42;
|
||||
float m43;
|
||||
float m44;
|
||||
|
||||
Mat4x4();
|
||||
Mat4x4(
|
||||
float m11, float m12, float m13, float m14,
|
||||
float m21, float m22, float m23, float m24,
|
||||
float m31, float m32, float m33, float m34,
|
||||
float m41, float m42, float m43, float m44);
|
||||
|
||||
|
||||
static const Mat4x4 identity;
|
||||
|
||||
static Mat4x4 create_ortho(float width, float height, float z_near_plane, float z_far_plane);
|
||||
static Mat4x4 create_ortho_offcenter(float left, float right, float bottom, float top, float z_near_plane, float z_far_plane);
|
||||
static Mat4x4 create_perspective(float field_of_view, float ratio, float z_near_plane, float z_far_plane);
|
||||
static Mat4x4 create_translation(float x, float y, float z);
|
||||
static Mat4x4 create_scale(float x, float y, float z);
|
||||
static Mat4x4 create_lookat(Vec3 position, Vec3 target, Vec3 up);
|
||||
|
||||
|
||||
Mat4x4 operator* (const Mat4x4& rhs);
|
||||
};
|
||||
}
|
@ -1,117 +0,0 @@
|
||||
#pragma once
|
||||
#include <blah/numerics/calc.h>
|
||||
|
||||
namespace Blah
|
||||
{
|
||||
struct Point
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
|
||||
constexpr Point()
|
||||
: x(0), y(0) {}
|
||||
|
||||
constexpr Point(int x, int y)
|
||||
: x(x), y(y) {}
|
||||
|
||||
constexpr Point operator +(const Point rhs) const
|
||||
{
|
||||
return Point(x + rhs.x, y + rhs.y);
|
||||
}
|
||||
|
||||
constexpr Point operator -(const Point rhs) const
|
||||
{
|
||||
return Point(x - rhs.x, y - rhs.y);
|
||||
}
|
||||
|
||||
constexpr Point operator /(const int rhs) const
|
||||
{
|
||||
return Point(x / rhs, y / rhs);
|
||||
}
|
||||
|
||||
constexpr Point operator *(const int rhs) const
|
||||
{
|
||||
return Point(x * rhs, y * rhs);
|
||||
}
|
||||
|
||||
constexpr Point operator -() const
|
||||
{
|
||||
return Point(-x, -y);
|
||||
}
|
||||
|
||||
|
||||
constexpr Point& operator +=(const Point& rhs)
|
||||
{
|
||||
x += rhs.x; y += rhs.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Point& operator -=(const Point& rhs)
|
||||
{
|
||||
x -= rhs.x; y -= rhs.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Point& operator /=(const Point& rhs)
|
||||
{
|
||||
x /= rhs.x; y /= rhs.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Point& operator *=(const Point& rhs)
|
||||
{
|
||||
x *= rhs.x; y *= rhs.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Point& operator /=(int rhs)
|
||||
{
|
||||
x /= rhs; y /= rhs;
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Point& operator *=(int rhs)
|
||||
{
|
||||
x *= rhs; y *= rhs;
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr bool operator ==(const Point& rhs) const
|
||||
{
|
||||
return x == rhs.x && y == rhs.y;
|
||||
}
|
||||
|
||||
constexpr bool operator !=(const Point& rhs) const
|
||||
{
|
||||
return x != rhs.x || y != rhs.y;
|
||||
}
|
||||
|
||||
float length() const
|
||||
{
|
||||
return Calc::sqrt((float)(x * x + y * y));
|
||||
}
|
||||
|
||||
constexpr int length_squared() const
|
||||
{
|
||||
return x * x + y * y;
|
||||
}
|
||||
|
||||
static const Point unitX;
|
||||
static const Point unitY;
|
||||
static const Point right;
|
||||
static const Point up;
|
||||
static const Point down;
|
||||
static const Point left;
|
||||
static const Point zero;
|
||||
static const Point one;
|
||||
};
|
||||
|
||||
inline const Point Point::unitX = Point(1, 0);
|
||||
inline const Point Point::unitY = Point(0, 1);
|
||||
inline const Point Point::right = Point(1, 0);
|
||||
inline const Point Point::up = Point(0, -1);
|
||||
inline const Point Point::down = Point(0, 1);
|
||||
inline const Point Point::left = Point(-1, 0);
|
||||
inline const Point Point::zero = Point(0, 0);
|
||||
inline const Point Point::one = Point(1, 1);
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
#pragma once
|
||||
#include <blah/numerics/vec2.h>
|
||||
|
||||
namespace Blah
|
||||
{
|
||||
struct Quad
|
||||
{
|
||||
Vec2 a;
|
||||
Vec2 b;
|
||||
Vec2 c;
|
||||
Vec2 d;
|
||||
|
||||
constexpr Quad()
|
||||
: a(), b(), c(), d() {}
|
||||
|
||||
constexpr Quad(const Vec2& a, const Vec2& b, const Vec2& c, const Vec2& d)
|
||||
: a(a), b(b), c(c), d(d) {}
|
||||
|
||||
constexpr void project(const Vec2& axis, float* min, float* max) const
|
||||
{
|
||||
float dot = Vec2::dot(a, axis);
|
||||
*min = dot;
|
||||
*max = dot;
|
||||
dot = Vec2::dot(b, axis);
|
||||
*min = dot < *min ? dot : *min;
|
||||
*max = dot > *max ? dot : *max;
|
||||
dot = Vec2::dot(c, axis);
|
||||
*min = dot < *min ? dot : *min;
|
||||
*max = dot > *max ? dot : *max;
|
||||
dot = Vec2::dot(d, axis);
|
||||
*min = dot < *min ? dot : *min;
|
||||
*max = dot > *max ? dot : *max;
|
||||
}
|
||||
};
|
||||
}
|
@ -1,173 +0,0 @@
|
||||
#pragma once
|
||||
#include <blah/numerics/point.h>
|
||||
#include <blah/numerics/vec2.h>
|
||||
#include <blah/numerics/rectI.h>
|
||||
#include <blah/numerics/line.h>
|
||||
#include <blah/numerics/mat3x2.h>
|
||||
|
||||
namespace Blah
|
||||
{
|
||||
struct Rect
|
||||
{
|
||||
float x;
|
||||
float y;
|
||||
float w;
|
||||
float h;
|
||||
|
||||
constexpr Rect()
|
||||
: x(0), y(0), w(0), h(0) {}
|
||||
|
||||
constexpr Rect(float x, float y, float w, float h)
|
||||
: x(x), y(y), w(w), h(h) {}
|
||||
|
||||
constexpr Rect(Vec2 pos, Vec2 size)
|
||||
: x(pos.x), y(pos.y), w(size.x), h(size.y) {}
|
||||
|
||||
constexpr Rect(const RectI& r)
|
||||
: x(static_cast<float>(r.x)), y(static_cast<float>(r.y)), w(static_cast<float>(r.w)), h(static_cast<float>(r.h)) {}
|
||||
|
||||
constexpr float left() const { return x; }
|
||||
constexpr float right() const { return x + w; }
|
||||
constexpr float top() const { return y; }
|
||||
constexpr float bottom() const { return y + h; }
|
||||
|
||||
constexpr Vec2 center() const { return Vec2(x + w / 2, y + h / 2); }
|
||||
constexpr float center_x() const { return x + w / 2; }
|
||||
constexpr float center_y() const { return y + h / 2; }
|
||||
|
||||
constexpr Vec2 top_left() const { return Vec2(x, y); }
|
||||
constexpr Vec2 top_right() const { return Vec2(x + w, y); }
|
||||
constexpr Vec2 bottom_right() const { return Vec2(x + w, y + h); }
|
||||
constexpr Vec2 bottom_left() const { return Vec2(x, y + h); }
|
||||
|
||||
constexpr Vec2 center_left() const { return Vec2(x, y + h / 2); }
|
||||
constexpr Vec2 center_right() const { return Vec2(x + w, y + h / 2); }
|
||||
constexpr Vec2 middle_top() const { return Vec2(x + w / 2, y); }
|
||||
constexpr Vec2 middle_bottom() const { return Vec2(x + w / 2, y + h); }
|
||||
|
||||
constexpr Line left_line() const { return Line(left(), top(), left(), bottom()); }
|
||||
constexpr Line right_line() const { return Line(right(), top(), right(), bottom()); }
|
||||
constexpr Line top_line() const { return Line(left(), top(), right(), top()); }
|
||||
constexpr Line bottom_line() const { return Line(left(), bottom(), right(), bottom()); }
|
||||
|
||||
constexpr bool contains(const Point& pt) const
|
||||
{
|
||||
return pt.x >= x && pt.x < x + w && pt.y >= y && pt.y < y + h;
|
||||
}
|
||||
|
||||
constexpr bool contains(const Vec2& pt) const
|
||||
{
|
||||
return pt.x >= x && pt.x < x + w && pt.y >= y && pt.y < y + h;
|
||||
}
|
||||
|
||||
constexpr bool overlaps(const Rect& rect) const
|
||||
{
|
||||
return x + w >= rect.x && y + h >= rect.y && x < rect.x + rect.w && y < rect.y + rect.h;
|
||||
}
|
||||
|
||||
Rect overlap_rect(const Rect& other) const;
|
||||
|
||||
bool intersects(const Line& line) const;
|
||||
bool intersects(const Line& line, Vec2* out_intersection_point) const;
|
||||
bool intersects(const Vec2& line_from, const Vec2& line_to) const;
|
||||
bool intersects(const Vec2& line_from, const Vec2& line_to, Vec2* out_intersection_point) const;
|
||||
|
||||
Vec2 intersection_point(const Line& line) const;
|
||||
Vec2 intersection_point(const Vec2& line_from, const Vec2& line_to) const;
|
||||
|
||||
constexpr Rect scale(float s) const
|
||||
{
|
||||
return Rect(x * s, y * s, w * s, h * s);
|
||||
}
|
||||
|
||||
constexpr Rect scale(float sx, float sy) const
|
||||
{
|
||||
return Rect(x * sx, y * sy, w * sx, h * sy);
|
||||
}
|
||||
|
||||
constexpr Rect inflate(float amount) const
|
||||
{
|
||||
return Rect(x - amount, y - amount, w + amount * 2, h + amount * 2);
|
||||
}
|
||||
|
||||
// Rect Sectors:
|
||||
// 0101 0100 0110
|
||||
// 0001 0000 0010
|
||||
// 1001 1000 1010
|
||||
// 0000 = inside rectangle, all others refer to sectors relative to the rectangle
|
||||
constexpr char get_sector(const Vec2& pt) const
|
||||
{
|
||||
char h = 0;
|
||||
if (pt.x < left())
|
||||
h = 0b0001;
|
||||
else if (pt.x >= right())
|
||||
h = 0b0010;
|
||||
|
||||
char v = 0;
|
||||
if (pt.y < top())
|
||||
v = 0b0100;
|
||||
else if (pt.y >= bottom())
|
||||
v = 0b1000;
|
||||
|
||||
return h | v;
|
||||
}
|
||||
|
||||
constexpr Rect operator+(const Vec2& rhs) const
|
||||
{
|
||||
return Rect(x + rhs.x, y + rhs.y, w, h);
|
||||
}
|
||||
|
||||
constexpr Rect operator-(const Vec2& rhs) const
|
||||
{
|
||||
return Rect(x - rhs.x, y - rhs.y, w, h);
|
||||
}
|
||||
|
||||
constexpr Rect& operator+=(const Vec2& rhs)
|
||||
{
|
||||
x += rhs.x; y += rhs.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Rect& operator-=(const Vec2& rhs)
|
||||
{
|
||||
x -= rhs.x; y -= rhs.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr bool operator==(const Rect& rhs) const
|
||||
{
|
||||
return x == rhs.x && y == rhs.y && w == rhs.w && h == rhs.h;
|
||||
}
|
||||
|
||||
constexpr bool operator!=(const Rect& rhs) const
|
||||
{
|
||||
return x != rhs.x || y != rhs.y || w != rhs.w || h != rhs.h;
|
||||
}
|
||||
|
||||
static constexpr Rect transform(const Rect& rect, const Mat3x2& matrix)
|
||||
{
|
||||
return Rect(
|
||||
(rect.x * matrix.m11) + (rect.y * matrix.m21) + matrix.m31,
|
||||
(rect.x * matrix.m12) + (rect.y * matrix.m22) + matrix.m32,
|
||||
(rect.w * matrix.m11) + (rect.h * matrix.m21),
|
||||
(rect.w * matrix.m12) + (rect.h * matrix.m22));
|
||||
}
|
||||
|
||||
static constexpr Rect transform(float x, float y, float w, float h, const Mat3x2& matrix)
|
||||
{
|
||||
return Rect(
|
||||
(x * matrix.m11) + (y * matrix.m21) + matrix.m31,
|
||||
(x * matrix.m12) + (y * matrix.m22) + matrix.m32,
|
||||
(w * matrix.m11) + (h * matrix.m21),
|
||||
(w * matrix.m12) + (h * matrix.m22));
|
||||
}
|
||||
|
||||
static constexpr Rect from_points(Vec2& from, Vec2& to)
|
||||
{
|
||||
auto min = Vec2(from.x < to.x ? from.x : to.x, from.y < to.y ? from.y : to.y);
|
||||
auto max = Vec2(from.x > to.x ? from.x : to.x, from.y > to.y ? from.y : to.y);
|
||||
|
||||
return Rect(min.x, min.y, max.x - min.x, max.y - min.y);
|
||||
}
|
||||
};
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
namespace Blah
|
||||
{
|
||||
struct Point;
|
||||
struct Rect;
|
||||
struct Vec2;
|
||||
|
||||
struct RectI
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
int w;
|
||||
int h;
|
||||
|
||||
RectI();
|
||||
RectI(int rx, int ry, int rw, int rh);
|
||||
RectI(Point pos, Point size);
|
||||
|
||||
int left() const;
|
||||
int right() const;
|
||||
int top() const;
|
||||
int bottom() const;
|
||||
int center_x() const;
|
||||
int center_y() const;
|
||||
|
||||
Point center() const;
|
||||
Point top_left() const;
|
||||
Point top_right() const;
|
||||
Point bottom_left() const;
|
||||
Point bottom_right() const;
|
||||
|
||||
bool overlaps(const RectI& other) const;
|
||||
RectI overlap_rect(const Rect& against) const;
|
||||
|
||||
bool contains(const Point& pt) const;
|
||||
bool contains(const Vec2& pt) const;
|
||||
|
||||
/*
|
||||
Rect Sectors:
|
||||
0101 0100 0110
|
||||
0001 0000 0010
|
||||
1001 1000 1010
|
||||
0000 = inside rectangle, all others refer to sectors relative to the rectangle
|
||||
*/
|
||||
char get_sector(const Point& pt) const;
|
||||
char get_sector(const Vec2& pt) const;
|
||||
|
||||
bool operator==(const RectI& rhs) const;
|
||||
bool operator!=(const RectI& rhs) const;
|
||||
|
||||
RectI operator+(const Point& rhs) const;
|
||||
RectI operator-(const Point& rhs) const;
|
||||
RectI operator*(const int& rhs) const;
|
||||
RectI operator/(const int& rhs) const;
|
||||
RectI& operator+=(const Point& rhs);
|
||||
RectI& operator-=(const Point& rhs);
|
||||
};
|
||||
}
|
1300
include/blah/numerics/spatial.h
Normal file
1300
include/blah/numerics/spatial.h
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,312 +0,0 @@
|
||||
#pragma once
|
||||
#include <blah/numerics/point.h>
|
||||
#include <blah/numerics/calc.h>
|
||||
#include <blah/numerics/mat3x2.h>
|
||||
|
||||
namespace Blah
|
||||
{
|
||||
struct Vec2
|
||||
{
|
||||
float x;
|
||||
float y;
|
||||
|
||||
constexpr Vec2()
|
||||
: x(0), y(0) {}
|
||||
|
||||
constexpr Vec2(float x, float y)
|
||||
: x(x), y(y) {}
|
||||
|
||||
constexpr Vec2(int x, float y)
|
||||
: x(static_cast<float>(x)), y(y) {}
|
||||
|
||||
constexpr Vec2(float x, int y)
|
||||
: x(x), y(static_cast<float>(y)) {}
|
||||
|
||||
constexpr Vec2(int x, int y)
|
||||
: x(static_cast<float>(x)), y(static_cast<float>(y)) {}
|
||||
|
||||
constexpr Vec2(const Point& p)
|
||||
: x(static_cast<float>(p.x)), y(static_cast<float>(p.y)) {}
|
||||
|
||||
constexpr Vec2 operator +(const Vec2 rhs) const
|
||||
{
|
||||
return Vec2(x + rhs.x, y + rhs.y);
|
||||
}
|
||||
|
||||
constexpr Vec2 operator -(const Vec2 rhs) const
|
||||
{
|
||||
return Vec2(x - rhs.x, y - rhs.y);
|
||||
}
|
||||
|
||||
constexpr Vec2 operator /(const float rhs) const
|
||||
{
|
||||
return Vec2(x / rhs, y / rhs);
|
||||
}
|
||||
|
||||
constexpr Vec2 operator *(const float rhs) const
|
||||
{
|
||||
return Vec2(x * rhs, y * rhs);
|
||||
}
|
||||
|
||||
constexpr Vec2 operator -() const
|
||||
{
|
||||
return Vec2(-x, -y);
|
||||
}
|
||||
|
||||
constexpr Vec2& operator +=(const Vec2& rhs)
|
||||
{
|
||||
x += rhs.x; y += rhs.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Vec2& operator -=(const Vec2& rhs)
|
||||
{
|
||||
x -= rhs.x; y -= rhs.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Vec2& operator /=(const Vec2& rhs)
|
||||
{
|
||||
x /= rhs.x; y /= rhs.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Vec2& operator *=(const Vec2& rhs)
|
||||
{
|
||||
x *= rhs.x; y *= rhs.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Vec2& operator /=(float rhs)
|
||||
{
|
||||
x /= rhs; y /= rhs;
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Vec2& operator *=(float rhs)
|
||||
{
|
||||
x *= rhs; y *= rhs;
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr bool operator ==(const Vec2& rhs) const
|
||||
{
|
||||
return x == rhs.x && y == rhs.y;
|
||||
}
|
||||
|
||||
constexpr bool operator !=(const Vec2& rhs) const
|
||||
{
|
||||
return x != rhs.x || y != rhs.y;
|
||||
}
|
||||
|
||||
// Returns the absolute value of the Vector
|
||||
constexpr Vec2 abs() const
|
||||
{
|
||||
return Vec2(x < 0 ? -x : x, y < 0 ? -y : 0);
|
||||
}
|
||||
|
||||
// Returns the Normalized Vector
|
||||
// If the length is 0, the resulting Vector is 0,0
|
||||
Vec2 normal() const
|
||||
{
|
||||
if (x == 0 && y == 0)
|
||||
return Vec2(0, 0);
|
||||
|
||||
const float len = Calc::sqrt((x * x) + (y * y));
|
||||
return Vec2(x / len, y / len);
|
||||
}
|
||||
|
||||
// Rotates the Vector 90 degrees right (-y, x)
|
||||
constexpr Vec2 turn_right() const
|
||||
{
|
||||
return Vec2(-y, x);
|
||||
}
|
||||
|
||||
// Rotates the Vector 90 degrees left (y, -x)
|
||||
constexpr Vec2 turn_left() const
|
||||
{
|
||||
return Vec2(y, -x);
|
||||
}
|
||||
|
||||
// Returns the length of the Vector
|
||||
float length() const
|
||||
{
|
||||
return Calc::sqrt((x * x) + (y * y));
|
||||
}
|
||||
|
||||
// Returns the squared length of the Vector
|
||||
constexpr float length_squared() const
|
||||
{
|
||||
return (x * x) + (y * y);
|
||||
}
|
||||
|
||||
// Gets the perpendicular Vector (-y, x)
|
||||
constexpr Vec2 perpendicular() const
|
||||
{
|
||||
return Vec2(-y, x);
|
||||
}
|
||||
|
||||
// Gets the angle, in radians, of the Vector
|
||||
float angle() const
|
||||
{
|
||||
return Calc::atan2(y, x);
|
||||
}
|
||||
|
||||
// Calculates the Dot Product between two vectors
|
||||
static constexpr float dot(Vec2 a, Vec2 b)
|
||||
{
|
||||
return (a.x * b.x + a.y * b.y);
|
||||
}
|
||||
|
||||
// Calculates the Dot Product between two vectors
|
||||
static constexpr float dot(float x, float y, Vec2 b)
|
||||
{
|
||||
return (x * b.x + y * b.y);
|
||||
}
|
||||
|
||||
// Calculates the Dot Product between two vectors
|
||||
static constexpr float dot(float x1, float y1, float x2, float y2)
|
||||
{
|
||||
return (x1 * x2 + y1 * y2);
|
||||
}
|
||||
|
||||
// Transforms a Vector by the given Matrix
|
||||
static constexpr Vec2 transform(const Vec2& vec, const Mat3x2& matrix)
|
||||
{
|
||||
return Vec2(
|
||||
(vec.x * matrix.m11) + (vec.y * matrix.m21) + matrix.m31,
|
||||
(vec.x * matrix.m12) + (vec.y * matrix.m22) + matrix.m32);
|
||||
}
|
||||
|
||||
// Transforms a Vector by the given Matrix
|
||||
static constexpr Vec2 transform(float x, float y, const Mat3x2& matrix)
|
||||
{
|
||||
return Vec2(
|
||||
(x * matrix.m11) + (y * matrix.m21) + matrix.m31,
|
||||
(x * matrix.m12) + (y * matrix.m22) + matrix.m32);
|
||||
}
|
||||
|
||||
// Transforms a Vector Normal by the given Matrix
|
||||
static constexpr Vec2 transform_normal(const Vec2& vec, const Mat3x2& matrix)
|
||||
{
|
||||
return Vec2(
|
||||
vec.x * matrix.m11 + vec.y * matrix.m21,
|
||||
vec.x * matrix.m12 + vec.y * matrix.m22);
|
||||
}
|
||||
|
||||
// Transforms a Vector Normal by the given Matrix
|
||||
static constexpr Vec2 transform_normal(float x, float y, const Mat3x2& matrix)
|
||||
{
|
||||
return Vec2(
|
||||
x * matrix.m11 + y * matrix.m21,
|
||||
x * matrix.m12 + y * matrix.m22);
|
||||
}
|
||||
|
||||
// Calculates a Vector value from the given radians
|
||||
static Vec2 from_angle(float radians, float length = 1.0f)
|
||||
{
|
||||
return Vec2(
|
||||
Calc::cos(radians) * length,
|
||||
Calc::sin(radians) * length);
|
||||
}
|
||||
|
||||
// Lerps between two Vectors
|
||||
static constexpr Vec2 lerp(Vec2 a, Vec2 b, float t)
|
||||
{
|
||||
if (t == 0)
|
||||
return a;
|
||||
else if (t == 1)
|
||||
return b;
|
||||
else
|
||||
return a + (b - a) * t;
|
||||
}
|
||||
|
||||
// Lerps between two Vectors along a Bezier curve
|
||||
static constexpr Vec2 lerp_bezier(Vec2 a, Vec2 b, Vec2 end, float t)
|
||||
{
|
||||
return lerp(lerp(a, b, t), lerp(b, end, t), t);
|
||||
}
|
||||
|
||||
// Lerps between two Vectors along a Bezier curve
|
||||
static constexpr Vec2 lerp_bezier(Vec2 a, Vec2 b, Vec2 c, Vec2 end, float t)
|
||||
{
|
||||
return lerp_bezier(lerp(a, b, t), lerp(b, c, t), lerp(c, end, t), t);
|
||||
}
|
||||
|
||||
// Reflects a vector along the given Normal
|
||||
static constexpr Vec2 reflect(const Vec2& vector, const Vec2& normal)
|
||||
{
|
||||
const float dot = vector.x * normal.x + vector.y * normal.y;
|
||||
|
||||
return Vec2(
|
||||
vector.x - 2.0f * dot * normal.x,
|
||||
vector.y - 2.0f * dot * normal.y);
|
||||
}
|
||||
|
||||
// Gets the minimum between two vectors
|
||||
static constexpr Vec2 min(const Vec2& a, const Vec2& b)
|
||||
{
|
||||
return Vec2(
|
||||
a.x < b.x ? a.x : b.x,
|
||||
a.y < b.y ? a.y : b.y);
|
||||
}
|
||||
|
||||
// Gets the maximum between two vectors
|
||||
static constexpr Vec2 max(const Vec2& a, const Vec2& b)
|
||||
{
|
||||
return Vec2(
|
||||
a.x > b.x ? a.x : b.x,
|
||||
a.y > b.y ? a.y : b.y);
|
||||
}
|
||||
|
||||
// (1, 0)
|
||||
static const Vec2 unit_x;
|
||||
|
||||
// (0, 1)
|
||||
static const Vec2 unit_y;
|
||||
|
||||
// (1, 0)
|
||||
static const Vec2 right;
|
||||
|
||||
// (0, -1)
|
||||
static const Vec2 up;
|
||||
|
||||
// (0, 1)
|
||||
static const Vec2 down;
|
||||
|
||||
// (-1, 0)
|
||||
static const Vec2 left;
|
||||
|
||||
// (0, 0)
|
||||
static const Vec2 zero;
|
||||
|
||||
// (1, 1)
|
||||
static const Vec2 one;
|
||||
|
||||
// (0.707, -0.707)
|
||||
static const Vec2 up_right;
|
||||
|
||||
// (-0.707, -0.707)
|
||||
static const Vec2 up_left;
|
||||
|
||||
// (0.707, 0.707)
|
||||
static const Vec2 down_right;
|
||||
|
||||
// (-0.707, 0.707)
|
||||
static const Vec2 down_left;
|
||||
};
|
||||
|
||||
inline const Vec2 Vec2::unit_x = Vec2(1, 0);
|
||||
inline const Vec2 Vec2::unit_y = Vec2(0, 1);
|
||||
inline const Vec2 Vec2::right = Vec2(1, 0);
|
||||
inline const Vec2 Vec2::up = Vec2(0, -1);
|
||||
inline const Vec2 Vec2::down = Vec2(0, 1);
|
||||
inline const Vec2 Vec2::left = Vec2(-1, 0);
|
||||
inline const Vec2 Vec2::zero = Vec2(0, 0);
|
||||
inline const Vec2 Vec2::one = Vec2(1, 1);
|
||||
inline const Vec2 Vec2::up_right = Vec2(0.70710678118f, -0.70710678118f);
|
||||
inline const Vec2 Vec2::up_left = Vec2(-0.70710678118f, -0.70710678118f);
|
||||
inline const Vec2 Vec2::down_right = Vec2(0.70710678118f, 0.70710678118f);
|
||||
inline const Vec2 Vec2::down_left = Vec2(-0.70710678118f, 0.70710678118f);
|
||||
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
#pragma once
|
||||
#include "calc.h"
|
||||
|
||||
namespace Blah
|
||||
{
|
||||
struct Vec3
|
||||
{
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
|
||||
constexpr Vec3()
|
||||
: x(0), y(0), z(0) {}
|
||||
|
||||
constexpr Vec3(float x, float y, float z)
|
||||
: x(x), y(y), z(z) {}
|
||||
|
||||
constexpr Vec3 operator +(const Vec3 rhs) const
|
||||
{
|
||||
return Vec3(x + rhs.x, y + rhs.y, z + rhs.z);
|
||||
}
|
||||
|
||||
constexpr Vec3 operator -(const Vec3 rhs) const
|
||||
{
|
||||
return Vec3(x + rhs.x, y + rhs.y, z + rhs.z);
|
||||
}
|
||||
|
||||
inline Vec3 normal() const
|
||||
{
|
||||
float ls = x * x + y * y + z * z;
|
||||
float length = (float)Calc::sqrt(ls);
|
||||
return Vec3(x / length, y / length, z / length);
|
||||
}
|
||||
|
||||
static constexpr float dot(Vec3 a, Vec3 b)
|
||||
{
|
||||
return a.x * b.x +
|
||||
a.y * b.y +
|
||||
a.z * b.z;
|
||||
}
|
||||
|
||||
static constexpr Vec3 cross(Vec3 a, Vec3 b)
|
||||
{
|
||||
return Vec3(
|
||||
a.y * b.z - a.z * b.y,
|
||||
a.z * b.x - a.x * b.z,
|
||||
a.x * b.y - a.y * b.x);
|
||||
}
|
||||
};
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
namespace Blah
|
||||
{
|
||||
struct Vec4
|
||||
{
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
float w;
|
||||
|
||||
constexpr Vec4()
|
||||
: x(0), y(0), z(0), w(0) {}
|
||||
|
||||
constexpr Vec4(float x, float y, float z, float w)
|
||||
: x(x), y(y), z(z), w(w) {}
|
||||
};
|
||||
}
|
@ -9,7 +9,7 @@ namespace Blah
|
||||
{
|
||||
public:
|
||||
MemoryStream();
|
||||
MemoryStream(char* data, size_t length);
|
||||
MemoryStream(unsigned char* data, size_t length);
|
||||
MemoryStream(MemoryStream&& ms) noexcept;
|
||||
MemoryStream& operator=(MemoryStream&& ms) noexcept;
|
||||
~MemoryStream() override { m_data = nullptr; m_length = m_position = 0; }
|
||||
@ -22,15 +22,15 @@ namespace Blah
|
||||
bool is_writable() const override;
|
||||
void close() override;
|
||||
|
||||
char* data();
|
||||
const char* data() const;
|
||||
unsigned char* data();
|
||||
const unsigned char* data() const;
|
||||
|
||||
protected:
|
||||
size_t read_data(void* ptr, size_t length) override;
|
||||
size_t write_data(const void* ptr, size_t length) override;
|
||||
|
||||
private:
|
||||
char* m_data;
|
||||
unsigned char* m_data;
|
||||
size_t m_length;
|
||||
size_t m_position;
|
||||
};
|
||||
|
@ -53,8 +53,8 @@ namespace Blah
|
||||
public:
|
||||
Stopwatch();
|
||||
void reset();
|
||||
u64 microseconds();
|
||||
u64 milliseconds();
|
||||
u64 microseconds() const;
|
||||
u64 milliseconds() const;
|
||||
|
||||
private:
|
||||
u64 start_time;
|
||||
|
Reference in New Issue
Block a user