diff --git a/src/org/nschmidt/ldparteditor/data/VM01SelectHelper.java b/src/org/nschmidt/ldparteditor/data/VM01SelectHelper.java index b0887f639..a865fc9b6 100644 --- a/src/org/nschmidt/ldparteditor/data/VM01SelectHelper.java +++ b/src/org/nschmidt/ldparteditor/data/VM01SelectHelper.java @@ -1812,7 +1812,7 @@ private List subfilesWithOneVertex() { .toList(); } - public Vector4f getSelectionCenter() { + public Vector3d getSelectionCenter() { final Set objectVertices = Collections.newSetFromMap(new ThreadsafeSortedMap<>()); objectVertices.addAll(selectedVertices); @@ -1856,18 +1856,24 @@ public Vector4f getSelectionCenter() { } } if (!objectVertices.isEmpty()) { - float x = 0f; - float y = 0f; - float z = 0f; - for (Vertex vertex : objectVertices) { - x = x + vertex.x; - y = y + vertex.y; - z = z + vertex.z; + final int count = objectVertices.size(); + if (count == 1) { + final Vertex v = objectVertices.iterator().next(); + return new Vector3d(v); + } else { + BigDecimal c = BigDecimal.valueOf(count); + BigDecimal sumX = BigDecimal.ZERO; + BigDecimal sumY = BigDecimal.ZERO; + BigDecimal sumZ = BigDecimal.ZERO; + for (Vertex vertex : objectVertices) { + sumX = sumX.add(vertex.xp); + sumY = sumY.add(vertex.yp); + sumZ = sumZ.add(vertex.zp); + } + return new Vector3d(sumX.divide(c, Threshold.MC), sumY.divide(c, Threshold.MC), sumZ.divide(c, Threshold.MC)); } - float count = objectVertices.size(); - return new Vector4f(x / count, y / count, z / count, 1f); } else { - return new Vector4f(0f, 0f, 0f, 1f); + return new Vector3d(); } } diff --git a/src/org/nschmidt/ldparteditor/shell/editor3d/toolitem/ManipulatorToolItem.java b/src/org/nschmidt/ldparteditor/shell/editor3d/toolitem/ManipulatorToolItem.java index adcad24c3..ee20c0417 100644 --- a/src/org/nschmidt/ldparteditor/shell/editor3d/toolitem/ManipulatorToolItem.java +++ b/src/org/nschmidt/ldparteditor/shell/editor3d/toolitem/ManipulatorToolItem.java @@ -25,6 +25,7 @@ import org.nschmidt.ldparteditor.helper.Manipulator; import org.nschmidt.ldparteditor.helper.WidgetSelectionHelper; import org.nschmidt.ldparteditor.helper.math.MatrixOperations; +import org.nschmidt.ldparteditor.helper.math.Vector3d; import org.nschmidt.ldparteditor.i18n.I18n; import org.nschmidt.ldparteditor.opengl.OpenGLRenderer; import org.nschmidt.ldparteditor.project.Project; @@ -470,12 +471,12 @@ public static void mntmManipulatorCameraToPos() { @SuppressWarnings("java:S2111") public static void mntmManipulatorToAverage() { if (Project.getFileToEdit() != null) { - Vector4f avg = Project.getFileToEdit().getVertexManager().getSelectionCenter(); + Vector3d avg = Project.getFileToEdit().getVertexManager().getSelectionCenter(); for (OpenGLRenderer renderer : Editor3DWindow.getRenders()) { Composite3D c3d = renderer.getC3D(); if (c3d.getLockableDatFileReference().equals(Project.getFileToEdit())) { - c3d.getManipulator().getPosition().set(avg.x, avg.y, avg.z, 1f); - c3d.getManipulator().setAccuratePosition(new BigDecimal(avg.x / 1000f), new BigDecimal(avg.y / 1000f), new BigDecimal(avg.z / 1000f)); + c3d.getManipulator().getPosition().set(avg.x.floatValue() * 1000f, avg.y.floatValue() * 1000f, avg.z.floatValue() * 1000f, 1f); + c3d.getManipulator().setAccuratePosition(avg.x, avg.y, avg.z); } } }