Skip to content

Commit c59b2c3

Browse files
committed
Display the Move Transform information in 3D mode (distances, etc.).
1 parent ea30ba7 commit c59b2c3

File tree

1 file changed

+39
-19
lines changed

1 file changed

+39
-19
lines changed

TheForceEngine/TFE_Editor/LevelEditor/levelEditor.cpp

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4056,6 +4056,27 @@ namespace LevelEditor
40564056
}
40574057
}
40584058

4059+
void displayViewportMoveTransformData(Vec3f p0, Vec3f p1, Vec2f v0, Vec2f v1, Vec2f v2, const char* distStr, const char* xDistStr, const char* zDistStr)
4060+
{
4061+
Vec2f offset = { p1.x - p0.x, p1.z - p0.z };
4062+
4063+
ImVec2 textSize = ImGui::CalcTextSize(distStr);
4064+
ImVec2 textSizeX = ImGui::CalcTextSize(xDistStr);
4065+
ImVec2 textSizeZ = ImGui::CalcTextSize(zDistStr);
4066+
4067+
Vec2i pos = { s32(v0.x + v1.x) / 2, s32(v0.z + v1.z) / 2 };
4068+
Vec2i posX = { s32(v1.x + v2.x) / 2, s32(v1.z + v2.z) / 2 };
4069+
Vec2i posZ = { s32(v0.x + v2.x) / 2, s32(v0.z + v2.z) / 2 };
4070+
4071+
const f32 threshold = 0.01f;
4072+
drawViewportInfo(1, pos, distStr, 0, 0);
4073+
if (fabsf(offset.x) > threshold && fabsf(offset.z) > threshold)
4074+
{
4075+
drawViewportInfo(2, posX, xDistStr, 0, 0);
4076+
drawViewportInfo(3, posZ, zDistStr, 0, 0);
4077+
}
4078+
}
4079+
40594080
void displayTransformToolLabels()
40604081
{
40614082
if (!edit_isTransformToolActive()) { return; }
@@ -4066,21 +4087,18 @@ namespace LevelEditor
40664087
Vec3f p0 = edit_getTransformAnchor();
40674088
Vec3f p1 = edit_getTransformPos();
40684089

4069-
if (s_view == EDIT_VIEW_2D)
4070-
{
4071-
Vec2f offset = { p1.x - p0.x, p1.z - p0.z };
4072-
f32 dx = offset.x;
4073-
f32 dz = offset.z;
4090+
Vec2f offset = { p1.x - p0.x, p1.z - p0.z };
4091+
f32 dx = offset.x;
4092+
f32 dz = offset.z;
40744093

4075-
char dist[256], xDist[256], zDist[256];
4076-
floatToString(sqrtf(offset.x*offset.x + offset.z*offset.z), dist);
4077-
floatToString(dx, xDist);
4078-
floatToString(dz, zDist);
4079-
4080-
Vec2f distOffsetDir = { fabsf(offset.z), fabsf(offset.x) };
4081-
distOffsetDir = TFE_Math::normalize(&distOffsetDir);
4082-
distOffsetDir = { offset.x < 0.0f ? -distOffsetDir.x : 0.0f, offset.z < 0.0f ? -distOffsetDir.z : distOffsetDir.z };
4094+
char dist[256], xDist[256], zDist[256];
4095+
floatToString(sqrtf(offset.x*offset.x + offset.z*offset.z), dist);
4096+
floatToString(dx, xDist);
4097+
floatToString(dz, zDist);
40834098

4099+
if (s_view == EDIT_VIEW_2D)
4100+
{
4101+
Vec2f distOffsetDir = { 4.0f, 4.0f };
40844102
ImVec2 textSize = ImGui::CalcTextSize(dist);
40854103
if (offset.x < 0.0f && offset.z < 0.0f)
40864104
{
@@ -4097,11 +4115,6 @@ namespace LevelEditor
40974115
distOffsetDir.x = -textSize.x - 16.0f;
40984116
distOffsetDir.z = 4.0f;
40994117
}
4100-
else if (offset.x >= 0.0f && offset.z >= 0.0f)
4101-
{
4102-
distOffsetDir.x = 4.0f;
4103-
distOffsetDir.z = 4.0f;
4104-
}
41054118

41064119
Vec2i p0map = worldPos2dToMap({ p0.x, p0.z });
41074120
Vec2i p1map = worldPos2dToMap({ p1.x, p1.z });
@@ -4111,7 +4124,6 @@ namespace LevelEditor
41114124

41124125
Vec2i posX = { ((p0map.x + p1map.x) / 2), offset.z > 0.0f ? p1map.z - 40 : p1map.z + 8 };
41134126
Vec2i posZ = { offset.x < 0.0f ? 8 + p0map.x : -ImGui::CalcTextSize(zDist).x - 24 + p0map.x, ((p0map.z + p1map.z) / 2) };
4114-
41154127
const f32 threshold = 8.0f * s_zoom2d;
41164128
drawViewportInfo(1, pos, dist, 0, 0);
41174129
if (fabsf(offset.x) > threshold && fabsf(offset.z) > threshold)
@@ -4122,6 +4134,14 @@ namespace LevelEditor
41224134
}
41234135
else // EDIT_VIEW_3D
41244136
{
4137+
// project the points onto the map.
4138+
Vec2f v0, v1, v2;
4139+
Vec3f p2 = { p0.x, p0.y, p1.z };
4140+
bool result = worldPosToViewportCoord(p0, &v0) && worldPosToViewportCoord(p1, &v1) && worldPosToViewportCoord(p2, &v2);
4141+
if (result)
4142+
{
4143+
displayViewportMoveTransformData(p0, p1, v0, v1, v2, dist, xDist, zDist);
4144+
}
41254145
}
41264146
}
41274147
else if (mode == TRANS_ROTATE)

0 commit comments

Comments
 (0)