@@ -4056,6 +4056,27 @@ namespace LevelEditor
4056
4056
}
4057
4057
}
4058
4058
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
+
4059
4080
void displayTransformToolLabels ()
4060
4081
{
4061
4082
if (!edit_isTransformToolActive ()) { return ; }
@@ -4066,21 +4087,18 @@ namespace LevelEditor
4066
4087
Vec3f p0 = edit_getTransformAnchor ();
4067
4088
Vec3f p1 = edit_getTransformPos ();
4068
4089
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 ;
4074
4093
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);
4083
4098
4099
+ if (s_view == EDIT_VIEW_2D)
4100
+ {
4101
+ Vec2f distOffsetDir = { 4 .0f , 4 .0f };
4084
4102
ImVec2 textSize = ImGui::CalcTextSize (dist);
4085
4103
if (offset.x < 0 .0f && offset.z < 0 .0f )
4086
4104
{
@@ -4097,11 +4115,6 @@ namespace LevelEditor
4097
4115
distOffsetDir.x = -textSize.x - 16 .0f ;
4098
4116
distOffsetDir.z = 4 .0f ;
4099
4117
}
4100
- else if (offset.x >= 0 .0f && offset.z >= 0 .0f )
4101
- {
4102
- distOffsetDir.x = 4 .0f ;
4103
- distOffsetDir.z = 4 .0f ;
4104
- }
4105
4118
4106
4119
Vec2i p0map = worldPos2dToMap ({ p0.x , p0.z });
4107
4120
Vec2i p1map = worldPos2dToMap ({ p1.x , p1.z });
@@ -4111,7 +4124,6 @@ namespace LevelEditor
4111
4124
4112
4125
Vec2i posX = { ((p0map.x + p1map.x ) / 2 ), offset.z > 0 .0f ? p1map.z - 40 : p1map.z + 8 };
4113
4126
Vec2i posZ = { offset.x < 0 .0f ? 8 + p0map.x : -ImGui::CalcTextSize (zDist).x - 24 + p0map.x , ((p0map.z + p1map.z ) / 2 ) };
4114
-
4115
4127
const f32 threshold = 8 .0f * s_zoom2d;
4116
4128
drawViewportInfo (1 , pos, dist, 0 , 0 );
4117
4129
if (fabsf (offset.x ) > threshold && fabsf (offset.z ) > threshold)
@@ -4122,6 +4134,14 @@ namespace LevelEditor
4122
4134
}
4123
4135
else // EDIT_VIEW_3D
4124
4136
{
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
+ }
4125
4145
}
4126
4146
}
4127
4147
else if (mode == TRANS_ROTATE)
0 commit comments