From: Daniel Karbach Date: Thu, 15 May 2014 19:36:42 +0000 (+0200) Subject: orientation for entities X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=4c12267c6727caa3522ac5e38b4f8c17d544ef3e;p=orbi.git orientation for entities --- diff --git a/src/app/Application.cpp b/src/app/Application.cpp index 3ddb414..048ec26 100644 --- a/src/app/Application.cpp +++ b/src/app/Application.cpp @@ -197,31 +197,47 @@ void Application::RenderEntities() { constexpr Color boundsColor(0xFA, 0x00, 0x00); constexpr Color vboxColor(0xFA, 0xFA, 0x00); constexpr Color hboxColor(0x00, 0xFA, 0x00); + constexpr Color dotColor(0x00, 0xFA, 0xFA); for (const Entity *e : world.Entities()) { canvas.SetColor(boundsColor); canvas.OutlineRect( - cam.ToScreen(e->bounds.Position()), + cam.ToScreen(e->bounds.LeftTop()), cam.ToScale(e->bounds.Size()) ); if (const Character *c = dynamic_cast(e)) { - canvas.OutlineRectRot( - Rect( - cam.ToScreen(c->bounds.Position() + c->arm.Position()), - cam.ToScale(c->arm.Size()) - ), - cam.ToScreen(c->bounds.Position() + c->armOrigin), - c->armAngle - ); + if (c->orient == Entity::LOOKS_LEFT) { + canvas.OutlineRectRot( + Rect( + cam.ToScreen(c->bounds.LeftTop() + c->arm.LeftTop()), + cam.ToScale(c->arm.Size()) + ), + cam.ToScreen(c->bounds.LeftTop() + c->armOrigin), + c->armAngle + ); + //canvas.SetColor(dotColor); + //canvas.Cross(cam.ToScreen(c->bounds.LeftTop() + c->armOrigin), 5); + } else { + canvas.OutlineRectRot( + Rect( + cam.ToScreen(c->bounds.RightTop() + MirrorY(c->arm.RightTop())), + cam.ToScale(c->arm.Size()) + ), + cam.ToScreen(c->bounds.RightTop() + MirrorY(c->armOrigin)), + -c->armAngle + ); + //canvas.SetColor(dotColor); + //canvas.Cross(cam.ToScreen(c->bounds.RightTop() + MirrorY(c->armOrigin)), 5); + } } canvas.SetColor(vboxColor); canvas.OutlineRect( - cam.ToScreen(e->vbox.Position()), + cam.ToScreen(e->vbox.LeftTop()), cam.ToScale(e->vbox.Size()) ); canvas.SetColor(hboxColor); canvas.OutlineRect( - cam.ToScreen(e->hbox.Position()), + cam.ToScreen(e->hbox.LeftTop()), cam.ToScale(e->hbox.Size()) ); } diff --git a/src/app/Controller.cpp b/src/app/Controller.cpp index 4d1bf0f..b98688a 100644 --- a/src/app/Controller.cpp +++ b/src/app/Controller.cpp @@ -40,6 +40,7 @@ void Controller::Update(float delta) { void Controller::MoveLeft() { moving -= 1; + e->orient = Entity::LOOKS_LEFT; } void Controller::StopLeft() { @@ -48,6 +49,7 @@ void Controller::StopLeft() { void Controller::MoveRight() { moving += 1; + e->orient = Entity::LOOKS_RIGHT; } void Controller::StopRight() { diff --git a/src/graphics/Vector.h b/src/graphics/Vector.h index 958be23..50ae8c8 100644 --- a/src/graphics/Vector.h +++ b/src/graphics/Vector.h @@ -198,6 +198,15 @@ constexpr Vector Norm(Vector v) { return v / Length(v); } +template +constexpr Vector MirrorX(Vector v) { + return Vector(v.x, -v.y); +} +template +constexpr Vector MirrorY(Vector v) { + return Vector(-v.x, v.y); +} + template constexpr Vector Rotate90(Vector v) { return Vector(-v.y, v.x); diff --git a/src/orbi.cpp b/src/orbi.cpp index 87e3866..a0dab98 100644 --- a/src/orbi.cpp +++ b/src/orbi.cpp @@ -59,6 +59,7 @@ int main(int argc, const char *argv[]) { player.hbox = AABB(0, .1, 2, 1.8); player.arm = AABB(.5, 1.4, 1, .5); player.armOrigin = Vector(1.4, 1.65); + //player.armAngle = 1; player.Move(Vector(5, 0)); world.AddEntity(player); diff --git a/src/world/AABB.h b/src/world/AABB.h index 5b482c4..ca7b857 100644 --- a/src/world/AABB.h +++ b/src/world/AABB.h @@ -23,7 +23,11 @@ public: float Right() const { return rb.x; } float Bottom() const { return rb.y; } - Vector Position() const { return lt; } + Vector LeftTop() const { return lt; } + Vector LeftBottom() const { return Vector(lt.x, rb.y); } + Vector RightTop() const { return Vector(rb.x, lt.y); } + Vector RightBottom() const { return rb; } + Vector Center() const { return lt + HalfSize(); } Vector HalfSize() const { return Size() / 2.0f; } Vector Size() const { return size; } diff --git a/src/world/Entity.h b/src/world/Entity.h index 21663d3..83135f9 100644 --- a/src/world/Entity.h +++ b/src/world/Entity.h @@ -9,6 +9,12 @@ namespace orbi { class Entity { +public: + enum Orientation { + LOOKS_LEFT, + LOOKS_RIGHT, + }; + public: constexpr Entity() { } virtual ~Entity() { } @@ -26,8 +32,7 @@ public: AABB vbox; AABB hbox; - float mass = 1.0f; - float elast = 0.75f; + Orientation orient = LOOKS_LEFT; bool onGround = false;