Browse Source

correctly position some things

feature/replace-renderer
Martin Dørum 3 years ago
parent
commit
33eda68f12

+ 1
- 1
core.mod/src/entities/PlayerEntity.h View File

@@ -39,7 +39,7 @@ private:
Swan::Animation(ctx.world.getSprite("core::entity/player-still"), 0.8),
Swan::Animation(
ctx.world.getSprite("core::entity/player-running"),
1, Cygnet::Mat3gf{}.scale({-1, 1})),
1, Cygnet::Mat3gf{}.scale({-1, 1}).translate({1, 0})),
Swan::Animation(ctx.world.getSprite("core::entity/player-running"), 1),
} {}


+ 8
- 0
include/swan-common/Matrix3.h View File

@@ -52,12 +52,20 @@ struct Matrix3 {
return *this;
}

constexpr Vec translation() {
return {at(2, 0), at(2, 1)};
}

constexpr Matrix3<T> &scale(Vec vec) {
at(0, 0) *= vec.x;
at(1, 1) *= vec.y;
return *this;
}

constexpr Vec scale() {
return {at(0, 0), at(1, 1)};
}

constexpr Matrix3<T> &rotate(T rads) {
T s = std::sin(rads);
T c = std::cos(rads);

+ 3
- 2
libcygnet/include/cygnet/Renderer.h View File

@@ -30,7 +30,7 @@ struct RenderTile {
struct RenderCamera {
SwanCommon::Vec2 pos;
SwanCommon::Vec2i size;
float zoom = 0;
float zoom = 1;
};

class Renderer {
@@ -90,7 +90,8 @@ inline void Renderer::drawSprite(RenderSprite sprite, SwanCommon::Vec2 pos, int
}

inline void Renderer::drawSpriteFlipped(RenderSprite sprite, SwanCommon::Vec2 pos, int frame) {
drawSprites_.push_back({Mat3gf{}.translate(pos).scale({ -1, 1 }), frame, sprite});
// TODO: Translate X by sprite.scale.x?
drawSprites_.push_back({Mat3gf{}.translate(pos).scale({-1, 1}), frame, sprite});
}

}

+ 1
- 1
libswan/src/Animation.cc View File

@@ -16,7 +16,7 @@ void Animation::tick(float dt) {
}

void Animation::draw(const Vec2 &pos, Cygnet::Renderer &rnd) {
rnd.drawSprite(sprite_, mat_, frame_);
rnd.drawSprite(sprite_, Cygnet::Mat3gf(mat_).translate(pos), frame_);
}

void Animation::reset() {

+ 2
- 1
libswan/src/World.cc View File

@@ -300,7 +300,6 @@ SDL_Color World::backgroundColor() {

void World::draw(Cygnet::Renderer &rnd) {
ZoneScopedN("World draw");
game_->cam_.pos = player_->pos; // - (win.getSize() / 2) + (player_->size / 2); TODO
planes_[currentPlane_]->draw(rnd);
}

@@ -308,6 +307,8 @@ void World::update(float dt) {
ZoneScopedN("World update");
for (auto &plane: planes_)
plane->update(dt);

game_->cam_.pos = player_->pos + Vec2{0.5, 0.5}; // - (win.getSize() / 2) + (player_->size / 2); TODO
}

void World::tick(float dt) {

+ 3
- 3
src/cygnet-test.cc View File

@@ -165,10 +165,10 @@ int main() {
y += 1 * dt;
}

rnd.drawChunk(chunk, { 0, 0 });
rnd.drawChunk(chunk, {0, 0});

rnd.drawSprite(playerSprite, { x, y }, (int)animAcc % 2);
cam.pos = { x + 0.5f, y + 0.5f };
rnd.drawSprite(playerSprite, {x, y}, (int)animAcc % 2);
cam.pos = {x + 0.5f, y + 0.5f};

win.clear();
rnd.draw(cam);

Loading…
Cancel
Save