diff options
author | Joshua Slack <[email protected]> | 2018-01-15 12:09:34 -0600 |
---|---|---|
committer | Joshua Slack <[email protected]> | 2018-01-15 12:09:34 -0600 |
commit | 76a2d2e8d0af9f11959dfcdd9711c7bf6c619f03 (patch) | |
tree | b896216d3906772d7cf6a54a4268dcd3a4e8af83 /ardor3d-examples | |
parent | 2817b5e3a39ca1c9fe42bdfe344db3400ff83264 (diff) |
Updated interact widget mouseover code to pass through Canvas and provided a callback for mouse over/out.
Added simple cursor setting callbacks to the basic interact classes.
Added a few cursor graphics that may be used with InteractWidgets
Diffstat (limited to 'ardor3d-examples')
-rw-r--r-- | ardor3d-examples/src/main/java/com/ardor3d/example/interact/InteractExample.java | 40 | ||||
-rw-r--r-- | ardor3d-examples/src/main/java/com/ardor3d/example/interact/TerrainInteractExample.java | 2 |
2 files changed, 39 insertions, 3 deletions
diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/interact/InteractExample.java b/ardor3d-examples/src/main/java/com/ardor3d/example/interact/InteractExample.java index 0fcbf1e..a615a3d 100644 --- a/ardor3d-examples/src/main/java/com/ardor3d/example/interact/InteractExample.java +++ b/ardor3d-examples/src/main/java/com/ardor3d/example/interact/InteractExample.java @@ -1,15 +1,17 @@ /** - * Copyright (c) 2008-2012 Ardor Labs, Inc. + * Copyright (c) 2008-2018 Ardor Labs, Inc. * * 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.interact; +import java.net.URISyntaxException; + import com.ardor3d.bounding.BoundingBox; import com.ardor3d.bounding.BoundingSphere; import com.ardor3d.example.ExampleBase; @@ -18,15 +20,20 @@ import com.ardor3d.extension.interact.InteractManager; import com.ardor3d.extension.interact.filter.AllowScaleFilter; import com.ardor3d.extension.interact.filter.MinMaxScaleFilter; import com.ardor3d.extension.interact.filter.PlaneBoundaryFilter; +import com.ardor3d.extension.interact.widget.AbstractInteractWidget; import com.ardor3d.extension.interact.widget.BasicFilterList; import com.ardor3d.extension.interact.widget.InteractMatrix; +import com.ardor3d.extension.interact.widget.MoveMultiPlanarWidget; +import com.ardor3d.extension.interact.widget.MovePlanarWidget; import com.ardor3d.extension.interact.widget.MoveWidget; import com.ardor3d.extension.interact.widget.RotateWidget; import com.ardor3d.extension.interact.widget.SimpleScaleWidget; import com.ardor3d.framework.Canvas; +import com.ardor3d.image.Image; import com.ardor3d.image.Texture; import com.ardor3d.image.Texture2D; import com.ardor3d.input.Key; +import com.ardor3d.input.MouseCursor; import com.ardor3d.input.logical.InputTrigger; import com.ardor3d.input.logical.KeyHeldCondition; import com.ardor3d.input.logical.KeyPressedCondition; @@ -49,6 +56,8 @@ import com.ardor3d.scenegraph.shape.Box; import com.ardor3d.scenegraph.shape.Sphere; import com.ardor3d.util.ReadOnlyTimer; import com.ardor3d.util.TextureManager; +import com.ardor3d.util.resource.ResourceLocatorTool; +import com.ardor3d.util.resource.SimpleResourceLocator; /** * An example illustrating the use of the interact framework. @@ -157,6 +166,8 @@ public class InteractExample extends ExampleBase { } private void addControls() { + setupCursors(); + // create our manager manager = new InteractManager(); manager.setupInput(_canvas, _physicalLayer, _logicalLayer); @@ -236,6 +247,31 @@ public class InteractExample extends ExampleBase { manager.addFilter(new PlaneBoundaryFilter(new Plane(Vector3.UNIT_Y, 0))); } + public static void setupCursors() { + try { + final SimpleResourceLocator srl = new SimpleResourceLocator(ResourceLocatorTool.getClassPathResource( + AbstractInteractWidget.class, "com/ardor3d/extension/interact/widget/")); + ResourceLocatorTool.addResourceLocator(ResourceLocatorTool.TYPE_TEXTURE, srl); + + // ROTATE + Image img = TextureManager.load("rotate.png", Texture.MinificationFilter.BilinearNoMipMaps, true) + .getImage(); + RotateWidget.DEFAULT_CURSOR = new MouseCursor("rotate", img, img.getWidth() / 2, img.getHeight() / 2); + + // SCALE + img = TextureManager.load("scale.png", Texture.MinificationFilter.BilinearNoMipMaps, true).getImage(); + SimpleScaleWidget.DEFAULT_CURSOR = new MouseCursor("scale", img, 3, img.getHeight() - 3); + + // MOVE + img = TextureManager.load("move.png", Texture.MinificationFilter.BilinearNoMipMaps, true).getImage(); + MoveWidget.DEFAULT_CURSOR = new MouseCursor("move", img, img.getWidth() / 2, img.getHeight() / 2); + MoveMultiPlanarWidget.DEFAULT_CURSOR = new MouseCursor("move", img, img.getWidth() / 2, img.getHeight() / 2); + MovePlanarWidget.DEFAULT_CURSOR = new MouseCursor("move", img, img.getWidth() / 2, img.getHeight() / 2); + } catch (final URISyntaxException ex) { + ex.printStackTrace(); + } + } + @Override protected void processPicks(final PrimitivePickResults pickResults) { final PickData pick = pickResults.findFirstIntersectingPickData(); diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/interact/TerrainInteractExample.java b/ardor3d-examples/src/main/java/com/ardor3d/example/interact/TerrainInteractExample.java index 668112d..30bc14f 100644 --- a/ardor3d-examples/src/main/java/com/ardor3d/example/interact/TerrainInteractExample.java +++ b/ardor3d-examples/src/main/java/com/ardor3d/example/interact/TerrainInteractExample.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.interact;
import java.util.concurrent.Callable;
import com.ardor3d.example.ExampleBase;
import com.ardor3d.example.Purpose;
import com.ardor3d.extension.interact.InteractManager;
import com.ardor3d.extension.interact.widget.CompoundInteractWidget;
import com.ardor3d.extension.interact.widget.InteractMatrix;
import com.ardor3d.extension.interact.widget.MovePlanarWidget.MovePlane;
import com.ardor3d.extension.terrain.client.Terrain;
import com.ardor3d.extension.terrain.client.TerrainBuilder;
import com.ardor3d.extension.terrain.client.TerrainDataProvider;
import com.ardor3d.extension.terrain.heightmap.MidPointHeightMapGenerator;
import com.ardor3d.extension.terrain.providers.array.ArrayTerrainDataProvider;
import com.ardor3d.framework.Canvas;
import com.ardor3d.framework.CanvasRenderer;
import com.ardor3d.image.Texture.MinificationFilter;
import com.ardor3d.image.Texture2D;
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.Vector3;
import com.ardor3d.renderer.RenderContext;
import com.ardor3d.renderer.Renderer;
import com.ardor3d.renderer.state.CullState;
import com.ardor3d.renderer.state.FogState;
import com.ardor3d.renderer.state.FogState.DensityFunction;
import com.ardor3d.scenegraph.shape.PQTorus;
import com.ardor3d.util.GameTaskQueue;
import com.ardor3d.util.GameTaskQueueManager;
import com.ardor3d.util.ReadOnlyTimer;
import com.ardor3d.util.TextureManager;
/**
* Example showing interact widgets with the Geometry Clipmap Terrain system. Requires GLSL support.
*/
@Purpose(htmlDescriptionKey = "com.ardor3d.example.interact.TerrainInteractExample", //
thumbnailPath = "com/ardor3d/example/media/thumbnails/interact_TerrainInteractExample.jpg", //
maxHeapMemory = 128)
public class TerrainInteractExample extends ExampleBase {
private final float farPlane = 3000.0f;
private Terrain terrain;
private InteractManager manager;
public static void main(final String[] args) {
ExampleBase.start(TerrainInteractExample.class);
}
@Override
protected void updateExample(final ReadOnlyTimer timer) {
manager.update(timer);
}
@Override
protected void updateLogicalLayer(final ReadOnlyTimer timer) {
manager.getLogicalLayer().checkTriggers(timer.getTimePerFrame());
}
@Override
protected void renderExample(final Renderer renderer) {
super.renderExample(renderer);
manager.render(renderer);
}
/**
* Initialize pssm pass and scene.
*/
@Override
protected void initExample() {
// Setup main camera.
_canvas.setTitle("Terrain Example");
_canvas.getCanvasRenderer().getCamera().setLocation(new Vector3(400, 220, 715));
_canvas.getCanvasRenderer().getCamera().lookAt(new Vector3(430, 200, 730), Vector3.UNIT_Y);
_canvas.getCanvasRenderer()
.getCamera()
.setFrustumPerspective(
70.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.GRAY);
return null;
}
});
_controlHandle.setMoveSpeed(500);
setupDefaultStates();
try {
final int SIZE = 2048;
final MidPointHeightMapGenerator raw = new MidPointHeightMapGenerator(SIZE, 0.6f);
raw.setHeightRange(0.2f);
final float[] heightMap = raw.getHeightData();
final TerrainDataProvider terrainDataProvider = new ArrayTerrainDataProvider(heightMap, SIZE, new Vector3(
1, 500, 1));
terrain = new TerrainBuilder(terrainDataProvider, _canvas.getCanvasRenderer().getCamera())
.setShowDebugPanels(false).build();
_root.attachChild(terrain);
} catch (final Exception ex1) {
System.out.println("Problem setting up terrain...");
ex1.printStackTrace();
}
addControls();
// Add something to move around
final PQTorus obj = new PQTorus("obj", 4, 3, 1.5, .5, 128, 8);
obj.setScale(10);
obj.updateModelBound();
_root.attachChild(obj);
_root.updateGeometricState(0);
try {
Thread.sleep(500);
} catch (final InterruptedException e) {
}
obj.setTranslation(630, terrain.getHeightAt(630, 830) + 20, 830);
manager.setSpatialTarget(obj);
}
private void setupDefaultStates() {
_lightState.detachAll();
final DirectionalLight dLight = new DirectionalLight();
dLight.setEnabled(true);
dLight.setAmbient(new ColorRGBA(0.4f, 0.4f, 0.5f, 1));
dLight.setDiffuse(new ColorRGBA(0.6f, 0.6f, 0.5f, 1));
dLight.setSpecular(new ColorRGBA(0.3f, 0.3f, 0.2f, 1));
dLight.setDirection(new Vector3(-1, -1, -1).normalizeLocal());
_lightState.attach(dLight);
_lightState.setEnabled(true);
final CullState cs = new CullState();
cs.setEnabled(true);
cs.setCullFace(CullState.Face.Back);
_root.setRenderState(cs);
final FogState fs = new FogState();
fs.setStart(farPlane / 2.0f);
fs.setEnd(farPlane);
fs.setColor(ColorRGBA.GRAY);
fs.setDensityFunction(DensityFunction.Linear);
_root.setRenderState(fs);
}
private void addControls() {
// create our manager
manager = new InteractManager();
manager.setupInput(_canvas, _physicalLayer, _logicalLayer);
// final add our widget
final CompoundInteractWidget widget = new CompoundInteractWidget()
.withMoveXAxis(new ColorRGBA(1, 0, 0, .65f), 1.2, .15, .5, .2)
.withMoveZAxis(new ColorRGBA(0, 0, 1, .65f), 1.2, .15, .5, .2) //
.withRotateYAxis() //
.withPlanarHandle(MovePlane.XZ, new ColorRGBA(1, 0, 1, .65f)) //
.withRingTexture((Texture2D) TextureManager.load("images/tick.png", MinificationFilter.Trilinear, true));
// widget.getHandle().setRenderState(_lightState);
manager.addWidget(widget);
manager.setActiveWidget(widget);
// add toggle for matrix mode on widget
manager.getLogicalLayer().registerTrigger(new InputTrigger(new KeyPressedCondition(Key.R), new TriggerAction() {
@Override
public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
widget.setInteractMatrix(widget.getInteractMatrix() == InteractMatrix.World ? InteractMatrix.Local
: InteractMatrix.World);
widget.targetDataUpdated(manager);
}
}));
// add a filter
manager.addFilter(new TerrainHeightFilter(terrain, 20));
}
}
\ 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.interact;
import java.util.concurrent.Callable;
import com.ardor3d.example.ExampleBase;
import com.ardor3d.example.Purpose;
import com.ardor3d.extension.interact.InteractManager;
import com.ardor3d.extension.interact.widget.CompoundInteractWidget;
import com.ardor3d.extension.interact.widget.InteractMatrix;
import com.ardor3d.extension.interact.widget.MovePlanarWidget.MovePlane;
import com.ardor3d.extension.terrain.client.Terrain;
import com.ardor3d.extension.terrain.client.TerrainBuilder;
import com.ardor3d.extension.terrain.client.TerrainDataProvider;
import com.ardor3d.extension.terrain.heightmap.MidPointHeightMapGenerator;
import com.ardor3d.extension.terrain.providers.array.ArrayTerrainDataProvider;
import com.ardor3d.framework.Canvas;
import com.ardor3d.framework.CanvasRenderer;
import com.ardor3d.image.Texture.MinificationFilter;
import com.ardor3d.image.Texture2D;
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.Vector3;
import com.ardor3d.renderer.RenderContext;
import com.ardor3d.renderer.Renderer;
import com.ardor3d.renderer.state.CullState;
import com.ardor3d.renderer.state.FogState;
import com.ardor3d.renderer.state.FogState.DensityFunction;
import com.ardor3d.scenegraph.shape.PQTorus;
import com.ardor3d.util.GameTaskQueue;
import com.ardor3d.util.GameTaskQueueManager;
import com.ardor3d.util.ReadOnlyTimer;
import com.ardor3d.util.TextureManager;
/**
* Example showing interact widgets with the Geometry Clipmap Terrain system. Requires GLSL support.
*/
@Purpose(htmlDescriptionKey = "com.ardor3d.example.interact.TerrainInteractExample", //
thumbnailPath = "com/ardor3d/example/media/thumbnails/interact_TerrainInteractExample.jpg", //
maxHeapMemory = 128)
public class TerrainInteractExample extends ExampleBase {
private final float farPlane = 3000.0f;
private Terrain terrain;
private InteractManager manager;
public static void main(final String[] args) {
ExampleBase.start(TerrainInteractExample.class);
}
@Override
protected void updateExample(final ReadOnlyTimer timer) {
manager.update(timer);
}
@Override
protected void updateLogicalLayer(final ReadOnlyTimer timer) {
manager.getLogicalLayer().checkTriggers(timer.getTimePerFrame());
}
@Override
protected void renderExample(final Renderer renderer) {
super.renderExample(renderer);
manager.render(renderer);
}
/**
* Initialize pssm pass and scene.
*/
@Override
protected void initExample() {
// Setup main camera.
_canvas.setTitle("Terrain Example");
_canvas.getCanvasRenderer().getCamera().setLocation(new Vector3(400, 220, 715));
_canvas.getCanvasRenderer().getCamera().lookAt(new Vector3(430, 200, 730), Vector3.UNIT_Y);
_canvas.getCanvasRenderer()
.getCamera()
.setFrustumPerspective(
70.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.GRAY);
return null;
}
});
_controlHandle.setMoveSpeed(500);
setupDefaultStates();
try {
final int SIZE = 2048;
final MidPointHeightMapGenerator raw = new MidPointHeightMapGenerator(SIZE, 0.6f);
raw.setHeightRange(0.2f);
final float[] heightMap = raw.getHeightData();
final TerrainDataProvider terrainDataProvider = new ArrayTerrainDataProvider(heightMap, SIZE, new Vector3(
1, 500, 1));
terrain = new TerrainBuilder(terrainDataProvider, _canvas.getCanvasRenderer().getCamera())
.setShowDebugPanels(false).build();
_root.attachChild(terrain);
} catch (final Exception ex1) {
System.out.println("Problem setting up terrain...");
ex1.printStackTrace();
}
addControls();
// Add something to move around
final PQTorus obj = new PQTorus("obj", 4, 3, 1.5, .5, 128, 8);
obj.setScale(10);
obj.updateModelBound();
_root.attachChild(obj);
_root.updateGeometricState(0);
try {
Thread.sleep(500);
} catch (final InterruptedException e) {
}
obj.setTranslation(630, terrain.getHeightAt(630, 830) + 20, 830);
manager.setSpatialTarget(obj);
}
private void setupDefaultStates() {
_lightState.detachAll();
final DirectionalLight dLight = new DirectionalLight();
dLight.setEnabled(true);
dLight.setAmbient(new ColorRGBA(0.4f, 0.4f, 0.5f, 1));
dLight.setDiffuse(new ColorRGBA(0.6f, 0.6f, 0.5f, 1));
dLight.setSpecular(new ColorRGBA(0.3f, 0.3f, 0.2f, 1));
dLight.setDirection(new Vector3(-1, -1, -1).normalizeLocal());
_lightState.attach(dLight);
_lightState.setEnabled(true);
final CullState cs = new CullState();
cs.setEnabled(true);
cs.setCullFace(CullState.Face.Back);
_root.setRenderState(cs);
final FogState fs = new FogState();
fs.setStart(farPlane / 2.0f);
fs.setEnd(farPlane);
fs.setColor(ColorRGBA.GRAY);
fs.setDensityFunction(DensityFunction.Linear);
_root.setRenderState(fs);
}
private void addControls() {
InteractExample.setupCursors();
// create our manager
manager = new InteractManager();
manager.setupInput(_canvas, _physicalLayer, _logicalLayer);
// final add our widget
final CompoundInteractWidget widget = new CompoundInteractWidget()
.withMoveXAxis(new ColorRGBA(1, 0, 0, .65f), 1.2, .15, .5, .2)
.withMoveZAxis(new ColorRGBA(0, 0, 1, .65f), 1.2, .15, .5, .2) //
.withRotateYAxis() //
.withPlanarHandle(MovePlane.XZ, new ColorRGBA(1, 0, 1, .65f)) //
.withRingTexture((Texture2D) TextureManager.load("images/tick.png", MinificationFilter.Trilinear, true));
// widget.getHandle().setRenderState(_lightState);
manager.addWidget(widget);
manager.setActiveWidget(widget);
// add toggle for matrix mode on widget
manager.getLogicalLayer().registerTrigger(new InputTrigger(new KeyPressedCondition(Key.R), new TriggerAction() {
@Override
public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
widget.setInteractMatrix(widget.getInteractMatrix() == InteractMatrix.World ? InteractMatrix.Local
: InteractMatrix.World);
widget.targetDataUpdated(manager);
}
}));
// add a filter
manager.addFilter(new TerrainHeightFilter(terrain, 20));
}
}
\ No newline at end of file |