]> git.localhorst.tv Git - orbi.git/commitdiff
orientation for entities master
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Thu, 15 May 2014 19:36:42 +0000 (21:36 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Thu, 15 May 2014 19:36:42 +0000 (21:36 +0200)
src/app/Application.cpp
src/app/Controller.cpp
src/graphics/Vector.h
src/orbi.cpp
src/world/AABB.h
src/world/Entity.h

index 3ddb41443a3d4bd6860603cd69a7e1073b670a87..048ec263a4c56be5a779e90e793a0c6602044022 100644 (file)
@@ -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<const Character *>(e)) {
-                       canvas.OutlineRectRot(
-                               Rect<float>(
-                                       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<float>(
+                                               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<float>(
+                                               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())
                );
        }
index 4d1bf0f31f0255bd4aafbed49bc027f8a984dce2..b98688a91ba8710b280998de26e699155f3c5fe5 100644 (file)
@@ -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() {
index 958be232b74ea991f3471d9de2e5c7ef229d085c..50ae8c8de067b184e7d49888c7c31c457fd724ef 100644 (file)
@@ -198,6 +198,15 @@ constexpr Vector<Scalar> Norm(Vector<Scalar> v) {
        return v / Length(v);
 }
 
+template<class Scalar>
+constexpr Vector<Scalar> MirrorX(Vector<Scalar> v) {
+       return Vector<Scalar>(v.x, -v.y);
+}
+template<class Scalar>
+constexpr Vector<Scalar> MirrorY(Vector<Scalar> v) {
+       return Vector<Scalar>(-v.x, v.y);
+}
+
 template<class Scalar>
 constexpr Vector<Scalar> Rotate90(Vector<Scalar> v) {
        return Vector<Scalar>(-v.y, v.x);
index 87e3866645203e08941b5bec2db69497386b3456..a0dab98a27621f29b19689480ea86882c3dd81bf 100644 (file)
@@ -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<float>(1.4, 1.65);
+       //player.armAngle = 1;
        player.Move(Vector<float>(5, 0));
        world.AddEntity(player);
 
index 5b482c4cc701ae9fe6fa9eb8d568bb5b56508f87..ca7b85729e6609efcbb4e156a1f729de70205b3b 100644 (file)
@@ -23,7 +23,11 @@ public:
        float Right() const { return rb.x; }
        float Bottom() const { return rb.y; }
 
-       Vector<float> Position() const { return lt; }
+       Vector<float> LeftTop() const { return lt; }
+       Vector<float> LeftBottom() const { return Vector<float>(lt.x, rb.y); }
+       Vector<float> RightTop() const { return Vector<float>(rb.x, lt.y); }
+       Vector<float> RightBottom() const { return rb; }
+
        Vector<float> Center() const { return lt + HalfSize(); }
        Vector<float> HalfSize() const { return Size() / 2.0f; }
        Vector<float> Size() const { return size; }
index 21663d31c216f230c1f5cc960f865589ba0c530a..83135f99115b10483a039e5f8754326b0eab3718 100644 (file)
@@ -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;