Skip to content

Commit

Permalink
feat(engine): add WireBox Gizmo
Browse files Browse the repository at this point in the history
  • Loading branch information
DiogoMendonc-a committed Oct 12, 2023
1 parent 3aa6d32 commit 05ac363
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
1 change: 1 addition & 0 deletions engine/include/cubos/engine/gizmos/gizmos.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ namespace cubos::engine
void color(const glm::vec3& color);
void drawLine(std::string id, glm::vec3 from, glm::vec3 to, float lifespan = 0);
void drawBox(std::string id, glm::vec3 corner, glm::vec3 oppositeCorner, float lifespan = 0);
void drawWireBox(std::string id, glm::vec3 corner, glm::vec3 oppositeCorner, float lifespan = 0);

void drawQueuedGizmos(DeltaTime deltaTime);

Expand Down
2 changes: 1 addition & 1 deletion engine/samples/gizmos/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ static void drawSystem(Write<Gizmos> gizmos)
gizmos->drawBox("test box", {0.4, 0.4, 0}, {0.6, 0.6, 1}, 0);

gizmos->color({1, 0, 1});
gizmos->drawBox("test box", {0.2, 0.7, 0}, {0.3, 0.1, 0}, 0);
gizmos->drawWireBox("test box", {0.2, 0.7, 0}, {0.3, 0.1, 0}, 0);
}
/// [System]

Expand Down
41 changes: 41 additions & 0 deletions engine/src/cubos/engine/gizmos/gizmos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,47 @@ void Gizmos::drawBox(std::string id, glm::vec3 corner, glm::vec3 oppositeCorner,
std::make_shared<BoxGizmo>(id, corner, oppositeCorner, mColor, lifespan, *mRenderDevice, mPipeline));
}

void Gizmos::drawWireBox(std::string id, glm::vec3 corner, glm::vec3 oppositeCorner, float lifespan)
{
// Front
mGizmosVector.push_back(std::make_shared<LineGizmo>(id, corner, glm::vec3{oppositeCorner[0], corner[1], corner[2]},
mColor, lifespan, *mRenderDevice, mPipeline));
mGizmosVector.push_back(std::make_shared<LineGizmo>(id, corner, glm::vec3{corner[0], oppositeCorner[1], corner[2]},
mColor, lifespan, *mRenderDevice, mPipeline));
mGizmosVector.push_back(std::make_shared<LineGizmo>(id, glm::vec3{oppositeCorner[0], oppositeCorner[1], corner[2]},
glm::vec3{corner[0], oppositeCorner[1], corner[2]}, mColor,
lifespan, *mRenderDevice, mPipeline));
mGizmosVector.push_back(std::make_shared<LineGizmo>(id, glm::vec3{oppositeCorner[0], oppositeCorner[1], corner[2]},
glm::vec3{oppositeCorner[0], corner[1], corner[2]}, mColor,
lifespan, *mRenderDevice, mPipeline));

// Back
mGizmosVector.push_back(std::make_shared<LineGizmo>(id, oppositeCorner,
glm::vec3{corner[0], oppositeCorner[1], oppositeCorner[2]},
mColor, lifespan, *mRenderDevice, mPipeline));
mGizmosVector.push_back(std::make_shared<LineGizmo>(id, oppositeCorner,
glm::vec3{oppositeCorner[0], corner[1], oppositeCorner[2]},
mColor, lifespan, *mRenderDevice, mPipeline));
mGizmosVector.push_back(std::make_shared<LineGizmo>(id, glm::vec3{corner[0], corner[1], oppositeCorner[2]},
glm::vec3{corner[0], oppositeCorner[1], oppositeCorner[2]},
mColor, lifespan, *mRenderDevice, mPipeline));
mGizmosVector.push_back(std::make_shared<LineGizmo>(id, glm::vec3{corner[0], corner[1], oppositeCorner[2]},
glm::vec3{oppositeCorner[0], corner[1], oppositeCorner[2]},
mColor, lifespan, *mRenderDevice, mPipeline));

// Sides
mGizmosVector.push_back(std::make_shared<LineGizmo>(id, corner, glm::vec3{corner[0], corner[1], oppositeCorner[2]},
mColor, lifespan, *mRenderDevice, mPipeline));
mGizmosVector.push_back(std::make_shared<LineGizmo>(id, glm::vec3{corner[0], oppositeCorner[1], corner[2]},
glm::vec3{corner[0], oppositeCorner[1], oppositeCorner[2]},
mColor, lifespan, *mRenderDevice, mPipeline));
mGizmosVector.push_back(std::make_shared<LineGizmo>(id, glm::vec3{oppositeCorner[0], corner[1], corner[2]},
glm::vec3{oppositeCorner[0], corner[1], oppositeCorner[2]},
mColor, lifespan, *mRenderDevice, mPipeline));
mGizmosVector.push_back(std::make_shared<LineGizmo>(id, glm::vec3{oppositeCorner[0], oppositeCorner[1], corner[2]},
oppositeCorner, mColor, lifespan, *mRenderDevice, mPipeline));
}

void Gizmos::drawQueuedGizmos(DeltaTime deltaTime)
{
std::vector<std::size_t> toRemove;
Expand Down

0 comments on commit 05ac363

Please sign in to comment.