Skip to content

Commit

Permalink
Added GMatrix44 using GLM library.
Browse files Browse the repository at this point in the history
  • Loading branch information
wqking committed Feb 15, 2017
1 parent fe811b2 commit 7c47866
Show file tree
Hide file tree
Showing 173 changed files with 38,770 additions and 330 deletions.
2 changes: 1 addition & 1 deletion build/android/jni/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ LOCAL_SRC_FILES := \
$(SRC_PATH)/sfml/gimage.cpp \
$(SRC_PATH)/sfml/ginputstream.cpp \
$(SRC_PATH)/sfml/gtextrender.cpp \
$(SRC_PATH)/sfml/gtransform.cpp \
$(SRC_PATH)/sfml/grectrender.cpp \
$(SRC_PATH)/sfml/grenderengine.cpp \
$(SRC_PATH)/sfml/gresourcemanager.cpp \
$(SRC_PATH)/sfml/gcamera.cpp \
$(SRC_PATH)/gtransform.cpp \
$(SRC_PATH)/gcomponent.cpp \
$(SRC_PATH)/gcomponentanchor.cpp \
$(SRC_PATH)/gcomponentanimation.cpp \
Expand Down
3 changes: 2 additions & 1 deletion include/gincu/gatlasrender.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define GATLASRENDER_H

#include "gincu/gatlas.h"
#include "gincu/gmatrix.h"

