improve TownLayout placement

This commit is contained in:
austin 2025-05-28 15:54:04 -04:00
parent e9beaba539
commit 5d2aeba4e9
2 changed files with 8 additions and 7 deletions

View File

@ -2023,6 +2023,7 @@ Body synchronization includes enabled state
Fix upright tree continuously re-enabling bodies Fix upright tree continuously re-enabling bodies
Fix server collision resolution never triggering for second body Fix server collision resolution never triggering for second body
Fix macro structure rotation generation Fix macro structure rotation generation
Improvement to building placement math in TownLayout

View File

@ -226,7 +226,7 @@ public class TownLayout {
MacroData macroData = realm.getMacroData(); MacroData macroData = realm.getMacroData();
//get values to scan along //get values to scan along
Vector3d dir = new Vector3d(endPoint).sub(startPoint).normalize(); // Vector3d dir = new Vector3d(endPoint).sub(startPoint).normalize();
int len = (int)startPoint.distance(endPoint); int len = (int)startPoint.distance(endPoint);
//determine if it's primarily north-south or east-west //determine if it's primarily north-south or east-west
@ -254,8 +254,8 @@ public class TownLayout {
rotQuat2 = CursorState.getBlockRotation(rotation2); rotQuat2 = CursorState.getBlockRotation(rotation2);
} else { } else {
roadOffset = new Vector3d(0,0,roadRadiusOffsetRaw); roadOffset = new Vector3d(0,0,roadRadiusOffsetRaw);
rotation1 = VirtualStructure.ROT_FACE_WEST; rotation1 = VirtualStructure.ROT_FACE_EAST;
rotation2 = VirtualStructure.ROT_FACE_EAST; rotation2 = VirtualStructure.ROT_FACE_WEST;
rotQuat1 = CursorState.getBlockRotation(rotation1); rotQuat1 = CursorState.getBlockRotation(rotation1);
rotQuat2 = CursorState.getBlockRotation(rotation2); rotQuat2 = CursorState.getBlockRotation(rotation2);
} }
@ -268,7 +268,7 @@ public class TownLayout {
StructureData structureData = allowedStructures.get(0); StructureData structureData = allowedStructures.get(0);
//scan along the length of the road //scan along the length of the road
for(int i = roadRadiusOffsetRaw; i < len; i++){ for(int i = roadRadiusOffsetRaw; i < len - roadRadiusOffsetRaw; i++){
//update rotation spatial offset based on current struct //update rotation spatial offset based on current struct
rotOffset.set(structureData.getDimensions()); rotOffset.set(structureData.getDimensions());
rotQuat1.transform(rotOffset); rotQuat1.transform(rotOffset);
@ -298,7 +298,7 @@ public class TownLayout {
} }
//scan along the length of the road //scan along the length of the road
for(int i = 0; i < len; i++){ for(int i = roadRadiusOffsetRaw; i < len - roadRadiusOffsetRaw; i++){
//update rotation spatial offset based on current struct //update rotation spatial offset based on current struct
rotOffset.set(structureData.getDimensions()); rotOffset.set(structureData.getDimensions());
rotQuat2.transform(rotOffset); rotQuat2.transform(rotOffset);
@ -308,12 +308,12 @@ public class TownLayout {
rotOffset.mul(-1); rotOffset.mul(-1);
//solve terrain position to place //solve terrain position to place
currPos.set(dir).mul(i).add(startPoint).sub(roadOffset).sub(structureData.getDimensions()); currPos.set(startPoint).lerp(endPoint,i/(double)len).sub(roadOffset);//.sub(structureData.getDimensions());
currPos.y = realm.getServerWorldData().getServerTerrainManager().getElevation(currPos); currPos.y = realm.getServerWorldData().getServerTerrainManager().getElevation(currPos);
//apply structure placement offset //apply structure placement offset
currPos.add(structureData.getPlacementOffset()); currPos.add(structureData.getPlacementOffset());
//add offset to re-align after rotation //add offset to re-align after rotation
// currPos.add(5,0,5); currPos.add(rotOffset.x,0,rotOffset.z);
//update aabb //update aabb
VirtualStructure.setAABB(aabb, currPos, structureData.getDimensions(), rotation2); VirtualStructure.setAABB(aabb, currPos, structureData.getDimensions(), rotation2);