From 84b4c1119918172bb6a8aa3884f2257879adbcf5 Mon Sep 17 00:00:00 2001 From: austin Date: Sat, 24 May 2025 14:20:33 -0400 Subject: [PATCH] work on rotating structures --- assets/Data/game/structure.json | 4 +-- docs/src/progress/renderertodo.md | 5 +++ .../macro/structure/VirtualStructure.java | 3 +- .../ServerBlockChunkGenerationThread.java | 32 +++++++++---------- 4 files changed, 25 insertions(+), 19 deletions(-) diff --git a/assets/Data/game/structure.json b/assets/Data/game/structure.json index 3f9444be..3c780c03 100644 --- a/assets/Data/game/structure.json +++ b/assets/Data/game/structure.json @@ -5,9 +5,9 @@ "displayName" : "Default House", "fabPath" : "Data/fab/defaultHouse.fab", "dimensions" : { - "x" : 5, + "x" : 4.75, "y" : 5, - "z" : 5 + "z" : 4.75 }, "placementOffset" : { "x" : 0, diff --git a/docs/src/progress/renderertodo.md b/docs/src/progress/renderertodo.md index e337d2e6..e91df7a2 100644 --- a/docs/src/progress/renderertodo.md +++ b/docs/src/progress/renderertodo.md @@ -1950,6 +1950,11 @@ Town layout work Macro broadphase filters prior to per-voxel macro data intersection checks Block chunks properly stride +(05/24/2025) +Work on rotating structures + + + diff --git a/src/main/java/electrosphere/server/macro/structure/VirtualStructure.java b/src/main/java/electrosphere/server/macro/structure/VirtualStructure.java index 562b692d..5d5a5431 100644 --- a/src/main/java/electrosphere/server/macro/structure/VirtualStructure.java +++ b/src/main/java/electrosphere/server/macro/structure/VirtualStructure.java @@ -7,6 +7,7 @@ import org.joml.Vector3d; import electrosphere.controls.cursor.CursorState; import electrosphere.data.block.fab.BlockFab; import electrosphere.data.struct.StructureData; +import electrosphere.server.datacell.ServerWorldData; import electrosphere.server.macro.MacroData; import electrosphere.server.macro.spatial.MacroAreaObject; import electrosphere.util.annotation.Exclude; @@ -90,7 +91,7 @@ public class VirtualStructure implements MacroAreaObject { rVal.fabPath = data.getFabPath(); rVal.fab = data.getFab(); rVal.type = data.getId(); - rVal.position = position; + rVal.position = ServerWorldData.clampRealToBlock(position); rVal.rotation = rotation; rVal.aabb = new AABBd(); VirtualStructure.setAABB(rVal.aabb, rVal.position, data.getDimensions(), rotation); diff --git a/src/main/java/electrosphere/server/physics/block/manager/ServerBlockChunkGenerationThread.java b/src/main/java/electrosphere/server/physics/block/manager/ServerBlockChunkGenerationThread.java index c97fce93..fe141da4 100644 --- a/src/main/java/electrosphere/server/physics/block/manager/ServerBlockChunkGenerationThread.java +++ b/src/main/java/electrosphere/server/physics/block/manager/ServerBlockChunkGenerationThread.java @@ -244,9 +244,9 @@ public class ServerBlockChunkGenerationThread implements Runnable { if(struct.getAABB().testPoint(currRealPos.x, currRealPos.y, currRealPos.z)){ AABBd aabb = struct.getAABB(); localBlockPos.set( - (int)Math.round((currRealPos.x - aabb.minX) / BlockChunkData.BLOCK_SIZE_MULTIPLIER), - (int)Math.round((currRealPos.y - aabb.minY) / BlockChunkData.BLOCK_SIZE_MULTIPLIER), - (int)Math.round((currRealPos.z - aabb.minZ) / BlockChunkData.BLOCK_SIZE_MULTIPLIER) + Math.round((currRealPos.x - aabb.minX) / BlockChunkData.BLOCK_SIZE_MULTIPLIER), + Math.round((currRealPos.y - aabb.minY) / BlockChunkData.BLOCK_SIZE_MULTIPLIER), + Math.round((currRealPos.z - aabb.minZ) / BlockChunkData.BLOCK_SIZE_MULTIPLIER) ); Quaterniond rotationQuat = CursorState.getBlockRotation(struct.getRotation()); @@ -255,27 +255,27 @@ public class ServerBlockChunkGenerationThread implements Runnable { rotationQuat.transform(dimVec); dimVec.absolute(); if(localBlockPos.x < 0){ - localBlockPos.x = (int)(dimVec.x + localBlockPos.x); + localBlockPos.x = dimVec.x + localBlockPos.x; } if(localBlockPos.y < 0){ - localBlockPos.y = (int)(dimVec.y + localBlockPos.y); + localBlockPos.y = dimVec.y + localBlockPos.y; } if(localBlockPos.z < 0){ - localBlockPos.z = (int)(dimVec.z + localBlockPos.z); + localBlockPos.z = dimVec.z + localBlockPos.z; } - localBlockPos.x = Math.round(localBlockPos.x); - localBlockPos.y = Math.round(localBlockPos.y); - localBlockPos.z = Math.round(localBlockPos.z); + int finalX = Math.round((float)localBlockPos.x); + int finalY = Math.round((float)localBlockPos.y); + int finalZ = Math.round((float)localBlockPos.z); //structure file might have dimensions larger than fab, so need to make sure we're inbounds on fab file to draw data from fab file if( - (int)localBlockPos.x >= 0 && - (int)localBlockPos.y >= 0 && - (int)localBlockPos.z >= 0 && - (int)localBlockPos.x < struct.getFab().getDimensions().x && - (int)localBlockPos.y < struct.getFab().getDimensions().y && - (int)localBlockPos.z < struct.getFab().getDimensions().z + finalX >= 0 && + finalY >= 0 && + finalZ >= 0 && + finalX < struct.getFab().getDimensions().x && + finalY < struct.getFab().getDimensions().y && + finalZ < struct.getFab().getDimensions().z ){ - short blocktype = struct.getFab().getType((int)localBlockPos.x,(int)localBlockPos.y,(int)localBlockPos.z); + short blocktype = struct.getFab().getType(finalX,finalY,finalZ); chunk.setType(x, y, z, blocktype); placedBlock = true; }