namespace gincu {

Expand All @@ -13,7 +14,7 @@ class GAtlasRender
GAtlasRender();
explicit GAtlasRender(const GAtlas & atlas);

void draw(const GTransform & transform, const GRenderInfo * renderInfo);
void draw(const GMatrix44 & matrix, const GRenderInfo * renderInfo);

GSize getSize() const;

Expand Down
3 changes: 2 additions & 1 deletion include/gincu/gcomponentanchor.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "gincu/gcomponent.h"
#include "gincu/ggeometry.h"
#include "gincu/gmatrix.h"

#include "cpgf/gflags.h"

Expand Down Expand Up @@ -41,7 +42,7 @@ class GComponentAnchor : public GComponent
bool isFlipY() const { return this->flags.has(Flags::flagFlipY); }
GComponentAnchor * setFlipY(const bool flipY);

void apply(GTransform & transform, const GSize & size);
void apply(GMatrix44 & matrix, const GSize & size);

private:
void doApplyGlobalFlipXy(const bool parentGlobalFlipX, const bool parentGlobalFlipY);
Expand Down
5 changes: 3 additions & 2 deletions include/gincu/gentityutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "gincu/gtransform.h"
#include "gincu/gcomponenttransform.h"
#include "gincu/gentity.h"
#include "gincu/gmatrix.h"

namespace gincu {

Expand Down Expand Up @@ -34,8 +35,8 @@ class GComponentRender;
class GEntity;
class GComponentManager;

GTransform computeRenderableTransform(GComponentTransform * componentTransform, const GSize & size);
GTransform computeRenderableTransform(GComponentTransform * componentTransform, GComponentRender * render = nullptr);
GMatrix44 computeRenderableTransform(GComponentTransform * componentTransform, const GSize & size);
GMatrix44 computeRenderableTransform(GComponentTransform * componentTransform, GComponentRender * render = nullptr);

GComponentManager * getComponentManagerFromEntity(const GEntity * entity);
GComponentLocalTransform * getParentLocalTransform(const GEntity * entity);
Expand Down
3 changes: 2 additions & 1 deletion include/gincu/gimage.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "gincu/ggeometry.h"
#include "gincu/grenderanchor.h"
#include "gincu/gmatrix.h"

#include <string>
#include <memory>
Expand All @@ -23,7 +24,7 @@ class GImage

void load(const std::string & fileName);

void draw(const GTransform & transform, const GRenderInfo * renderInfo);
void draw(const GMatrix44 & matrix, const GRenderInfo * renderInfo);

GSize getSize() const;

Expand Down
41 changes: 41 additions & 0 deletions include/gincu/gmatrix.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#ifndef GMATRIX_H
#define GMATRIX_H

#include "gincu/ggeometry.h"
#include "glm/mat4x4.hpp"
#include "glm/gtc/matrix_transform.hpp"
#include "glm/gtc/matrix_inverse.hpp"

namespace gincu {

typedef glm::mat4 GMatrix44;

inline GMatrix44 translateMatrix(const GMatrix44 & matrix, const GPoint & p)
{
return glm::translate(matrix, { p.x, p.y, 0 });
}

inline GMatrix44 scaleMatrix(const GMatrix44 & matrix, const GScale & scale)
{
return glm::scale(matrix, { scale.x, scale.y, 1 });
}

inline GMatrix44 inverseMatrix(const GMatrix44 & matrix)
{
return glm::inverse(matrix);
}

inline GPoint transformPoint(const GMatrix44 & matrix, const GPoint & point)
{
auto p = matrix * glm::vec4 { point.x, point.y, 0, 1 };
return { p.x, p.y };
}


} //namespace gincu




#endif

3 changes: 2 additions & 1 deletion include/gincu/grectrender.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "gincu/gcolor.h"
#include "gincu/ggeometry.h"
#include "gincu/grenderanchor.h"
#include "gincu/gmatrix.h"

#include <memory>

Expand All @@ -20,7 +21,7 @@ class GRectRender
GRectRender();
~GRectRender();

void draw(const GTransform & transform, const GRenderInfo * renderInfo);
void draw(const GMatrix44 & matrix, const GRenderInfo * renderInfo);

void setColor(const GColor color);
GColor getColor() const;
Expand Down
11 changes: 6 additions & 5 deletions include/gincu/grenderengine.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "gincu/ggeometry.h"
#include "gincu/gcolor.h"
#include "gincu/gmatrix.h"

#include "cpgf/gcallbackList.h"

Expand Down Expand Up @@ -46,10 +47,10 @@ class GRenderEngine
bool isAlive() const;

void switchCamera(const GCamera & camera);
void draw(const GImage & image, const GTransform & transform, const GRenderInfo * renderInfo);
void draw(const GAtlasRender & atlasRender, const GTransform & transform, const GRenderInfo * renderInfo);
void draw(const GTextRender & text, const GTransform & transform, const GRenderInfo * renderInfo);
void draw(const GRectRender & rect, const GTransform & transform, const GRenderInfo * renderInfo);
void draw(const GImage & image, const GMatrix44 & matrix, const GRenderInfo * renderInfo);
void draw(const GAtlasRender & atlasRender, const GMatrix44 & matrix, const GRenderInfo * renderInfo);
void draw(const GTextRender & text, const GMatrix44 & matrix, const GRenderInfo * renderInfo);
void draw(const GRectRender & rect, const GMatrix44 & matrix, const GRenderInfo * renderInfo);

GPoint mapWindowToView(const GPoint & point) const;

Expand All @@ -63,7 +64,7 @@ class GRenderEngine
private:
void doInitialize();
void doFinalize();
void doDrawTexture(const std::shared_ptr<GImageData> & texture, const GRect & rect, const GTransform & transform, const GRenderInfo * renderInfo);
void doDrawTexture(const std::shared_ptr<GImageData> & texture, const GRect & rect, const GMatrix44 & matrix, const GRenderInfo * renderInfo);

void doFitView();

Expand Down
3 changes: 2 additions & 1 deletion include/gincu/gtextrender.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "gincu/gcolor.h"
#include "gincu/ggeometry.h"
#include "gincu/grenderanchor.h"
#include "gincu/gmatrix.h"

#include <string>
#include <memory>
Expand All @@ -25,7 +26,7 @@ class GTextRender
void setColor(const GColor textColor);
void setFontSize(const int fontSize);

void draw(const GTransform & transform, const GRenderInfo * renderInfo);
void draw(const GMatrix44 & matrix, const GRenderInfo * renderInfo);

GSize getSize() const;

Expand Down
60 changes: 59 additions & 1 deletion include/gincu/gtransform.h
Original file line number Diff line number Diff line change
@@ -1 +1,59 @@
#include "gincu/sfml/gtransform.h"
#ifndef GTRANSFORM_H
#define GTRANSFORM_H

#include "gincu/ggeometry.h"
#include "gincu/grenderanchor.h"
#include "gincu/gmatrix.h"

#include "cpgf/gflags.h"

namespace gincu {

class GTransform
{
private:
enum class Flags {
flagDirty = 1 << 0,
flagProjection = 1 << 1
};

public:
GTransform();
explicit GTransform(const GPoint & position, const GScale & scale = {1.0f, 1.0f});
explicit GTransform(const GMatrix44 & matrix);

GPoint getPosition() const;
void setPosition(const GPoint & position);

GPoint getOrigin() const;
void setOrigin(const GPoint & origin);

GScale getScale() const;
void setScale(const GScale & scale);

float getRotation() const;
void setRotation(const float rotation);

const GMatrix44 & getMatrix() const;

void setProjectionMode(const bool projectionMode) const;

private:
void doUpdateTransform() const;

bool isProjectionMode() const { return this->flags.has(Flags::flagProjection); }

private:
GPoint position;
GPoint origin;
GScale scaleValue;
float rotation; // degree
mutable cpgf::GFlags<Flags> flags;
mutable GMatrix44 matrix;
};


} //namespace gincu


#endif
67 changes: 0 additions & 67 deletions include/gincu/sfml/gtransform.h

This file was deleted.

4 changes: 2 additions & 2 deletions src/gatlasrender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ GAtlasRender::GAtlasRender(const GAtlas & atlas)
{
}

void GAtlasRender::draw(const GTransform & transform, const GRenderInfo * renderInfo)
void GAtlasRender::draw(const GMatrix44 & matrix, const GRenderInfo * renderInfo)
{
if(this->index >= 0 && this->index < this->atlas.getImageCount()) {
GRenderEngine::getInstance()->draw(*this, transform, renderInfo);
GRenderEngine::getInstance()->draw(*this, matrix, renderInfo);
}
}

Expand Down
Loading

0 comments on commit 7c47866

Please sign in to comment.