From 38818e2abc0fb4e8f71f2c262f10ef5cb7fc4710 Mon Sep 17 00:00:00 2001 From: chai Date: Thu, 17 May 2018 21:02:44 +0800 Subject: change file tree --- src/libjin/core/core.h | 6 + src/libjin/fs/buffer.h | 12 +- src/libjin/fs/fs.h | 7 ++ src/libjin/input/input.h | 8 ++ src/libjin/jin.h | 12 ++ src/libjin/render/canvas.cpp | 2 +- src/libjin/render/color.h | 2 +- src/libjin/render/drawable.cpp | 3 +- src/libjin/render/graphics.cpp | 2 +- src/libjin/render/image.cpp | 2 +- src/libjin/render/jsl.cpp | 2 +- src/libjin/render/render.h | 14 +++ src/libjin/render/window.cpp | 2 +- src/libjin/utils/endian.h | 26 ++++ src/libjin/utils/macros.h | 6 + src/libjin/utils/math.h | 8 ++ src/libjin/utils/matrix.cpp | 177 +++++++++++++++++++++++++++ src/libjin/utils/matrix.h | 153 +++++++++++++++++++++++ src/libjin/utils/utils.h | 16 +++ src/script/audio/luaopen_audio.cpp | 2 +- src/script/core/luaopen_core.cpp | 2 +- src/script/event/luaopen_event.cpp | 5 +- src/script/filesystem/luaopen_filesystem.cpp | 2 +- src/script/graphics/luaopen_Canvas.cpp | 2 +- src/script/graphics/luaopen_Font.cpp | 2 +- src/script/graphics/luaopen_Image.cpp | 2 +- src/script/graphics/luaopen_JSL.cpp | 3 +- src/script/graphics/luaopen_graphics.cpp | 9 +- src/utils/endian.h | 26 ---- src/utils/macros.h | 6 - src/utils/math.h | 8 -- src/utils/matrix.cpp | 177 --------------------------- src/utils/matrix.h | 153 ----------------------- src/utils/utils.h | 11 -- 34 files changed, 458 insertions(+), 412 deletions(-) create mode 100644 src/libjin/core/core.h create mode 100644 src/libjin/fs/fs.h create mode 100644 src/libjin/input/input.h create mode 100644 src/libjin/jin.h create mode 100644 src/libjin/render/render.h create mode 100644 src/libjin/utils/endian.h create mode 100644 src/libjin/utils/macros.h create mode 100644 src/libjin/utils/math.h create mode 100644 src/libjin/utils/matrix.cpp create mode 100644 src/libjin/utils/matrix.h create mode 100644 src/libjin/utils/utils.h delete mode 100644 src/utils/endian.h delete mode 100644 src/utils/macros.h delete mode 100644 src/utils/math.h delete mode 100644 src/utils/matrix.cpp delete mode 100644 src/utils/matrix.h delete mode 100644 src/utils/utils.h (limited to 'src') diff --git a/src/libjin/core/core.h b/src/libjin/core/core.h new file mode 100644 index 0000000..dd902b4 --- /dev/null +++ b/src/libjin/core/core.h @@ -0,0 +1,6 @@ +#ifndef __JIN_CORE_H +#define __JIN_CORE_H + +#include "game.h" + +#endif \ No newline at end of file diff --git a/src/libjin/fs/buffer.h b/src/libjin/fs/buffer.h index d727d84..dfdea21 100644 --- a/src/libjin/fs/buffer.h +++ b/src/libjin/fs/buffer.h @@ -1,3 +1,6 @@ +#ifndef __JIN_BUFFER_H +#define __JIN_BUFFER_H + #include namespace jin @@ -5,9 +8,6 @@ namespace jin namespace fs { - /** - * A file data buffer. - */ class Buffer { public: @@ -30,7 +30,7 @@ namespace fs public: - // data position in memory + // data position in memory void* data; // data buffer size @@ -39,4 +39,6 @@ namespace fs }; } -} \ No newline at end of file +} + +#endif \ No newline at end of file diff --git a/src/libjin/fs/fs.h b/src/libjin/fs/fs.h new file mode 100644 index 0000000..6fbf33f --- /dev/null +++ b/src/libjin/fs/fs.h @@ -0,0 +1,7 @@ +#ifndef __JIN_FS_H +#define __JIN_FS_H + +#include "buffer.h" +#include "filesystem.h" + +#endif \ No newline at end of file diff --git a/src/libjin/input/input.h b/src/libjin/input/input.h new file mode 100644 index 0000000..217edd2 --- /dev/null +++ b/src/libjin/input/input.h @@ -0,0 +1,8 @@ +#ifndef __JIN_INPUT_H +#define __JIN_INPUT_H + +#include "event.h" +#include "keyboard.h" +#include "mouse.h" + +#endif \ No newline at end of file diff --git a/src/libjin/jin.h b/src/libjin/jin.h new file mode 100644 index 0000000..95895f7 --- /dev/null +++ b/src/libjin/jin.h @@ -0,0 +1,12 @@ +#ifndef __JIN_H +#define __JIN_H + +#include "utils/utils.h" +#include "audio/audio.h" +#include "core/core.h" +#include "fs/fs.h" +#include "input/input.h" +#include "net/net.h" +#include "render/render.h" + +#endif \ No newline at end of file diff --git a/src/libjin/render/canvas.cpp b/src/libjin/render/canvas.cpp index 494b0fa..376c076 100644 --- a/src/libjin/render/canvas.cpp +++ b/src/libjin/render/canvas.cpp @@ -1,4 +1,4 @@ -#include "utils/macros.h" +#include "../utils/macros.h" #include "canvas.h" #include "window.h" diff --git a/src/libjin/render/color.h b/src/libjin/render/color.h index dfb02e1..6f34b4a 100644 --- a/src/libjin/render/color.h +++ b/src/libjin/render/color.h @@ -3,7 +3,7 @@ */ #ifndef __JIN_COLOR_H #define __JIN_COLOR_H -#include "utils/endian.h" +#include "../utils/endian.h" namespace jin { diff --git a/src/libjin/render/drawable.cpp b/src/libjin/render/drawable.cpp index 45d6044..7acd3bf 100644 --- a/src/libjin/render/drawable.cpp +++ b/src/libjin/render/drawable.cpp @@ -1,6 +1,7 @@ #include "drawable.h" -#include "utils/matrix.h" +#include "../utils/matrix.h" #include + namespace jin { namespace render diff --git a/src/libjin/render/graphics.cpp b/src/libjin/render/graphics.cpp index 15d8a9c..254b6a4 100644 --- a/src/libjin/render/graphics.cpp +++ b/src/libjin/render/graphics.cpp @@ -1,5 +1,5 @@ #include "graphics.h" -#include "utils/math.h" +#include "../utils/math.h" #include namespace jin { diff --git a/src/libjin/render/image.cpp b/src/libjin/render/image.cpp index ac5947a..b27b9a6 100644 --- a/src/libjin/render/image.cpp +++ b/src/libjin/render/image.cpp @@ -1,6 +1,6 @@ #include "image.h" #include "3rdparty/stb/stb_image.h" -#include "utils/utils.h" +#include "../utils/utils.h" namespace jin { namespace render diff --git a/src/libjin/render/jsl.cpp b/src/libjin/render/jsl.cpp index 6fcee53..1fb4482 100644 --- a/src/libjin/render/jsl.cpp +++ b/src/libjin/render/jsl.cpp @@ -1,4 +1,4 @@ -#include "utils/macros.h" +#include "../utils/macros.h" #include "jsl.h" namespace jin { diff --git a/src/libjin/render/render.h b/src/libjin/render/render.h new file mode 100644 index 0000000..8939480 --- /dev/null +++ b/src/libjin/render/render.h @@ -0,0 +1,14 @@ +#ifndef __JIN_RENDER_H +#define __JIN_RENDER_H + +#include "canvas.h" +#include "color.h" +#include "font.h" +#include "graphics.h" +#include "image.h" +#include "jsl.h" +#include "quad.h" +#include "rect.h" +#include "window.h" + +#endif \ No newline at end of file diff --git a/src/libjin/render/window.cpp b/src/libjin/render/window.cpp index 20a6adc..e5d26a7 100644 --- a/src/libjin/render/window.cpp +++ b/src/libjin/render/window.cpp @@ -1,7 +1,7 @@ #include "window.h" #include "3rdparty/GLee/GLee.h" #include "canvas.h" -#include "utils/macros.h" +#include "../utils/macros.h" namespace jin { namespace render diff --git a/src/libjin/utils/endian.h b/src/libjin/utils/endian.h new file mode 100644 index 0000000..df28ddb --- /dev/null +++ b/src/libjin/utils/endian.h @@ -0,0 +1,26 @@ +/** +* +*/ +#ifndef JIN_LIL_ENDIAN && JIN_BIG_ENDIAN + +#define JIN_LIL_ENDIAN 2 +#define JIN_BIG_ENDIAN 4 + +#endif + +#ifndef JIN_BYTEORDER +#ifdef __linux__ +#include +#define JIN_BYTEORDER __BYTE_ORDER +#else /* __linux__ */ +#if defined(__hppa__) || \ + defined(__m68k__) || defined(mc68000) || defined(_M_M68K) || \ + (defined(__MIPS__) && defined(__MISPEB__)) || \ + defined(__ppc__) || defined(__POWERPC__) || defined(_M_PPC) || \ + defined(__sparc__) +#define JIN_BYTEORDER JIN_BIG_ENDIAN +#else +#define JIN_BYTEORDER JIN_LIL_ENDIAN +#endif +#endif /* __linux__ */ +#endif /* !SDL_BYTEORDER */ \ No newline at end of file diff --git a/src/libjin/utils/macros.h b/src/libjin/utils/macros.h new file mode 100644 index 0000000..4f739a9 --- /dev/null +++ b/src/libjin/utils/macros.h @@ -0,0 +1,6 @@ +#ifndef __JIN_MACROS_H +#define __JIN_MACROS_H + +#define shared + +#endif \ No newline at end of file diff --git a/src/libjin/utils/math.h b/src/libjin/utils/math.h new file mode 100644 index 0000000..5e44ce7 --- /dev/null +++ b/src/libjin/utils/math.h @@ -0,0 +1,8 @@ +#ifndef __JIN_UTILS_MATH_H +#define __JIN_UTILS_MATH_H + +#include + +#define PI 3.1415926f + +#endif \ No newline at end of file diff --git a/src/libjin/utils/matrix.cpp b/src/libjin/utils/matrix.cpp new file mode 100644 index 0000000..b970ec0 --- /dev/null +++ b/src/libjin/utils/matrix.cpp @@ -0,0 +1,177 @@ +#include "Matrix.h" + +#include // memcpy +#include + +namespace jin +{ +namespace util +{ + + // | e0 e4 e8 e12 | + // | e1 e5 e9 e13 | + // | e2 e6 e10 e14 | + // | e3 e7 e11 e15 | + + Matrix::Matrix() + { + setIdentity(); + } + + Matrix::~Matrix() + { + } + + // | e0 e4 e8 e12 | + // | e1 e5 e9 e13 | + // | e2 e6 e10 e14 | + // | e3 e7 e11 e15 | + // | e0 e4 e8 e12 | + // | e1 e5 e9 e13 | + // | e2 e6 e10 e14 | + // | e3 e7 e11 e15 | + + Matrix Matrix::operator * (const Matrix & m) const + { + Matrix t; + + t.e[0] = (e[0] * m.e[0]) + (e[4] * m.e[1]) + (e[8] * m.e[2]) + (e[12] * m.e[3]); + t.e[4] = (e[0] * m.e[4]) + (e[4] * m.e[5]) + (e[8] * m.e[6]) + (e[12] * m.e[7]); + t.e[8] = (e[0] * m.e[8]) + (e[4] * m.e[9]) + (e[8] * m.e[10]) + (e[12] * m.e[11]); + t.e[12] = (e[0] * m.e[12]) + (e[4] * m.e[13]) + (e[8] * m.e[14]) + (e[12] * m.e[15]); + + t.e[1] = (e[1] * m.e[0]) + (e[5] * m.e[1]) + (e[9] * m.e[2]) + (e[13] * m.e[3]); + t.e[5] = (e[1] * m.e[4]) + (e[5] * m.e[5]) + (e[9] * m.e[6]) + (e[13] * m.e[7]); + t.e[9] = (e[1] * m.e[8]) + (e[5] * m.e[9]) + (e[9] * m.e[10]) + (e[13] * m.e[11]); + t.e[13] = (e[1] * m.e[12]) + (e[5] * m.e[13]) + (e[9] * m.e[14]) + (e[13] * m.e[15]); + + t.e[2] = (e[2] * m.e[0]) + (e[6] * m.e[1]) + (e[10] * m.e[2]) + (e[14] * m.e[3]); + t.e[6] = (e[2] * m.e[4]) + (e[6] * m.e[5]) + (e[10] * m.e[6]) + (e[14] * m.e[7]); + t.e[10] = (e[2] * m.e[8]) + (e[6] * m.e[9]) + (e[10] * m.e[10]) + (e[14] * m.e[11]); + t.e[14] = (e[2] * m.e[12]) + (e[6] * m.e[13]) + (e[10] * m.e[14]) + (e[14] * m.e[15]); + + t.e[3] = (e[3] * m.e[0]) + (e[7] * m.e[1]) + (e[11] * m.e[2]) + (e[15] * m.e[3]); + t.e[7] = (e[3] * m.e[4]) + (e[7] * m.e[5]) + (e[11] * m.e[6]) + (e[15] * m.e[7]); + t.e[11] = (e[3] * m.e[8]) + (e[7] * m.e[9]) + (e[11] * m.e[10]) + (e[15] * m.e[11]); + t.e[15] = (e[3] * m.e[12]) + (e[7] * m.e[13]) + (e[11] * m.e[14]) + (e[15] * m.e[15]); + + return t; + } + + void Matrix::operator *= (const Matrix & m) + { + Matrix t = (*this) * m; + memcpy((void*)this->e, (void*)t.e, sizeof(float) * 16); + } + + const float * Matrix::getElements() const + { + return e; + } + + void Matrix::setIdentity() + { + memset(e, 0, sizeof(float) * 16); + e[0] = e[5] = e[10] = e[15] = 1; + } + + void Matrix::setTranslation(float x, float y) + { + setIdentity(); + e[12] = x; + e[13] = y; + } + + void Matrix::setRotation(float rad) + { + setIdentity(); + float c = cos(rad), s = sin(rad); + e[0] = c; e[4] = -s; + e[1] = s; e[5] = c; + } + + void Matrix::setScale(float sx, float sy) + { + setIdentity(); + e[0] = sx; + e[5] = sy; + } + + void Matrix::setShear(float kx, float ky) + { + setIdentity(); + e[1] = ky; + e[4] = kx; + } + + void Matrix::setTransformation(float x, float y, float angle, float sx, float sy, float ox, float oy) + { + memset(e, 0, sizeof(float) * 16); // zero out matrix + float c = cos(angle), s = sin(angle); + // matrix multiplication carried out on paper: + // |1 x| |c -s | |sx | |1 -ox| + // | 1 y| |s c | | sy | | 1 -oy| + // | 1 | | 1 | | 1 | | 1 | + // | 1| | 1| | 1| | 1 | + // move rotate scale origin + e[10] = e[15] = 1.0f; + e[0] = c * sx ; // = a + e[1] = s * sx ; // = b + e[4] = - s * sy; // = c + e[5] = c * sy; // = d + e[12] = x - ox * e[0] - oy * e[4]; + e[13] = y - ox * e[1] - oy * e[5]; + } + + void Matrix::translate(float x, float y) + { + Matrix t; + t.setTranslation(x, y); + this->operator *=(t); + } + + void Matrix::rotate(float rad) + { + Matrix t; + t.setRotation(rad); + this->operator *=(t); + } + + void Matrix::scale(float sx, float sy) + { + Matrix t; + t.setScale(sx, sy); + this->operator *=(t); + } + + void Matrix::shear(float kx, float ky) + { + Matrix t; + t.setShear(kx, ky); + this->operator *=(t); + } + + // | x | + // | y | + // | 0 | + // | 1 | + // | e0 e4 e8 e12 | + // | e1 e5 e9 e13 | + // | e2 e6 e10 e14 | + // | e3 e7 e11 e15 | + + void Matrix::transform(vertex * dst, const vertex * src, int size) const + { + for (int i = 0; i +namespace jin +{ +namespace util +{ + + struct vertex + { + unsigned char r, g, b, a; + float x, y; + float s, t; + }; + /** + * This class is the basis for all transformations in LOVE. Althought not + * really needed for 2D, it contains 4x4 elements to be compatible with + * OpenGL without conversions. + **/ + class Matrix + { + private: + + /** + * | e0 e4 e8 e12 | + * | e1 e5 e9 e13 | + * | e2 e6 e10 e14 | + * | e3 e7 e11 e15 | + **/ + float e[16]; + + public: + + /** + * Creates a new identity matrix. + **/ + Matrix(); + + /** + * Destructor. + **/ + ~Matrix(); + + /** + * Multiplies this Matrix with another Matrix, changing neither. + * @param m The Matrix to multiply with this Matrix. + * @return The combined matrix. + **/ + Matrix operator * (const Matrix & m) const; + + /** + * Multiplies a Matrix into this Matrix. + * @param m The Matrix to combine into this Matrix. + **/ + void operator *= (const Matrix & m); + + /** + * Gets a pointer to the 16 array elements. + * @return The array elements. + **/ + const float * getElements() const; + + /** + * Resets this Matrix to the identity matrix. + **/ + void setIdentity(); + + /** + * Resets this Matrix to a translation. + * @param x Translation along x-axis. + * @param y Translation along y-axis. + **/ + void setTranslation(float x, float y); + + /** + * Resets this Matrix to a rotation. + * @param r The angle in radians. + **/ + void setRotation(float r); + + /** + * Resets this Matrix to a scale transformation. + * @param sx Scale factor along the x-axis. + * @param sy Scale factor along the y-axis. + **/ + void setScale(float sx, float sy); + + /** + * Resets this Matrix to a shear transformation. + * @param kx Shear along x-axis. + * @param ky Shear along y-axis. + **/ + void setShear(float kx, float ky); + + /** + * Creates a transformation with a certain position, orientation, scale + * and offset. Perfect for Drawables -- what a coincidence! + * + * @param x The translation along the x-axis. + * @param y The translation along the y-axis. + * @param angle The rotation (rad) around the center with offset (ox,oy). + * @param sx Scale along x-axis. + * @param sy Scale along y-axis. + * @param ox The offset for rotation along the x-axis. + * @param oy The offset for rotation along the y-axis. + * @param kx Shear along x-axis + * @param ky Shear along y-axis + **/ + void setTransformation(float x, float y, float angle, float sx, float sy, float ox, float oy); + + /** + * Multiplies this Matrix with a translation. + * @param x Translation along x-axis. + * @param y Translation along y-axis. + **/ + void translate(float x, float y); + + /** + * Multiplies this Matrix with a rotation. + * @param r Angle in radians. + **/ + void rotate(float r); + + /** + * Multiplies this Matrix with a scale transformation. + * @param sx Scale factor along the x-axis. + * @param sy Scale factor along the y-axis. + **/ + void scale(float sx, float sy); + + /** + * Multiplies this Matrix with a shear transformation. + * @param kx Shear along the x-axis. + * @param ky Shear along the y-axis. + **/ + void shear(float kx, float ky); + + /** + * Transforms an array of vertices by this Matrix. The sources and + * destination arrays may be the same. + * + * @param dst Storage for the transformed vertices. + * @param src The source vertices. + * @param size The number of vertices. + **/ + void transform(vertex * dst, const vertex * src, int size) const; + + }; + +} +} + +#endif diff --git a/src/libjin/utils/utils.h b/src/libjin/utils/utils.h new file mode 100644 index 0000000..45c8ff9 --- /dev/null +++ b/src/libjin/utils/utils.h @@ -0,0 +1,16 @@ +#ifndef __JIN_UTILS_H +#define __JIN_UTILS_H + +#define min(a,b) (((a) < (b)) ? (a) : (b)) +#define max(a,b) (((a) > (b)) ? (a) : (b)) +#define clamp(a, mi,ma) min(max(a,mi),ma) + +#define within(a,min,max) (a >= min && a <= max) +#define without(a,min,max) (a < min || a > max) + +#include "macros.h" +#include "endian.h" +#include "math.h" +#include "matrix.h" + +#endif \ No newline at end of file diff --git a/src/script/audio/luaopen_audio.cpp b/src/script/audio/luaopen_audio.cpp index 361eeeb..f170115 100644 --- a/src/script/audio/luaopen_audio.cpp +++ b/src/script/audio/luaopen_audio.cpp @@ -1,7 +1,7 @@ #include #include "3rdparty/luax/luax.h" -#include "libjin/audio/audio.h" +#include "libjin/jin.h" namespace jin { diff --git a/src/script/core/luaopen_core.cpp b/src/script/core/luaopen_core.cpp index 82065c2..0d76ada 100644 --- a/src/script/core/luaopen_core.cpp +++ b/src/script/core/luaopen_core.cpp @@ -1,5 +1,5 @@ #include "3rdparty/luax/luax.h" -#include "libjin/core/game.h" +#include "libjin/jin.h" namespace jin { diff --git a/src/script/event/luaopen_event.cpp b/src/script/event/luaopen_event.cpp index 2935761..87882e7 100644 --- a/src/script/event/luaopen_event.cpp +++ b/src/script/event/luaopen_event.cpp @@ -4,10 +4,7 @@ #include #include "3rdparty/luax/luax.h" -#include "libjin/input/event.h" -#include "libjin/input/event.h" -#include "libjin/input/mouse.h" -#include "libjin/input/keyboard.h" +#include "libjin/jin.h" using namespace jin::input; diff --git a/src/script/filesystem/luaopen_filesystem.cpp b/src/script/filesystem/luaopen_filesystem.cpp index d02feb9..2060d40 100644 --- a/src/script/filesystem/luaopen_filesystem.cpp +++ b/src/script/filesystem/luaopen_filesystem.cpp @@ -1,5 +1,5 @@ #include "3rdparty/luax/luax.h" -#include "libjin/fs/filesystem.h" +#include "libjin/jin.h" #include using namespace jin::fs; diff --git a/src/script/graphics/luaopen_Canvas.cpp b/src/script/graphics/luaopen_Canvas.cpp index 7371020..f869882 100644 --- a/src/script/graphics/luaopen_Canvas.cpp +++ b/src/script/graphics/luaopen_Canvas.cpp @@ -1,6 +1,6 @@ #include "3rdparty/luax/luax.h" #include "../luaopen_types.h" -#include "libjin/render/canvas.h" +#include "libjin/jin.h" namespace jin { diff --git a/src/script/graphics/luaopen_Font.cpp b/src/script/graphics/luaopen_Font.cpp index 2bdb421..82dc078 100644 --- a/src/script/graphics/luaopen_Font.cpp +++ b/src/script/graphics/luaopen_Font.cpp @@ -1,6 +1,6 @@ #include "3rdparty/luax/luax.h" #include "../luaopen_types.h" -#include "libjin/render/font.h" +#include "libjin/jin.h" using namespace jin::render; diff --git a/src/script/graphics/luaopen_Image.cpp b/src/script/graphics/luaopen_Image.cpp index 6fe089f..7b9b96a 100644 --- a/src/script/graphics/luaopen_Image.cpp +++ b/src/script/graphics/luaopen_Image.cpp @@ -1,5 +1,5 @@ #include "3rdparty/luax/luax.h" -#include "libjin/render/image.h" +#include "libjin/jin.h" #include "../luaopen_types.h" using namespace jin::render; diff --git a/src/script/graphics/luaopen_JSL.cpp b/src/script/graphics/luaopen_JSL.cpp index c7b4e5e..218a973 100644 --- a/src/script/graphics/luaopen_JSL.cpp +++ b/src/script/graphics/luaopen_JSL.cpp @@ -1,6 +1,7 @@ #include "3rdparty/luax/luax.h" -#include "libjin/render/jsl.h" +#include "libjin/jin.h" #include "../luaopen_types.h" + namespace jin { namespace lua diff --git a/src/script/graphics/luaopen_graphics.cpp b/src/script/graphics/luaopen_graphics.cpp index 379cdf5..71637a9 100644 --- a/src/script/graphics/luaopen_graphics.cpp +++ b/src/script/graphics/luaopen_graphics.cpp @@ -1,13 +1,6 @@ -#include "utils/macros.h" #include "3rdparty/luax/luax.h" -#include "libjin/render/image.h" -#include "libjin/render/canvas.h" -#include "libjin/render/jsl.h" -#include "libjin/render/graphics.h" -#include "libjin/render/window.h" -#include "libjin/render/font.h" -#include "libjin/fs/filesystem.h" +#include "libjin/jin.h" #include "../luaopen_types.h" #include "../embed/graphics.lua.h" diff --git a/src/utils/endian.h b/src/utils/endian.h deleted file mode 100644 index df28ddb..0000000 --- a/src/utils/endian.h +++ /dev/null @@ -1,26 +0,0 @@ -/** -* -*/ -#ifndef JIN_LIL_ENDIAN && JIN_BIG_ENDIAN - -#define JIN_LIL_ENDIAN 2 -#define JIN_BIG_ENDIAN 4 - -#endif - -#ifndef JIN_BYTEORDER -#ifdef __linux__ -#include -#define JIN_BYTEORDER __BYTE_ORDER -#else /* __linux__ */ -#if defined(__hppa__) || \ - defined(__m68k__) || defined(mc68000) || defined(_M_M68K) || \ - (defined(__MIPS__) && defined(__MISPEB__)) || \ - defined(__ppc__) || defined(__POWERPC__) || defined(_M_PPC) || \ - defined(__sparc__) -#define JIN_BYTEORDER JIN_BIG_ENDIAN -#else -#define JIN_BYTEORDER JIN_LIL_ENDIAN -#endif -#endif /* __linux__ */ -#endif /* !SDL_BYTEORDER */ \ No newline at end of file diff --git a/src/utils/macros.h b/src/utils/macros.h deleted file mode 100644 index 4f739a9..0000000 --- a/src/utils/macros.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef __JIN_MACROS_H -#define __JIN_MACROS_H - -#define shared - -#endif \ No newline at end of file diff --git a/src/utils/math.h b/src/utils/math.h deleted file mode 100644 index 5e44ce7..0000000 --- a/src/utils/math.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef __JIN_UTILS_MATH_H -#define __JIN_UTILS_MATH_H - -#include - -#define PI 3.1415926f - -#endif \ No newline at end of file diff --git a/src/utils/matrix.cpp b/src/utils/matrix.cpp deleted file mode 100644 index b970ec0..0000000 --- a/src/utils/matrix.cpp +++ /dev/null @@ -1,177 +0,0 @@ -#include "Matrix.h" - -#include // memcpy -#include - -namespace jin -{ -namespace util -{ - - // | e0 e4 e8 e12 | - // | e1 e5 e9 e13 | - // | e2 e6 e10 e14 | - // | e3 e7 e11 e15 | - - Matrix::Matrix() - { - setIdentity(); - } - - Matrix::~Matrix() - { - } - - // | e0 e4 e8 e12 | - // | e1 e5 e9 e13 | - // | e2 e6 e10 e14 | - // | e3 e7 e11 e15 | - // | e0 e4 e8 e12 | - // | e1 e5 e9 e13 | - // | e2 e6 e10 e14 | - // | e3 e7 e11 e15 | - - Matrix Matrix::operator * (const Matrix & m) const - { - Matrix t; - - t.e[0] = (e[0] * m.e[0]) + (e[4] * m.e[1]) + (e[8] * m.e[2]) + (e[12] * m.e[3]); - t.e[4] = (e[0] * m.e[4]) + (e[4] * m.e[5]) + (e[8] * m.e[6]) + (e[12] * m.e[7]); - t.e[8] = (e[0] * m.e[8]) + (e[4] * m.e[9]) + (e[8] * m.e[10]) + (e[12] * m.e[11]); - t.e[12] = (e[0] * m.e[12]) + (e[4] * m.e[13]) + (e[8] * m.e[14]) + (e[12] * m.e[15]); - - t.e[1] = (e[1] * m.e[0]) + (e[5] * m.e[1]) + (e[9] * m.e[2]) + (e[13] * m.e[3]); - t.e[5] = (e[1] * m.e[4]) + (e[5] * m.e[5]) + (e[9] * m.e[6]) + (e[13] * m.e[7]); - t.e[9] = (e[1] * m.e[8]) + (e[5] * m.e[9]) + (e[9] * m.e[10]) + (e[13] * m.e[11]); - t.e[13] = (e[1] * m.e[12]) + (e[5] * m.e[13]) + (e[9] * m.e[14]) + (e[13] * m.e[15]); - - t.e[2] = (e[2] * m.e[0]) + (e[6] * m.e[1]) + (e[10] * m.e[2]) + (e[14] * m.e[3]); - t.e[6] = (e[2] * m.e[4]) + (e[6] * m.e[5]) + (e[10] * m.e[6]) + (e[14] * m.e[7]); - t.e[10] = (e[2] * m.e[8]) + (e[6] * m.e[9]) + (e[10] * m.e[10]) + (e[14] * m.e[11]); - t.e[14] = (e[2] * m.e[12]) + (e[6] * m.e[13]) + (e[10] * m.e[14]) + (e[14] * m.e[15]); - - t.e[3] = (e[3] * m.e[0]) + (e[7] * m.e[1]) + (e[11] * m.e[2]) + (e[15] * m.e[3]); - t.e[7] = (e[3] * m.e[4]) + (e[7] * m.e[5]) + (e[11] * m.e[6]) + (e[15] * m.e[7]); - t.e[11] = (e[3] * m.e[8]) + (e[7] * m.e[9]) + (e[11] * m.e[10]) + (e[15] * m.e[11]); - t.e[15] = (e[3] * m.e[12]) + (e[7] * m.e[13]) + (e[11] * m.e[14]) + (e[15] * m.e[15]); - - return t; - } - - void Matrix::operator *= (const Matrix & m) - { - Matrix t = (*this) * m; - memcpy((void*)this->e, (void*)t.e, sizeof(float) * 16); - } - - const float * Matrix::getElements() const - { - return e; - } - - void Matrix::setIdentity() - { - memset(e, 0, sizeof(float) * 16); - e[0] = e[5] = e[10] = e[15] = 1; - } - - void Matrix::setTranslation(float x, float y) - { - setIdentity(); - e[12] = x; - e[13] = y; - } - - void Matrix::setRotation(float rad) - { - setIdentity(); - float c = cos(rad), s = sin(rad); - e[0] = c; e[4] = -s; - e[1] = s; e[5] = c; - } - - void Matrix::setScale(float sx, float sy) - { - setIdentity(); - e[0] = sx; - e[5] = sy; - } - - void Matrix::setShear(float kx, float ky) - { - setIdentity(); - e[1] = ky; - e[4] = kx; - } - - void Matrix::setTransformation(float x, float y, float angle, float sx, float sy, float ox, float oy) - { - memset(e, 0, sizeof(float) * 16); // zero out matrix - float c = cos(angle), s = sin(angle); - // matrix multiplication carried out on paper: - // |1 x| |c -s | |sx | |1 -ox| - // | 1 y| |s c | | sy | | 1 -oy| - // | 1 | | 1 | | 1 | | 1 | - // | 1| | 1| | 1| | 1 | - // move rotate scale origin - e[10] = e[15] = 1.0f; - e[0] = c * sx ; // = a - e[1] = s * sx ; // = b - e[4] = - s * sy; // = c - e[5] = c * sy; // = d - e[12] = x - ox * e[0] - oy * e[4]; - e[13] = y - ox * e[1] - oy * e[5]; - } - - void Matrix::translate(float x, float y) - { - Matrix t; - t.setTranslation(x, y); - this->operator *=(t); - } - - void Matrix::rotate(float rad) - { - Matrix t; - t.setRotation(rad); - this->operator *=(t); - } - - void Matrix::scale(float sx, float sy) - { - Matrix t; - t.setScale(sx, sy); - this->operator *=(t); - } - - void Matrix::shear(float kx, float ky) - { - Matrix t; - t.setShear(kx, ky); - this->operator *=(t); - } - - // | x | - // | y | - // | 0 | - // | 1 | - // | e0 e4 e8 e12 | - // | e1 e5 e9 e13 | - // | e2 e6 e10 e14 | - // | e3 e7 e11 e15 | - - void Matrix::transform(vertex * dst, const vertex * src, int size) const - { - for (int i = 0; i -namespace jin -{ -namespace util -{ - - struct vertex - { - unsigned char r, g, b, a; - float x, y; - float s, t; - }; - /** - * This class is the basis for all transformations in LOVE. Althought not - * really needed for 2D, it contains 4x4 elements to be compatible with - * OpenGL without conversions. - **/ - class Matrix - { - private: - - /** - * | e0 e4 e8 e12 | - * | e1 e5 e9 e13 | - * | e2 e6 e10 e14 | - * | e3 e7 e11 e15 | - **/ - float e[16]; - - public: - - /** - * Creates a new identity matrix. - **/ - Matrix(); - - /** - * Destructor. - **/ - ~Matrix(); - - /** - * Multiplies this Matrix with another Matrix, changing neither. - * @param m The Matrix to multiply with this Matrix. - * @return The combined matrix. - **/ - Matrix operator * (const Matrix & m) const; - - /** - * Multiplies a Matrix into this Matrix. - * @param m The Matrix to combine into this Matrix. - **/ - void operator *= (const Matrix & m); - - /** - * Gets a pointer to the 16 array elements. - * @return The array elements. - **/ - const float * getElements() const; - - /** - * Resets this Matrix to the identity matrix. - **/ - void setIdentity(); - - /** - * Resets this Matrix to a translation. - * @param x Translation along x-axis. - * @param y Translation along y-axis. - **/ - void setTranslation(float x, float y); - - /** - * Resets this Matrix to a rotation. - * @param r The angle in radians. - **/ - void setRotation(float r); - - /** - * Resets this Matrix to a scale transformation. - * @param sx Scale factor along the x-axis. - * @param sy Scale factor along the y-axis. - **/ - void setScale(float sx, float sy); - - /** - * Resets this Matrix to a shear transformation. - * @param kx Shear along x-axis. - * @param ky Shear along y-axis. - **/ - void setShear(float kx, float ky); - - /** - * Creates a transformation with a certain position, orientation, scale - * and offset. Perfect for Drawables -- what a coincidence! - * - * @param x The translation along the x-axis. - * @param y The translation along the y-axis. - * @param angle The rotation (rad) around the center with offset (ox,oy). - * @param sx Scale along x-axis. - * @param sy Scale along y-axis. - * @param ox The offset for rotation along the x-axis. - * @param oy The offset for rotation along the y-axis. - * @param kx Shear along x-axis - * @param ky Shear along y-axis - **/ - void setTransformation(float x, float y, float angle, float sx, float sy, float ox, float oy); - - /** - * Multiplies this Matrix with a translation. - * @param x Translation along x-axis. - * @param y Translation along y-axis. - **/ - void translate(float x, float y); - - /** - * Multiplies this Matrix with a rotation. - * @param r Angle in radians. - **/ - void rotate(float r); - - /** - * Multiplies this Matrix with a scale transformation. - * @param sx Scale factor along the x-axis. - * @param sy Scale factor along the y-axis. - **/ - void scale(float sx, float sy); - - /** - * Multiplies this Matrix with a shear transformation. - * @param kx Shear along the x-axis. - * @param ky Shear along the y-axis. - **/ - void shear(float kx, float ky); - - /** - * Transforms an array of vertices by this Matrix. The sources and - * destination arrays may be the same. - * - * @param dst Storage for the transformed vertices. - * @param src The source vertices. - * @param size The number of vertices. - **/ - void transform(vertex * dst, const vertex * src, int size) const; - - }; - -} -} - -#endif diff --git a/src/utils/utils.h b/src/utils/utils.h deleted file mode 100644 index f1a340b..0000000 --- a/src/utils/utils.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef __JIN_UTILS_H -#define __JIN_UTILS_H - -#define min(a,b) (((a) < (b)) ? (a) : (b)) -#define max(a,b) (((a) > (b)) ? (a) : (b)) -#define clamp(a, mi,ma) min(max(a,mi),ma) - -#define within(a,min,max) (a >= min && a <= max) -#define without(a,min,max) (a < min || a > max) - -#endif \ No newline at end of file -- cgit v1.1-26-g67d0