aboutsummaryrefslogtreecommitdiffstats
path: root/ardor3d-examples/src/main
diff options
context:
space:
mode:
authorJulien Gouesse <[email protected]>2016-02-23 21:44:09 +0100
committerJulien Gouesse <[email protected]>2016-02-23 21:44:09 +0100
commitdad016899a7e81bfba2c56dcd9066e7788a5724c (patch)
tree9648998fb83a4ea1ec47483bcda4cff9be95861f /ardor3d-examples/src/main
parent8d11fee3eb9c92cbc4df815dce452ecaf9fe6b2e (diff)
Drops applet support: http://github.com/gouessej/Ardor3D/issues/22
Diffstat (limited to 'ardor3d-examples/src/main')
-rw-r--r--ardor3d-examples/src/main/java/com/ardor3d/example/applet/JoglBaseApplet.java335
-rw-r--r--ardor3d-examples/src/main/java/com/ardor3d/example/applet/JoglBoxApplet.java73
2 files changed, 0 insertions, 408 deletions
diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/applet/JoglBaseApplet.java b/ardor3d-examples/src/main/java/com/ardor3d/example/applet/JoglBaseApplet.java
deleted file mode 100644
index 867d129..0000000
--- a/ardor3d-examples/src/main/java/com/ardor3d/example/applet/JoglBaseApplet.java
+++ /dev/null
@@ -1,335 +0,0 @@
-/**
- * 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.applet;
-
-import java.applet.Applet;
-import java.awt.BorderLayout;
-import java.awt.event.ComponentAdapter;
-import java.awt.event.ComponentEvent;
-import java.net.URISyntaxException;
-import java.util.concurrent.Callable;
-
-import com.jogamp.nativewindow.util.DimensionImmutable;
-import com.ardor3d.annotation.MainThread;
-import com.ardor3d.framework.DisplaySettings;
-import com.ardor3d.framework.FrameHandler;
-import com.ardor3d.framework.Scene;
-import com.ardor3d.framework.Updater;
-import com.ardor3d.framework.jogl.JoglCanvasRenderer;
-import com.ardor3d.framework.jogl.awt.JoglNewtAwtCanvas;
-import com.ardor3d.image.util.awt.AWTImageLoader;
-import com.ardor3d.input.GrabbedState;
-import com.ardor3d.input.Key;
-import com.ardor3d.input.MouseButton;
-import com.ardor3d.input.PhysicalLayer;
-import com.ardor3d.input.control.FirstPersonControl;
-import com.ardor3d.input.jogl.JoglNewtFocusWrapper;
-import com.ardor3d.input.jogl.JoglNewtKeyboardWrapper;
-import com.ardor3d.input.jogl.JoglNewtMouseManager;
-import com.ardor3d.input.jogl.JoglNewtMouseWrapper;
-import com.ardor3d.input.logical.InputTrigger;
-import com.ardor3d.input.logical.KeyReleasedCondition;
-import com.ardor3d.input.logical.LogicalLayer;
-import com.ardor3d.input.logical.MouseButtonPressedCondition;
-import com.ardor3d.input.logical.MouseButtonReleasedCondition;
-import com.ardor3d.input.logical.TriggerAction;
-import com.ardor3d.input.logical.TwoInputStates;
-import com.ardor3d.intersection.PickResults;
-import com.ardor3d.math.Ray3;
-import com.ardor3d.math.Vector3;
-import com.ardor3d.renderer.Camera;
-import com.ardor3d.renderer.Renderer;
-import com.ardor3d.renderer.TextureRendererFactory;
-import com.ardor3d.renderer.jogl.JoglTextureRendererProvider;
-import com.ardor3d.renderer.state.ZBufferState;
-import com.ardor3d.scenegraph.Node;
-import com.ardor3d.util.Constants;
-import com.ardor3d.util.ContextGarbageCollector;
-import com.ardor3d.util.GameTaskQueue;
-import com.ardor3d.util.GameTaskQueueManager;
-import com.ardor3d.util.ReadOnlyTimer;
-import com.ardor3d.util.Timer;
-import com.ardor3d.util.resource.ResourceLocatorTool;
-import com.ardor3d.util.resource.SimpleResourceLocator;
-import com.ardor3d.util.stat.StatCollector;
-
-/**
- * An example base class for ardor3d/jogl applets. This is not meant to be a "best-practices" applet, just a rough demo
- * showing possibilities. As such, there are likely bugs, etc. Please report these. :)
- */
-public abstract class JoglBaseApplet extends Applet implements Scene {
-
- private static final long serialVersionUID = 1L;
-
- protected DisplaySettings _settings;
- protected JoglNewtAwtCanvas _glCanvas;
- protected LogicalLayer _logicalLayer;
- protected PhysicalLayer _physicalLayer;
- protected JoglNewtMouseManager _mouseManager;
-
- protected FirstPersonControl _controlHandle;
- protected Vector3 _worldUp = new Vector3(0, 1, 0);
-
- protected Thread _gameThread;
- protected boolean _running = false;
-
- protected final Timer _timer = new Timer();
- protected final Node _root = new Node();
- protected final FrameHandler frameHandler = new FrameHandler(_timer);
-
- @Override
- public void init() {
- _settings = getSettings();
- setLayout(new BorderLayout(0, 0));
- try {
- TextureRendererFactory.INSTANCE.setProvider(new JoglTextureRendererProvider());
- final JoglCanvasRenderer canvasRenderer = new JoglCanvasRenderer(this);
- _glCanvas = new JoglNewtAwtCanvas(_settings, canvasRenderer) {
- private static final long serialVersionUID = 1L;
-
- @Override
- public final void removeNotify() {
- stopJOGL();
- super.removeNotify();
- }
- };
- ;
- _glCanvas.setSize(getWidth(), getHeight());
- _glCanvas.setFocusable(true);
- _glCanvas.requestFocus();
- _glCanvas.setIgnoreRepaint(true);
- _glCanvas.addComponentListener(new ComponentAdapter() {
- @Override
- public void componentResized(final ComponentEvent e) {
- GameTaskQueueManager.getManager(_glCanvas.getCanvasRenderer().getRenderContext()).update(
- new Callable<Void>() {
- @Override
- public Void call() throws Exception {
- final Camera cam = _glCanvas.getCanvasRenderer().getCamera();
- cam.resize(getWidth(), getHeight());
- cam.setFrustumPerspective(cam.getFovY(), getWidth() / (double) getHeight(),
- cam.getFrustumNear(), cam.getFrustumFar());
- appletResized(getWidth(), getHeight());
- return null;
- }
- });
- }
- });
- frameHandler.addCanvas(_glCanvas);
- frameHandler.addUpdater(new Updater() {
-
- @Override
- @MainThread
- public void update(final ReadOnlyTimer timer) {
- JoglBaseApplet.this.update();
- }
-
- @Override
- @MainThread
- public void init() {
- initInput();
- initBaseScene();
- initAppletScene();
- }
- });
- add(_glCanvas, BorderLayout.CENTER);
- setVisible(true);
- startJOGL();
- } catch (final Exception e) {
- System.err.println(e);
- throw new RuntimeException("Unable to create display");
- }
- }
-
- protected DisplaySettings getSettings() {
- return new DisplaySettings(getWidth(), getHeight(), 8, 0);
- }
-
- @Override
- public void destroy() {
- remove(_glCanvas);
- }
-
- protected void startJOGL() {
- frameHandler.init();
- _gameThread = new Thread() {
- @Override
- public void run() {
- _running = true;
- gameLoop();
- }
- };
- _gameThread.start();
- }
-
- protected void stopJOGL() {
- _running = false;
- try {
- _gameThread.join();
- } catch (final InterruptedException e) {
- e.printStackTrace();
- }
- }
-
- protected void gameLoop() {
- while (_running) {
- frameHandler.updateFrame();
- Thread.yield();
- }
- }
-
- public void update() {
- _timer.update();
-
- /** update stats, if enabled. */
- if (Constants.stats) {
- StatCollector.update();
- }
- updateLogicalLayer(_timer);
-
- // Execute updateQueue item
- GameTaskQueueManager.getManager(_glCanvas.getCanvasRenderer().getRenderContext())
- .getQueue(GameTaskQueue.UPDATE).execute();
- updateAppletScene(_timer);
-
- // Update controllers/render states/transforms/bounds for rootNode.
- _root.updateGeometricState(_timer.getTimePerFrame(), true);
- }
-
- protected void updateLogicalLayer(final ReadOnlyTimer timer) {
- // check and execute any input triggers, if we are concerned with input
- if (_logicalLayer != null) {
- _logicalLayer.checkTriggers(timer.getTimePerFrame());
- }
- }
-
- protected void initInput() {
- _mouseManager = new JoglNewtMouseManager(_glCanvas);
- _logicalLayer = new LogicalLayer();
- _physicalLayer = new PhysicalLayer(new JoglNewtKeyboardWrapper(_glCanvas), new JoglNewtMouseWrapper(_glCanvas,
- _mouseManager), new JoglNewtFocusWrapper(_glCanvas));
- _logicalLayer.registerInput(_glCanvas, _physicalLayer);
- _controlHandle = FirstPersonControl.setupTriggers(_logicalLayer, _worldUp, true);
-
- _logicalLayer.registerTrigger(new InputTrigger(new KeyReleasedCondition(Key.F), new TriggerAction() {
-
- @Override
- public void perform(final com.ardor3d.framework.Canvas source, final TwoInputStates inputState,
- final double tpf) {
-
- _glCanvas.getNewtWindow().setFullscreen(!_glCanvas.getNewtWindow().isFullscreen());
- final Camera cam = _glCanvas.getCanvasRenderer().getCamera();
- if (_glCanvas.getNewtWindow().isFullscreen()) {
- final DimensionImmutable screenSizeMM = _glCanvas.getNewtWindow().getMainMonitor().getSizeMM();
- cam.resize(screenSizeMM.getWidth(), screenSizeMM.getHeight());
- cam.setFrustumPerspective(cam.getFovY(),
- screenSizeMM.getWidth() / (float) screenSizeMM.getHeight(), cam.getFrustumNear(),
- cam.getFrustumFar());
- appletResized(screenSizeMM.getWidth(), screenSizeMM.getHeight());
- } else {
- cam.resize(getWidth(), getHeight());
- cam.setFrustumPerspective(cam.getFovY(), getWidth() / (float) getHeight(), cam.getFrustumNear(),
- cam.getFrustumFar());
- appletResized(getWidth(), getHeight());
- }
- }
- }));
-
- _logicalLayer.registerTrigger(new InputTrigger(new KeyReleasedCondition(Key.V), new TriggerAction() {
- @Override
- public void perform(final com.ardor3d.framework.Canvas source, final TwoInputStates inputState,
- final double tpf) {
- _glCanvas.setVSyncEnabled(true);
- }
- }));
-
- _logicalLayer.registerTrigger(new InputTrigger(new KeyReleasedCondition(Key.B), new TriggerAction() {
- @Override
- public void perform(final com.ardor3d.framework.Canvas source, final TwoInputStates inputState,
- final double tpf) {
- _glCanvas.setVSyncEnabled(false);
- }
- }));
-
- _logicalLayer.registerTrigger(new InputTrigger(new MouseButtonPressedCondition(MouseButton.LEFT),
- new TriggerAction() {
- @Override
- public void perform(final com.ardor3d.framework.Canvas source, final TwoInputStates inputState,
- final double tpf) {
- if (_mouseManager.isSetGrabbedSupported()) {
- _mouseManager.setGrabbed(GrabbedState.GRABBED);
- }
- }
- }));
-
- _logicalLayer.registerTrigger(new InputTrigger(new MouseButtonReleasedCondition(MouseButton.LEFT),
- new TriggerAction() {
- @Override
- public void perform(final com.ardor3d.framework.Canvas source, final TwoInputStates inputState,
- final double tpf) {
- if (_mouseManager.isSetGrabbedSupported()) {
- _mouseManager.setGrabbed(GrabbedState.NOT_GRABBED);
- }
- }
- }));
- }
-
- protected void initBaseScene() {
- // Add our awt based image loader.
- AWTImageLoader.registerLoader();
-
- // Set the location of our example resources.
- try {
- final SimpleResourceLocator srl = new SimpleResourceLocator(ResourceLocatorTool.getClassPathResource(
- JoglBaseApplet.class, "com/ardor3d/example/media/"));
- ResourceLocatorTool.addResourceLocator(ResourceLocatorTool.TYPE_TEXTURE, srl);
- } catch (final URISyntaxException ex) {
- ex.printStackTrace();
- }
-
- // Create a ZBuffer to display pixels closest to the camera above farther ones.
- final ZBufferState buf = new ZBufferState();
- buf.setEnabled(true);
- buf.setFunction(ZBufferState.TestFunction.LessThanOrEqualTo);
- _root.setRenderState(buf);
- }
-
- @Override
- public PickResults doPick(final Ray3 pickRay) {
- // ignore
- return null;
- }
-
- @Override
- public boolean renderUnto(final Renderer renderer) {
- // Execute renderQueue item
- GameTaskQueueManager.getManager(_glCanvas.getCanvasRenderer().getRenderContext())
- .getQueue(GameTaskQueue.RENDER).execute(renderer);
-
- // Clean up card garbage such as textures, vbos, etc.
- ContextGarbageCollector.doRuntimeCleanup(renderer);
-
- renderScene(renderer);
-
- return true;
- }
-
- protected abstract void initAppletScene();
-
- protected void updateAppletScene(final ReadOnlyTimer timer) {};
-
- protected void renderScene(final Renderer renderer) {
- // Draw the root and all its children.
- renderer.draw(_root);
- }
-
- protected void appletResized(final int width, final int height) {}
-}
diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/applet/JoglBoxApplet.java b/ardor3d-examples/src/main/java/com/ardor3d/example/applet/JoglBoxApplet.java
deleted file mode 100644
index 352ffc0..0000000
--- a/ardor3d-examples/src/main/java/com/ardor3d/example/applet/JoglBoxApplet.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/**
- * 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.applet;
-
-import com.ardor3d.bounding.BoundingBox;
-import com.ardor3d.image.Texture;
-import com.ardor3d.math.MathUtils;
-import com.ardor3d.math.Matrix3;
-import com.ardor3d.math.Vector3;
-import com.ardor3d.renderer.state.TextureState;
-import com.ardor3d.scenegraph.Spatial;
-import com.ardor3d.scenegraph.controller.SpatialController;
-import com.ardor3d.scenegraph.shape.Box;
-import com.ardor3d.util.TextureManager;
-
-/**
- * The classic "Box Example" as an Ardor3D/JOGL applet.
- */
-public class JoglBoxApplet extends JoglBaseApplet {
-
- private static final long serialVersionUID = 1L;
-
- @Override
- protected void initAppletScene() {
- // Make a box...
- final Box box = new Box("Box", Vector3.ZERO, 5, 5, 5);
-
- // Make it a bit more colorful.
- box.setRandomColors();
-
- // Setup a bounding box for it.
- box.setModelBound(new BoundingBox());
-
- // Set its location in space.
- box.setTranslation(new Vector3(0, 0, -15));
-
- // Add to root.
- _root.attachChild(box);
-
- // set it to rotate:
- box.addController(new SpatialController<Spatial>() {
- private final Vector3 _axis = new Vector3(1, 1, 0.5f).normalizeLocal();
- private final Matrix3 _rotate = new Matrix3();
- private double _angle = 0;
-
- @Override
- public void update(final double time, final Spatial caller) {
- // update our rotation
- _angle = _angle + (_timer.getTimePerFrame() * 25);
- if (_angle > 180) {
- _angle = -180;
- }
-
- _rotate.fromAngleNormalAxis(_angle * MathUtils.DEG_TO_RAD, _axis);
- box.setRotation(_rotate);
- }
- });
-
- // Create a texture from the Ardor3D logo.
- final TextureState ts = new TextureState();
- ts.setEnabled(true);
- ts.setTexture(TextureManager.load("images/ardor3d_white_256.jpg", Texture.MinificationFilter.Trilinear, true));
- box.setRenderState(ts);
- }
-}