diff options
author | chai <chaifix@163.com> | 2018-11-20 08:35:18 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2018-11-20 08:35:18 +0800 |
commit | 5bd4477d4cf413e90a6b9ef5c8991798a687a0ec (patch) | |
tree | 7abef5041cf93b505f9bc47520f60529a72fc06e /src | |
parent | 22715652592b326feae3010a8bc80d6f8fadba50 (diff) |
*更新sprite
Diffstat (limited to 'src')
-rw-r--r-- | src/libjin/common/je_singleton.hpp | 2 | ||||
-rw-r--r-- | src/libjin/graphics/animations/je_animation.h | 27 | ||||
-rw-r--r-- | src/libjin/graphics/animations/je_animator.cpp | 14 | ||||
-rw-r--r-- | src/libjin/graphics/animations/je_animator.h | 50 | ||||
-rw-r--r-- | src/libjin/graphics/je_graphic.h | 3 | ||||
-rw-r--r-- | src/libjin/graphics/je_sprite.cpp | 122 | ||||
-rw-r--r-- | src/libjin/graphics/je_sprite.h | 56 | ||||
-rw-r--r-- | src/libjin/graphics/je_sprite_sheet.cpp | 9 | ||||
-rw-r--r-- | src/libjin/graphics/particles/je_particle.cpp | 15 | ||||
-rw-r--r-- | src/libjin/graphics/particles/je_particle.h | 6 | ||||
-rw-r--r-- | src/libjin/graphics/particles/je_particle_emitter.cpp | 2 | ||||
-rw-r--r-- | src/libjin/graphics/particles/je_particle_system.cpp | 17 | ||||
-rw-r--r-- | src/libjin/graphics/particles/je_particle_system.h | 28 | ||||
-rw-r--r-- | src/libjin/graphics/shaders/je_jsl_compiler.h | 2 | ||||
-rw-r--r-- | src/libjin/math/je_quad.h | 4 | ||||
-rw-r--r-- | src/libjin/math/je_transform.cpp | 5 | ||||
-rw-r--r-- | src/libjin/math/je_transform.h | 1 |
17 files changed, 159 insertions, 204 deletions
diff --git a/src/libjin/common/je_singleton.hpp b/src/libjin/common/je_singleton.hpp index d7f52c9..2f387df 100644 --- a/src/libjin/common/je_singleton.hpp +++ b/src/libjin/common/je_singleton.hpp @@ -77,4 +77,4 @@ namespace JinEngine } // namespace JinEngine -#endif // __JE_SINGLETON_H__ +#endif // __JE_SINGLETON_H__
\ No newline at end of file diff --git a/src/libjin/graphics/animations/je_animation.h b/src/libjin/graphics/animations/je_animation.h index 9926cf9..a13a83b 100644 --- a/src/libjin/graphics/animations/je_animation.h +++ b/src/libjin/graphics/animations/je_animation.h @@ -19,12 +19,34 @@ namespace JinEngine class Animation { public: + /// + /// + /// void update(float dt); + /// + /// + /// void start(); + + /// + /// + /// void pause(); + + /// + /// + /// void stop(); + + /// + /// Force rewind. + /// void rewind(); + + /// + /// + /// void setSpeed(float speed); /// @@ -44,6 +66,11 @@ namespace JinEngine /// void setCurrentFrame(uint frame); + /// + /// + /// + void render(float x, float y, float sx, float sy, float r); + private: /// /// Key frames. diff --git a/src/libjin/graphics/animations/je_animator.cpp b/src/libjin/graphics/animations/je_animator.cpp deleted file mode 100644 index 360bd5d..0000000 --- a/src/libjin/graphics/animations/je_animator.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include "je_animator.h" - -namespace JinEngine -{ - namespace Graphics - { - namespace Animations - { - - - - } - } -}
\ No newline at end of file diff --git a/src/libjin/graphics/animations/je_animator.h b/src/libjin/graphics/animations/je_animator.h deleted file mode 100644 index 6510a7d..0000000 --- a/src/libjin/graphics/animations/je_animator.h +++ /dev/null @@ -1,50 +0,0 @@ -#ifndef __JE_ANIMATOR_H__ -#define __JE_ANIMATOR_H__ - -#include <map> -#include <vector> -#include <string> - -#include "je_animation.h" - -namespace JinEngine -{ - namespace Graphics - { - namespace Animations - { - - /// - /// - /// - class Animator - { - public: - void addAnimation(const std::string& key, Animation* clip); - bool hasKey(const std::string& key); - - void play(); - void switchAnimation(const std::string& key); - - /// - /// Control clips. - /// - void stopAnimation(); - void pauseAnimation(); - void rewindAnimation(); - void startAnimation(); - - private: - /// - /// Map a key to clips. - /// - std::map<std::string, Animation*> mAnimations; - Animation* mCurrentAnimation; - - }; - - } // namespace Animations - } // namespace Graphics -} // namespace JinEngine - -#endif
\ No newline at end of file diff --git a/src/libjin/graphics/je_graphic.h b/src/libjin/graphics/je_graphic.h index b113891..636ea60 100644 --- a/src/libjin/graphics/je_graphic.h +++ b/src/libjin/graphics/je_graphic.h @@ -16,7 +16,8 @@ namespace JinEngine { /// - /// Class inherites Graphic doesn't keep any state such as origin, scale and other properties. + /// Class inherites Graphic doesn't keep any state such as origin, scale and other properties. Very low + /// level visualized resources. /// class Graphic { diff --git a/src/libjin/graphics/je_sprite.cpp b/src/libjin/graphics/je_sprite.cpp index b92a2c2..b45fdf3 100644 --- a/src/libjin/graphics/je_sprite.cpp +++ b/src/libjin/graphics/je_sprite.cpp @@ -1,19 +1,39 @@ -#include "shaders/je_shader.h" - +#include "je_graphic.h" #include "je_sprite.h" using namespace JinEngine::Math; -using namespace JinEngine::Graphics::Shaders; +using namespace JinEngine::Graphics; namespace JinEngine { namespace Graphics { - Sprite::Sprite() - : mGraphic(nullptr) - , mColor(255, 255, 255, 255) - , mIsOriginEnum(false) + Sprite::Sprite(const Graphic* graphic, const Math::Quad& quad, Origin origin) + : mGraphic(graphic) + , mQuad(quad) + { + setOrigin(origin); + } + + Sprite::Sprite(const Graphic* graphic, const Math::Quad& quad, float ox, float oy) + : mGraphic(graphic) + , mQuad(quad) + , mOrigin(ox, oy) + { + } + + Sprite::Sprite(const Graphic* graphic, Origin origin) + : mGraphic(graphic) + , mQuad(0, 0, graphic->getWidth(), graphic->getHeight()) + { + setOrigin(origin); + } + + Sprite::Sprite(const Graphic* graphic, float ox, float oy) + : mGraphic(graphic) + , mQuad(0, 0, graphic->getWidth(), graphic->getHeight()) + , mOrigin(ox, oy) { } @@ -21,113 +41,55 @@ namespace JinEngine { } - void Sprite::setQuad(int x, int y, int w, int h) + Math::Vector2<int> Sprite::getSize() { - mQuad.x = x; - mQuad.y = y; - mQuad.w = w; - mQuad.h = h; - if (mIsOriginEnum) - setOrigin(mOriginEnum); + return Math::Vector2<int>(mQuad.w, mQuad.h); } - void Sprite::setRotation(float r) + void Sprite::render(float x, float y, float sx, float sy, float r) const { - mTransform.setRotation(r); + if (mGraphic != nullptr) + mGraphic->render(mQuad, x, y, sx, sy, r, mOrigin.x, mOrigin.y); } void Sprite::setOrigin(Origin origin) { - mIsOriginEnum = true; - mOriginEnum = origin; int l = 0, r = 0, t = 0, b = 0; Vector2<int> size = getSize(); r = size.w; b = size.h; + Vector2<float>* org = const_cast<Vector2<float>*>(&mOrigin); switch (origin) { case TopLeft: - mTransform.setOrigin(1, t); + org->set(1, t); break; case TopCenter: - mTransform.setOrigin(r / 2.f, t); + org->set(r / 2.f, t); break; case TopRight: - mTransform.setOrigin(r, t); + org->set(r, t); break; case MiddleLeft: - mTransform.setOrigin(1, b / 2.f); + org->set(1, b / 2.f); break; case MiddleCenter: - mTransform.setOrigin(r / 2.f, b / 2.f); + org->set(r / 2.f, b / 2.f); break; case MiddleRight: - mTransform.setOrigin(r, b / 2.f); + org->set(r, b / 2.f); break; case BottomLeft: - mTransform.setOrigin(l, b); + org->set(l, b); break; case BottomCenter: - mTransform.setOrigin(r / 2.f, b); + org->set(r / 2.f, b); break; case BottomRight: - mTransform.setOrigin(r, b); + org->set(r, b); break; } } - void Sprite::setOrigin(int x, int y) - { - mTransform.setOrigin(x, y); - mIsOriginEnum = false; - } - - void Sprite::setPosition(float x, float y) - { - mTransform.setPosition(x, y); - } - - void Sprite::setScale(float x, float y) - { - mTransform.setScale(x, y); - } - - void Sprite::setColor(Color color) - { - mColor = color; - } - - void Sprite::setGraphic(const Graphic* graphic) - { - mGraphic = graphic; - int w = mGraphic->getWidth(); - int h = mGraphic->getHeight(); - setQuad(0, 0, w, h); - } - - void Sprite::move(float x, float y) - { - mTransform.move(x, y); - } - - void Sprite::rotate(float r) - { - mTransform.rotate(r); - } - - void Sprite::scale(float sx, float sy) - { - mTransform.scale(sx, sy); - } - - void Sprite::render() - { - Color c = gl.getColor(); - gl.setColor(mColor); - if (mGraphic != nullptr) - mGraphic->render(mQuad, mTransform); - gl.setColor(c); - } - } // namespace Graphics } // namespace JinEngine
\ No newline at end of file diff --git a/src/libjin/graphics/je_sprite.h b/src/libjin/graphics/je_sprite.h index faf16df..4050ed8 100644 --- a/src/libjin/graphics/je_sprite.h +++ b/src/libjin/graphics/je_sprite.h @@ -4,8 +4,8 @@ #include "../common/je_types.h" #include "../math/je_vector2.hpp" -#include "shaders/je_shader.h" #include "je_color.h" +#include "je_graphic.h" namespace JinEngine { @@ -18,8 +18,6 @@ namespace JinEngine class Sprite { public: - Sprite(); - virtual ~Sprite(); enum Origin { @@ -34,42 +32,30 @@ namespace JinEngine BottomRight }; - void setQuad(int x, int y, int w, int h); - void setRotation(float r); - void setOrigin(Origin origin); - void setOrigin(int x, int y); - void setPosition(float x, float y); - void setScale(float sx, float sy); - void setColor(Color color); - void setGraphic(const Graphic* graphic); - - void move(float x, float y); - void rotate(float r); - void scale(float sx, float sy); - - float getRotation() { return mTransform.getRotation(); } - Math::Vector2<int> getSize() { return Math::Vector2<int>(mQuad.w, mQuad.h); } - const Math::Quad& getQuad() { return mQuad; } - const Math::Vector2<float>& getPosition() { return mTransform.getPosition(); } - const Math::Vector2<float>& getOrigin() { return mTransform.getOrigin(); } - const Math::Vector2<float>& getScale() { return mTransform.getScale(); } - const Color& getColor() { return mColor; } - const Graphic* getGraphic() { return mGraphic; } - - void render(); + Sprite(const Graphic* graphic, const Math::Quad& quad, Origin origin); + + Sprite(const Graphic* graphic, const Math::Quad& quad, float ox, float oy); + + Sprite(const Graphic* graphic, Origin origin); + + Sprite(const Graphic* graphic, float ox, float oy); + + virtual ~Sprite(); + + Math::Vector2<int> getSize(); + + void render(float x, float y, float sx, float sy, float r) const; private: - /// - /// Origin must be 0~1 float value. - /// - Math::Transform mTransform; - - Color mColor; - Math::Quad mQuad; + void setOrigin(Origin origin); - bool mIsOriginEnum; - Origin mOriginEnum; + const Math::Vector2<float> mOrigin; + + /// + /// Quad of graphic. + /// + const Math::Quad mQuad; const Graphic* mGraphic; diff --git a/src/libjin/graphics/je_sprite_sheet.cpp b/src/libjin/graphics/je_sprite_sheet.cpp index 3a08751..936eeab 100644 --- a/src/libjin/graphics/je_sprite_sheet.cpp +++ b/src/libjin/graphics/je_sprite_sheet.cpp @@ -12,10 +12,11 @@ namespace JinEngine Sprite* SpriteSheet::createSprite(const Math::Quad& quad) { - Sprite* spr = new Sprite(); - spr->setGraphic(mGraphic); - spr->setQuad(quad.x, quad.y, quad.w, quad.h); - return spr; + //Sprite* spr = new Sprite(); + //spr->setGraphic(mGraphic); + //spr->setQuad(quad.x, quad.y, quad.w, quad.h); + //return spr; + return nullptr; } } diff --git a/src/libjin/graphics/particles/je_particle.cpp b/src/libjin/graphics/particles/je_particle.cpp index 20e4b9e..1fa8bc2 100644 --- a/src/libjin/graphics/particles/je_particle.cpp +++ b/src/libjin/graphics/particles/je_particle.cpp @@ -1,5 +1,7 @@ #include "../../math/je_math.h" +#include "../je_sprite.h" + #include "je_particle.h" using namespace JinEngine::Math; @@ -11,8 +13,8 @@ namespace JinEngine namespace Particles { - Particle::Particle(const Graphic* grc) - : graphic(grc) + Particle::Particle(const Sprite* spr) + : sprite(spr) { reset(); } @@ -62,8 +64,13 @@ namespace JinEngine { Color c = gl.getColor(); gl.setColor(color); - if (graphic != nullptr) - graphic->render(transform); + if (sprite != nullptr) + { + Vector2<float>& position = transform.getPosition(); + Vector2<float>& scale = transform.getScale(); + float r = transform.getRotation(); + sprite->render(position.x, position.y, scale.x, scale.y, r); + } gl.getColor(); } diff --git a/src/libjin/graphics/particles/je_particle.h b/src/libjin/graphics/particles/je_particle.h index 6da05ac..c03f4ca 100644 --- a/src/libjin/graphics/particles/je_particle.h +++ b/src/libjin/graphics/particles/je_particle.h @@ -4,7 +4,7 @@ #include "../../math/je_transform.h" #include "../../math/je_vector2.hpp" #include "../je_color.h" -#include "../je_graphic.h" +#include "../je_sprite.h" namespace JinEngine { @@ -95,7 +95,7 @@ namespace JinEngine /// /// Default constructor. /// - Particle(const Graphic* graphic); + Particle(const Sprite* sprite); /// /// Reset to default. @@ -124,7 +124,7 @@ namespace JinEngine /// float life = 0.0f; - const Graphic* graphic; + const Sprite* sprite; /// /// Color over lifetime. diff --git a/src/libjin/graphics/particles/je_particle_emitter.cpp b/src/libjin/graphics/particles/je_particle_emitter.cpp index 35d654e..de5ef5d 100644 --- a/src/libjin/graphics/particles/je_particle_emitter.cpp +++ b/src/libjin/graphics/particles/je_particle_emitter.cpp @@ -54,6 +54,8 @@ namespace JinEngine { float x = rng.randf(mDef.positionDef.position.random.floor.x, mDef.positionDef.position.random.ceil.x, ACCURACY_4); float y = rng.randf(mDef.positionDef.position.random.floor.y, mDef.positionDef.position.random.ceil.y, ACCURACY_4); + x += mPS.mPosition.x; + y += mPS.mPosition.y; p->transform.setPosition(x, y); } else diff --git a/src/libjin/graphics/particles/je_particle_system.cpp b/src/libjin/graphics/particles/je_particle_system.cpp index 942da99..dcb84dd 100644 --- a/src/libjin/graphics/particles/je_particle_system.cpp +++ b/src/libjin/graphics/particles/je_particle_system.cpp @@ -18,6 +18,12 @@ namespace JinEngine { } + void ParticleSystem::setPosition(float x, float y) + { + mPosition.x = x; + mPosition.y = y; + } + void ParticleSystem::update(float dt) { mEmitter.update(dt); @@ -36,23 +42,20 @@ namespace JinEngine } } - void ParticleSystem::render(float x, float y, float sx /* = 1 */, float sy /* = 1 */, float r /* = 0 */, float ax /* = 0 */, float ay /* = 0 */) + void ParticleSystem::render() { - gl.push(); - gl.translate(x, y); for (Particle* p : mAliveParticles) p->render(); - gl.pop(); } - void ParticleSystem::setGraphic(const Graphic* graphic) + void ParticleSystem::setSprite(const Sprite* sprite) { - mGraphic = graphic; + mSprite = sprite; } Particle* ParticleSystem::claim() { - Particle* p = new (mParticlePool.GetNextWithoutInitializing()) Particle(mGraphic); + Particle* p = new (mParticlePool.GetNextWithoutInitializing()) Particle(mSprite); mAliveParticles.push_back(p); return p; } diff --git a/src/libjin/graphics/particles/je_particle_system.h b/src/libjin/graphics/particles/je_particle_system.h index 8ee79ec..fb4b8c7 100644 --- a/src/libjin/graphics/particles/je_particle_system.h +++ b/src/libjin/graphics/particles/je_particle_system.h @@ -33,7 +33,7 @@ namespace JinEngine /// /// Particle emitter, handle all particles it emitts. /// - class ParticleSystem/* : public Game::GameObject*/ + class ParticleSystem { public: /// @@ -56,14 +56,29 @@ namespace JinEngine /// /// Render particle system. /// - void render(float x, float y, float sx = 1, float sy = 1, float r = 0, float ax = 0, float ay = 0); + void render(); /// /// Set sprite to render. /// /// @param sprite Sprite to render. /// - void setGraphic(const Graphic* graphic); + void setSprite(const Sprite* sprite); + + /// + /// Set particle system position. + /// + void setPosition(float x, float y); + + /// + /// Pause particle spawn. + /// + void pause(bool isPause); + + /// + /// Clear all particles. + /// + void clear(); private: @@ -72,6 +87,11 @@ namespace JinEngine ParticleSystem(); /// + /// Particle system position. + /// + Math::Vector2<float> mPosition; + + /// /// /// Particle* claim(); @@ -89,7 +109,7 @@ namespace JinEngine /// /// Sprite to be drawn. /// - const Graphic* mGraphic; + const Sprite* mSprite; /// /// Particle emitter. diff --git a/src/libjin/graphics/shaders/je_jsl_compiler.h b/src/libjin/graphics/shaders/je_jsl_compiler.h index df1e827..fb2f8bb 100644 --- a/src/libjin/graphics/shaders/je_jsl_compiler.h +++ b/src/libjin/graphics/shaders/je_jsl_compiler.h @@ -42,4 +42,4 @@ namespace JinEngine #endif // (jin_graphics) && (jin_graphics & jin_graphics_shader) -#endif // __JE_JSL_COMPILER_H__ +#endif // __JE_JSL_COMPILER_H__
\ No newline at end of file diff --git a/src/libjin/math/je_quad.h b/src/libjin/math/je_quad.h index 8a7bd64..74cd294 100644 --- a/src/libjin/math/je_quad.h +++ b/src/libjin/math/je_quad.h @@ -11,6 +11,10 @@ namespace JinEngine /// struct Quad { + Quad(float _x, float _y, float _w, float _h) + : x(_x), y(_y), w(_w), h(_h) + { + } /// /// /// diff --git a/src/libjin/math/je_transform.cpp b/src/libjin/math/je_transform.cpp index c0676cb..fba63fa 100644 --- a/src/libjin/math/je_transform.cpp +++ b/src/libjin/math/je_transform.cpp @@ -13,6 +13,11 @@ namespace JinEngine { } + Transform::Transform(float x, float y, float sx, float sy, float r, float ox, float oy) + { + set(x, y, sx, sy, r, ox, oy); + } + void Transform::set(float x, float y, float sx, float sy, float r, float ox, float oy) { setPosition(x, y); diff --git a/src/libjin/math/je_transform.h b/src/libjin/math/je_transform.h index 95328f9..45f26e0 100644 --- a/src/libjin/math/je_transform.h +++ b/src/libjin/math/je_transform.h @@ -13,6 +13,7 @@ namespace JinEngine { public: Transform(); + Transform(float x, float y, float sx, float sy, float r, float ox, float oy); void set(float x, float y, float sx, float sy, float r, float ox, float oy); |