diff options
author | chai <chaifix@163.com> | 2018-08-27 07:55:00 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2018-08-27 07:55:00 +0800 |
commit | 1480c9445100075c9e1a894eb07c0ef727b509a1 (patch) | |
tree | 1e694f40b9720a4ecaf6c67310629906f08d5a41 /src | |
parent | 4013357b9dd88c614906263cd5b0657b535bd9cb (diff) |
*update
Diffstat (limited to 'src')
-rw-r--r-- | src/libjin/Audio/source.cpp | 28 | ||||
-rw-r--r-- | src/libjin/Graphics/Shapes.cpp | 122 | ||||
-rw-r--r-- | src/libjin/Graphics/Shapes.h | 43 | ||||
-rw-r--r-- | src/libjin/Graphics/Texture.h | 2 | ||||
-rw-r--r-- | src/libjin/Physics/Physics.h | 2 | ||||
-rw-r--r-- | src/libjin/Physics/Rigid.h | 0 | ||||
-rw-r--r-- | src/libjin/jin.h | 1 | ||||
-rw-r--r-- | src/libjin/physics/physics.h | 2 | ||||
-rw-r--r-- | src/libjin/physics/rigid.h | 0 | ||||
-rw-r--r-- | src/lua/modules/physics/physics.cpp | 16 |
10 files changed, 214 insertions, 2 deletions
diff --git a/src/libjin/Audio/source.cpp b/src/libjin/Audio/source.cpp new file mode 100644 index 0000000..61f4055 --- /dev/null +++ b/src/libjin/Audio/source.cpp @@ -0,0 +1,28 @@ +#include "../modules.h" +#if JIN_MODULES_AUDIO + +#include <cstring> +#include "source.h" + +namespace jin +{ +namespace audio +{ + + static int check_header(const void *data, int size, const char *str, int offset) { + int len = strlen(str); + return (size >= offset + len) && !memcmp((char*)data + offset, str, len); + } + + SourceType Source::getType(const void* mem, int size) + { + if(check_header(mem, size, "WAVE", 8)) + return SourceType::WAV; + if(check_header(mem, size, "OggS", 0)) + return SourceType::OGG; + return SourceType::INVALID; + } + +} +} +#endif // JIN_MODULES_AUDIO
\ No newline at end of file diff --git a/src/libjin/Graphics/Shapes.cpp b/src/libjin/Graphics/Shapes.cpp new file mode 100644 index 0000000..4b136a1 --- /dev/null +++ b/src/libjin/Graphics/Shapes.cpp @@ -0,0 +1,122 @@ +#include "../modules.h" +#if JIN_MODULES_RENDER + +#include "Shapes.h" +#include "../math/matrix.h" +#include "../math/constant.h" +#include <string> + +namespace jin +{ +namespace graphics +{ + + void point(int x, int y) + { + float vers[] = { x + 0.5f , y + 0.5f }; + glEnableClientState(GL_VERTEX_ARRAY); + glVertexPointer(2, GL_FLOAT, 0, (GLvoid*)vers); + glDrawArrays(GL_POINTS, 0, 1); + glDisableClientState(GL_VERTEX_ARRAY); + } + + void points(int n, GLshort* p) + { + glEnableClientState(GL_VERTEX_ARRAY); + + glVertexPointer(2, GL_SHORT, 0, (GLvoid*)p); + glDrawArrays(GL_POINTS, 0, n); + + glDisableClientState(GL_VERTEX_ARRAY); + } + + void line(int x1, int y1, int x2, int y2) + { + glDisable(GL_TEXTURE_2D); + float verts[] = { + x1, y1, + x2, y2 + }; + + glEnableClientState(GL_VERTEX_ARRAY); + glVertexPointer(2, GL_FLOAT, 0, (GLvoid*)verts); + glDrawArrays(GL_LINES, 0, 2); + glDisableClientState(GL_VERTEX_ARRAY); + } + + void circle(RENDER_MODE mode, int x, int y, int r) + { + r = r < 0 ? 0 : r; + + int points = 40; + float two_pi = static_cast<float>(PI * 2); + if (points <= 0) points = 1; + float angle_shift = (two_pi / points); + float phi = .0f; + + float *coords = new float[2 * (points + 1)]; + for (int i = 0; i < points; ++i, phi += angle_shift) + { + coords[2 * i] = x + r * cos(phi); + coords[2 * i + 1] = y + r * sin(phi); + } + + coords[2 * points] = coords[0]; + coords[2 * points + 1] = coords[1]; + + polygon(mode, coords, points); + + delete[] coords; + } + + void rect(RENDER_MODE mode, int x, int y, int w, int h) + { + float coords[] = { x, y, x + w, y, x + w, y + h, x, y + h }; + polygon(mode, coords, 4); + } + + void triangle(RENDER_MODE mode, int x1, int y1, int x2, int y2, int x3, int y3) + { + float coords[] = { x1, y1, x2, y2, x3, y3 }; + polygon(mode, coords, 3); + } + + void polygon_line(float* p, int count) + { + float* verts = new float[count * 4]; + for (int i = 0; i < count; ++i) + { + // each line has two point n,n+1 + verts[i * 4] = p[i * 2]; + verts[i * 4 + 1] = p[i * 2 + 1]; + verts[i * 4 + 2] = p[(i + 1) % count * 2]; + verts[i * 4 + 3] = p[(i + 1) % count * 2 + 1]; + } + + glEnableClientState(GL_VERTEX_ARRAY); + glVertexPointer(2, GL_FLOAT, 0, (GLvoid*)verts); + glDrawArrays(GL_LINES, 0, count * 2); + glDisableClientState(GL_VERTEX_ARRAY); + + delete[] verts; + } + + void polygon(RENDER_MODE mode, float* p, int count) + { + if (mode == LINE) + { + polygon_line(p, count); + } + else if (mode == FILL) + { + glEnableClientState(GL_VERTEX_ARRAY); + glVertexPointer(2, GL_FLOAT, 0, (const GLvoid*)p); + glDrawArrays(GL_POLYGON, 0, count); + glDisableClientState(GL_VERTEX_ARRAY); + } + } + +} +} + +#endif // JIN_MODULES_RENDER
\ No newline at end of file diff --git a/src/libjin/Graphics/Shapes.h b/src/libjin/Graphics/Shapes.h new file mode 100644 index 0000000..742345e --- /dev/null +++ b/src/libjin/Graphics/Shapes.h @@ -0,0 +1,43 @@ +#ifndef __JIN_GRAPHICS_SHAPES_H +#define __JIN_GRAPHICS_SHAPES_H +#include "../modules.h" +#if JIN_MODULES_RENDER + +#include "color.h" +#include "canvas.h" +#include "texture.h" + +namespace jin +{ +namespace graphics +{ + + typedef enum { + NONE = 0, + FILL , + LINE + }RENDER_MODE; + + /** + * TODO: + * drawPixels(int n, points) + */ + extern void line(int x1, int y1, int x2, int y2); + + extern void rect(RENDER_MODE mode, int x, int y, int w, int h); + + extern void triangle(RENDER_MODE mode, int x1, int y1, int x2, int y2, int x3, int y3); + + extern void circle(RENDER_MODE mode, int x, int y, int r); + + extern void point(int x, int y); + + extern void points(int n, GLshort* p, GLubyte* c); + + extern void polygon(RENDER_MODE mode, float* p, int count); + +} +} + +#endif // JIN_MODULES_RENDER +#endif // __JIN_GEOMETRY_H
\ No newline at end of file diff --git a/src/libjin/Graphics/Texture.h b/src/libjin/Graphics/Texture.h index 47f8d53..1fdb50d 100644 --- a/src/libjin/Graphics/Texture.h +++ b/src/libjin/Graphics/Texture.h @@ -19,6 +19,8 @@ namespace graphics static Texture* createTexture(const char* file); static Texture* createTexture(const void* mem, size_t size); + static void destroyTexture(Texture* tex); + ~Texture(); color getPixel(int x, int y); diff --git a/src/libjin/Physics/Physics.h b/src/libjin/Physics/Physics.h index 9927301..126911e 100644 --- a/src/libjin/Physics/Physics.h +++ b/src/libjin/Physics/Physics.h @@ -5,7 +5,7 @@ namespace jin { namespace physics { - + #include "../3rdparty/Box2D/Box2D.h" } } diff --git a/src/libjin/Physics/Rigid.h b/src/libjin/Physics/Rigid.h deleted file mode 100644 index e69de29..0000000 --- a/src/libjin/Physics/Rigid.h +++ /dev/null diff --git a/src/libjin/jin.h b/src/libjin/jin.h index 239fddd..c8d1193 100644 --- a/src/libjin/jin.h +++ b/src/libjin/jin.h @@ -7,6 +7,7 @@ #ifdef JIN_MODULES_AUDIO && JIN_AUDIO_SDLAUDIO #include "Audio/SDL/SDLAudio.h" #endif // JIN_MODULES_AUDIO && JIN_AUDIO_SDLAUDIO +#include "Physics/Physics.h" #include "Core/Core.h" #include "Filesystem/Filesystem.h" #include "Input/Input.h" diff --git a/src/libjin/physics/physics.h b/src/libjin/physics/physics.h index 9927301..126911e 100644 --- a/src/libjin/physics/physics.h +++ b/src/libjin/physics/physics.h @@ -5,7 +5,7 @@ namespace jin { namespace physics { - + #include "../3rdparty/Box2D/Box2D.h" } } diff --git a/src/libjin/physics/rigid.h b/src/libjin/physics/rigid.h deleted file mode 100644 index e69de29..0000000 --- a/src/libjin/physics/rigid.h +++ /dev/null diff --git a/src/lua/modules/physics/physics.cpp b/src/lua/modules/physics/physics.cpp new file mode 100644 index 0000000..a5b9162 --- /dev/null +++ b/src/lua/modules/physics/physics.cpp @@ -0,0 +1,16 @@ +#include "../luax.h" +#include "libjin/Physics/Physics.h" + +namespace jin +{ +namespace lua +{ + + using namespace jin::physics; + + int luaopen_physics(lua_State* L) + { + } + +} // physics +} // jin
\ No newline at end of file |