Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1068 add rotation to box gizmos #1071

Merged
merged 2 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- ECS Statistics tesseratos plugin (#1024, **@RiscadoA**).
- Global position, rotation and scale getters (#1002, **@DiogoMendonc-a**).
- Show childOf hierarchy on the world inspector (#991, **@diogomsmiranda**).
- Rotation Gizmo (#878, **@DiogoMendonc-a**).
- Rotation to the Transform Gizmo (#878, **@DiogoMendonc-a**).
- Rotated box Gizmo (#878, **@DiogoMendonc-a**).

### Fixed

Expand Down
9 changes: 9 additions & 0 deletions engine/include/cubos/engine/gizmos/gizmos.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ namespace cubos::engine
void drawBox(const std::string& id, glm::vec3 corner, glm::vec3 oppositeCorner, float lifespan = 0.0F,
Space space = Space::World);

/// @brief Draws a filled box gizmo.
/// @param id Identifier of the gizmo.
/// @param transform Transformation matrix to apply to a unit-sized box centered at the origin.
/// @param lifespan How long the line will be on screen for, in seconds. Defaults to 0, which means a single
/// frame.
/// @param space Space to draw the gizmo in.
void drawBox(const std::string& id, const glm::mat4& transform, float lifespan = 0.0F,
Space space = Space::World);

/// @brief Draws a cut cone gizmo.
/// @param id Identifier of the gizmo.
/// @param firstBaseCenter Center of one of the bases.
Expand Down
11 changes: 10 additions & 1 deletion engine/src/gizmos/gizmos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,16 @@

void Gizmos::drawBox(const std::string& id, glm::vec3 corner, glm::vec3 oppositeCorner, float lifespan, Space space)
{
push(std::make_shared<BoxGizmo>((uint32_t)mHasher(id), corner, oppositeCorner, mColor, lifespan), space);
push(std::make_shared<BoxGizmo>((uint32_t)mHasher(id), corner, oppositeCorner, glm::identity<glm::mat4>(), mColor,

Check warning on line 101 in engine/src/gizmos/gizmos.cpp

View check run for this annotation

Codecov / codecov/patch

engine/src/gizmos/gizmos.cpp#L101

Added line #L101 was not covered by tests
lifespan),
space);
}

void Gizmos::drawBox(const std::string& id, const glm::mat4& transform, float lifespan, Space space)

Check warning on line 106 in engine/src/gizmos/gizmos.cpp

View check run for this annotation

Codecov / codecov/patch

engine/src/gizmos/gizmos.cpp#L106

Added line #L106 was not covered by tests
{
push(std::make_shared<BoxGizmo>((uint32_t)mHasher(id), glm::vec3{-0.5F, -0.5F, -0.5F}, glm::vec3{0.5F, 0.5F, 0.5F},
transform, mColor, lifespan),

Check warning on line 109 in engine/src/gizmos/gizmos.cpp

View check run for this annotation

Codecov / codecov/patch

engine/src/gizmos/gizmos.cpp#L108-L109

Added lines #L108 - L109 were not covered by tests
space);
}

void Gizmos::drawWireBox(const std::string& id, glm::vec3 corner, glm::vec3 oppositeCorner, float lifespan, Space space)
Expand Down
21 changes: 12 additions & 9 deletions engine/src/gizmos/types/box.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
{
glm::vec3 mPointA;
glm::vec3 mPointB;
glm::mat4 mTransform;

public:
/// @brief Constructs.
Expand All @@ -21,10 +22,12 @@
/// @param oppositeCorner Point at the opposite corner of the box.
/// @param color Color for the gizmo to be drawn in.
/// @param lifespan Time the gizmo will remain on screen, in seconds.
BoxGizmo(uint32_t id, glm::vec3 corner, glm::vec3 oppositeCorner, const glm::vec3& color, float lifespan)
BoxGizmo(uint32_t id, glm::vec3 corner, glm::vec3 oppositeCorner, glm::mat4 transform, const glm::vec3& color,

Check warning on line 25 in engine/src/gizmos/types/box.hpp

View check run for this annotation

Codecov / codecov/patch

engine/src/gizmos/types/box.hpp#L25

Added line #L25 was not covered by tests
float lifespan)
: cubos::engine::Gizmos::Gizmo(id, color, lifespan)
, mPointA(corner)
, mPointB(oppositeCorner)
, mTransform(transform)

Check warning on line 30 in engine/src/gizmos/types/box.hpp

View check run for this annotation

Codecov / codecov/patch

engine/src/gizmos/types/box.hpp#L30

Added line #L30 was not covered by tests
{
}

Expand All @@ -36,14 +39,14 @@
const glm::mat<4, 4, float, glm::packed_highp>& mvp) override
{
auto* verts = static_cast<glm::vec3*>(renderer.boxPrimitive.vb->map());
verts[0] = {mPointA[0], mPointA[1], mPointA[2]};
verts[1] = {mPointB[0], mPointA[1], mPointA[2]};
verts[2] = {mPointB[0], mPointA[1], mPointB[2]};
verts[3] = {mPointA[0], mPointA[1], mPointB[2]};
verts[4] = {mPointA[0], mPointB[1], mPointB[2]};
verts[5] = {mPointA[0], mPointB[1], mPointA[2]};
verts[6] = {mPointB[0], mPointB[1], mPointA[2]};
verts[7] = {mPointB[0], mPointB[1], mPointB[2]};
verts[0] = mTransform * glm::vec4{mPointA[0], mPointA[1], mPointA[2], 1.0F};
verts[1] = mTransform * glm::vec4{mPointB[0], mPointA[1], mPointA[2], 1.0F};
verts[2] = mTransform * glm::vec4{mPointB[0], mPointA[1], mPointB[2], 1.0F};
verts[3] = mTransform * glm::vec4{mPointA[0], mPointA[1], mPointB[2], 1.0F};
verts[4] = mTransform * glm::vec4{mPointA[0], mPointB[1], mPointB[2], 1.0F};
verts[5] = mTransform * glm::vec4{mPointA[0], mPointB[1], mPointA[2], 1.0F};
verts[6] = mTransform * glm::vec4{mPointB[0], mPointB[1], mPointA[2], 1.0F};
verts[7] = mTransform * glm::vec4{mPointB[0], mPointB[1], mPointB[2], 1.0F};

Check warning on line 49 in engine/src/gizmos/types/box.hpp

View check run for this annotation

Codecov / codecov/patch

engine/src/gizmos/types/box.hpp#L42-L49

Added lines #L42 - L49 were not covered by tests

renderer.boxPrimitive.vb->unmap();

Expand Down
77 changes: 47 additions & 30 deletions tools/tesseratos/src/tesseratos/transform_gizmo/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,38 +168,55 @@ static void drawPositionGizmo(Query<const Camera&, LocalToWorld&> cameraQuery,
zColor = {1, 1, 0};
}

if (!useLocalAxis)
// Planar movement
if (gizmos.locked("transform_gizmo.position.xy"))
{
// Planar movement
if (gizmos.locked("transform_gizmo.position.xy"))
{
checkPlanarMovement(position, localToWorld.worldPosition(), forwardVector, window->size(), input, pv,
cameraPosition);
xyColor = {1, 1, 1};
}
if (gizmos.locked("transform_gizmo.position.xz"))
{
checkPlanarMovement(position, localToWorld.worldPosition(), upVector, window->size(), input, pv,
cameraPosition);
xzColor = {1, 1, 1};
}
if (gizmos.locked("transform_gizmo.position.yz"))
{
checkPlanarMovement(position, localToWorld.worldPosition(), rightVector, window->size(), input, pv,
cameraPosition);
yzColor = {1, 1, 1};
}

gizmos.color(xyColor);
gizmos.drawBox("transform_gizmo.position.xy", localToWorld.worldPosition() - glm::vec3{0, 0, 0.015F},
localToWorld.worldPosition() + glm::vec3{0.25F, 0.25F, 0.015F});
gizmos.color(xzColor);
gizmos.drawBox("transform_gizmo.position.xz", localToWorld.worldPosition() - glm::vec3{0, 0.015F, 0},
localToWorld.worldPosition() + glm::vec3{0.25F, 0.015F, 0.25F});
gizmos.color(yzColor);
gizmos.drawBox("transform_gizmo.position.yz", localToWorld.worldPosition() - glm::vec3{0.015F, 0, 0},
localToWorld.worldPosition() + glm::vec3{0.015F, 0.25F, 0.25F});
checkPlanarMovement(position, localToWorld.worldPosition(), forwardVector, window->size(), input, pv,
cameraPosition);
xyColor = {1, 1, 1};
}
if (gizmos.locked("transform_gizmo.position.xz"))
{
checkPlanarMovement(position, localToWorld.worldPosition(), upVector, window->size(), input, pv,
cameraPosition);
xzColor = {1, 1, 1};
}
if (gizmos.locked("transform_gizmo.position.yz"))
{
checkPlanarMovement(position, localToWorld.worldPosition(), rightVector, window->size(), input, pv,
cameraPosition);
yzColor = {1, 1, 1};
}

gizmos.color(xyColor);
glm::mat4 transformXY =
glm::translate(glm::mat4(1.0F), localToWorld.worldPosition() + (rightVector + upVector) * 0.125F);
if (useLocalAxis)
{
transformXY = transformXY * glm::toMat4(localToWorld.worldRotation());
}
transformXY = glm::scale(transformXY, glm::vec3(0.25F, 0.25F, 0.015F));

gizmos.drawBox("transform_gizmo.position.xy", transformXY);
gizmos.color(xzColor);
glm::mat4 transformXZ =
glm::translate(glm::mat4(1.0F), localToWorld.worldPosition() + (rightVector + forwardVector) * 0.125F);
if (useLocalAxis)
{
transformXZ = transformXZ * glm::toMat4(localToWorld.worldRotation());
}
transformXZ = glm::scale(transformXZ, glm::vec3(0.25F, 0.015F, 0.25F));

gizmos.drawBox("transform_gizmo.position.xz", transformXZ);
gizmos.color(yzColor);
glm::mat4 transformYZ =
glm::translate(glm::mat4(1.0F), localToWorld.worldPosition() + (upVector + forwardVector) * 0.125F);
if (useLocalAxis)
{
transformYZ = transformYZ * glm::toMat4(localToWorld.worldRotation());
}
transformYZ = glm::scale(transformYZ, glm::vec3(0.015F, 0.25F, 0.25F));
gizmos.drawBox("transform_gizmo.position.yz", transformYZ);

gizmos.color({0.7F, 0.7F, 0.7F});
gizmos.drawBox("", localToWorld.worldPosition() + glm::vec3{0.03F, 0.03F, 0.03F},
Expand Down
Loading