Ver código fonte

Add ability to convert a graphics object to a vertex list

Sam Jaffe 6 anos atrás
pai
commit
ab05fcb49d
2 arquivos alterados com 28 adições e 7 exclusões
  1. 7 7
      graphics/include/game/graphics/object.hpp
  2. 21 0
      graphics/src/object.cpp

+ 7 - 7
graphics/include/game/graphics/object.hpp

@@ -7,6 +7,8 @@
 
 #pragma once
 
+#include <vector>
+
 #include "game/math/math_fwd.hpp"
 #include "game/math/shape.hpp"
 #include "game/util/flyweight.hpp"
@@ -14,16 +16,14 @@
 
 namespace graphics {
   class material;
-
-  struct bound {
-    math::vec2 corner;
-    math::vec2 size;
-  };
+  struct vertex;
 
   struct object {
-    bound location;
+    std::vector<vertex> vertices() const;
+
+    math::dim2::rectangle location;
     math::dim2::quad points;
     flyweight<material> material;
-    bound frame;
+    math::dim2::rectangle frame;
   }; // size:56, align:4
 }

+ 21 - 0
graphics/src/object.cpp

@@ -6,3 +6,24 @@
 //
 
 #include "game/graphics/object.hpp"
+
+#include "game/graphics/vertex.h"
+
+using namespace graphics;
+
+std::vector<vertex> object::vertices() const {
+  static const math::rgba CLEAR{{255, 255, 255, 255}};
+  std::vector<vertex> rval;
+  rval.reserve(6);
+
+  math::dim2::quad frame_quad = frame;
+
+  rval.emplace_back(vertex{points.ll, frame_quad.ll, CLEAR});
+  rval.emplace_back(vertex{points.lr, frame_quad.lr, CLEAR});
+  rval.emplace_back(vertex{points.ur, frame_quad.ur, CLEAR});
+  rval.emplace_back(vertex{points.ll, frame_quad.ll, CLEAR});
+  rval.emplace_back(vertex{points.ur, frame_quad.ur, CLEAR});
+  rval.emplace_back(vertex{points.ul, frame_quad.ul, CLEAR});
+
+  return rval;
+}