summaryrefslogtreecommitdiffstats
path: root/src/main/java/dev
diff options
context:
space:
mode:
authorLibravatar bigfoot547 <[email protected]>2024-06-16 12:50:07 -0500
committerLibravatar bigfoot547 <[email protected]>2024-06-16 12:50:07 -0500
commit1a581914e19ba02626edb91995840d579a6e8197 (patch)
tree5866e2fefdd171b0669065e123fc48f881b117e9 /src/main/java/dev
parentcomplete refactor (diff)
add per-axis world scale
Diffstat (limited to 'src/main/java/dev')
-rw-r--r--src/main/java/dev/figboot/cuberender/api/PlayerModel.java23
-rw-r--r--src/main/java/dev/figboot/cuberender/test/TestWindow.java2
-rw-r--r--src/main/java/dev/figboot/cuberender/test/TestWindowControl.java12
3 files changed, 31 insertions, 6 deletions
diff --git a/src/main/java/dev/figboot/cuberender/api/PlayerModel.java b/src/main/java/dev/figboot/cuberender/api/PlayerModel.java
index ac9c8ba..c1555b3 100644
--- a/src/main/java/dev/figboot/cuberender/api/PlayerModel.java
+++ b/src/main/java/dev/figboot/cuberender/api/PlayerModel.java
@@ -79,7 +79,7 @@ public class PlayerModel {
private float worldRotY;
private float worldRotX;
private float headPitch;
- private float worldScale;
+ private float worldScaleX, worldScaleY, worldScaleZ;
private boolean transformAngleDirty;
@@ -106,7 +106,8 @@ public class PlayerModel {
worldRotY = 0.0f;
worldRotX = 0.0f;
headPitch = 0.0f;
- worldScale = 0.75f;
+
+ setWorldScale(0.75f);
Texture tex = new Texture(skinTexture);
@@ -249,12 +250,24 @@ public class PlayerModel {
}
/**
- * Sets the world scale.
+ * Sets the world scale. This is equivalent to {@code setWorldScale(scale, scale, scale)}.
* @param scale the world scale (default is 0.75)
* @see PlayerModel#updateTransforms()
*/
public void setWorldScale(float scale) {
- this.worldScale = scale;
+ setWorldScale(scale, scale, scale);
+ }
+
+ /**
+ * Sets the world scale on each axis.
+ * @param scaleX the world scale along the X axis (left to right)
+ * @param scaleY the world scale along the Y axis (top to bottom)
+ * @param scaleZ the world scale along the Z axis (towards the viewer)
+ */
+ public void setWorldScale(float scaleX, float scaleY, float scaleZ) {
+ this.worldScaleX = scaleX;
+ this.worldScaleY = scaleY;
+ this.worldScaleZ = scaleZ;
transformAngleDirty = true;
}
@@ -285,7 +298,7 @@ public class PlayerModel {
transforms.put(BodyPart.CAPE, calculateTransform(BodyPart.CAPE, capeAngle, 0));
- Matrix4f worldTransform = Matrix4f.scale(worldScale).times(Matrix4f.rotateX(worldRotX)).times(Matrix4f.rotateY(worldRotY));
+ Matrix4f worldTransform = Matrix4f.scale(worldScaleX, worldScaleY, worldScaleZ).times(Matrix4f.rotateX(worldRotX)).times(Matrix4f.rotateY(worldRotY));
for (BodyPart part : BodyPart.values()) {
transforms.put(part, worldTransform.times(transforms.get(part), new Matrix4f()));
}
diff --git a/src/main/java/dev/figboot/cuberender/test/TestWindow.java b/src/main/java/dev/figboot/cuberender/test/TestWindow.java
index 95af070..aa5a03f 100644
--- a/src/main/java/dev/figboot/cuberender/test/TestWindow.java
+++ b/src/main/java/dev/figboot/cuberender/test/TestWindow.java
@@ -6,7 +6,7 @@ class TestWindow extends JFrame {
public TestWindow() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setTitle("Graphics test");
- setSize(300, 300);
+ setSize(200, 300);
setLocationRelativeTo(null);
GraphicsPanel gp = new GraphicsPanel();
diff --git a/src/main/java/dev/figboot/cuberender/test/TestWindowControl.java b/src/main/java/dev/figboot/cuberender/test/TestWindowControl.java
index 9c8d2b0..2076fbc 100644
--- a/src/main/java/dev/figboot/cuberender/test/TestWindowControl.java
+++ b/src/main/java/dev/figboot/cuberender/test/TestWindowControl.java
@@ -9,6 +9,8 @@ import javax.swing.border.LineBorder;
import javax.swing.event.ChangeEvent;
import java.awt.*;
import java.awt.event.ActionEvent;
+import java.awt.event.ComponentAdapter;
+import java.awt.event.ComponentEvent;
import java.util.EnumMap;
import java.util.Map;
@@ -142,6 +144,16 @@ class TestWindowControl extends JFrame {
setResizable(false);
setLocationRelativeTo(null);
+ graphicsPanel.addComponentListener(new ComponentAdapter() {
+ @Override
+ public void componentResized(ComponentEvent e) {
+ float aspect = (float)graphicsPanel.getWidth() / graphicsPanel.getHeight();
+ graphicsPanel.getModel().setWorldScale(0.75f / aspect, 0.75f, 0.75f);
+ graphicsPanel.getModel().updateTransforms();
+ graphicsPanel.repaint();
+ }
+ });
+
updateGraphics(true, true);
}