From 684bd739b9dc269ccbfcecf86664f3d724603e27 Mon Sep 17 00:00:00 2001 From: Sjoerd van de Goor Date: Wed, 8 Feb 2023 01:30:12 +0100 Subject: [PATCH] Slope rotation (unfinished) --- .../volmit/iris/engine/object/IrisObject.java | 28 +++++++++++++++++++ .../engine/object/IrisObjectPlacement.java | 6 ++++ 2 files changed, 34 insertions(+) diff --git a/src/main/java/com/volmit/iris/engine/object/IrisObject.java b/src/main/java/com/volmit/iris/engine/object/IrisObject.java index 8569ba2c7..74a2ac495 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisObject.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisObject.java @@ -503,6 +503,34 @@ public class IrisObject extends IrisRegistrant { return -1; } + // Rotation calculation + double slopeRotationY = 0; + ProceduralStream heightStream = rdata.getEngine().getComplex().getHeightStream(); + if (config.isRotateTowardsSlope()) { + // TODO: Make this respect object rotation (I have no idea how. So just make sure your objects are sort of square and you'll be fine) + // Whichever side of the rectangle that bounds the object is lowest is the 'direction' of the slope (simply said). + double hNorth = heightStream.get(x, z + ((float)h) / 2); + double hEast = heightStream.get(x + ((float)w) / 2, z); + double hSouth = heightStream.get(x, z - ((float)h) / 2); + double hWest = heightStream.get(x - ((float)w) / 2, z); + double min = Math.min(Math.min(hNorth, hEast), Math.min(hSouth, hWest)); + if (min == hNorth) { + slopeRotationY = 0; + } else if (min == hEast) { + slopeRotationY = 90; + } else if (min == hSouth) { + slopeRotationY = 180; + } else if (min == hWest) { + slopeRotationY = 270; + } + } else if (config.isRotateTowardsSlopePrecise()) { + // I take three points which together make a plane that decently represents the slope beneath the object + double hNorth = heightStream.get(x, z + ((float)h) / 2); + double hEast = heightStream.get(x + ((float)w) / 2, z); + double hSouthWest = heightStream.get(x - ((float)w) / 2, z - ((float)h) / 2); + // TODO: Complex math + } + if (config.isSmartBore()) { ensureSmartBored(placer.isDebugSmartBore()); } diff --git a/src/main/java/com/volmit/iris/engine/object/IrisObjectPlacement.java b/src/main/java/com/volmit/iris/engine/object/IrisObjectPlacement.java index 7b7a08562..13e6dd743 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisObjectPlacement.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisObjectPlacement.java @@ -64,6 +64,12 @@ public class IrisObjectPlacement { private boolean isDolphinTarget = false; @Desc("The slope at which this object can be placed. Range from 0 to 10 by default. Calculated from the corners of the object.") private IrisSlopeClip slopeCondition = new IrisSlopeClip(); + @Desc("Set to true to add the rotation of the direction of the slope of the terrain (wherever the slope is going down) to the y-axis rotation of the object. See also rotateTowardsSlopePrecise.") + private boolean rotateTowardsSlope = false; + @Desc("By default the 'rotateTowardsSlope' function simply calculates which direction" + + " (North East South or West) is the lowest, resulting in a 0, 90, 180 or 270 degree rotations. " + + "Setting this to true does a precise calculation, which may give unwanted side-effects due to non-90 degree rotations.") + private boolean rotateTowardsSlopePrecise = false; @MinNumber(0) @MaxNumber(1) @Desc("The chance for this to place in a chunk. If you need multiple per chunk, set this to 1 and use density.")