Skip to content

Commit 0f824f5

Browse files
committed
The rotation gizmo now works correctly in Entity mode.
1 parent a3c2491 commit 0f824f5

File tree

1 file changed

+120
-29
lines changed

1 file changed

+120
-29
lines changed

TheForceEngine/TFE_Editor/LevelEditor/editTransforms.cpp

Lines changed: 120 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,37 @@ namespace LevelEditor
166166
s_center.y = boundsMin.y;
167167
}
168168
}
169+
else if (s_editMode == LEDIT_ENTITY)
170+
{
171+
const u32 objCount = selection_getCount();
172+
if (objCount)
173+
{
174+
s_transformToolActive = true;
175+
176+
// Get bounds based on vertex set.
177+
s32 objIndex = -1;
178+
EditorSector* sector = nullptr;
179+
Vec3f boundsMin = { FLT_MAX, FLT_MAX, FLT_MAX };
180+
Vec3f boundsMax = { -FLT_MAX,-FLT_MAX,-FLT_MAX };
181+
182+
for (u32 v = 0; v < objCount; v++)
183+
{
184+
selection_getEntity(v, sector, objIndex);
185+
const EditorObject* obj = &sector->obj[objIndex];
186+
boundsMin.x = std::min(boundsMin.x, obj->pos.x);
187+
boundsMin.z = std::min(boundsMin.z, obj->pos.z);
188+
boundsMax.x = std::max(boundsMax.x, obj->pos.x);
189+
boundsMax.z = std::max(boundsMax.z, obj->pos.z);
190+
191+
const Entity* entity = &s_level.entities[obj->entityId];
192+
const f32 base = (entity->type == ETYPE_3D) ? obj->pos.y + entity->obj3d->bounds[0].y : obj->pos.y;
193+
boundsMin.y = std::min(boundsMin.y, obj->pos.y);
194+
}
195+
s_center.x = (boundsMin.x + boundsMax.x) * 0.5f;
196+
s_center.z = (boundsMin.z + boundsMax.z) * 0.5f;
197+
s_center.y = boundsMin.y;
198+
}
199+
}
169200
else if (s_editMode == LEDIT_GUIDELINES)
170201
{
171202
}
@@ -927,7 +958,7 @@ namespace LevelEditor
927958
return totalObjCount;
928959
}
929960

930-
void captureObjectRotationData(u32 vertexCount)
961+
void captureObjectRotationData()
931962
{
932963
if (s_editMode != LEDIT_SECTOR) { return; }
933964
u32 totalObjectCount = captureGetTotalObjectCount();
@@ -959,16 +990,31 @@ namespace LevelEditor
959990
EditorSector* sector = nullptr;
960991
s32 index = -1;
961992

962-
const u32 vertexCount = selection_getCount(SEL_VERTEX);
963-
const u32 totalObjCount = captureGetTotalObjectCount();
964-
s_vertexData.resize(vertexCount);
965-
Vec2f* vtxData = s_vertexData.data();
966-
for (u32 v = 0; v < vertexCount; v++)
993+
if (s_editMode == LEDIT_ENTITY)
967994
{
968-
selection_getVertex(v, sector, index);
969-
vtxData[v] = sector->vtx[index];
995+
const u32 objCount = selection_getCount(SEL_ENTITY);
996+
s_objData.resize(objCount);
997+
Vec3f* objData = s_objData.data();
998+
for (u32 s = 0; s < objCount; s++)
999+
{
1000+
selection_getEntity(s, sector, index);
1001+
EditorObject* obj = &sector->obj[index];
1002+
objData[s] = { obj->pos.x, obj->pos.z, obj->angle };
1003+
}
1004+
}
1005+
else
1006+
{
1007+
const u32 vertexCount = selection_getCount(SEL_VERTEX);
1008+
const u32 totalObjCount = captureGetTotalObjectCount();
1009+
s_vertexData.resize(vertexCount);
1010+
Vec2f* vtxData = s_vertexData.data();
1011+
for (u32 v = 0; v < vertexCount; v++)
1012+
{
1013+
selection_getVertex(v, sector, index);
1014+
vtxData[v] = sector->vtx[index];
1015+
}
1016+
captureObjectRotationData();
9701017
}
971-
captureObjectRotationData(vertexCount);
9721018
}
9731019
}
9741020

@@ -1002,8 +1048,12 @@ namespace LevelEditor
10021048

