Back to project page jmini3d.
The source code is released under:
Copyright 2012 Mobialia http://www.mobialia.com/ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to ...
If you think the Android project jmini3d listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package jmini3d.demo; /*from w w w . j a va2 s .c om*/ import java.util.HashMap; import jmini3d.Scene; import jmini3d.SceneController; import jmini3d.Vector3; import jmini3d.input.KeyListener; import jmini3d.input.TouchListener; import jmini3d.input.TouchPointer; public class DemoSceneController implements SceneController, TouchListener, KeyListener { float cameraAngle; long initialTime; int sceneIndex = 0; Scene scenes[] = {new TeapotScene(), new CubeScene(), new EnvMapCubeScene(), new CubesScene(), new NormalMapScene()}; int cameraModes[] = {0, 0, 0, 0, 1}; public DemoSceneController() { initialTime = System.currentTimeMillis(); } @Override public Scene getScene() { return scenes[sceneIndex]; } @Override public boolean updateScene(int width, int height) { scenes[sceneIndex].setViewPort(width, height); // Rotate camera... cameraAngle = 0.0005f * (System.currentTimeMillis() - initialTime); float d = 5; Vector3 target = scenes[sceneIndex].getCamera().getTarget(); scenes[sceneIndex].getCamera().setPosition((float) (target.x - d * Math.cos(cameraAngle)), // (float) (target.y - d * Math.sin(cameraAngle)), // target.z + (cameraModes[sceneIndex] == 0 ? (float) (d * Math.sin(cameraAngle)) : d / 2)// ); ((ParentScene) scenes[sceneIndex]).update(); return true; } private void nextScene() { if (sceneIndex >= scenes.length - 1) { sceneIndex = 0; } else { sceneIndex++; } } private void previousScene() { if (sceneIndex <= 0) { sceneIndex = scenes.length - 1; } else { sceneIndex--; } } @Override public boolean onTouch(HashMap<Integer, TouchPointer> pointers) { for (Integer key : pointers.keySet()) { TouchPointer pointer = pointers.get(key); if (pointer.status == TouchPointer.TOUCH_DOWN) { if (pointer.x > scenes[sceneIndex].getCamera().getWidth() / 2) { nextScene(); } else { previousScene(); } } } return true; } @Override public boolean onKeyDown(int key) { switch (key) { case KeyListener.KEY_RIGHT: nextScene(); return true; case KeyListener.KEY_LEFT: previousScene(); return true; } return false; } @Override public boolean onKeyUp(int key) { return false; } }