Advertisement
Guest User

Untitled

a guest
Apr 4th, 2020
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.69 KB | None | 0 0
  1. //
  2. // Created by petr on 4/4/20.
  3. //
  4.  
  5. #ifndef RAYMARCHING_CSGTREE_H
  6. #define RAYMARCHING_CSGTREE_H
  7.  
  8. #include <glm/vec3.hpp>
  9. #include <memory>
  10. #include <vector>
  11.  
  12. struct CSGRawData {
  13.   virtual std::vector<uint8_t> getRaw()=0;
  14.   virtual ~CSGRawData() = default;
  15. };
  16.  
  17. struct Operation : public CSGRawData {
  18.   virtual ~Operation() = default;
  19. };
  20.  
  21. struct OperationUnion : public Operation {
  22.   std::vector<uint8_t> getRaw() override;
  23. };
  24.  
  25. struct Shape : public CSGRawData {
  26.   explicit Shape(const glm::vec3 &position) : position(position) {}
  27.   glm::vec3 position;
  28. };
  29.  
  30. struct BoxShape : public Shape {
  31.   BoxShape(const glm::vec3 &position, const glm::vec3 &dimensions) : Shape(position), dimensions(dimensions) {}
  32.   glm::vec3 dimensions;
  33.   std::vector<uint8_t> getRaw() override { return std::vector<uint8_t>(); }
  34. };
  35.  
  36. class CSGNode {
  37. public:
  38.   [[nodiscard]] virtual auto getLeftChild() -> CSGNode & = 0;
  39.   [[nodiscard]] virtual auto getRightChild() -> CSGNode & = 0;
  40.   [[nodiscard]] virtual auto isLeaf() const -> bool = 0;
  41.  
  42.   virtual ~CSGNode() = default;
  43. };
  44.  
  45.  
  46. class OperationCSGNode : public CSGNode {
  47. public:
  48.   auto getLeftChild() -> CSGNode & override;
  49.   auto getRightChild() -> CSGNode & override;
  50.   [[nodiscard]] auto isLeaf() const -> bool override;
  51.  
  52. private:
  53.   std::unique_ptr<CSGNode> leftChild;
  54.   std::unique_ptr<CSGNode> rightChild;
  55.   std::unique_ptr<Operation> operation;
  56. };
  57.  
  58.  
  59. class ShapeCSGNode : public CSGNode {
  60. public:
  61.   auto getLeftChild() -> CSGNode & override;
  62.   auto getRightChild() -> CSGNode & override;
  63.   [[nodiscard]] auto isLeaf() const -> bool override;
  64.  
  65. private:
  66.   std::unique_ptr<Shape> shape;
  67. };
  68.  
  69. class CSGTree {};
  70.  
  71. #endif // RAYMARCHING_CSGTREE_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement