aboutsummaryrefslogtreecommitdiffstats
path: root/ardor3d-examples
diff options
context:
space:
mode:
authorJoshua Slack <[email protected]>2017-10-18 22:58:08 -0500
committerJoshua Slack <[email protected]>2017-10-18 22:58:08 -0500
commitfd6f4654f290521487dcc1cd9ac700e3b94ecd0e (patch)
tree319636e9a6546c72dca5bae6fbad0e29350d49e4 /ardor3d-examples
parent661c3a01c249b6d94de898f299b0e20e8d372119 (diff)
Cleanup of pack/layout/updateMinimum calls. Components can be packed now. Removed pack(int,int) - should use setMinimum on contents to dictate appropriate pack size. Can still use setContentSize if specific size needed.
UIHud now requires a Canvas to construct, cleaning up the ambiguous use of Camera.getCurrent and making it easier to use a hud size. Cleaned up examples to use nicer flow.
Diffstat (limited to 'ardor3d-examples')
-rw-r--r--ardor3d-examples/src/main/java/com/ardor3d/example/benchmark/ball/BubbleMarkUIExample.java61
-rw-r--r--ardor3d-examples/src/main/java/com/ardor3d/example/effect/NewDynamicSmokerExample.java11
-rw-r--r--ardor3d-examples/src/main/java/com/ardor3d/example/pipeline/AnimationCopyExample.java31
-rw-r--r--ardor3d-examples/src/main/java/com/ardor3d/example/pipeline/AnimationStateExample.java17
-rw-r--r--ardor3d-examples/src/main/java/com/ardor3d/example/pipeline/ColladaExample.java13
-rw-r--r--ardor3d-examples/src/main/java/com/ardor3d/example/renderer/GeneratedTexturesExample.java23
-rw-r--r--ardor3d-examples/src/main/java/com/ardor3d/example/terrain/MountainShadowTerrainExample.java2
-rw-r--r--ardor3d-examples/src/main/java/com/ardor3d/example/ui/InteractUIExample.java91
-rw-r--r--ardor3d-examples/src/main/java/com/ardor3d/example/ui/PopOverUIExample.java21
-rw-r--r--ardor3d-examples/src/main/java/com/ardor3d/example/ui/RotatingUIExample.java13
-rw-r--r--ardor3d-examples/src/main/java/com/ardor3d/example/ui/SimpleUIExample.java9
11 files changed, 135 insertions, 157 deletions
diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/benchmark/ball/BubbleMarkUIExample.java b/ardor3d-examples/src/main/java/com/ardor3d/example/benchmark/ball/BubbleMarkUIExample.java
index 8e8e2d4..5d05024 100644
--- a/ardor3d-examples/src/main/java/com/ardor3d/example/benchmark/ball/BubbleMarkUIExample.java
+++ b/ardor3d-examples/src/main/java/com/ardor3d/example/benchmark/ball/BubbleMarkUIExample.java
@@ -3,13 +3,15 @@
*
* This file is part of Ardor3D.
*
- * Ardor3D is free software: you can redistribute it and/or modify it
+ * Ardor3D is free software: you can redistribute it and/or modify it
* under the terms of its license which may be found in the accompanying
* LICENSE file or at <http://www.ardor3d.com/LICENSE>.
*/
package com.ardor3d.example.benchmark.ball;
+import java.util.concurrent.Callable;
+
import com.ardor3d.example.ExampleBase;
import com.ardor3d.example.Purpose;
import com.ardor3d.extension.ui.UICheckBox;
@@ -17,6 +19,7 @@ import com.ardor3d.extension.ui.UIContainer;
import com.ardor3d.extension.ui.UIFrame;
import com.ardor3d.extension.ui.UIHud;
import com.ardor3d.extension.ui.UILabel;
+import com.ardor3d.extension.ui.UIPanel;
import com.ardor3d.extension.ui.UIRadioButton;
import com.ardor3d.extension.ui.backdrop.SolidBackdrop;
import com.ardor3d.extension.ui.event.ActionEvent;
@@ -30,6 +33,7 @@ import com.ardor3d.image.Texture;
import com.ardor3d.image.TextureStoreFormat;
import com.ardor3d.math.ColorRGBA;
import com.ardor3d.ui.text.BasicText;
+import com.ardor3d.util.GameTaskQueueManager;
import com.ardor3d.util.ReadOnlyTimer;
import com.ardor3d.util.TextureManager;
@@ -69,16 +73,15 @@ public class BubbleMarkUIExample extends ExampleBase {
final int width = _canvas.getCanvasRenderer().getCamera().getWidth();
final int height = _canvas.getCanvasRenderer().getCamera().getHeight();
- hud = new UIHud();
+ hud = new UIHud(_canvas);
// Add Frame for balls
_ballFrame = new UIFrame("Bubbles");
- _ballFrame.updateMinimumSizeFromContents();
- _ballFrame.pack(500, 300);
- _ballFrame.layout();
+ _ballFrame.getContentPanel().setMinimumContentSize(600, 300);
_ballFrame.setResizeable(false);
_ballFrame.setHudXY(5, 5);
_ballFrame.setUseStandin(false);
+ _ballFrame.pack();
hud.add(_ballFrame);
// Add background
@@ -93,35 +96,39 @@ public class BubbleMarkUIExample extends ExampleBase {
// Add fps display
frameRateLabel = BasicText.createDefaultTextLabel("fpsLabel", "");
- frameRateLabel.setTranslation(5, _canvas.getCanvasRenderer().getCamera().getHeight() - 5
- - frameRateLabel.getHeight(), 0);
+ frameRateLabel.setTranslation(5, hud.getHeight() - 5 - frameRateLabel.getHeight(), 0);
frameRateLabel.setTextColor(ColorRGBA.WHITE);
frameRateLabel.getSceneHints().setOrthoOrder(-1);
_root.attachChild(frameRateLabel);
- hud.setupInput(_canvas, _physicalLayer, _logicalLayer);
+ hud.setupInput(_physicalLayer, _logicalLayer);
}
private void buildConfigFrame(final int width, final int height) {
_configFrame = new UIFrame("Config");
- _configFrame.updateMinimumSizeFromContents();
- _configFrame.pack(320, 240);
+ final UIPanel panel = _configFrame.getContentPanel();
+ panel.setLayout(new AnchorLayout());
+ panel.setMinimumContentSize(320, 240);
_configFrame.setUseStandin(true);
- _configFrame.setHudXY(width - _configFrame.getLocalComponentWidth() - 5, height
- - _configFrame.getLocalComponentHeight() - 5);
-
- _configFrame.getContentPanel().setLayout(new AnchorLayout());
+ _configFrame.setHudXY(width - _configFrame.getLocalComponentWidth() - 5,
+ height - _configFrame.getLocalComponentHeight() - 5);
final UICheckBox vsync = new UICheckBox("Enable vsync");
- vsync.setLayoutData(new AnchorLayoutData(Alignment.TOP_LEFT, _configFrame.getContentPanel(),
- Alignment.TOP_LEFT, 5, -5));
+ vsync.setLayoutData(new AnchorLayoutData(Alignment.TOP_LEFT, panel, Alignment.TOP_LEFT, 5, -5));
vsync.setSelectable(true);
vsync.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent event) {
- _canvas.setVSyncEnabled(vsync.isSelected());
+ GameTaskQueueManager.getManager(_canvas.getCanvasRenderer().getRenderContext()).render(
+ new Callable<Void>() {
+ public Void call() throws Exception {
+ _canvas.setVSyncEnabled(vsync.isSelected());
+ return null;
+ }
+ });
+
}
});
- _configFrame.getContentPanel().add(vsync);
+ panel.add(vsync);
final UICheckBox collide = new UICheckBox("Enable ball-ball collision");
collide.setLayoutData(new AnchorLayoutData(Alignment.TOP_LEFT, vsync, Alignment.BOTTOM_LEFT, 0, -5));
@@ -132,11 +139,11 @@ public class BubbleMarkUIExample extends ExampleBase {
skipBallCollide = !collide.isSelected();
}
});
- _configFrame.getContentPanel().add(collide);
+ panel.add(collide);
final UILabel ballsLabel = new UILabel("# of balls:");
ballsLabel.setLayoutData(new AnchorLayoutData(Alignment.TOP_LEFT, collide, Alignment.BOTTOM_LEFT, 0, -15));
- _configFrame.getContentPanel().add(ballsLabel);
+ panel.add(ballsLabel);
final ButtonGroup ballsGroup = new ButtonGroup();
@@ -150,7 +157,7 @@ public class BubbleMarkUIExample extends ExampleBase {
}
});
balls16.setGroup(ballsGroup);
- _configFrame.getContentPanel().add(balls16);
+ panel.add(balls16);
final UIRadioButton balls32 = new UIRadioButton("32");
balls32.setLayoutData(new AnchorLayoutData(Alignment.TOP_LEFT, balls16, Alignment.BOTTOM_LEFT, 0, -5));
@@ -162,7 +169,7 @@ public class BubbleMarkUIExample extends ExampleBase {
}
});
balls32.setGroup(ballsGroup);
- _configFrame.getContentPanel().add(balls32);
+ panel.add(balls32);
final UIRadioButton balls64 = new UIRadioButton("64");
balls64.setLayoutData(new AnchorLayoutData(Alignment.TOP_LEFT, balls32, Alignment.BOTTOM_LEFT, 0, -5));
@@ -174,7 +181,7 @@ public class BubbleMarkUIExample extends ExampleBase {
}
});
balls64.setGroup(ballsGroup);
- _configFrame.getContentPanel().add(balls64);
+ panel.add(balls64);
final UIRadioButton balls128 = new UIRadioButton("128");
balls128.setLayoutData(new AnchorLayoutData(Alignment.TOP_LEFT, balls64, Alignment.BOTTOM_LEFT, 0, -5));
@@ -186,9 +193,9 @@ public class BubbleMarkUIExample extends ExampleBase {
}
});
balls128.setGroup(ballsGroup);
- _configFrame.getContentPanel().add(balls128);
+ panel.add(balls128);
- _configFrame.layout();
+ _configFrame.pack();
}
@Override
@@ -209,8 +216,8 @@ public class BubbleMarkUIExample extends ExampleBase {
// Add balls
for (int i = 0; i < balls.length; i++) {
- final BallComponent ballComp = new BallComponent("ball", tex, Ball.radius * 2, Ball.radius * 2, container
- .getContentWidth(), container.getContentHeight());
+ final BallComponent ballComp = new BallComponent("ball", tex, Ball.radius * 2, Ball.radius * 2,
+ container.getContentWidth(), container.getContentHeight());
container.add(ballComp);
balls[i] = ballComp;
}
diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/effect/NewDynamicSmokerExample.java b/ardor3d-examples/src/main/java/com/ardor3d/example/effect/NewDynamicSmokerExample.java
index 739beba..c307b77 100644
--- a/ardor3d-examples/src/main/java/com/ardor3d/example/effect/NewDynamicSmokerExample.java
+++ b/ardor3d-examples/src/main/java/com/ardor3d/example/effect/NewDynamicSmokerExample.java
@@ -3,7 +3,7 @@
*
* This file is part of Ardor3D.
*
- * Ardor3D is free software: you can redistribute it and/or modify it
+ * Ardor3D is free software: you can redistribute it and/or modify it
* under the terms of its license which may be found in the accompanying
* LICENSE file or at <http://www.ardor3d.com/LICENSE>.
*/
@@ -236,8 +236,8 @@ public class NewDynamicSmokerExample extends ExampleBase {
private void addUI() {
// setup hud
- hud = new UIHud();
- hud.setupInput(_canvas, _physicalLayer, _logicalLayer);
+ hud = new UIHud(_canvas);
+ hud.setupInput(_physicalLayer, _logicalLayer);
hud.setMouseManager(_mouseManager);
final UIFrame frame = new UIFrame("Controls", EnumSet.noneOf(FrameButtons.class));
@@ -307,9 +307,8 @@ public class NewDynamicSmokerExample extends ExampleBase {
frame.setContentPanel(panel);
frame.pack();
- final Camera cam = _canvas.getCanvasRenderer().getCamera();
- frame.setLocalXY(cam.getWidth() - frame.getLocalComponentWidth(),
- cam.getHeight() - frame.getLocalComponentHeight());
+ frame.setLocalXY(hud.getWidth() - frame.getLocalComponentWidth(),
+ hud.getHeight() - frame.getLocalComponentHeight());
hud.add(frame);
}
}
diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/pipeline/AnimationCopyExample.java b/ardor3d-examples/src/main/java/com/ardor3d/example/pipeline/AnimationCopyExample.java
index 6ff67d7..7909261 100644
--- a/ardor3d-examples/src/main/java/com/ardor3d/example/pipeline/AnimationCopyExample.java
+++ b/ardor3d-examples/src/main/java/com/ardor3d/example/pipeline/AnimationCopyExample.java
@@ -3,7 +3,7 @@
*
* This file is part of Ardor3D.
*
- * Ardor3D is free software: you can redistribute it and/or modify it
+ * Ardor3D is free software: you can redistribute it and/or modify it
* under the terms of its license which may be found in the accompanying
* LICENSE file or at <http://www.ardor3d.com/LICENSE>.
*/
@@ -145,24 +145,23 @@ public class AnimationCopyExample extends ExampleBase {
}
private void createHUD() {
- hud = new UIHud();
- hud.setupInput(_canvas, _physicalLayer, _logicalLayer);
+ hud = new UIHud(_canvas);
+ hud.setupInput(_physicalLayer, _logicalLayer);
hud.setMouseManager(_mouseManager);
// Add fps display
frameRateLabel = new UILabel("X");
- frameRateLabel.setHudXY(5,
- _canvas.getCanvasRenderer().getCamera().getHeight() - 5 - frameRateLabel.getContentHeight());
+ frameRateLabel.setHudXY(5, hud.getHeight() - 5 - frameRateLabel.getContentHeight());
frameRateLabel.setForegroundColor(ColorRGBA.WHITE);
hud.add(frameRateLabel);
final UIFrame optionsFrame = new UIFrame("Controls", EnumSet.noneOf(FrameButtons.class));
- final UIPanel basePanel = optionsFrame.getContentPanel();
- basePanel.setLayout(new AnchorLayout());
+ final UIPanel panel = optionsFrame.getContentPanel();
+ panel.setLayout(new AnchorLayout());
runWalkButton = new UIButton("Start running...");
- runWalkButton.setLayoutData(new AnchorLayoutData(Alignment.TOP_LEFT, basePanel, Alignment.TOP_LEFT, 5, -5));
+ runWalkButton.setLayoutData(new AnchorLayoutData(Alignment.TOP_LEFT, panel, Alignment.TOP_LEFT, 5, -5));
runWalkButton.addActionListener(new ActionListener() {
boolean walk = true;
@@ -180,7 +179,7 @@ public class AnimationCopyExample extends ExampleBase {
}
}
});
- basePanel.add(runWalkButton);
+ panel.add(runWalkButton);
punchButton = new UIButton("PUNCH!");
punchButton
@@ -191,7 +190,7 @@ public class AnimationCopyExample extends ExampleBase {
punchButton.setEnabled(false);
}
});
- basePanel.add(punchButton);
+ panel.add(punchButton);
headCheck = new UICheckBox("Procedurally turn head");
headCheck.setLayoutData(new AnchorLayoutData(Alignment.TOP_LEFT, punchButton, Alignment.BOTTOM_LEFT, 0, -5));
@@ -202,7 +201,7 @@ public class AnimationCopyExample extends ExampleBase {
manager.getValuesStore().put("head_blend", headCheck.isSelected() ? 1.0 : 0.0);
}
});
- basePanel.add(headCheck);
+ panel.add(headCheck);
final UICheckBox gpuSkinningCheck = new UICheckBox("Use GPU skinning");
gpuSkinningCheck
@@ -228,7 +227,7 @@ public class AnimationCopyExample extends ExampleBase {
}, true);
}
});
- basePanel.add(gpuSkinningCheck);
+ panel.add(gpuSkinningCheck);
final UICheckBox vboCheck = new UICheckBox("Use VBO");
vboCheck.setLayoutData(new AnchorLayoutData(Alignment.TOP_LEFT, gpuSkinningCheck, Alignment.BOTTOM_LEFT, 0, -5));
@@ -239,7 +238,7 @@ public class AnimationCopyExample extends ExampleBase {
gpuShader.setUseAttributeVBO(vboCheck.isSelected());
}
});
- basePanel.add(vboCheck);
+ panel.add(vboCheck);
final UICheckBox skeletonCheck = new UICheckBox("Show skeleton");
final UICheckBox boneLabelCheck = new UICheckBox("Show joint labels");
@@ -252,7 +251,7 @@ public class AnimationCopyExample extends ExampleBase {
boneLabelCheck.setEnabled(showSkeleton);
}
});
- basePanel.add(skeletonCheck);
+ panel.add(skeletonCheck);
boneLabelCheck.setLayoutData(new AnchorLayoutData(Alignment.TOP_LEFT, skeletonCheck, Alignment.BOTTOM_LEFT, 0,
-5));
@@ -264,10 +263,8 @@ public class AnimationCopyExample extends ExampleBase {
showJointLabels = boneLabelCheck.isSelected();
}
});
- basePanel.add(boneLabelCheck);
+ panel.add(boneLabelCheck);
- optionsFrame.updateMinimumSizeFromContents();
- optionsFrame.layout();
optionsFrame.pack();
optionsFrame.setUseStandin(true);
diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/pipeline/AnimationStateExample.java b/ardor3d-examples/src/main/java/com/ardor3d/example/pipeline/AnimationStateExample.java
index 44b3407..8a87497 100644
--- a/ardor3d-examples/src/main/java/com/ardor3d/example/pipeline/AnimationStateExample.java
+++ b/ardor3d-examples/src/main/java/com/ardor3d/example/pipeline/AnimationStateExample.java
@@ -3,7 +3,7 @@
*
* This file is part of Ardor3D.
*
- * Ardor3D is free software: you can redistribute it and/or modify it
+ * Ardor3D is free software: you can redistribute it and/or modify it
* under the terms of its license which may be found in the accompanying
* LICENSE file or at <http://www.ardor3d.com/LICENSE>.
*/
@@ -140,14 +140,13 @@ public class AnimationStateExample extends ExampleBase {
}
private void createHUD() {
- hud = new UIHud();
- hud.setupInput(_canvas, _physicalLayer, _logicalLayer);
+ hud = new UIHud(_canvas);
+ hud.setupInput(_physicalLayer, _logicalLayer);
hud.setMouseManager(_mouseManager);
// Add fps display
frameRateLabel = new UILabel("X");
- frameRateLabel.setHudXY(5,
- _canvas.getCanvasRenderer().getCamera().getHeight() - 5 - frameRateLabel.getContentHeight());
+ frameRateLabel.setHudXY(5, hud.getHeight() - 5 - frameRateLabel.getContentHeight());
frameRateLabel.setForegroundColor(ColorRGBA.WHITE);
hud.add(frameRateLabel);
@@ -179,7 +178,7 @@ public class AnimationStateExample extends ExampleBase {
punchButton = new UIButton("PUNCH!");
punchButton
- .setLayoutData(new AnchorLayoutData(Alignment.TOP_LEFT, runWalkButton, Alignment.BOTTOM_LEFT, 0, -5));
+ .setLayoutData(new AnchorLayoutData(Alignment.TOP_LEFT, runWalkButton, Alignment.BOTTOM_LEFT, 0, -5));
punchButton.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent event) {
manager.findAnimationLayer("punch").setCurrentState("punch_right", true);
@@ -206,7 +205,7 @@ public class AnimationStateExample extends ExampleBase {
stopButton = new UIButton("Stop");
stopButton
- .setLayoutData(new AnchorLayoutData(Alignment.TOP_LEFT, playPauseButton, Alignment.BOTTOM_LEFT, 0, -5));
+ .setLayoutData(new AnchorLayoutData(Alignment.TOP_LEFT, playPauseButton, Alignment.BOTTOM_LEFT, 0, -5));
stopButton.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent event) {
manager.stop();
@@ -217,7 +216,7 @@ public class AnimationStateExample extends ExampleBase {
final UICheckBox resetAnimCheck = new UICheckBox("Reset Animation On Stop");
resetAnimCheck
- .setLayoutData(new AnchorLayoutData(Alignment.TOP_LEFT, stopButton, Alignment.BOTTOM_LEFT, 0, -5));
+ .setLayoutData(new AnchorLayoutData(Alignment.TOP_LEFT, stopButton, Alignment.BOTTOM_LEFT, 0, -5));
resetAnimCheck.setSelected(false);
resetAnimCheck.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent event) {
@@ -289,8 +288,6 @@ public class AnimationStateExample extends ExampleBase {
});
basePanel.add(boneLabelCheck);
- optionsFrame.updateMinimumSizeFromContents();
- optionsFrame.layout();
optionsFrame.pack();
optionsFrame.setUseStandin(true);
diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/pipeline/ColladaExample.java b/ardor3d-examples/src/main/java/com/ardor3d/example/pipeline/ColladaExample.java
index f9c93d2..750a727 100644
--- a/ardor3d-examples/src/main/java/com/ardor3d/example/pipeline/ColladaExample.java
+++ b/ardor3d-examples/src/main/java/com/ardor3d/example/pipeline/ColladaExample.java
@@ -3,7 +3,7 @@
*
* This file is part of Ardor3D.
*
- * Ardor3D is free software: you can redistribute it and/or modify it
+ * Ardor3D is free software: you can redistribute it and/or modify it
* under the terms of its license which may be found in the accompanying
* LICENSE file or at <http://www.ardor3d.com/LICENSE>.
*/
@@ -132,14 +132,13 @@ public class ColladaExample extends ExampleBase {
_root.attachChild(t1);
_root.getSceneHints().setCullHint(CullHint.Never);
- hud = new UIHud();
- hud.setupInput(_canvas, _physicalLayer, _logicalLayer);
+ hud = new UIHud(_canvas);
+ hud.setupInput(_physicalLayer, _logicalLayer);
hud.setMouseManager(_mouseManager);
// Add fps display
frameRateLabel = new UILabel("X");
- frameRateLabel.setHudXY(5,
- _canvas.getCanvasRenderer().getCamera().getHeight() - 5 - frameRateLabel.getContentHeight());
+ frameRateLabel.setHudXY(5, hud.getHeight() - 5 - frameRateLabel.getContentHeight());
frameRateLabel.setForegroundColor(ColorRGBA.WHITE);
hud.add(frameRateLabel);
@@ -166,7 +165,7 @@ public class ColladaExample extends ExampleBase {
final UICheckBox skinCheck = new UICheckBox("Show skin mesh");
skinCheck
- .setLayoutData(new AnchorLayoutData(Alignment.TOP_LEFT, loadSceneButton, Alignment.BOTTOM_LEFT, 0, -5));
+ .setLayoutData(new AnchorLayoutData(Alignment.TOP_LEFT, loadSceneButton, Alignment.BOTTOM_LEFT, 0, -5));
skinCheck.setSelected(true);
skinCheck.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent event) {
@@ -198,8 +197,6 @@ public class ColladaExample extends ExampleBase {
});
basePanel.add(boneLabelCheck);
- optionsFrame.updateMinimumSizeFromContents();
- optionsFrame.layout();
optionsFrame.pack();
optionsFrame.setUseStandin(true);
diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/renderer/GeneratedTexturesExample.java b/ardor3d-examples/src/main/java/com/ardor3d/example/renderer/GeneratedTexturesExample.java
index 4fdc002..74c68b3 100644
--- a/ardor3d-examples/src/main/java/com/ardor3d/example/renderer/GeneratedTexturesExample.java
+++ b/ardor3d-examples/src/main/java/com/ardor3d/example/renderer/GeneratedTexturesExample.java
@@ -3,7 +3,7 @@
*
* This file is part of Ardor3D.
*
- * Ardor3D is free software: you can redistribute it and/or modify it
+ * Ardor3D is free software: you can redistribute it and/or modify it
* under the terms of its license which may be found in the accompanying
* LICENSE file or at <http://www.ardor3d.com/LICENSE>.
*/
@@ -144,8 +144,8 @@ public class GeneratedTexturesExample extends ExampleBase {
padding = wside / 10;
// Set up hud
- hud = new UIHud();
- hud.setupInput(_canvas, _physicalLayer, _logicalLayer);
+ hud = new UIHud(_canvas);
+ hud.setupInput(_physicalLayer, _logicalLayer);
// Set up the frames
for (int i = 0; i < views.length; i++) {
@@ -246,8 +246,7 @@ public class GeneratedTexturesExample extends ExampleBase {
zoomed = null;
}
- final int endY = 0, endX = (_canvas.getCanvasRenderer().getCamera().getWidth() - _canvas.getCanvasRenderer()
- .getCamera().getHeight()) / 2;
+ final int endY = 0, endX = (hud.getWidth() - hud.getHeight()) / 2;
// add an animator to do the zoom
uiPanel.addController(new SpatialController<UIPanel>() {
@@ -270,12 +269,12 @@ public class GeneratedTexturesExample extends ExampleBase {
// use an scurve to smoothly zoom
final float sCurve = MathUtils.scurve5(ratio);
- final float size = sCurve * (_canvas.getCanvasRenderer().getCamera().getHeight() - hside) + hside;
+ final float size = sCurve * (hud.getHeight() - hside) + hside;
parent.setLocalComponentSize((int) (size * hside / wside), (int) size);
// use an scurve to smoothly shift origin
- parent.setHudXY(Math.round(MathUtils.lerp(sCurve, originX, endX)), Math.round(MathUtils.lerp(sCurve,
- originY, endY)));
+ parent.setHudXY(Math.round(MathUtils.lerp(sCurve, originX, endX)),
+ Math.round(MathUtils.lerp(sCurve, originY, endY)));
parent.layout();
}
@@ -414,8 +413,8 @@ public class GeneratedTexturesExample extends ExampleBase {
final Function3D combinedWood = Functions.add(baseWood, woodGrain);
final Function3D perturbedWood = new TurbulenceFunction3D(combinedWood, 1 / 256.0, 4, 4.0);
final Function3D translatedWood = Functions.translateInput(perturbedWood, 0, 0, 1.5);
- final Function3D rotatedWood = Functions.rotateInput(translatedWood, new Matrix3().fromAngles(
- MathUtils.DEG_TO_RAD * 6, 0, 0));
+ final Function3D rotatedWood = Functions.rotateInput(translatedWood,
+ new Matrix3().fromAngles(MathUtils.DEG_TO_RAD * 6, 0, 0));
final Function3D finalWood = new TurbulenceFunction3D(rotatedWood, 1 / 512.0, 2, 2.0);
final ReadOnlyColorRGBA[] woodColors = new ReadOnlyColorRGBA[256];
@@ -442,8 +441,8 @@ public class GeneratedTexturesExample extends ExampleBase {
// Build up our function
final Function3D primaryJade = new RidgeFunction3D(Functions.simplexNoise(), 6, 2.0, 2.207);
final Function3D baseSecondaryJade = new CylinderFunction3D(2);
- final Function3D rotatedBaseSecondaryJade = Functions.rotateInput(baseSecondaryJade, new Matrix3().fromAngles(
- 0, MathUtils.DEG_TO_RAD * 65, MathUtils.DEG_TO_RAD * 85));
+ final Function3D rotatedBaseSecondaryJade = Functions.rotateInput(baseSecondaryJade,
+ new Matrix3().fromAngles(0, MathUtils.DEG_TO_RAD * 65, MathUtils.DEG_TO_RAD * 85));
final Function3D perturbedBaseSecondaryJade = new TurbulenceFunction3D(rotatedBaseSecondaryJade, 1.0 / 4.0, 4,
4.0);
final Function3D secondaryJade = Functions.scaleBias(perturbedBaseSecondaryJade, .25, 0);
diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/terrain/MountainShadowTerrainExample.java b/ardor3d-examples/src/main/java/com/ardor3d/example/terrain/MountainShadowTerrainExample.java
index d25912d..6d334be 100644
--- a/ardor3d-examples/src/main/java/com/ardor3d/example/terrain/MountainShadowTerrainExample.java
+++ b/ardor3d-examples/src/main/java/com/ardor3d/example/terrain/MountainShadowTerrainExample.java
@@ -1 +1 @@
-/** * Copyright (c) 2008-2012 Ardor Labs, Inc. * * This file is part of Ardor3D. * * Ardor3D is free software: you can redistribute it and/or modify it * under the terms of its license which may be found in the accompanying * LICENSE file or at <http://www.ardor3d.com/LICENSE>. */ package com.ardor3d.example.terrain; import java.awt.image.BufferedImage; import java.io.IOException; import java.util.EnumSet; import java.util.concurrent.Callable; import javax.imageio.ImageIO; import com.ardor3d.example.ExampleBase; import com.ardor3d.example.Purpose; import com.ardor3d.extension.model.collada.jdom.ColladaImporter; import com.ardor3d.extension.model.collada.jdom.data.ColladaStorage; import com.ardor3d.extension.shadow.map.ParallelSplitShadowMapPass; import com.ardor3d.extension.shadow.map.ParallelSplitShadowMapPass.Filter; import com.ardor3d.extension.shadow.map.ShadowCasterManager; import com.ardor3d.extension.terrain.client.Terrain; import com.ardor3d.extension.terrain.client.TerrainBuilder; import com.ardor3d.extension.terrain.client.UrlInputSupplier; import com.ardor3d.extension.terrain.heightmap.ImageHeightMap; import com.ardor3d.extension.terrain.providers.array.ArrayTerrainDataProvider; import com.ardor3d.extension.ui.Orientation; import com.ardor3d.extension.ui.UIButton; import com.ardor3d.extension.ui.UIFrame; import com.ardor3d.extension.ui.UIFrame.FrameButtons; import com.ardor3d.extension.ui.UIHud; import com.ardor3d.extension.ui.UILabel; import com.ardor3d.extension.ui.UIPanel; import com.ardor3d.extension.ui.UISlider; import com.ardor3d.extension.ui.event.ActionEvent; import com.ardor3d.extension.ui.event.ActionListener; import com.ardor3d.extension.ui.layout.RowLayout; import com.ardor3d.extension.ui.text.StyleConstants; import com.ardor3d.extension.ui.util.Insets; import com.ardor3d.framework.Canvas; import com.ardor3d.framework.CanvasRenderer; import com.ardor3d.image.Image; import com.ardor3d.image.Texture; import com.ardor3d.image.Texture2D; import com.ardor3d.image.util.awt.AWTImageLoader; import com.ardor3d.input.Key; import com.ardor3d.input.logical.InputTrigger; import com.ardor3d.input.logical.KeyPressedCondition; import com.ardor3d.input.logical.TriggerAction; import com.ardor3d.input.logical.TwoInputStates; import com.ardor3d.light.DirectionalLight; import com.ardor3d.math.ColorRGBA; import com.ardor3d.math.MathUtils; import com.ardor3d.math.Quaternion; import com.ardor3d.math.Vector3; import com.ardor3d.renderer.Camera; import com.ardor3d.renderer.RenderContext; import com.ardor3d.renderer.Renderer; import com.ardor3d.renderer.queue.RenderBucketType; import com.ardor3d.renderer.state.FogState; import com.ardor3d.renderer.state.FogState.DensityFunction; import com.ardor3d.renderer.state.RenderState.StateType; import com.ardor3d.renderer.state.TextureState; import com.ardor3d.renderer.state.ZBufferState; import com.ardor3d.scenegraph.Node; import com.ardor3d.scenegraph.hint.CullHint; import com.ardor3d.scenegraph.hint.LightCombineMode; import com.ardor3d.scenegraph.hint.TextureCombineMode; import com.ardor3d.scenegraph.shape.Quad; import com.ardor3d.util.GameTaskQueue; import com.ardor3d.util.GameTaskQueueManager; import com.ardor3d.util.ReadOnlyTimer; import com.ardor3d.util.geom.Debugger; import com.ardor3d.util.resource.ResourceLocatorTool; /** * Example showing the Geometry Clipmap Terrain system with 'MegaTextures' where the terrain data is provided from a * float array populated from a heightmap generated from an Image. Requires GLSL support. */ @Purpose(htmlDescriptionKey = "com.ardor3d.example.terrain.ImageMapTerrainExample", // thumbnailPath = "com/ardor3d/example/media/thumbnails/terrain_ImageMapTerrainExample.jpg", // maxHeapMemory = 128) public class MountainShadowTerrainExample extends ExampleBase { private final float farPlane = 8000.0f; /** Quads used for debug showing shadowmaps. */ private Quad _orthoQuad[]; private Terrain terrain; private final Node terrainNode = new Node("terrain"); private boolean groundCamera = false; private Camera terrainCamera; /** Text fields used to present info about the example. */ private final UILabel _exampleInfo[] = new UILabel[2]; /** Pssm shadow map pass. */ private ParallelSplitShadowMapPass _pssmPass; private DirectionalLight light; private double lightTime; private boolean moveLight = false; private UIHud hud; public static void main(final String[] args) { ExampleBase._minDepthBits = 24; ExampleBase.start(MountainShadowTerrainExample.class); } @Override protected void renderExample(final Renderer renderer) { // Lazy init since it needs the renderer... if (!_pssmPass.isInitialised()) { _pssmPass.init(renderer); _pssmPass.setPssmShader(terrain.getGeometryClipmapShader()); for (int i = 0; i < _pssmPass.getNumOfSplits(); i++) { terrain.getClipTextureState().setTexture(_pssmPass.getShadowMapTexture(i), i + 1); } for (int i = 0; i < ParallelSplitShadowMapPass._MAX_SPLITS; i++) { terrain.getGeometryClipmapShader().setUniform("shadowMap" + i, i + 1); } } terrain.getGeometryClipmapShader().setUniform("lightDir", light.getDirection()); for (int i = 0; i < _pssmPass.getNumOfSplits(); i++) { TextureState screen = (TextureState) _orthoQuad[i].getLocalRenderState(StateType.Texture); Texture copy; if (screen == null) { screen = new TextureState(); _orthoQuad[i].setRenderState(screen); copy = new Texture2D(); screen.setTexture(copy); _orthoQuad[i].updateGeometricState(0.0); } else { copy = screen.getTexture(); } copy.setTextureKey(_pssmPass.getShadowMapTexture(i).getTextureKey()); } // XXX: Use a rougher LOD for shadows - tweak? terrain.setMinVisibleLevel(4); // Update shadowmaps - this will update our terrain camera to light pos _pssmPass.updateShadowMaps(renderer); // XXX: reset LOD for drawing from view camera terrain.setMinVisibleLevel(0); // Render scene and terrain with shadows terrainNode.onDraw(renderer); _root.onDraw(renderer); // Render overlay shadows for all objects except the terrain renderer.renderBuckets(); _pssmPass.renderShadowedScene(renderer); renderer.renderBuckets(); // draw ui renderer.draw(hud); } private double counter = 0; private int frames = 0; @Override protected void updateExample(final ReadOnlyTimer timer) { counter += timer.getTimePerFrame(); frames++; if (counter > 1) { final double fps = frames / counter; counter = 0; frames = 0; System.out.printf("%7.1f FPS\n", fps); } final Camera camera = _canvas.getCanvasRenderer().getCamera(); // Make sure camera is above terrain final double height = terrain.getHeightAt(camera.getLocation().getX(), camera.getLocation().getZ()); if (height > -Float.MAX_VALUE && (groundCamera || camera.getLocation().getY() < height + 3)) { camera.setLocation(new Vector3(camera.getLocation().getX(), height + 3, camera.getLocation().getZ())); terrainCamera.set(camera); } else { terrainCamera.set(_canvas.getCanvasRenderer().getCamera()); } // move terrain to view pos terrainNode.updateGeometricState(timer.getTimePerFrame()); hud.updateGeometricState(timer.getTimePerFrame()); if (moveLight) { lightTime += timer.getTimePerFrame(); light.setDirection(new Vector3(Math.sin(lightTime), -.8, Math.cos(lightTime)).normalizeLocal()); } } /** * Initialize pssm pass and scene. */ @Override protected void initExample() { // Setup main camera. _canvas.setTitle("Terrain Example"); final Camera canvasCamera = _canvas.getCanvasRenderer().getCamera(); canvasCamera.setLocation(new Vector3(2176, 790, 688)); canvasCamera.lookAt(new Vector3(canvasCamera.getLocation()).addLocal(-0.87105768019686, -0.4349655341112313, 0.22817427967541867), Vector3.UNIT_Y); canvasCamera.setFrustumPerspective(45.0, (float) _canvas.getCanvasRenderer().getCamera().getWidth() / _canvas.getCanvasRenderer().getCamera().getHeight(), 1.0f, farPlane); final CanvasRenderer canvasRenderer = _canvas.getCanvasRenderer(); final RenderContext renderContext = canvasRenderer.getRenderContext(); final Renderer renderer = canvasRenderer.getRenderer(); GameTaskQueueManager.getManager(renderContext).getQueue(GameTaskQueue.RENDER).enqueue(new Callable<Void>() { @Override public Void call() throws Exception { renderer.setBackgroundColor(ColorRGBA.BLUE); return null; } }); _controlHandle.setMoveSpeed(400); setupDefaultStates(); addRover(); addUI(); // Initialize PSSM shadows _pssmPass = new ParallelSplitShadowMapPass(light, 2048, 4); _pssmPass.setFiltering(Filter.None); _pssmPass.setRenderShadowedScene(false); _pssmPass.setKeepMainShader(true); // _pssmPass.setMinimumLightDistance(500); // XXX: Tune this _pssmPass.setUseSceneTexturing(false); _pssmPass.setUseObjectCullFace(false); _pssmPass.getShadowOffsetState().setFactor(1.1f); _pssmPass.getShadowOffsetState().setUnits(4.0f); // _pssmPass.setDrawDebug(true); // TODO: backside lock test final Quad floor = new Quad("floor", 2048, 2048); floor.updateModelBound(); floor.setRotation(new Quaternion().fromAngleAxis(MathUtils.HALF_PI, Vector3.UNIT_X)); floor.setTranslation(1024, 0, 1024); terrainNode.attachChild(floor); _pssmPass.addBoundsReceiver(terrainNode); // Add objects that will get shadowed through overlay render _pssmPass.add(_root); // Add our occluders that will produce shadows ShadowCasterManager.INSTANCE.addSpatial(terrainNode); ShadowCasterManager.INSTANCE.addSpatial(_root); final int quadSize = _canvas.getCanvasRenderer().getCamera().getWidth() / 10; _orthoQuad = new Quad[ParallelSplitShadowMapPass._MAX_SPLITS]; for (int i = 0; i < ParallelSplitShadowMapPass._MAX_SPLITS; i++) { _orthoQuad[i] = new Quad("OrthoQuad", quadSize, quadSize); _orthoQuad[i].setTranslation(new Vector3(quadSize / 2 + 5 + (quadSize + 5) * i, quadSize / 2 + 5, 1)); _orthoQuad[i].setScale(1, -1, 1); _orthoQuad[i].getSceneHints().setRenderBucketType(RenderBucketType.Ortho); _orthoQuad[i].getSceneHints().setLightCombineMode(LightCombineMode.Off); _orthoQuad[i].getSceneHints().setTextureCombineMode(TextureCombineMode.Replace); _orthoQuad[i].getSceneHints().setCullHint(CullHint.Never); hud.attachChild(_orthoQuad[i]); } try { // Keep a separate camera to be able to freeze terrain update final Camera camera = _canvas.getCanvasRenderer().getCamera(); terrainCamera = new Camera(camera); // IMAGE LOADING AND CONVERSION TO HEIGHTMAP DONE HERE final BufferedImage heightmap = ImageIO.read(ResourceLocatorTool.getClassPathResource( MountainShadowTerrainExample.class, "com/ardor3d/example/media/images/heightmap.jpg")); final Image ardorImage = AWTImageLoader.makeArdor3dImage(heightmap, false); final float[] heightMap = ImageHeightMap.generateHeightMap(ardorImage, 0.05f, .33f); // END OF IMAGE CONVERSION final int SIZE = ardorImage.getWidth(); final ArrayTerrainDataProvider terrainDataProvider = new ArrayTerrainDataProvider(heightMap, SIZE, new Vector3(5, 2048, 5), true); terrainDataProvider.setHeightMax(0.34f); final TerrainBuilder builder = new TerrainBuilder(terrainDataProvider, terrainCamera) .setShowDebugPanels(true); terrain = builder.build(); terrain.setPixelShader(new UrlInputSupplier(ResourceLocatorTool.getClassPathResource( ShadowedTerrainExample.class, "com/ardor3d/extension/terrain/shadowedGeometryClipmapShader_normalMap.frag"))); terrain.reloadShader(); terrain.getGeometryClipmapShader().setUniform("normalMap", 5); terrainNode.attachChild(terrain); terrain.setCullingEnabled(false); } catch (final Exception ex1) { System.out.println("Problem setting up terrain..."); ex1.printStackTrace(); } final double infoStartY = _canvas.getCanvasRenderer().getCamera().getHeight() / 2; for (int i = 0; i < _exampleInfo.length; i++) { _exampleInfo[i] = new UILabel("Text"); _exampleInfo[i].setForegroundColor(ColorRGBA.WHITE, true); _exampleInfo[i].addFontStyle(StyleConstants.KEY_SIZE, 16); _exampleInfo[i].addFontStyle(StyleConstants.KEY_BOLD, Boolean.TRUE); _exampleInfo[i].setTranslation(new Vector3(10, infoStartY - i * 20, 0)); hud.add(_exampleInfo[i]); } updateText(); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.ONE), new TriggerAction() { @Override public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { _controlHandle.setMoveSpeed(5); updateText(); } })); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.TWO), new TriggerAction() { @Override public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { _controlHandle.setMoveSpeed(50); updateText(); } })); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.THREE), new TriggerAction() { @Override public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { _controlHandle.setMoveSpeed(400); updateText(); } })); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.FOUR), new TriggerAction() { @Override public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { _controlHandle.setMoveSpeed(1000); updateText(); } })); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.SPACE), new TriggerAction() { @Override public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { groundCamera = !groundCamera; updateText(); } })); } private void addRover() { try { final ColladaStorage storage = new ColladaImporter().load("collada/sketchup/NASA Mars Rover.dae"); final Node rover = storage.getScene(); rover.setTranslation(440, 102, 160.1); rover.setScale(3); rover.setRotation(new Quaternion().fromAngleAxis(-MathUtils.HALF_PI, Vector3.UNIT_X)); _root.attachChild(rover); } catch (final IOException ex) { ex.printStackTrace(); } } private void setupDefaultStates() { terrainNode.setRenderState(_lightState); terrainNode.setRenderState(_wireframeState); terrainNode.setRenderState(new ZBufferState()); _lightState.detachAll(); light = new DirectionalLight(); light.setEnabled(true); light.setAmbient(new ColorRGBA(0.4f, 0.4f, 0.5f, 1)); light.setDiffuse(new ColorRGBA(0.6f, 0.6f, 0.5f, 1)); light.setSpecular(new ColorRGBA(0.3f, 0.3f, 0.2f, 1)); light.setDirection(new Vector3(-1, -1, -1).normalizeLocal()); _lightState.attach(light); _lightState.setEnabled(true); final FogState fs = new FogState(); fs.setStart(farPlane / 2.0f); fs.setEnd(farPlane); fs.setColor(new ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f)); fs.setDensityFunction(DensityFunction.Linear); terrainNode.setRenderState(fs); } /** * Update text information. */ private void updateText() { _exampleInfo[0].setText("[1/2/3/4] Moving speed: " + _controlHandle.getMoveSpeed() * 3.6 + " km/h"); _exampleInfo[1].setText("[SPACE] Toggle fly/walk: " + (groundCamera ? "walk" : "fly")); } @Override protected void updateLogicalLayer(final ReadOnlyTimer timer) { hud.getLogicalLayer().checkTriggers(timer.getTimePerFrame()); } @Override protected void renderDebug(final Renderer renderer) { super.renderDebug(renderer); if (_showBounds) { Debugger.drawBounds(terrainNode, renderer, true); } } private void addUI() { // setup hud hud = new UIHud(); hud.setupInput(_canvas, _physicalLayer, _logicalLayer); hud.setMouseManager(_mouseManager); final UIFrame frame = new UIFrame("Controls", EnumSet.noneOf(FrameButtons.class)); frame.setResizeable(false); final UILabel distLabel = new UILabel("Max Shadow Distance: 1500"); final UISlider distSlider = new UISlider(Orientation.Horizontal, 0, 2000, 1500); distSlider.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent event) { _pssmPass.setMaxShadowDistance(distSlider.getValue()); distLabel.setText("Max Shadow Distance: " + distSlider.getValue()); } }); final UIButton updateCamera = new UIButton("Update Shadow Camera"); updateCamera.setSelectable(true); updateCamera.setSelected(true); updateCamera.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent event) { _pssmPass.setUpdateMainCamera(updateCamera.isSelected()); updateText(); } }); final UIButton rotateLight = new UIButton("Rotate Light"); rotateLight.setSelectable(true); rotateLight.setSelected(false); rotateLight.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent event) { moveLight = rotateLight.isSelected(); updateText(); } }); final UIPanel panel = new UIPanel(new RowLayout(false, true, false)); panel.setPadding(new Insets(10, 20, 10, 20)); panel.add(distLabel); panel.add(distSlider); panel.add(updateCamera); panel.add(rotateLight); frame.setContentPanel(panel); frame.pack(); final Camera cam = _canvas.getCanvasRenderer().getCamera(); frame.setLocalXY(cam.getWidth() - frame.getLocalComponentWidth(), cam.getHeight() - frame.getLocalComponentHeight()); hud.add(frame); } } \ No newline at end of file
+/** * Copyright (c) 2008-2012 Ardor Labs, Inc. * * This file is part of Ardor3D. * * Ardor3D is free software: you can redistribute it and/or modify it * under the terms of its license which may be found in the accompanying * LICENSE file or at <http://www.ardor3d.com/LICENSE>. */ package com.ardor3d.example.terrain; import java.awt.image.BufferedImage; import java.io.IOException; import java.util.EnumSet; import java.util.concurrent.Callable; import javax.imageio.ImageIO; import com.ardor3d.example.ExampleBase; import com.ardor3d.example.Purpose; import com.ardor3d.extension.model.collada.jdom.ColladaImporter; import com.ardor3d.extension.model.collada.jdom.data.ColladaStorage; import com.ardor3d.extension.shadow.map.ParallelSplitShadowMapPass; import com.ardor3d.extension.shadow.map.ParallelSplitShadowMapPass.Filter; import com.ardor3d.extension.shadow.map.ShadowCasterManager; import com.ardor3d.extension.terrain.client.Terrain; import com.ardor3d.extension.terrain.client.TerrainBuilder; import com.ardor3d.extension.terrain.client.UrlInputSupplier; import com.ardor3d.extension.terrain.heightmap.ImageHeightMap; import com.ardor3d.extension.terrain.providers.array.ArrayTerrainDataProvider; import com.ardor3d.extension.ui.Orientation; import com.ardor3d.extension.ui.UIButton; import com.ardor3d.extension.ui.UIFrame; import com.ardor3d.extension.ui.UIFrame.FrameButtons; import com.ardor3d.extension.ui.UIHud; import com.ardor3d.extension.ui.UILabel; import com.ardor3d.extension.ui.UIPanel; import com.ardor3d.extension.ui.UISlider; import com.ardor3d.extension.ui.event.ActionEvent; import com.ardor3d.extension.ui.event.ActionListener; import com.ardor3d.extension.ui.layout.RowLayout; import com.ardor3d.extension.ui.text.StyleConstants; import com.ardor3d.extension.ui.util.Insets; import com.ardor3d.framework.Canvas; import com.ardor3d.framework.CanvasRenderer; import com.ardor3d.image.Image; import com.ardor3d.image.Texture; import com.ardor3d.image.Texture2D; import com.ardor3d.image.util.awt.AWTImageLoader; import com.ardor3d.input.Key; import com.ardor3d.input.logical.InputTrigger; import com.ardor3d.input.logical.KeyPressedCondition; import com.ardor3d.input.logical.TriggerAction; import com.ardor3d.input.logical.TwoInputStates; import com.ardor3d.light.DirectionalLight; import com.ardor3d.math.ColorRGBA; import com.ardor3d.math.MathUtils; import com.ardor3d.math.Quaternion; import com.ardor3d.math.Vector3; import com.ardor3d.renderer.Camera; import com.ardor3d.renderer.RenderContext; import com.ardor3d.renderer.Renderer; import com.ardor3d.renderer.queue.RenderBucketType; import com.ardor3d.renderer.state.FogState; import com.ardor3d.renderer.state.FogState.DensityFunction; import com.ardor3d.renderer.state.RenderState.StateType; import com.ardor3d.renderer.state.TextureState; import com.ardor3d.renderer.state.ZBufferState; import com.ardor3d.scenegraph.Node; import com.ardor3d.scenegraph.hint.CullHint; import com.ardor3d.scenegraph.hint.LightCombineMode; import com.ardor3d.scenegraph.hint.TextureCombineMode; import com.ardor3d.scenegraph.shape.Quad; import com.ardor3d.util.GameTaskQueue; import com.ardor3d.util.GameTaskQueueManager; import com.ardor3d.util.ReadOnlyTimer; import com.ardor3d.util.geom.Debugger; import com.ardor3d.util.resource.ResourceLocatorTool; /** * Example showing the Geometry Clipmap Terrain system with 'MegaTextures' where the terrain data is provided from a * float array populated from a heightmap generated from an Image. Requires GLSL support. */ @Purpose(htmlDescriptionKey = "com.ardor3d.example.terrain.ImageMapTerrainExample", // thumbnailPath = "com/ardor3d/example/media/thumbnails/terrain_ImageMapTerrainExample.jpg", // maxHeapMemory = 128) public class MountainShadowTerrainExample extends ExampleBase { private final float farPlane = 8000.0f; /** Quads used for debug showing shadowmaps. */ private Quad _orthoQuad[]; private Terrain terrain; private final Node terrainNode = new Node("terrain"); private boolean groundCamera = false; private Camera terrainCamera; /** Text fields used to present info about the example. */ private final UILabel _exampleInfo[] = new UILabel[2]; /** Pssm shadow map pass. */ private ParallelSplitShadowMapPass _pssmPass; private DirectionalLight light; private double lightTime; private boolean moveLight = false; private UIHud hud; public static void main(final String[] args) { ExampleBase._minDepthBits = 24; ExampleBase.start(MountainShadowTerrainExample.class); } @Override protected void renderExample(final Renderer renderer) { // Lazy init since it needs the renderer... if (!_pssmPass.isInitialised()) { _pssmPass.init(renderer); _pssmPass.setPssmShader(terrain.getGeometryClipmapShader()); for (int i = 0; i < _pssmPass.getNumOfSplits(); i++) { terrain.getClipTextureState().setTexture(_pssmPass.getShadowMapTexture(i), i + 1); } for (int i = 0; i < ParallelSplitShadowMapPass._MAX_SPLITS; i++) { terrain.getGeometryClipmapShader().setUniform("shadowMap" + i, i + 1); } } terrain.getGeometryClipmapShader().setUniform("lightDir", light.getDirection()); for (int i = 0; i < _pssmPass.getNumOfSplits(); i++) { TextureState screen = (TextureState) _orthoQuad[i].getLocalRenderState(StateType.Texture); Texture copy; if (screen == null) { screen = new TextureState(); _orthoQuad[i].setRenderState(screen); copy = new Texture2D(); screen.setTexture(copy); _orthoQuad[i].updateGeometricState(0.0); } else { copy = screen.getTexture(); } copy.setTextureKey(_pssmPass.getShadowMapTexture(i).getTextureKey()); } // XXX: Use a rougher LOD for shadows - tweak? terrain.setMinVisibleLevel(4); // Update shadowmaps - this will update our terrain camera to light pos _pssmPass.updateShadowMaps(renderer); // XXX: reset LOD for drawing from view camera terrain.setMinVisibleLevel(0); // Render scene and terrain with shadows terrainNode.onDraw(renderer); _root.onDraw(renderer); // Render overlay shadows for all objects except the terrain renderer.renderBuckets(); _pssmPass.renderShadowedScene(renderer); renderer.renderBuckets(); // draw ui renderer.draw(hud); } private double counter = 0; private int frames = 0; @Override protected void updateExample(final ReadOnlyTimer timer) { counter += timer.getTimePerFrame(); frames++; if (counter > 1) { final double fps = frames / counter; counter = 0; frames = 0; System.out.printf("%7.1f FPS\n", fps); } final Camera camera = _canvas.getCanvasRenderer().getCamera(); // Make sure camera is above terrain final double height = terrain.getHeightAt(camera.getLocation().getX(), camera.getLocation().getZ()); if (height > -Float.MAX_VALUE && (groundCamera || camera.getLocation().getY() < height + 3)) { camera.setLocation(new Vector3(camera.getLocation().getX(), height + 3, camera.getLocation().getZ())); terrainCamera.set(camera); } else { terrainCamera.set(_canvas.getCanvasRenderer().getCamera()); } // move terrain to view pos terrainNode.updateGeometricState(timer.getTimePerFrame()); hud.updateGeometricState(timer.getTimePerFrame()); if (moveLight) { lightTime += timer.getTimePerFrame(); light.setDirection(new Vector3(Math.sin(lightTime), -.8, Math.cos(lightTime)).normalizeLocal()); } } /** * Initialize pssm pass and scene. */ @Override protected void initExample() { // Setup main camera. _canvas.setTitle("Terrain Example"); final Camera canvasCamera = _canvas.getCanvasRenderer().getCamera(); canvasCamera.setLocation(new Vector3(2176, 790, 688)); canvasCamera.lookAt(new Vector3(canvasCamera.getLocation()).addLocal(-0.87105768019686, -0.4349655341112313, 0.22817427967541867), Vector3.UNIT_Y); canvasCamera.setFrustumPerspective(45.0, (float) _canvas.getCanvasRenderer().getCamera().getWidth() / _canvas.getCanvasRenderer().getCamera().getHeight(), 1.0f, farPlane); final CanvasRenderer canvasRenderer = _canvas.getCanvasRenderer(); final RenderContext renderContext = canvasRenderer.getRenderContext(); final Renderer renderer = canvasRenderer.getRenderer(); GameTaskQueueManager.getManager(renderContext).getQueue(GameTaskQueue.RENDER).enqueue(new Callable<Void>() { @Override public Void call() throws Exception { renderer.setBackgroundColor(ColorRGBA.BLUE); return null; } }); _controlHandle.setMoveSpeed(400); setupDefaultStates(); addRover(); addUI(); // Initialize PSSM shadows _pssmPass = new ParallelSplitShadowMapPass(light, 2048, 4); _pssmPass.setFiltering(Filter.None); _pssmPass.setRenderShadowedScene(false); _pssmPass.setKeepMainShader(true); // _pssmPass.setMinimumLightDistance(500); // XXX: Tune this _pssmPass.setUseSceneTexturing(false); _pssmPass.setUseObjectCullFace(false); _pssmPass.getShadowOffsetState().setFactor(1.1f); _pssmPass.getShadowOffsetState().setUnits(4.0f); // _pssmPass.setDrawDebug(true); // TODO: backside lock test final Quad floor = new Quad("floor", 2048, 2048); floor.updateModelBound(); floor.setRotation(new Quaternion().fromAngleAxis(MathUtils.HALF_PI, Vector3.UNIT_X)); floor.setTranslation(1024, 0, 1024); terrainNode.attachChild(floor); _pssmPass.addBoundsReceiver(terrainNode); // Add objects that will get shadowed through overlay render _pssmPass.add(_root); // Add our occluders that will produce shadows ShadowCasterManager.INSTANCE.addSpatial(terrainNode); ShadowCasterManager.INSTANCE.addSpatial(_root); final int quadSize = _canvas.getCanvasRenderer().getCamera().getWidth() / 10; _orthoQuad = new Quad[ParallelSplitShadowMapPass._MAX_SPLITS]; for (int i = 0; i < ParallelSplitShadowMapPass._MAX_SPLITS; i++) { _orthoQuad[i] = new Quad("OrthoQuad", quadSize, quadSize); _orthoQuad[i].setTranslation(new Vector3(quadSize / 2 + 5 + (quadSize + 5) * i, quadSize / 2 + 5, 1)); _orthoQuad[i].setScale(1, -1, 1); _orthoQuad[i].getSceneHints().setRenderBucketType(RenderBucketType.Ortho); _orthoQuad[i].getSceneHints().setLightCombineMode(LightCombineMode.Off); _orthoQuad[i].getSceneHints().setTextureCombineMode(TextureCombineMode.Replace); _orthoQuad[i].getSceneHints().setCullHint(CullHint.Never); hud.attachChild(_orthoQuad[i]); } try { // Keep a separate camera to be able to freeze terrain update final Camera camera = _canvas.getCanvasRenderer().getCamera(); terrainCamera = new Camera(camera); // IMAGE LOADING AND CONVERSION TO HEIGHTMAP DONE HERE final BufferedImage heightmap = ImageIO.read(ResourceLocatorTool.getClassPathResource( MountainShadowTerrainExample.class, "com/ardor3d/example/media/images/heightmap.jpg")); final Image ardorImage = AWTImageLoader.makeArdor3dImage(heightmap, false); final float[] heightMap = ImageHeightMap.generateHeightMap(ardorImage, 0.05f, .33f); // END OF IMAGE CONVERSION final int SIZE = ardorImage.getWidth(); final ArrayTerrainDataProvider terrainDataProvider = new ArrayTerrainDataProvider(heightMap, SIZE, new Vector3(5, 2048, 5), true); terrainDataProvider.setHeightMax(0.34f); final TerrainBuilder builder = new TerrainBuilder(terrainDataProvider, terrainCamera) .setShowDebugPanels(true); terrain = builder.build(); terrain.setPixelShader(new UrlInputSupplier(ResourceLocatorTool.getClassPathResource( ShadowedTerrainExample.class, "com/ardor3d/extension/terrain/shadowedGeometryClipmapShader_normalMap.frag"))); terrain.reloadShader(); terrain.getGeometryClipmapShader().setUniform("normalMap", 5); terrainNode.attachChild(terrain); terrain.setCullingEnabled(false); } catch (final Exception ex1) { System.out.println("Problem setting up terrain..."); ex1.printStackTrace(); } final double infoStartY = _canvas.getCanvasRenderer().getCamera().getHeight() / 2; for (int i = 0; i < _exampleInfo.length; i++) { _exampleInfo[i] = new UILabel("Text"); _exampleInfo[i].setForegroundColor(ColorRGBA.WHITE, true); _exampleInfo[i].addFontStyle(StyleConstants.KEY_SIZE, 16); _exampleInfo[i].addFontStyle(StyleConstants.KEY_BOLD, Boolean.TRUE); _exampleInfo[i].setTranslation(new Vector3(10, infoStartY - i * 20, 0)); hud.add(_exampleInfo[i]); } updateText(); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.ONE), new TriggerAction() { @Override public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { _controlHandle.setMoveSpeed(5); updateText(); } })); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.TWO), new TriggerAction() { @Override public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { _controlHandle.setMoveSpeed(50); updateText(); } })); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.THREE), new TriggerAction() { @Override public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { _controlHandle.setMoveSpeed(400); updateText(); } })); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.FOUR), new TriggerAction() { @Override public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { _controlHandle.setMoveSpeed(1000); updateText(); } })); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.SPACE), new TriggerAction() { @Override public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { groundCamera = !groundCamera; updateText(); } })); } private void addRover() { try { final ColladaStorage storage = new ColladaImporter().load("collada/sketchup/NASA Mars Rover.dae"); final Node rover = storage.getScene(); rover.setTranslation(440, 102, 160.1); rover.setScale(3); rover.setRotation(new Quaternion().fromAngleAxis(-MathUtils.HALF_PI, Vector3.UNIT_X)); _root.attachChild(rover); } catch (final IOException ex) { ex.printStackTrace(); } } private void setupDefaultStates() { terrainNode.setRenderState(_lightState); terrainNode.setRenderState(_wireframeState); terrainNode.setRenderState(new ZBufferState()); _lightState.detachAll(); light = new DirectionalLight(); light.setEnabled(true); light.setAmbient(new ColorRGBA(0.4f, 0.4f, 0.5f, 1)); light.setDiffuse(new ColorRGBA(0.6f, 0.6f, 0.5f, 1)); light.setSpecular(new ColorRGBA(0.3f, 0.3f, 0.2f, 1)); light.setDirection(new Vector3(-1, -1, -1).normalizeLocal()); _lightState.attach(light); _lightState.setEnabled(true); final FogState fs = new FogState(); fs.setStart(farPlane / 2.0f); fs.setEnd(farPlane); fs.setColor(new ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f)); fs.setDensityFunction(DensityFunction.Linear); terrainNode.setRenderState(fs); } /** * Update text information. */ private void updateText() { _exampleInfo[0].setText("[1/2/3/4] Moving speed: " + _controlHandle.getMoveSpeed() * 3.6 + " km/h"); _exampleInfo[1].setText("[SPACE] Toggle fly/walk: " + (groundCamera ? "walk" : "fly")); } @Override protected void updateLogicalLayer(final ReadOnlyTimer timer) { hud.getLogicalLayer().checkTriggers(timer.getTimePerFrame()); } @Override protected void renderDebug(final Renderer renderer) { super.renderDebug(renderer); if (_showBounds) { Debugger.drawBounds(terrainNode, renderer, true); } } private void addUI() { // setup hud hud = new UIHud(_canvas); hud.setupInput(_physicalLayer, _logicalLayer); hud.setMouseManager(_mouseManager); final UIFrame frame = new UIFrame("Controls", EnumSet.noneOf(FrameButtons.class)); frame.setResizeable(false); final UILabel distLabel = new UILabel("Max Shadow Distance: 1500"); final UISlider distSlider = new UISlider(Orientation.Horizontal, 0, 2000, 1500); distSlider.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent event) { _pssmPass.setMaxShadowDistance(distSlider.getValue()); distLabel.setText("Max Shadow Distance: " + distSlider.getValue()); } }); final UIButton updateCamera = new UIButton("Update Shadow Camera"); updateCamera.setSelectable(true); updateCamera.setSelected(true); updateCamera.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent event) { _pssmPass.setUpdateMainCamera(updateCamera.isSelected()); updateText(); } }); final UIButton rotateLight = new UIButton("Rotate Light"); rotateLight.setSelectable(true); rotateLight.setSelected(false); rotateLight.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent event) { moveLight = rotateLight.isSelected(); updateText(); } }); final UIPanel panel = new UIPanel(new RowLayout(false, true, false)); panel.setPadding(new Insets(10, 20, 10, 20)); panel.add(distLabel); panel.add(distSlider); panel.add(updateCamera); panel.add(rotateLight); frame.setContentPanel(panel); frame.pack(); frame.setLocalXY(hud.getWidth() - frame.getLocalComponentWidth(), hud.getHeight() - frame.getLocalComponentHeight()); hud.add(frame); } } \ No newline at end of file
diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/ui/InteractUIExample.java b/ardor3d-examples/src/main/java/com/ardor3d/example/ui/InteractUIExample.java
index 2e1e44e..0a405dc 100644
--- a/ardor3d-examples/src/main/java/com/ardor3d/example/ui/InteractUIExample.java
+++ b/ardor3d-examples/src/main/java/com/ardor3d/example/ui/InteractUIExample.java
@@ -26,19 +26,16 @@ import com.ardor3d.extension.interact.widget.BasicFilterList;
import com.ardor3d.extension.interact.widget.IFilterList;
import com.ardor3d.extension.interact.widget.MovePlanarWidget;
import com.ardor3d.extension.interact.widget.MovePlanarWidget.MovePlane;
-import com.ardor3d.extension.ui.FloatingUIContainer;
import com.ardor3d.extension.ui.Orientation;
import com.ardor3d.extension.ui.UIButton;
import com.ardor3d.extension.ui.UIComboBox;
import com.ardor3d.extension.ui.UIContainer;
-import com.ardor3d.extension.ui.UIFrame;
import com.ardor3d.extension.ui.UIHud;
import com.ardor3d.extension.ui.UIPanel;
import com.ardor3d.extension.ui.UIPieMenu;
import com.ardor3d.extension.ui.UIPieMenuItem;
import com.ardor3d.extension.ui.UISlider;
import com.ardor3d.extension.ui.backdrop.EmptyBackdrop;
-import com.ardor3d.extension.ui.border.EmptyBorder;
import com.ardor3d.extension.ui.event.ActionEvent;
import com.ardor3d.extension.ui.event.ActionListener;
import com.ardor3d.extension.ui.event.SelectionListener;
@@ -87,7 +84,7 @@ thumbnailPath = "com/ardor3d/example/media/thumbnails/interact_InteractUIExample
maxHeapMemory = 64)
public class InteractUIExample extends ExampleBase {
- final UIHud hud = new UIHud();
+ private UIHud hud;
private InteractManager manager;
private MovePlanarWidget moveWidget;
private InsertMarkerUIWidget insertWidget;
@@ -121,6 +118,7 @@ public class InteractUIExample extends ExampleBase {
@Override
protected void initExample() {
_canvas.setTitle("Interact Example");
+ hud = new UIHud(_canvas);
final Camera camera = _canvas.getCanvasRenderer().getCamera();
camera.setLocation(15, 11, -9);
@@ -273,7 +271,7 @@ public class InteractUIExample extends ExampleBase {
manager = new InteractManager(new MarkerState());
manager.setupInput(_canvas, _physicalLayer, _logicalLayer);
- hud.setupInput(_canvas, _physicalLayer, manager.getLogicalLayer());
+ hud.setupInput(_physicalLayer, manager.getLogicalLayer());
hud.setMouseManager(_mouseManager);
final BasicFilterList filterList = new BasicFilterList();
@@ -447,7 +445,7 @@ public class InteractUIExample extends ExampleBase {
class InsertMarkerUIWidget extends AbstractInteractWidget {
- UIFrame popupFrame;
+ UIPanel uiPanel;
public InsertMarkerUIWidget(final IFilterList filterList) {
super(filterList);
@@ -495,16 +493,11 @@ public class InteractUIExample extends ExampleBase {
}
});
- popupFrame = new FloatingUIContainer();
- popupFrame.getContentPanel().add(centerPanel);
- popupFrame.getBasePanel().setBackdrop(new EmptyBackdrop());
- popupFrame.getBasePanel().setBorder(new EmptyBorder());
+ uiPanel = new UIPanel();
+ uiPanel.add(centerPanel);
+ uiPanel.pack();
- popupFrame.updateMinimumSizeFromContents();
- popupFrame.layout();
- popupFrame.pack();
-
- _handle = popupFrame;
+ _handle = uiPanel;
}
private void AddButton(final UIContainer parent, final String label, final ActionListener actionListener) {
@@ -527,7 +520,7 @@ public class InteractUIExample extends ExampleBase {
tempVec.zero();
tempVec.set(Camera.getCurrentCamera().getScreenCoordinates(spat.getWorldTransform().applyForward(tempVec)));
tempVec.setZ(0);
- tempVec.subtractLocal(popupFrame.getContentWidth() / 2, -10, 0);
+ tempVec.subtractLocal(uiPanel.getContentWidth() / 2, -10, 0);
_handle.setTranslation(tempVec);
_handle.updateWorldTransform(true);
}
@@ -537,14 +530,14 @@ public class InteractUIExample extends ExampleBase {
super.receivedControl(manager);
final Spatial spat = manager.getSpatialTarget();
if (spat != null) {
- hud.add(popupFrame);
+ hud.add(uiPanel);
}
}
@Override
public void lostControl(final InteractManager manager) {
super.lostControl(manager);
- hud.remove(popupFrame);
+ hud.remove(uiPanel);
}
@Override
@@ -553,9 +546,9 @@ public class InteractUIExample extends ExampleBase {
if (manager.getActiveWidget() == this) {
final Spatial spat = manager.getSpatialTarget();
if (spat == null) {
- hud.remove(popupFrame);
+ hud.remove(uiPanel);
} else {
- hud.add(popupFrame);
+ hud.add(uiPanel);
}
}
}
@@ -563,7 +556,7 @@ public class InteractUIExample extends ExampleBase {
class ColorSelectUIWidget extends AbstractInteractWidget {
- UIFrame popupFrame;
+ UIPanel uiPanel;
ColorRGBA unconsumedColor;
public ColorSelectUIWidget(final IFilterList filterList) {
@@ -574,13 +567,13 @@ public class InteractUIExample extends ExampleBase {
private void createFrame() {
- final UIPanel centerPanel = new UIPanel(null);
+ final UIPanel centerPanel = new UIPanel();
centerPanel.setBackdrop(new EmptyBackdrop());
centerPanel.setLayoutData(BorderLayoutData.CENTER);
final UIComboBox combo = new UIComboBox(new DefaultComboBoxModel("White", "Black", "Red", "Green", "Blue",
"Yellow", "Magenta", "Cyan"));
- combo.setLocalComponentWidth(100);
+ combo.setMinimumContentWidth(100);
combo.addSelectionListener(new SelectionListener<UIComboBox>() {
@Override
public void selectionChanged(final UIComboBox component, final Object newValue) {
@@ -598,16 +591,11 @@ public class InteractUIExample extends ExampleBase {
});
centerPanel.add(combo);
- popupFrame = new FloatingUIContainer();
- popupFrame.getContentPanel().add(centerPanel);
- popupFrame.getBasePanel().setBackdrop(new EmptyBackdrop());
- popupFrame.getBasePanel().setBorder(null);
-
- popupFrame.updateMinimumSizeFromContents();
- popupFrame.layout();
- popupFrame.pack();
+ uiPanel = new UIPanel();
+ uiPanel.add(centerPanel);
+ uiPanel.pack();
- _handle = popupFrame;
+ _handle = uiPanel;
}
@Override
@@ -620,7 +608,7 @@ public class InteractUIExample extends ExampleBase {
tempVec.zero();
tempVec.set(Camera.getCurrentCamera().getScreenCoordinates(spat.getWorldTransform().applyForward(tempVec)));
tempVec.setZ(0);
- tempVec.subtractLocal(popupFrame.getContentWidth() / 2, -20, 0);
+ tempVec.subtractLocal(uiPanel.getContentWidth() / 2, -20, 0);
_handle.setTranslation(tempVec);
_handle.updateWorldTransform(true);
}
@@ -630,14 +618,14 @@ public class InteractUIExample extends ExampleBase {
super.receivedControl(manager);
final Spatial spat = manager.getSpatialTarget();
if (spat != null) {
- hud.add(popupFrame);
+ hud.add(uiPanel);
}
}
@Override
public void lostControl(final InteractManager manager) {
super.lostControl(manager);
- hud.remove(popupFrame);
+ hud.remove(uiPanel);
}
@Override
@@ -657,9 +645,9 @@ public class InteractUIExample extends ExampleBase {
if (manager.getActiveWidget() == this) {
final Spatial spat = manager.getSpatialTarget();
if (spat == null) {
- hud.remove(popupFrame);
+ hud.remove(uiPanel);
} else {
- hud.add(popupFrame);
+ hud.add(uiPanel);
}
}
}
@@ -667,7 +655,7 @@ public class InteractUIExample extends ExampleBase {
class PulseControlUIWidget extends AbstractInteractWidget {
- UIFrame popupFrame;
+ UIPanel uiPanel;
Double unconsumedPulse;
public PulseControlUIWidget(final IFilterList filterList) {
@@ -678,7 +666,7 @@ public class InteractUIExample extends ExampleBase {
private void createFrame() {
- final UIPanel centerPanel = new UIPanel(null);
+ final UIPanel centerPanel = new UIPanel();
centerPanel.setBackdrop(new EmptyBackdrop());
centerPanel.setLayoutData(BorderLayoutData.CENTER);
@@ -694,19 +682,14 @@ public class InteractUIExample extends ExampleBase {
}
}
});
- slider.setLocalComponentWidth(100);
+ slider.setMinimumContentWidth(100);
centerPanel.add(slider);
- popupFrame = new FloatingUIContainer();
- popupFrame.getContentPanel().add(centerPanel);
- popupFrame.getBasePanel().setBackdrop(new EmptyBackdrop());
- popupFrame.getBasePanel().setBorder(null);
-
- popupFrame.updateMinimumSizeFromContents();
- popupFrame.layout();
- popupFrame.pack();
+ uiPanel = new UIPanel();
+ uiPanel.add(centerPanel);
+ uiPanel.pack();
- _handle = popupFrame;
+ _handle = uiPanel;
}
@Override
@@ -719,7 +702,7 @@ public class InteractUIExample extends ExampleBase {
tempVec.zero();
tempVec.set(Camera.getCurrentCamera().getScreenCoordinates(spat.getWorldTransform().applyForward(tempVec)));
tempVec.setZ(0);
- tempVec.subtractLocal(popupFrame.getContentWidth() / 2, -20, 0);
+ tempVec.subtractLocal(uiPanel.getContentWidth() / 2, -20, 0);
_handle.setTranslation(tempVec);
_handle.updateWorldTransform(true);
}
@@ -729,14 +712,14 @@ public class InteractUIExample extends ExampleBase {
super.receivedControl(manager);
final Spatial spat = manager.getSpatialTarget();
if (spat != null) {
- hud.add(popupFrame);
+ hud.add(uiPanel);
}
}
@Override
public void lostControl(final InteractManager manager) {
super.lostControl(manager);
- hud.remove(popupFrame);
+ hud.remove(uiPanel);
}
@Override
@@ -756,9 +739,9 @@ public class InteractUIExample extends ExampleBase {
if (manager.getActiveWidget() == this) {
final Spatial spat = manager.getSpatialTarget();
if (spat == null) {
- hud.remove(popupFrame);
+ hud.remove(uiPanel);
} else {
- hud.add(popupFrame);
+ hud.add(uiPanel);
}
}
}
diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/ui/PopOverUIExample.java b/ardor3d-examples/src/main/java/com/ardor3d/example/ui/PopOverUIExample.java
index 31799f1..5e6953c 100644
--- a/ardor3d-examples/src/main/java/com/ardor3d/example/ui/PopOverUIExample.java
+++ b/ardor3d-examples/src/main/java/com/ardor3d/example/ui/PopOverUIExample.java
@@ -38,7 +38,6 @@ import com.ardor3d.math.MathUtils;
import com.ardor3d.math.Matrix3;
import com.ardor3d.math.Vector3;
import com.ardor3d.math.type.ReadOnlyVector3;
-import com.ardor3d.renderer.Camera;
import com.ardor3d.renderer.Renderer;
import com.ardor3d.renderer.state.MaterialState;
import com.ardor3d.renderer.state.MaterialState.ColorMaterial;
@@ -87,15 +86,14 @@ public class PopOverUIExample extends ExampleBase implements ActionListener {
setTexture("Logo");
setSpin("Around Y");
- hud = new UIHud();
- hud.setupInput(_canvas, _physicalLayer, _logicalLayer);
+ hud = new UIHud(_canvas);
+ hud.setupInput(_physicalLayer, _logicalLayer);
hud.setMouseManager(_mouseManager);
- final Camera cam = _canvas.getCanvasRenderer().getCamera();
final UIButton dropButton = new UIButton("Drop Menu");
dropButton.setPadding(new Insets(6, 15, 6, 15));
- dropButton.setHudXY(cam.getWidth() / 10 - dropButton.getLocalComponentWidth() / 2,
- cam.getHeight() - dropButton.getLocalComponentHeight() - 5);
+ dropButton.setHudXY(hud.getWidth() / 10 - dropButton.getLocalComponentWidth() / 2,
+ hud.getHeight() - dropButton.getLocalComponentHeight() - 5);
dropButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent event) {
@@ -106,12 +104,12 @@ public class PopOverUIExample extends ExampleBase implements ActionListener {
final UIButton pieButton = new UIButton("Pie Menu");
pieButton.setPadding(new Insets(6, 15, 6, 15));
- pieButton.setHudXY(9 * cam.getWidth() / 10 - pieButton.getLocalComponentWidth() / 2, cam.getHeight()
+ pieButton.setHudXY(9 * hud.getWidth() / 10 - pieButton.getLocalComponentWidth() / 2, hud.getHeight()
- pieButton.getLocalComponentHeight() - 5);
pieButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent event) {
- showPieMenu(cam.getWidth() / 2, cam.getHeight() / 2);
+ showPieMenu(hud.getWidth() / 2, hud.getHeight() / 2);
}
});
hud.add(pieButton);
@@ -290,7 +288,10 @@ public class PopOverUIExample extends ExampleBase implements ActionListener {
final UIFrame scaleDialog = new UIFrame("Set Scale...", EnumSet.of(FrameButtons.CLOSE));
scaleDialog.setResizeable(false);
final UIPanel contentPanel = scaleDialog.getContentPanel();
- contentPanel.setLayout(new RowLayout(true, false, false));
+ final RowLayout layout = new RowLayout(true, false, false);
+ layout.setSpacing(4);
+ contentPanel.setLayout(layout);
+ contentPanel.setMargin(new Insets(0, 5, 0, 5));
final UISlider scaleSlider = new UISlider(Orientation.Horizontal, 1, 20, (int) (box.getScale().getX() * 10));
scaleSlider.setMinimumContentWidth(200);
@@ -311,7 +312,7 @@ public class PopOverUIExample extends ExampleBase implements ActionListener {
});
hud.add(scaleDialog);
- scaleDialog.pack(235, 80);
+ scaleDialog.pack();
scaleDialog.centerOn(hud);
}
diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/ui/RotatingUIExample.java b/ardor3d-examples/src/main/java/com/ardor3d/example/ui/RotatingUIExample.java
index 8251e99..7784d4d 100644
--- a/ardor3d-examples/src/main/java/com/ardor3d/example/ui/RotatingUIExample.java
+++ b/ardor3d-examples/src/main/java/com/ardor3d/example/ui/RotatingUIExample.java
@@ -52,13 +52,10 @@ public class RotatingUIExample extends ExampleBase {
final UIFrame frame = new UIFrame("Sample");
frame.setContentPanel(panel);
- frame.updateMinimumSizeFromContents();
- frame.layout();
- frame.pack(300, 200);
+ frame.pack();
frame.setUseStandin(false);
frame.setOpacity(1f);
- frame.setLocationRelativeTo(_canvas.getCanvasRenderer().getCamera());
frame.setName("sample");
final Matrix3 rotate = new Matrix3();
@@ -66,11 +63,11 @@ public class RotatingUIExample extends ExampleBase {
rotate.fromAngleNormalAxis(45 * MathUtils.DEG_TO_RAD, axis);
frame.setRotation(rotate);
- hud = new UIHud();
+ hud = new UIHud(_canvas);
hud.add(frame);
- hud.setupInput(_canvas, _physicalLayer, _logicalLayer);
+ hud.setupInput(_physicalLayer, _logicalLayer);
- frame.setLocationRelativeTo(_canvas.getCanvasRenderer().getCamera());
+ frame.centerOn(hud);
}
private UIPanel makePanel() {
@@ -105,6 +102,8 @@ public class RotatingUIExample extends ExampleBase {
});
rotatingLabel.setLayoutData(BorderLayoutData.NORTH);
+ panel.setMinimumContentSize(300, 200);
+
return panel;
}
diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/ui/SimpleUIExample.java b/ardor3d-examples/src/main/java/com/ardor3d/example/ui/SimpleUIExample.java
index 59d8192..0ecc8ad 100644
--- a/ardor3d-examples/src/main/java/com/ardor3d/example/ui/SimpleUIExample.java
+++ b/ardor3d-examples/src/main/java/com/ardor3d/example/ui/SimpleUIExample.java
@@ -125,13 +125,10 @@ public class SimpleUIExample extends ExampleBase {
frame = new UIFrame("UI Sample");
frame.setContentPanel(pane);
- frame.updateMinimumSizeFromContents();
- frame.layout();
frame.pack();
frame.setUseStandin(true);
frame.setOpacity(1f);
- frame.setLocationRelativeTo(_canvas.getCanvasRenderer().getCamera());
frame.setName("sample");
// Uncomment #1...
@@ -152,10 +149,12 @@ public class SimpleUIExample extends ExampleBase {
// }
// });
- hud = new UIHud();
+ hud = new UIHud(_canvas);
hud.add(frame);
- hud.setupInput(_canvas, _physicalLayer, _logicalLayer);
+ hud.setupInput(_physicalLayer, _logicalLayer);
hud.setMouseManager(_mouseManager);
+
+ frame.centerOn(hud);
}
private UIPanel makeLoginPanel() {