10031049
void applyRotationToData(f32 angle)
10041050
{
1005-
const u32 vertexCount = selection_getCount(SEL_VERTEX);
1006-
if (!vertexCount) { return; }
1051+
if ((s_editMode == LEDIT_ENTITY && !selection_getCount()) ||
1052+
(s_editMode != LEDIT_ENTITY && !selection_getCount(SEL_VERTEX)))
1053+
{
1054+
return;
1055+
}
1056+
10071057
if (!s_dataCaptured)
10081058
{
10091059
captureRotationData();
@@ -1021,37 +1071,78 @@ namespace LevelEditor
10211071

10221072
EditorSector* sector;
10231073
s32 index;
1024-
const Vec2f* srcVtx = s_vertexData.data();
1025-
if (fabsf(angle) < 0.0001f)
1074+
if (s_editMode == LEDIT_ENTITY)
10261075
{
1027-
// If the angle is very close to zero, then just copy the original data.
1028-
for (u32 v = 0; v < vertexCount; v++)
1076+
const u32 objCount = selection_getCount();
1077+
const Vec3f* srcObjData = s_objData.data();
1078+
if (fabsf(angle) < 0.0001f)
10291079
{
1030-
selection_getVertex(v, sector, index);
1031-
sector->vtx[index] = srcVtx[v];
1032-
if (sector->searchKey != s_searchKey)
1080+
for (u32 o = 0; o < objCount; o++)
10331081
{
1034-
s_sectorChangeList.push_back(sector);
1035-
sector->searchKey = s_searchKey;
1082+
selection_getEntity(o, sector, index);
1083+
EditorObject* obj = &sector->obj[index];
1084+
obj->pos.x = srcObjData[o].x;
1085+
obj->pos.z = srcObjData[o].y;
1086+
obj->angle = srcObjData[o].z;
1087+
if (sector->searchKey != s_searchKey)
1088+
{
1089+
s_sectorChangeList.push_back(sector);
1090+
sector->searchKey = s_searchKey;
1091+
}
1092+
}
1093+
}
1094+
else
1095+
{
1096+
for (u32 o = 0; o < objCount; o++)
1097+
{
1098+
selection_getEntity(o, sector, index);
1099+
EditorObject* obj = &sector->obj[index];
1100+
obj->pos.x = (srcObjData[o].x - s_center.x) * mtx[0].x + (srcObjData[o].y - s_center.z) * mtx[0].y + mtx[0].z;
1101+
obj->pos.z = (srcObjData[o].x - s_center.x) * mtx[1].x + (srcObjData[o].y - s_center.z) * mtx[1].y + mtx[1].z;
1102+
obj->angle = srcObjData[o].z + angle;
1103+
if (sector->searchKey != s_searchKey)
1104+
{
1105+
s_sectorChangeList.push_back(sector);
1106+
sector->searchKey = s_searchKey;
1107+
}
10361108
}
10371109
}
10381110
}
10391111
else
10401112
{
1041-
// Otherwise apply the rotation.
1042-
for (u32 v = 0; v < vertexCount; v++)
1113+
const u32 vertexCount = selection_getCount(SEL_VERTEX);
1114+
const Vec2f* srcVtx = s_vertexData.data();
1115+
if (fabsf(angle) < 0.0001f)
10431116
{
1044-
selection_getVertex(v, sector, index);
1045-
sector->vtx[index].x = (srcVtx[v].x - s_center.x) * mtx[0].x + (srcVtx[v].z - s_center.z) * mtx[0].y + mtx[0].z;
1046-
sector->vtx[index].z = (srcVtx[v].x - s_center.x) * mtx[1].x + (srcVtx[v].z - s_center.z) * mtx[1].y + mtx[1].z;
1047-
if (sector->searchKey != s_searchKey)
1117+
// If the angle is very close to zero, then just copy the original data.
1118+
for (u32 v = 0; v < vertexCount; v++)
10481119
{
1049-
s_sectorChangeList.push_back(sector);
1050-
sector->searchKey = s_searchKey;
1120+
selection_getVertex(v, sector, index);
1121+
sector->vtx[index] = srcVtx[v];
1122+
if (sector->searchKey != s_searchKey)
1123+
{
1124+
s_sectorChangeList.push_back(sector);
1125+
sector->searchKey = s_searchKey;
1126+
}
1127+
}
1128+
}
1129+
else
1130+
{
1131+
// Otherwise apply the rotation.
1132+
for (u32 v = 0; v < vertexCount; v++)
1133+
{
1134+
selection_getVertex(v, sector, index);
1135+
sector->vtx[index].x = (srcVtx[v].x - s_center.x) * mtx[0].x + (srcVtx[v].z - s_center.z) * mtx[0].y + mtx[0].z;
1136+
sector->vtx[index].z = (srcVtx[v].x - s_center.x) * mtx[1].x + (srcVtx[v].z - s_center.z) * mtx[1].y + mtx[1].z;
1137+
if (sector->searchKey != s_searchKey)
1138+
{
1139+
s_sectorChangeList.push_back(sector);
1140+
sector->searchKey = s_searchKey;
1141+
}
10511142
}
10521143
}
1144+
applyRotationToObjects(mtx, angle);
10531145
}
1054-
applyRotationToObjects(mtx, angle);
10551146

10561147
// Update sectors after changes.
10571148
const size_t changeCount = s_sectorChangeList.size();

0 commit comments

Comments
 (0)