diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/libjin/graphics/je_canvas.h | 2 | ||||
-rw-r--r-- | src/libjin/graphics/je_gl.cpp | 14 | ||||
-rw-r--r-- | src/libjin/graphics/je_gl.h | 27 | ||||
-rw-r--r-- | src/libjin/graphics/particles/je_particle.cpp | 9 | ||||
-rw-r--r-- | src/libjin/graphics/particles/je_particle.h | 10 | ||||
-rw-r--r-- | src/libjin/graphics/particles/je_particle_emitter.cpp | 8 | ||||
-rw-r--r-- | src/libjin/graphics/particles/je_particle_system.cpp | 39 | ||||
-rw-r--r-- | src/libjin/graphics/particles/je_particle_system.h | 14 | ||||
-rw-r--r-- | src/libjin/graphics/shaders/je_shader.h | 2 | ||||
-rw-r--r-- | src/libjin/math/je_quad.h | 7 | ||||
-rw-r--r-- | src/libjin/math/je_vector2.hpp | 5 | ||||
-rw-r--r-- | src/lua/common/je_lua_constant.h | 15 |
12 files changed, 124 insertions, 28 deletions
diff --git a/src/libjin/graphics/je_canvas.h b/src/libjin/graphics/je_canvas.h index a908747..c88decc 100644 --- a/src/libjin/graphics/je_canvas.h +++ b/src/libjin/graphics/je_canvas.h @@ -42,6 +42,8 @@ namespace JinEngine /// ~Canvas(); + inline GLuint getGLFrameBuffer() { return fbo; }; + protected: static const Canvas* const DEFAULT_CANVAS; static const Canvas* current; diff --git a/src/libjin/graphics/je_gl.cpp b/src/libjin/graphics/je_gl.cpp index 745bbb2..c45a50e 100644 --- a/src/libjin/graphics/je_gl.cpp +++ b/src/libjin/graphics/je_gl.cpp @@ -1,6 +1,10 @@ #define OGL2D_IMPLEMENT #include "je_gl.h" #include "je_color.h" +#include "je_canvas.h" +#include "je_texture.h" +#include "shaders/je_shader.h" +#include "fonts/je_font.h" using namespace JinEngine::Math; @@ -15,7 +19,7 @@ namespace JinEngine : mBlendMode(BlendMode::NONE) { memset(&mColor, 0xff, sizeof(mColor)); - memset(&mPrecolor, 0xff, sizeof(mPrecolor)); + memset(&mBackColor, 0xff, sizeof(mBackColor)); // Set default modelview matrix. mModelViewMatrices.push_back(Matrix()); mModelViewMatrix.setIdentity(); @@ -29,7 +33,7 @@ namespace JinEngine void OpenGL::pushColor(GLubyte r, GLubyte g, GLubyte b, GLubyte a) { - memcpy(&mPrecolor, &mColor, sizeof(mPrecolor)); + memcpy(&mBackColor, &mColor, sizeof(mBackColor)); mColor.r = r; mColor.g = g; mColor.b = b; @@ -54,7 +58,7 @@ namespace JinEngine void OpenGL::popColor() { - memcpy(&mColor, &mPrecolor, sizeof(mPrecolor)); + memcpy(&mColor, &mBackColor, sizeof(mBackColor)); glColor4ub(mColor.r, mColor.g, mColor.b, mColor.a); } @@ -161,13 +165,13 @@ namespace JinEngine void OpenGL::setColor(Color c) { - mCurrentColor = c; + mColor = c; glColor4f(c.r / 255.f, c.g / 255.f, c.b / 255.f, c.a / 255.f); } Color OpenGL::getColor() { - return mCurrentColor; + return mColor; } void OpenGL::clearMatrix() diff --git a/src/libjin/graphics/je_gl.h b/src/libjin/graphics/je_gl.h index 4f53152..ee0194e 100644 --- a/src/libjin/graphics/je_gl.h +++ b/src/libjin/graphics/je_gl.h @@ -18,6 +18,9 @@ namespace JinEngine namespace Shaders { class Shader; }; namespace Fonts { class Font; }; + + class Texture; + class Canvas; class OpenGL @@ -130,22 +133,22 @@ namespace JinEngine /// /// /// - void useShader(); + void useShader(const Shaders::Shader* shader); /// /// /// - void useFont(); + void useFont(const Fonts::Font* font); /// /// /// - void useCanvas(); + void useCanvas(const Canvas* canvas); /// /// /// - void unUseShader(); + void unuseShader(); /// /// @@ -177,31 +180,33 @@ namespace JinEngine /// /// /// - Color mCurrentColor; + Color mColor; /// /// /// BlendMode mBlendMode; - struct { GLubyte r, g, b, a; } mColor; // current draw color - struct { GLubyte r, g, b, a; } mPrecolor; // previous draw color - GLuint mTexture; // current binded texture + //struct { GLubyte r, g, b, a; } mColor; // current draw color + //struct { GLubyte r, g, b, a; } mBackColor; // previous draw color + Color mBackColor; + + GLuint mTexture; // current binded texture /// /// /// - Canvas* mCurrentCanvas; + Canvas* mCanvas; /// /// /// - Shaders::Shader* mCurrentShader; + Shaders::Shader* mShader; /// /// /// - Fonts::Font* mCurrentFont; + Fonts::Font* mFont; }; diff --git a/src/libjin/graphics/particles/je_particle.cpp b/src/libjin/graphics/particles/je_particle.cpp index 6cab9db..00e593f 100644 --- a/src/libjin/graphics/particles/je_particle.cpp +++ b/src/libjin/graphics/particles/je_particle.cpp @@ -127,6 +127,11 @@ namespace JinEngine float t = life / lifeTime; if ((updateFlags & UPDATE_COLOR) != 0) color = def->colorDef.overTime.value.getColor(t); + // transparency + if (def->transparencyDef.overTime.enable) + color.a *= def->transparencyDef.overTime.value.getValue(t); + else + color.a *= def->transparencyDef.transparency.value; if ((updateFlags & UPDATE_SCALE) != 0) { // Lerp scale. @@ -151,8 +156,8 @@ namespace JinEngine int n = def->spritesDef.sprites.size(); if (def->spritesDef.mode == SpriteMode::ANIMATED) spriteIndex = lerp<int>(0, n - 1, t); - else - spriteIndex = rng.rand(0, n - 1); + //else + // spriteIndex = rng.rand(0, n - 1); } life += dt; alive = life < lifeTime; diff --git a/src/libjin/graphics/particles/je_particle.h b/src/libjin/graphics/particles/je_particle.h index 1efdc11..bef3e6d 100644 --- a/src/libjin/graphics/particles/je_particle.h +++ b/src/libjin/graphics/particles/je_particle.h @@ -78,6 +78,15 @@ namespace JinEngine ); }; + struct TransparencyDef + { + Math::Percentage transparency = 1.f; + Struct(overTime, + bool enable = false; + ScaledRangedValue value; + ); + }; + struct linearAccelarationDef { Math::Vector2<float> linearAccelaration; @@ -135,6 +144,7 @@ namespace JinEngine // Optional definitions. ScaleDef scaleDef; ///< ColorDef colorDef; ///< + TransparencyDef transparencyDef; ///< private: friend class ParticleEmitter; diff --git a/src/libjin/graphics/particles/je_particle_emitter.cpp b/src/libjin/graphics/particles/je_particle_emitter.cpp index 533bbf4..47957b6 100644 --- a/src/libjin/graphics/particles/je_particle_emitter.cpp +++ b/src/libjin/graphics/particles/je_particle_emitter.cpp @@ -60,7 +60,9 @@ namespace JinEngine p->transform.setPosition(x, y); } else - p->transform.setPosition(mDef.positionDef.position.position); + { + p->transform.setPosition(mDef.positionDef.position.position + mPS.mPosition); + } // Init speed. float r = 0; if (mDef.directionDef.enableRandom) @@ -104,7 +106,11 @@ namespace JinEngine p->color = mPDef.colorDef.color; // Sprite if (mPDef.spritesDef.mode != SpriteMode::SINGLE) + { p->updateFlags |= Particle::UPDATE_SPRITE; + if (mPDef.spritesDef.mode == SpriteMode::RANDOM) + p->spriteIndex = rng.rand(0, mPDef.spritesDef.sprites.size() - 1); + } } } diff --git a/src/libjin/graphics/particles/je_particle_system.cpp b/src/libjin/graphics/particles/je_particle_system.cpp index d16b918..2c2f9bb 100644 --- a/src/libjin/graphics/particles/je_particle_system.cpp +++ b/src/libjin/graphics/particles/je_particle_system.cpp @@ -1,3 +1,5 @@ +#include <stdarg.h> + #include "je_particle_system.h" namespace JinEngine @@ -7,6 +9,12 @@ namespace JinEngine namespace Particles { + ParticleSystem::ParticleSystem(uint maxCount) + : mEmitter(*this) + , mParticlePool(maxCount, sizeof(Particle)) + { + } + ParticleSystem::ParticleSystem(const ParticleSystemDef& def) : mDef(def) , mEmitter(*this) @@ -164,11 +172,23 @@ namespace JinEngine mDef.particleDef.spritesDef.mode = mode; } - void ParticleSystem::addParticleSprites(const Sprite* sprite) + void ParticleSystem::addParticleSprite(const Sprite* sprite) { mDef.particleDef.spritesDef.sprites.push_back(sprite); } + void ParticleSystem::addParticleSprites(uint count, ...) + { + va_list args; + va_start(args, count); + while (count--) + { + Sprite* spr = va_arg(args, Sprite*); + addParticleSprite(spr); + } + va_end(args); + } + void ParticleSystem::removeParticleSprite(uint i) { mDef.particleDef.spritesDef.sprites.erase(mDef.particleDef.spritesDef.sprites.begin() + i); @@ -213,6 +233,23 @@ namespace JinEngine mDef.particleDef.colorDef.overTime.value.removeColor(i); } + void ParticleSystem::setParticleTransparency(float transparency) + { + mDef.particleDef.transparencyDef.overTime.enable = false; + mDef.particleDef.transparencyDef.transparency = transparency; + } + + void ParticleSystem::addParticleTransparencyPoint(float transparency, float t) + { + mDef.particleDef.transparencyDef.overTime.enable = true; + mDef.particleDef.transparencyDef.overTime.value.addPoint(t, transparency); + } + + void ParticleSystem::removeParticleTransparencyPoint(uint i) + { + mDef.particleDef.transparencyDef.overTime.value.removePoint(i); + } + } } }
\ No newline at end of file diff --git a/src/libjin/graphics/particles/je_particle_system.h b/src/libjin/graphics/particles/je_particle_system.h index 1a07588..20f39dc 100644 --- a/src/libjin/graphics/particles/je_particle_system.h +++ b/src/libjin/graphics/particles/je_particle_system.h @@ -44,6 +44,11 @@ namespace JinEngine ParticleSystem(const ParticleSystemDef& def); /// + /// + /// + ParticleSystem(uint maxCount = 64); + + /// /// Particle system destructor. /// ~ParticleSystem(); @@ -109,7 +114,8 @@ namespace JinEngine void setParticleAngularSpeed(float speed); void setParticleSpritesMode(SpriteMode mode); - void addParticleSprites(const Sprite* sprite); + void addParticleSprite(const Sprite* sprite); + void addParticleSprites(uint count, ...); void removeParticleSprite(uint i); void enableParticleBlendAdditive(bool enable); @@ -122,12 +128,14 @@ namespace JinEngine void addParticleColorPoint(Color color, float t); void removeParticleColorPoint(uint i); + void setParticleTransparency(float transparency); + void addParticleTransparencyPoint(float transparency, float t); + void removeParticleTransparencyPoint(uint i); + private: friend class ParticleEmitter; - ParticleSystem(); - /// /// Particle system position. /// diff --git a/src/libjin/graphics/shaders/je_shader.h b/src/libjin/graphics/shaders/je_shader.h index 2009e79..36f3a40 100644 --- a/src/libjin/graphics/shaders/je_shader.h +++ b/src/libjin/graphics/shaders/je_shader.h @@ -159,6 +159,8 @@ namespace JinEngine /// void setUVPointer(int n, GLenum type, GLsizei stride, const GLvoid * pointers); + inline GLuint getGLProgramID() { return mPID; }; + protected: /// /// Reference of current used shader. diff --git a/src/libjin/math/je_quad.h b/src/libjin/math/je_quad.h index fd5e7a1..b07b5f6 100644 --- a/src/libjin/math/je_quad.h +++ b/src/libjin/math/je_quad.h @@ -15,17 +15,16 @@ namespace JinEngine : x(0), y(0), w(0), h(0) { } + Quad(float _x, float _y, float _w, float _h) : x(_x), y(_y), w(_w), h(_h) { } - /// - /// - /// + float x, y, w, h; }; } // namespace Math } // namespace JinEngine -#endif // __JE_QUAD_H__ +#endif // __JE_QUAD_H__
\ No newline at end of file diff --git a/src/libjin/math/je_vector2.hpp b/src/libjin/math/je_vector2.hpp index 0a1a1e8..406b756 100644 --- a/src/libjin/math/je_vector2.hpp +++ b/src/libjin/math/je_vector2.hpp @@ -42,6 +42,11 @@ namespace JinEngine data[1] += v.data[1]; } + Vector2<T> operator +(const Vector2<T>& v) + { + return Vector2<T>(data[0] + v.data[0], data[1] + v.data[1]); + } + void set(T _x, T _y) { data[0] = _x; diff --git a/src/lua/common/je_lua_constant.h b/src/lua/common/je_lua_constant.h index 6f70f09..c173b88 100644 --- a/src/lua/common/je_lua_constant.h +++ b/src/lua/common/je_lua_constant.h @@ -1 +1,14 @@ -#pragma once +#ifndef __JE_LUA_CONSTANT_H__ +#define __JE_LUA_CONSTANT_H__ + +namespace JinEngine +{ + namespace Lua + { + + + + } +} + +#endif
\ No newline at end of file |