package com.jme3.app;\r
\r
import java.util.logging.Handler;\r
+import java.util.logging.Level;\r
import java.util.logging.Logger;\r
import java.util.logging.SimpleFormatter;\r
import com.jme3.util.JmeFormatter;\r
import com.jme3.system.android.OGLESContext;\r
import com.jme3.system.android.AndroidConfigChooser.ConfigType;\r
\r
-\r
/**\r
* <code>AndroidHarness</code> wraps a jme application object and runs it on Android\r
* @author Kirill\r
* @author larynx\r
*/\r
-public class AndroidHarness extends Activity implements TouchListener, DialogInterface.OnClickListener\r
-{\r
+public class AndroidHarness extends Activity implements TouchListener, DialogInterface.OnClickListener {\r
+\r
protected final static Logger logger = Logger.getLogger(AndroidHarness.class.getName());\r
- \r
/**\r
* The application class to start\r
*/\r
protected String appClass = "jme3test.android.Test";\r
- \r
/**\r
* The jme3 application object\r
*/\r
protected Application app = null;\r
- \r
/**\r
* ConfigType.FASTEST is RGB565, GLSurfaceView default\r
* ConfigType.BEST is RGBA8888 or better if supported by the hardware\r
*/\r
protected ConfigType eglConfigType = ConfigType.FASTEST;\r
- \r
/**\r
* If true all valid and not valid egl configs are logged\r
*/\r
protected boolean eglConfigVerboseLogging = false;\r
-\r
/**\r
* If true MouseEvents are generated from TouchEvents\r
*/\r
- protected boolean mouseEventsEnabled = true; \r
+ protected boolean mouseEventsEnabled = true;\r
/**\r
* Flip X axis\r
*/\r
* Flip Y axis\r
*/\r
protected boolean mouseEventsInvertY = true;\r
- \r
/**\r
* Title of the exit dialog, default is "Do you want to exit?"\r
*/\r
* Message of the exit dialog, default is "Use your home key to bring this app into the background or exit to terminate it."\r
*/\r
protected String exitDialogMessage = "Use your home key to bring this app into the background or exit to terminate it.";\r
-\r
/**\r
* Set the screen orientation, default is SENSOR\r
* ActivityInfo.SCREEN_ORIENTATION_* constants\r
* SCREEN_ORIENTATION_NOSENSOR\r
*/\r
protected int screenOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR;\r
- \r
protected OGLESContext ctx;\r
protected GLSurfaceView view = null;\r
protected boolean isGLThreadPaused = true;\r
- final private String ESCAPE_EVENT = "TouchEscape"; \r
+ final private String ESCAPE_EVENT = "TouchEscape";\r
\r
@Override\r
- public void onCreate(Bundle savedInstanceState) \r
- {\r
+ public void onCreate(Bundle savedInstanceState) {\r
super.onCreate(savedInstanceState);\r
- \r
+\r
Logger log = logger;\r
boolean bIsLogFormatSet = false;\r
- do\r
- {\r
- if (log.getHandlers().length == 0)\r
- {\r
+ do {\r
+ if (log.getHandlers().length == 0) {\r
log = logger.getParent();\r
- if (log != null)\r
- for (Handler h : log.getHandlers())\r
- {\r
+ if (log != null) {\r
+ for (Handler h : log.getHandlers()) {\r
//h.setFormatter(new SimpleFormatter());\r
h.setFormatter(new JmeFormatter());\r
bIsLogFormatSet = true;\r
}\r
+ }\r
}\r
} while (log != null && !bIsLogFormatSet);\r
\r
\r
requestWindowFeature(Window.FEATURE_NO_TITLE);\r
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,\r
- WindowManager.LayoutParams.FLAG_FULLSCREEN);\r
- \r
+ WindowManager.LayoutParams.FLAG_FULLSCREEN);\r
+\r
setRequestedOrientation(screenOrientation);\r
- \r
+\r
// Create Settings\r
AppSettings settings = new AppSettings(true);\r
- \r
+\r
// Create the input class\r
- AndroidInput input = new AndroidInput(this); \r
+ AndroidInput input = new AndroidInput(this);\r
input.setMouseEventsInvertX(mouseEventsInvertX);\r
input.setMouseEventsInvertY(mouseEventsInvertY);\r
input.setMouseEventsEnabled(mouseEventsEnabled);\r
- \r
+\r
// Create application instance\r
- try\r
- { \r
- if (app == null)\r
- { \r
+ try {\r
+ if (app == null) {\r
@SuppressWarnings("unchecked")\r
Class<? extends Application> clazz = (Class<? extends Application>) Class.forName(appClass);\r
app = clazz.newInstance();\r
}\r
- \r
+\r
app.setSettings(settings);\r
- app.start(); \r
+ app.start();\r
ctx = (OGLESContext) app.getContext();\r
view = ctx.createView(input, eglConfigType, eglConfigVerboseLogging);\r
- setContentView(view); \r
- \r
+ setContentView(view);\r
+\r
// Set the screen reolution\r
WindowManager wind = this.getWindowManager();\r
Display disp = wind.getDefaultDisplay();\r
ctx.getSettings().setResolution(disp.getWidth(), disp.getHeight());\r
- \r
- AppSettings s = ctx.getSettings(); \r
- logger.info("Settings: Width " + s.getWidth() + " Height " + s.getHeight());\r
- \r
- \r
- }\r
- catch (Exception ex)\r
- {\r
+\r
+ AppSettings s = ctx.getSettings();\r
+ logger.log(Level.INFO, "Settings: Width {0} Height {1}", new Object[]{s.getWidth(), s.getHeight()});\r
+ } catch (Exception ex) {\r
handleError("Class " + appClass + " init failed", ex);\r
setContentView(new TextView(this));\r
}\r
- \r
}\r
\r
-\r
@Override\r
- protected void onRestart()\r
- {\r
- super.onRestart(); \r
- if (app != null)\r
+ protected void onRestart() {\r
+ super.onRestart();\r
+ if (app != null) {\r
app.restart();\r
+ }\r
logger.info("onRestart");\r
}\r
- \r
\r
@Override\r
- protected void onStart()\r
- {\r
+ protected void onStart() {\r
super.onStart();\r
logger.info("onStart");\r
}\r
- \r
+\r
@Override\r
- protected void onResume() \r
- {\r
+ protected void onResume() {\r
super.onResume();\r
- if (view != null)\r
+ if (view != null) {\r
view.onResume();\r
+ }\r
isGLThreadPaused = false;\r
logger.info("onResume");\r
}\r
\r
@Override\r
- protected void onPause() \r
- {\r
+ protected void onPause() {\r
super.onPause();\r
- if (view != null)\r
+ if (view != null) {\r
view.onPause();\r
+ }\r
isGLThreadPaused = true;\r
logger.info("onPause");\r
}\r
- \r
+\r
@Override\r
- protected void onStop()\r
- {\r
+ protected void onStop() {\r
super.onStop();\r
logger.info("onStop");\r
}\r
\r
@Override\r
- protected void onDestroy()\r
- {\r
- if (app != null)\r
- app.stop(! isGLThreadPaused);\r
- super.onDestroy(); \r
+ protected void onDestroy() {\r
+ if (app != null) {\r
+ app.stop(!isGLThreadPaused);\r
+ }\r
+ super.onDestroy();\r
logger.info("onDestroy");\r
}\r
\r
- public Application getJmeApplication()\r
- {\r
+ public Application getJmeApplication() {\r
return app;\r
}\r
- \r
+\r
/**\r
* Called when an error has occured. This is typically\r
- * invoked when an uncought exception is thrown in the render thread.\r
+ * invoked when an uncaught exception is thrown in the render thread.\r
* @param errorMsg The error message, if any, or null.\r
* @param t Throwable object, or null.\r
*/\r
- public void handleError(final String errorMsg, final Throwable t)\r
- {\r
- \r
- String s = "";\r
- if (t != null && t.getStackTrace() != null)\r
- {\r
- for (StackTraceElement ste: t.getStackTrace())\r
- {\r
- s += ste.getClassName() + "." + ste.getMethodName() + "(" + + ste.getLineNumber() + ") ";\r
+ public void handleError(final String errorMsg, final Throwable t) {\r
+ String sTrace = "";\r
+ if (t != null && t.getStackTrace() != null) {\r
+ for (StackTraceElement ste : t.getStackTrace()) {\r
+ sTrace += "\tat " + ste.getClassName() + "." + ste.getMethodName() + "(";\r
+ if (ste.isNativeMethod()){\r
+ sTrace += "Native";\r
+ }else{\r
+ sTrace += ste.getLineNumber();\r
+ }\r
+ sTrace += ")\n";\r
}\r
- } \r
- \r
- final String sTrace = s;\r
- \r
- logger.severe(t != null ? t.toString() : "OpenGL Exception");\r
- logger.severe((errorMsg != null ? errorMsg + ": " : "") + sTrace);\r
- \r
+ }\r
+\r
+ final String stackTrace = sTrace;\r
+\r
+ logger.log(Level.SEVERE, t != null ? t.toString() : "OpenGL Exception");\r
+ logger.log(Level.SEVERE, "{0}{1}", new Object[]{errorMsg != null ? errorMsg + ": " : "", stackTrace});\r
+\r
this.runOnUiThread(new Runnable() {\r
@Override\r
- public void run() \r
- { \r
- AlertDialog dialog = new AlertDialog.Builder(AndroidHarness.this)\r
- // .setIcon(R.drawable.alert_dialog_icon)\r
- .setTitle(t != null ? (t.getMessage() != null ? (t.getMessage() + ": " + t.getClass().getName()) : t.getClass().getName()) : "OpenGL Exception")\r
- .setPositiveButton("Kill", AndroidHarness.this)\r
- .setMessage((errorMsg != null ? errorMsg + ": " : "") + sTrace)\r
- .create(); \r
- dialog.show(); \r
+ public void run() {\r
+ AlertDialog dialog = new AlertDialog.Builder(AndroidHarness.this) // .setIcon(R.drawable.alert_dialog_icon)\r
+ .setTitle(t != null ? (t.getMessage() != null ? (t.getMessage() + ": " + t.getClass().getName()) : t.getClass().getName()) : "OpenGL Exception").setPositiveButton("Kill", AndroidHarness.this).setMessage((errorMsg != null ? errorMsg + ": " : "") + stackTrace).create();\r
+ dialog.show();\r
}\r
});\r
- \r
+\r
}\r
- \r
+\r
/**\r
* Called by the android alert dialog, terminate the activity and OpenGL rendering\r
* @param dialog\r
* @param whichButton\r
*/\r
- public void onClick(DialogInterface dialog, int whichButton) \r
- { \r
- if (whichButton != -2)\r
- {\r
- if (app != null)\r
+ public void onClick(DialogInterface dialog, int whichButton) {\r
+ if (whichButton != -2) {\r
+ if (app != null) {\r
app.stop(true);\r
+ }\r
this.finish();\r
}\r
}\r
- \r
+\r
/**\r
* Gets called by the InputManager on all touch/drag/scale events\r
- */ \r
- @Override \r
- public void onTouch(String name, TouchEvent evt, float tpf) \r
- {\r
- if (name.equals(ESCAPE_EVENT))\r
- {\r
- switch(evt.getType())\r
- { \r
+ */\r
+ @Override\r
+ public void onTouch(String name, TouchEvent evt, float tpf) {\r
+ if (name.equals(ESCAPE_EVENT)) {\r
+ switch (evt.getType()) {\r
case KEY_UP:\r
- this.runOnUiThread(new Runnable() \r
- {\r
+ this.runOnUiThread(new Runnable() {\r
@Override\r
- public void run() \r
- { \r
- AlertDialog dialog = new AlertDialog.Builder(AndroidHarness.this)\r
- // .setIcon(R.drawable.alert_dialog_icon)\r
- .setTitle(exitDialogTitle)\r
- .setPositiveButton("Yes", AndroidHarness.this)\r
- .setNegativeButton("No", AndroidHarness.this)\r
- .setMessage(exitDialogMessage)\r
- .create(); \r
- dialog.show(); \r
+ public void run() {\r
+ AlertDialog dialog = new AlertDialog.Builder(AndroidHarness.this) // .setIcon(R.drawable.alert_dialog_icon)\r
+ .setTitle(exitDialogTitle).setPositiveButton("Yes", AndroidHarness.this).setNegativeButton("No", AndroidHarness.this).setMessage(exitDialogMessage).create();\r
+ dialog.show();\r
}\r
});\r
- \r
- \r
+\r
+ break;\r
+ default:\r
break;\r
- \r
- default:\r
- break;\r
}\r
}\r
- \r
- } \r
- \r
+\r
+ }\r
}\r
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-
package com.jme3.asset;
import com.jme3.texture.Texture;
private static final Logger logger = Logger.getLogger(AndroidAssetManager.class.getName());
- public AndroidAssetManager(){
+ public AndroidAssetManager() {
this(null);
}
@Deprecated
- public AndroidAssetManager(boolean loadDefaults){
+ public AndroidAssetManager(boolean loadDefaults) {
//this(Thread.currentThread().getContextClassLoader().getResource("com/jme3/asset/Android.cfg"));
- this(null);
+ this(null);
}
/**
* If URL == null then a default list of locators and loaders for android is set
* @param configFile
*/
- public AndroidAssetManager(URL configFile)
- {
-
- System.setProperty("org.xml.sax.driver","org.xmlpull.v1.sax2.Driver");
-
-
- // Set Default Android config
- this.registerLocator("", AndroidLocator.class);
+ public AndroidAssetManager(URL configFile) {
+
+ System.setProperty("org.xml.sax.driver", "org.xmlpull.v1.sax2.Driver");
+
+
+ // Set Default Android config
+ this.registerLocator("", AndroidLocator.class);
this.registerLocator("", ClasspathLocator.class);
this.registerLoader(AndroidImageLoader.class, "jpg", "bmp", "gif", "png", "jpeg");
this.registerLoader(AndroidAudioLoader.class, "ogg", "mp3");
this.registerLoader(com.jme3.scene.plugins.ogre.MaterialLoader.class, "material");
this.registerLoader(com.jme3.scene.plugins.ogre.SceneLoader.class, "scene");
this.registerLoader(com.jme3.shader.plugins.GLSLLoader.class, "vert", "frag", "glsl", "glsllib");
-
-
+
+
logger.info("AndroidAssetManager created.");
}
* @return
*/
@Override
- public Texture loadTexture(TextureKey key){
- Texture tex = (Texture) loadAsset(key);
-
- // Needed for Android
+ public Texture loadTexture(TextureKey key) {
+ Texture tex = (Texture) loadAsset(key);
+
+ // Needed for Android
tex.setMagFilter(Texture.MagFilter.Nearest);
tex.setAnisotropicFilter(0);
- if (tex.getMinFilter().usesMipMapLevels()){
+ if (tex.getMinFilter().usesMipMapLevels()) {
tex.setMinFilter(Texture.MinFilter.NearestNearestMipMap);
- }else{
+ } else {
tex.setMinFilter(Texture.MinFilter.NearestNoMipMaps);
}
- return tex;
+ return tex;
}
-
}
package com.jme3.system;\r
\r
-\r
import android.app.Activity;\r
import android.content.res.Resources;\r
import com.jme3.util.AndroidLogHandler;\r
\r
import java.net.URL;\r
\r
-\r
-\r
-public class JmeSystem \r
-{\r
-\r
- public static enum Platform {\r
-\r
- /**\r
- * Microsoft Windows 32 bit\r
- */\r
- Windows32,\r
-\r
- /**\r
- * Microsoft Windows 64 bit\r
- */\r
- Windows64,\r
-\r
- /**\r
- * Linux 32 bit\r
- */\r
- Linux32,\r
-\r
-\r
- /**\r
- * Linux 64 bit\r
- */\r
- Linux64,\r
-\r
- /**\r
- * Apple Mac OS X 32 bit\r
- */\r
- MacOSX32,\r
-\r
- /**\r
- * Apple Mac OS X 64 bit\r
- */\r
- MacOSX64,\r
-\r
- /**\r
- * Apple Mac OS X 32 bit PowerPC\r
- */\r
- MacOSX_PPC32,\r
-\r
- /**\r
- * Apple Mac OS X 64 bit PowerPC\r
- */\r
- MacOSX_PPC64,\r
- \r
- /**\r
- * Android 2.2\r
- */\r
- Android_Froyo,\r
- \r
- /**\r
- * Android 2.3\r
- */\r
- Android_Gingerbread,\r
- \r
- /**\r
- * Android 3.0\r
- */\r
- Android_Honeycomb,\r
- \r
- \r
- }\r
+public class JmeSystem {\r
\r
private static final Logger logger = Logger.getLogger(JmeSystem.class.getName());\r
-\r
private static boolean initialized = false;\r
private static boolean lowPermissions = false;\r
private static Resources res;\r
private static Activity activity;\r
\r
- public static void initialize(AppSettings settings)\r
- {\r
- \r
- if (initialized)\r
+ public static void initialize(AppSettings settings) {\r
+ if (initialized) {\r
return;\r
+ }\r
\r
initialized = true;\r
- try \r
- {\r
+ try {\r
JmeFormatter formatter = new JmeFormatter();\r
\r
Handler consoleHandler = new AndroidLogHandler();\r
consoleHandler.setFormatter(formatter);\r
- } \r
- catch (SecurityException ex)\r
- {\r
+ } catch (SecurityException ex) {\r
logger.log(Level.SEVERE, "Security error in creating log file", ex);\r
}\r
- logger.info("Running on "+getFullName());\r
+ logger.log(Level.INFO, "Running on {0}", getFullName());\r
}\r
\r
- public static String getFullName()\r
- {\r
- return "jMonkey Engine 3 ALPHA 0.7 Android";\r
+ public static String getFullName() {\r
+ return "jMonkeyEngine 3.0.0 Beta (Android)";\r
}\r
- \r
- public static void setLowPermissions(boolean lowPerm)\r
- {\r
+\r
+ public static void setLowPermissions(boolean lowPerm) {\r
lowPermissions = lowPerm;\r
}\r
\r
- public static boolean isLowPermissions() \r
- {\r
+ public static boolean isLowPermissions() {\r
return lowPermissions;\r
}\r
- \r
- public static JmeContext newContext(AppSettings settings, Type contextType) \r
- {\r
+\r
+ public static JmeContext newContext(AppSettings settings, Type contextType) {\r
initialize(settings);\r
return new OGLESContext();\r
}\r
\r
- public static AudioRenderer newAudioRenderer(AppSettings settings) \r
- {\r
- return new AndroidAudioRenderer(activity); \r
+ public static AudioRenderer newAudioRenderer(AppSettings settings) {\r
+ return new AndroidAudioRenderer(activity);\r
}\r
\r
- public static void setResources(Resources res)\r
- {\r
+ public static void setResources(Resources res) {\r
JmeSystem.res = res;\r
}\r
\r
- public static Resources getResources()\r
- {\r
+ public static Resources getResources() {\r
return res;\r
}\r
\r
- public static void setActivity(Activity activity)\r
- {\r
+ public static void setActivity(Activity activity) {\r
JmeSystem.activity = activity;\r
}\r
\r
- public static Activity getActivity()\r
- {\r
+ public static Activity getActivity() {\r
return activity;\r
- } \r
- \r
+ }\r
\r
- public static AssetManager newAssetManager()\r
- {\r
- logger.info("newAssetManager()");\r
+ public static AssetManager newAssetManager() {\r
+ logger.log(Level.INFO, "newAssetManager()");\r
return new AndroidAssetManager(null);\r
}\r
\r
- public static AssetManager newAssetManager(URL url)\r
- {\r
- logger.info("newAssetManager(" + url + ")");\r
+ public static AssetManager newAssetManager(URL url) {\r
+ logger.log(Level.INFO, "newAssetManager({0})", url);\r
return new AndroidAssetManager(url);\r
}\r
\r
- public static boolean showSettingsDialog(AppSettings settings, boolean loadSettings) \r
- {\r
+ public static boolean showSettingsDialog(AppSettings settings, boolean loadSettings) {\r
return true;\r
}\r
- \r
- public static Platform getPlatform()\r
- {\r
- String os = System.getProperty("os.name").toLowerCase();\r
- String arch = System.getProperty("os.arch").toLowerCase();\r
\r
- return Platform.Android_Froyo;\r
- // throw new UnsupportedOperationException("The specified platform: "+os+" is not supported.");\r
- \r
+ public static Platform getPlatform() {\r
+ String arch = System.getProperty("os.arch").toLowerCase();\r
+ if (arch.contains("arm")){\r
+ if (arch.contains("v5")){\r
+ return Platform.Android_ARM5;\r
+ }else if (arch.contains("v6")){\r
+ return Platform.Android_ARM6;\r
+ }else if (arch.contains("v7")){\r
+ return Platform.Android_ARM7;\r
+ }else{\r
+ return Platform.Android_ARM5; // unknown ARM\r
+ }\r
+ }else{\r
+ throw new UnsupportedOperationException("Unsupported Android Platform");\r
+ }\r
}\r
-\r
}\r
import java.io.InputStream;
import java.nio.ByteBuffer;
-public class AndroidImageLoader implements AssetLoader
-{
+public class AndroidImageLoader implements AssetLoader {
- public Object load2(AssetInfo info) throws IOException
- {
+ public Object load2(AssetInfo info) throws IOException {
ByteBuffer bb = BufferUtils.createByteBuffer(1 * 1 * 2);
- bb.put( (byte) 0xff ).put( (byte) 0xff );
+ bb.put((byte) 0xff).put((byte) 0xff);
bb.clear();
return new Image(Format.RGB5A1, 1, 1, bb);
}
- public Object load(AssetInfo info) throws IOException
- {
+ public Object load(AssetInfo info) throws IOException {
InputStream in = null;
Bitmap bitmap = null;
try {
in = info.openStream();
bitmap = BitmapFactory.decodeStream(in);
- if (bitmap == null){
- throw new IOException("Failed to load image: "+info.getKey().getName());
+ if (bitmap == null) {
+ throw new IOException("Failed to load image: " + info.getKey().getName());
}
} finally {
- if (in != null)
+ if (in != null) {
in.close();
+ }
}
int width = bitmap.getWidth();
int height = bitmap.getHeight();
Format fmt;
- switch (bitmap.getConfig()){
+ switch (bitmap.getConfig()) {
case ALPHA_8:
fmt = Format.Alpha8;
break;
case ARGB_8888:
fmt = Format.RGBA8;
break;
- case RGB_565:
+ case RGB_565:
fmt = Format.RGB565;
break;
default:
return null;
}
- if ( ((TextureKey)info.getKey()).isFlipY() )
- {
+ if (((TextureKey) info.getKey()).isFlipY()) {
Bitmap newBitmap = null;
Matrix flipMat = new Matrix();
flipMat.preScale(1.0f, -1.0f);
bitmap.recycle();
bitmap = newBitmap;
- if (bitmap == null){
- throw new IOException("Failed to flip image: "+info.getKey().getName());
+ if (bitmap == null) {
+ throw new IOException("Failed to flip image: " + info.getKey().getName());
}
}
Image image = new Image(fmt, width, height, null);
- image.setEfficentData(bitmap);
+ image.setEfficentData(bitmap);
return image;
}
-
}
*/
// suppress unchecked warnings in Java 1.5.0_6 and later
@SuppressWarnings("unchecked")
-public class RingBuffer<Item> implements Iterable<Item>
-{
+public class RingBuffer<Item> implements Iterable<Item> {
+
private Item[] buffer; // queue elements
private int count = 0; // number of elements on queue
private int indexOut = 0; // index of first element of queue
- private int indexIn = 0; // index of next available slot
+ private int indexIn = 0; // index of next available slot
// cast needed since no generic array creation in Java
- public RingBuffer(int capacity)
- {
+ public RingBuffer(int capacity) {
buffer = (Item[]) new Object[capacity];
}
- public boolean isEmpty() { return count == 0; }
- public int size() { return count; }
+ public boolean isEmpty() {
+ return count == 0;
+ }
- public void push(Item item)
- {
- if (count == buffer.length) { throw new RuntimeException("Ring buffer overflow"); }
+ public int size() {
+ return count;
+ }
+
+ public void push(Item item) {
+ if (count == buffer.length) {
+ throw new RuntimeException("Ring buffer overflow");
+ }
buffer[indexIn] = item;
indexIn = (indexIn + 1) % buffer.length; // wrap-around
count++;
}
- public Item pop()
- {
- if (isEmpty()) { throw new RuntimeException("Ring buffer underflow"); }
+ public Item pop() {
+ if (isEmpty()) {
+ throw new RuntimeException("Ring buffer underflow");
+ }
Item item = buffer[indexOut];
buffer[indexOut] = null; // to help with garbage collection
count--;
return item;
}
- public Iterator<Item> iterator() { return new RingBufferIterator(); }
+ public Iterator<Item> iterator() {
+ return new RingBufferIterator();
+ }
// an iterator, doesn't implement remove() since it's optional
private class RingBufferIterator implements Iterator<Item> {
+
private int i = 0;
- public boolean hasNext() { return i < count; }
- public void remove() { throw new UnsupportedOperationException(); }
+
+ public boolean hasNext() {
+ return i < count;
+ }
+
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
public Item next() {
- if (!hasNext()) throw new NoSuchElementException();
+ if (!hasNext()) {
+ throw new NoSuchElementException();
+ }
return buffer[i++];
}
}
-
-
-
-
}
-
package com.jme3.util.android;
-import java.util.ArrayList;
-import android.graphics.Bitmap;
import com.jme3.asset.AssetManager;
-import com.jme3.asset.TextureKey;
-import com.jme3.material.Material;
import com.jme3.math.Vector3f;
-import com.jme3.renderer.queue.RenderQueue.Bucket;
-import com.jme3.scene.Geometry;
import com.jme3.scene.Spatial;
-import com.jme3.scene.shape.Sphere;
-import com.jme3.texture.Image;
-import com.jme3.texture.Image.Format;
import com.jme3.texture.Texture;
-import com.jme3.texture.TextureCubeMap;
-
+import com.jme3.util.SkyFactory;
/**
* <code>AndroidSkyFactory</code> creates a sky box spatial
* @author larynx, derived from SkyFactory and adapted for android
- *
+ * @deprecated Use {@link SkyFactory} instead
*/
-public class AndroidSkyFactory
-{
- private static final Sphere sphereMesh = new Sphere(10, 10, 101f, false, true);
-
- public static Spatial createSky(AssetManager assetManager, Texture texture, Vector3f normalScale, boolean sphereMap)
- {
- Geometry sky = new Geometry("Sky", sphereMesh);
- sky.setQueueBucket(Bucket.Sky);
- sky.setCullHint(Spatial.CullHint.Never);
-
- Material skyMat = new Material(assetManager, "Common/MatDefs/Misc/Sky.j3md");
- skyMat.setVector3("NormalScale", normalScale);
- if (sphereMap)
- {
- skyMat.setBoolean("SphereMap", sphereMap);
- }
- else if (!(texture instanceof TextureCubeMap))
- {
- // make sure its a cubemap
- Image img = texture.getImage();
- texture = new TextureCubeMap();
- texture.setImage(img);
- }
- skyMat.setTexture("Texture", texture);
- sky.setMaterial(skyMat);
-
- return sky;
- }
-
- private static void checkImage(Image image)
- {
- if (image.getWidth() != image.getHeight())
- throw new IllegalArgumentException("Image width and height must be the same");
-
- if (image.getMultiSamples() != 1)
- throw new IllegalArgumentException("Multisample textures not allowed");
- }
-
- private static void checkImagesForCubeMap(Image ... images)
- {
- if (images.length == 1) return;
-
- Format fmt = images[0].getFormat();
- int width = images[0].getWidth();
- int height = images[0].getHeight();
+@Deprecated
+public class AndroidSkyFactory {
- checkImage(images[0]);
-
- for (int i = 1; i < images.length; i++)
- {
- Image image = images[i];
- checkImage(images[i]);
- if (image.getFormat() != fmt) throw new IllegalArgumentException("Images must have same format");
- if (image.getWidth() != width) throw new IllegalArgumentException("Images must have same width");
- if (image.getHeight() != height) throw new IllegalArgumentException("Images must have same height");
- }
+ public static Spatial createSky(AssetManager assetManager, Texture texture, Vector3f normalScale, boolean sphereMap) {
+ return SkyFactory.createSky(assetManager, texture, normalScale, sphereMap);
}
- public static Spatial createSky(AssetManager assetManager, Texture west, Texture east, Texture north, Texture south,
- Texture up, Texture down, Vector3f normalScale)
- {
- Geometry sky = new Geometry("Sky", sphereMesh);
- sky.setQueueBucket(Bucket.Sky);
- sky.setCullHint(Spatial.CullHint.Never);
-
- Image westImg = west.getImage();
- Image eastImg = east.getImage();
- Image northImg = north.getImage();
- Image southImg = south.getImage();
- Image upImg = up.getImage();
- Image downImg = down.getImage();
-
- checkImagesForCubeMap(westImg, eastImg, northImg, southImg, upImg, downImg);
-
- Image cubeImage = new Image(westImg.getFormat(), westImg.getWidth(), westImg.getHeight(), null);
-
- ArrayList<Bitmap> arrayList = new ArrayList<Bitmap>(6);
-
- arrayList.add((Bitmap)westImg.getEfficentData());
- arrayList.add((Bitmap)eastImg.getEfficentData());
-
- arrayList.add((Bitmap)downImg.getEfficentData());
- arrayList.add((Bitmap)upImg.getEfficentData());
-
- arrayList.add((Bitmap)southImg.getEfficentData());
- arrayList.add((Bitmap)northImg.getEfficentData());
-
- cubeImage.setEfficentData(arrayList);
-
- TextureCubeMap cubeMap = new TextureCubeMap(cubeImage);
- cubeMap.setAnisotropicFilter(0);
- cubeMap.setMagFilter(Texture.MagFilter.Bilinear);
- cubeMap.setMinFilter(Texture.MinFilter.BilinearNoMipMaps);
- cubeMap.setWrap(Texture.WrapMode.EdgeClamp);
-
-
- Material skyMat = new Material(assetManager, "Common/MatDefs/Misc/Sky.j3md");
- skyMat.setTexture("Texture", cubeMap);
- skyMat.setVector3("NormalScale", normalScale);
- sky.setMaterial(skyMat);
-
- return sky;
+ public static Spatial createSky(AssetManager assetManager, Texture west, Texture east, Texture north, Texture south,
+ Texture up, Texture down, Vector3f normalScale) {
+ return SkyFactory.createSky(assetManager, west, east, north, south, up, down, normalScale);
}
- public static Spatial createSky(AssetManager assetManager, Texture west, Texture east, Texture north, Texture south,
- Texture up, Texture down)
- {
- return createSky(assetManager, west, east, north, south, up, down, Vector3f.UNIT_XYZ);
+ public static Spatial createSky(AssetManager assetManager, Texture west, Texture east, Texture north, Texture south,
+ Texture up, Texture down) {
+ return SkyFactory.createSky(assetManager, west, east, north, south, up, down, Vector3f.UNIT_XYZ);
}
- public static Spatial createSky(AssetManager assetManager, Texture texture, boolean sphereMap)
- {
- return createSky(assetManager, texture, Vector3f.UNIT_XYZ, sphereMap);
+ public static Spatial createSky(AssetManager assetManager, Texture texture, boolean sphereMap) {
+ return SkyFactory.createSky(assetManager, texture, Vector3f.UNIT_XYZ, sphereMap);
}
- public static Spatial createSky(AssetManager assetManager, String textureName, boolean sphereMap)
- {
- TextureKey key = new TextureKey(textureName, true);
- key.setGenerateMips(true);
- key.setAsCube(!sphereMap);
- Texture tex = assetManager.loadTexture(key);
- return createSky(assetManager, tex, sphereMap);
+ public static Spatial createSky(AssetManager assetManager, String textureName, boolean sphereMap) {
+ return SkyFactory.createSky(assetManager, textureName, sphereMap);
}
}
\ No newline at end of file
package jme3test.android;
-
import java.util.ArrayList;
import java.util.List;
import java.net.URI;
-
public class AboutActivity extends Activity {
- private static final java.util.logging.Logger logger = java.util.logging.Logger.getLogger(AboutActivity.class.getName());
-
+ private static final java.util.logging.Logger logger = java.util.logging.Logger.getLogger(AboutActivity.class.getName());
- @Override
- public void onCreate(Bundle savedInstanceState) {
- logger.info("onCreate(" + savedInstanceState + ")");
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ logger.info("onCreate(" + savedInstanceState + ")");
- super.onCreate(savedInstanceState);
+ super.onCreate(savedInstanceState);
- //setContentView(R.layout.about);
- }
+ //setContentView(R.layout.about);
+ }
- @Override
- public void onDestroy() {
- logger.info("onDestroy()");
- super.onDestroy();
- }
+ @Override
+ public void onDestroy() {
+ logger.info("onDestroy()");
+ super.onDestroy();
+ }
+ @Override
+ protected void onResume() {
+ super.onResume();
+ }
- @Override
- protected void onResume() {
- super.onResume();
- }
-
- @Override
- protected void onStart() {
- super.onStart();
- }
-
- @Override
- protected void onStop() {
- super.onStop();
- }
-
+ @Override
+ protected void onStart() {
+ super.onStart();
+ }
+ @Override
+ protected void onStop() {
+ super.onStop();
+ }
}
-
*
* created: Mon Nov 8 00:08:07 EST 2010
*/
-
package jme3test.android;
import android.app.Activity;
import com.jme3.app.Application;
import com.jme3.app.SimpleApplication;
-
public class AndroidActivity extends Activity {
- private final static java.util.logging.Logger logger = java.util.logging.Logger.getLogger(AndroidActivity.class.getName());
+ private final static java.util.logging.Logger logger = java.util.logging.Logger.getLogger(AndroidActivity.class.getName());
+ private OGLESContext ctx;
+ private GLSurfaceView view;
+ private boolean useVA = false;
+ private boolean verboseLogging = false;
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
- private OGLESContext ctx;
- private GLSurfaceView view;
+ super.onCreate(savedInstanceState);
- private boolean useVA = false;
- private boolean verboseLogging = false;
+ JmeSystem.setResources(getResources());
- @Override
- public void onCreate(Bundle savedInstanceState) {
+ requestWindowFeature(Window.FEATURE_NO_TITLE);
+ getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
+ WindowManager.LayoutParams.FLAG_FULLSCREEN);
- super.onCreate(savedInstanceState);
+ AppSettings settings = new AppSettings(true);
- JmeSystem.setResources(getResources());
+ String testClassName = getIntent().getStringExtra(AndroidActivity.class.getName() + ".TEST_CLASS_NAME");
- requestWindowFeature(Window.FEATURE_NO_TITLE);
- getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
- WindowManager.LayoutParams.FLAG_FULLSCREEN);
+ logger.info("test class name: [" + testClassName + "]");
- AppSettings settings = new AppSettings(true);
+ String appClass = (testClassName != null ? testClassName : "jme3test.android.SimpleTexturedTest");
- String testClassName = getIntent().getStringExtra(AndroidActivity.class.getName() + ".TEST_CLASS_NAME");
+ useVA = getIntent().getBooleanExtra(AndroidActivity.class.getName() + ".USE_VA", false);
- logger.info("test class name: [" + testClassName + "]");
+ logger.info("USE_VA -> [" + useVA + "]");
- String appClass = (testClassName != null? testClassName: "jme3test.android.SimpleTexturedTest");
+ settings.putBoolean("USE_VA", useVA);
- useVA = getIntent().getBooleanExtra(AndroidActivity.class.getName() + ".USE_VA", false);
+ verboseLogging = getIntent().getBooleanExtra(AndroidActivity.class.getName() + ".VERBOSE_LOGGING", false);
- logger.info("USE_VA -> [" + useVA + "]");
+ settings.putBoolean("VERBOSE_LOGGING", verboseLogging);
- settings.putBoolean("USE_VA", useVA);
+ Application app = null;
- verboseLogging = getIntent().getBooleanExtra(AndroidActivity.class.getName() + ".VERBOSE_LOGGING", false);
+ try {
+ Class<? extends Application> clazz = (Class<? extends Application>) Class.forName(
+ appClass);
- settings.putBoolean("VERBOSE_LOGGING", verboseLogging);
+ app = clazz.newInstance();
+ /*
+ app = (Application) java.lang.reflect.Proxy.newProxyInstance(
+ this.getClass().getClassLoader(),
+ new Class[] {Class.forName(appClass)},
+
+ new java.lang.reflect.InvocationHandler() {
+ public Object invoke(Object proxy, java.lang.reflect.Method method, Object[] args) throws Throwable {
+ if (
+ method.getName().equals("loadFPSText") ||
+ method.getName().equals("loadStatsView")
+ ) {
+ logger.info("ignoring method: [" + method + "]");
+ return null;
+ }
+
+ return method.invoke(proxy, args);
+ }
+ }
+ );
+ */
- Application app = null;
- try {
- Class<? extends Application> clazz = (Class<? extends Application>) Class.forName(
- appClass
- );
+ if (app instanceof SimpleApplication) {
+ ((SimpleApplication) app).setShowSettings(false);
+ }
- app = clazz.newInstance();
-/*
- app = (Application) java.lang.reflect.Proxy.newProxyInstance(
- this.getClass().getClassLoader(),
- new Class[] {Class.forName(appClass)},
-
- new java.lang.reflect.InvocationHandler() {
- public Object invoke(Object proxy, java.lang.reflect.Method method, Object[] args) throws Throwable {
- if (
- method.getName().equals("loadFPSText") ||
- method.getName().equals("loadStatsView")
- ) {
- logger.info("ignoring method: [" + method + "]");
- return null;
- }
-
- return method.invoke(proxy, args);
- }
- }
- );
-*/
-
-
- if (app instanceof SimpleApplication) {
- ((SimpleApplication) app).setShowSettings(false);
- }
-
- logger.info("setting settings ...");
- app.setSettings(settings);
- logger.info("setting settings ... done.");
-
- logger.info("starting app ...");
- app.start();
- logger.info("starting app ... done.");
-
- if (app instanceof SimpleApplication)
- ((SimpleApplication) app).getGuiNode().detachAllChildren();
-
- logger.info("creating context ...");
- ctx = (OGLESContext) app.getContext();
- logger.info("creating context ... done.");
-
- ctx.setSettings(settings);
-
- logger.info("creating view ...");
- view = ctx.createView(this);
- logger.info("creating view ... done.");
-
- logger.info("setting content view ...");
- setContentView(view);
- logger.info("setting content done ...");
-
- } catch (Throwable exception) {
- logger.warning("exception: " + exception);
- exception.printStackTrace(System.err);
- }
- }
-
- @Override
- protected void onResume() {
- logger.info("onResume ...");
- super.onResume();
- logger.info("view.onResume ...");
-
- view.onResume();
-
- logger.info("view.onResume ... done.");
- logger.info("onResume ... done.");
- }
-
- @Override
- protected void onPause() {
- super.onPause();
- view.onPause();
- }
+ logger.info("setting settings ...");
+ app.setSettings(settings);
+ logger.info("setting settings ... done.");
+
+ logger.info("starting app ...");
+ app.start();
+ logger.info("starting app ... done.");
+
+ if (app instanceof SimpleApplication) {
+ ((SimpleApplication) app).getGuiNode().detachAllChildren();
+ }
+
+ logger.info("creating context ...");
+ ctx = (OGLESContext) app.getContext();
+ logger.info("creating context ... done.");
+
+ ctx.setSettings(settings);
+
+ logger.info("creating view ...");
+ view = ctx.createView(this);
+ logger.info("creating view ... done.");
+ logger.info("setting content view ...");
+ setContentView(view);
+ logger.info("setting content done ...");
+
+ } catch (Throwable exception) {
+ logger.warning("exception: " + exception);
+ exception.printStackTrace(System.err);
+ }
+ }
+
+ @Override
+ protected void onResume() {
+ logger.info("onResume ...");
+ super.onResume();
+ logger.info("view.onResume ...");
+
+ view.onResume();
+
+ logger.info("view.onResume ... done.");
+ logger.info("onResume ... done.");
+ }
+
+ @Override
+ protected void onPause() {
+ super.onPause();
+ view.onPause();
+ }
// @Override
// protected void onDestroy(){
// super.onDestroy();
-
// Debug.stopMethodTracing();
// }
-
}
-
*
* created: Mon Nov 8 00:08:22 EST 2010
*/
-
package jme3test.android;
-
import java.util.List;
import java.util.ArrayList;
import jme3tools.converters.model.ModelConverter;
-
public class SimpleTexturedTest extends SimpleApplication {
- private static final java.util.logging.Logger logger = java.util.logging.Logger.getLogger(SimpleTexturedTest.class.getName());
-
-
- private Node spheresContainer = new Node("spheres-container");
-
-
- private boolean lightingEnabled = true;
- private boolean texturedEnabled = true;
- private boolean spheres = true;
-
- @Override
- public void simpleInitApp() {
-
- /*
- * GUI rendering is broken on Android right now and prevents the main view from rendering.
- * Detaching all children lets the main view to be rendered.
- */
-
- guiNode.detachAllChildren();
+ private static final java.util.logging.Logger logger = java.util.logging.Logger.getLogger(SimpleTexturedTest.class.getName());
+ private Node spheresContainer = new Node("spheres-container");
+ private boolean lightingEnabled = true;
+ private boolean texturedEnabled = true;
+ private boolean spheres = true;
+
+ @Override
+ public void simpleInitApp() {
+
+ /*
+ * GUI rendering is broken on Android right now and prevents the main view from rendering.
+ * Detaching all children lets the main view to be rendered.
+ */
+
+ guiNode.detachAllChildren();
+
+ Mesh shape = null;
+
+ if (spheres) {
+ shape = new Sphere(16, 16, .5f);
+ } else {
+ shape = new Box(Vector3f.ZERO, 0.3f, 0.3f, 0.3f);
+ }
+
+ // ModelConverter.optimize(geom);
+
+ Texture texture = assetManager.loadTexture(new TextureKey("icons/textured.png"));
+
+ Material material = null;
+
+ if (texturedEnabled) {
+ if (lightingEnabled) {
+ material = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
+ material.setBoolean("VertexLighting", true);
+ material.setFloat("Shininess", 127);
+ material.setBoolean("LowQuality", true);
+ material.setTexture("DiffuseMap", texture);
+ } else {
+ material = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
+ material.setTexture("ColorMap", texture);
+ }
+ } else {
+ material = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
+ material.setColor("Color", ColorRGBA.Red);
+ }
+
+ TangentBinormalGenerator.generate(shape);
+
+ for (int y = -1; y < 2; y++) {
+ for (int x = -1; x < 2; x++) {
+ // int x = 0;
+ // int y = 0;
+ Geometry geomClone = new Geometry("geometry-" + y + "-" + x, shape);
+ geomClone.setMaterial(material);
+ geomClone.setLocalTranslation(x, y, 0);
- Mesh shape = null;
-
- if (spheres) {
- shape = new Sphere(16, 16, .5f);
- } else {
- shape = new Box(Vector3f.ZERO, 0.3f, 0.3f, 0.3f);
- }
-
- // ModelConverter.optimize(geom);
-
- Texture texture = assetManager.loadTexture(new TextureKey("icons/textured.png"));
-
- Material material = null;
-
- if (texturedEnabled) {
- if (lightingEnabled) {
- material = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
- material.setBoolean("VertexLighting", true);
- material.setFloat("Shininess", 127);
- material.setBoolean("LowQuality", true);
- material.setTexture("DiffuseMap", texture);
- } else {
- material = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
- material.setTexture("ColorMap", texture);
- }
- } else {
- material = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
- material.setColor("Color", ColorRGBA.Red);
- }
-
- TangentBinormalGenerator.generate(shape);
-
- for (int y = -1; y < 2; y++) {
- for (int x = -1; x < 2; x++){
- // int x = 0;
- // int y = 0;
- Geometry geomClone = new Geometry("geometry-" + y + "-" + x, shape);
- geomClone.setMaterial(material);
- geomClone.setLocalTranslation(x, y, 0);
-
// Transform t = geom.getLocalTransform().clone();
// Transform t2 = geomClone.getLocalTransform().clone();
// t.combineWithParent(t2);
// geomClone.setLocalTransform(t);
- spheresContainer.attachChild(geomClone);
- }
- }
+ spheresContainer.attachChild(geomClone);
+ }
+ }
- spheresContainer.setLocalTranslation(new Vector3f(0, 0, -4f));
- spheresContainer.setLocalScale(2.0f);
+ spheresContainer.setLocalTranslation(new Vector3f(0, 0, -4f));
+ spheresContainer.setLocalScale(2.0f);
- rootNode.attachChild(spheresContainer);
+ rootNode.attachChild(spheresContainer);
- PointLight pointLight = new PointLight();
+ PointLight pointLight = new PointLight();
- pointLight.setColor(new ColorRGBA(0.7f, 0.7f, 1.0f, 1.0f));
+ pointLight.setColor(new ColorRGBA(0.7f, 0.7f, 1.0f, 1.0f));
- pointLight.setPosition(new Vector3f(0f, 0f, 0f));
- pointLight.setRadius(8);
+ pointLight.setPosition(new Vector3f(0f, 0f, 0f));
+ pointLight.setRadius(8);
- rootNode.addLight(pointLight);
- }
+ rootNode.addLight(pointLight);
+ }
- @Override
- public void simpleUpdate(float tpf) {
+ @Override
+ public void simpleUpdate(float tpf) {
- if (secondCounter == 0)
- logger.info("Frames per second: " + timer.getFrameRate());
-
- spheresContainer.rotate(0.2f * tpf, 0.4f * tpf, 0.8f * tpf);
- }
+ if (secondCounter == 0) {
+ logger.info("Frames per second: " + timer.getFrameRate());
+ }
+ spheresContainer.rotate(0.2f * tpf, 0.4f * tpf, 0.8f * tpf);
+ }
}
-
public void simpleInitApp() {
Sphere s = new Sphere(8, 8, .5f);
Geometry geom = new Geometry("sphere", s);
- // ModelConverter.optimize(geom);
+ // ModelConverter.optimize(geom);
Material mat = new Material(assetManager, "plain_texture.j3md");
Texture tex = assetManager.loadTexture(new TextureKey("monkey.j3i"));
mat.setTexture("ColorMap", tex);
// geom.setMaterial(mat);
- for (int y = -1; y < 2; y++){
- for (int x = -1; x < 2; x++){
+ for (int y = -1; y < 2; y++) {
+ for (int x = -1; x < 2; x++) {
Geometry geomClone = new Geometry("geom", s);
geomClone.setMaterial(mat);
geomClone.setLocalTranslation(x, y, 0);
-
+
Transform t = geom.getLocalTransform().clone();
Transform t2 = geomClone.getLocalTransform().clone();
t.combineWithParent(t2);
}
}
}
-
}
import com.jme3.scene.Spatial;
import com.jme3.scene.Spatial.CullHint;
-
public class TestSceneLoading extends SimpleApplication {
- private void setState(Spatial s){
+ private void setState(Spatial s) {
s.setCullHint(CullHint.Never);
- if (s instanceof Node){
+ if (s instanceof Node) {
Node n = (Node) s;
- for (int i = 0; i < n.getQuantity(); i++){
+ for (int i = 0; i < n.getQuantity(); i++) {
Spatial s2 = n.getChild(i);
setState(s2);
}
}
public void simpleInitApp() {
- /* XXX: does not compile */
+ /* XXX: does not compile */
-/* Spatial scene = inputManager.loadModel("FINAL_LEVEL2.j3o");
-// setState(scene);
+ /* Spatial scene = inputManager.loadModel("FINAL_LEVEL2.j3o");
+ // setState(scene);
rootNode.attachChild(scene);
-
+
cam.setLocation(new Vector3f(-18.059685f, 34.64228f, 4.5048084f));
cam.setRotation(new Quaternion(0.22396432f, 0.5235024f, -0.1448922f, 0.8091919f));
cam.update();
-*/
+ */
}
-
}
package jme3test.android;
-
import java.util.ArrayList;
import java.util.List;
import java.net.URI;
-
public class TestsActivity extends Activity {
- private static final java.util.logging.Logger logger = java.util.logging.Logger.getLogger(TestsActivity.class.getName());
-
-
- public static class Test {
+ private static final java.util.logging.Logger logger = java.util.logging.Logger.getLogger(TestsActivity.class.getName());
- private String name = null;
- private String className = null;
+ public static class Test {
- public Test(String name, String className) {
- this.name = name;
- this.className = className;
- }
+ private String name = null;
+ private String className = null;
- public String getName() {
- return name;
- }
+ public Test(String name, String className) {
+ this.name = name;
+ this.className = className;
+ }
- public String getClassName() {
- return className;
- }
- }
+ public String getName() {
+ return name;
+ }
- private final static Test[] tests = {
- new Test("SimpleTextured", "jme3test.android.SimpleTexturedTest"),
- new Test("light.TestLightRadius", "jme3test.light.TestLightRadius"),
- new Test("bullet.TestSimplePhysics", "jme3test.bullet.TestSimplePhysics"),
- new Test("helloworld.HelloJME3", "jme3test.helloworld.HelloJME3"),
- new Test("helloworld.HelloLoop", "jme3test.helloworld.HelloLoop"),
- new Test("helloworld.HelloNode", "jme3test.helloworld.HelloNode"),
- new Test("helloworld.HelloEffects", "jme3test.helloworld.HelloEffects"),
- new Test("helloworld.HelloTerrain", "jme3test.helloworld.HelloTerrain")
- };
+ public String getClassName() {
+ return className;
+ }
+ }
+ private final static Test[] tests = {
+ new Test("SimpleTextured", "jme3test.android.SimpleTexturedTest"),
+ new Test("light.TestLightRadius", "jme3test.light.TestLightRadius"),
+ new Test("bullet.TestSimplePhysics", "jme3test.bullet.TestSimplePhysics"),
+ new Test("helloworld.HelloJME3", "jme3test.helloworld.HelloJME3"),
+ new Test("helloworld.HelloLoop", "jme3test.helloworld.HelloLoop"),
+ new Test("helloworld.HelloNode", "jme3test.helloworld.HelloNode"),
+ new Test("helloworld.HelloEffects", "jme3test.helloworld.HelloEffects"),
+ new Test("helloworld.HelloTerrain", "jme3test.helloworld.HelloTerrain")
+ };
+ private boolean useVA;
- private boolean useVA;
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ logger.info("onCreate(" + savedInstanceState + ")");
- @Override
- public void onCreate(Bundle savedInstanceState) {
- logger.info("onCreate(" + savedInstanceState + ")");
+ super.onCreate(savedInstanceState);
- super.onCreate(savedInstanceState);
+ //setContentView(R.layout.tests);
- //setContentView(R.layout.tests);
+ try {
- try {
+ useVA = true;
- useVA = true;
+ //LinearLayout buttonsContainer = (LinearLayout) findViewById(R.id.buttonsContainer);
- //LinearLayout buttonsContainer = (LinearLayout) findViewById(R.id.buttonsContainer);
+ for (Test test : tests) {
+ final Button button = new Button(this);
+ final String finalName = test.getName();
+ final String finalClassName = test.getClassName();
- for (Test test: tests) {
- final Button button = new Button(this);
- final String finalName = test.getName();
- final String finalClassName = test.getClassName();
-
- button.setText(test.getName());
+ button.setText(test.getName());
// button.setTextSize(10.0f);
// button.setTextColor(Color.rgb(100, 200, 200));
- //buttonsContainer.addView(button);
-
- button.setOnClickListener(
- new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- Intent intent = new Intent(view.getContext(), AndroidActivity.class);
- intent.putExtra(AndroidActivity.class.getName() + ".TEST_CLASS_NAME", finalClassName);
- intent.putExtra(AndroidActivity.class.getName() + ".USE_VA", useVA);
- startActivityForResult(intent, 0);
- }
- }
- );
- }
- } catch (Exception exception) {
- logger.warning("exception: " + exception);
- exception.printStackTrace(System.err);
- }
- }
-
- @Override
- public void onDestroy() {
- logger.info("onDestroy()");
- super.onDestroy();
- }
-
-
- @Override
- protected void onResume() {
- super.onResume();
- }
-
- @Override
- protected void onStart() {
- super.onStart();
- }
-
- @Override
- protected void onStop() {
- super.onStop();
- }
-
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- MenuInflater inflater = getMenuInflater();
- //inflater.inflate(R.menu.options, menu);
- return true;
- }
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- /*
- switch (item.getItemId()) {
- case R.id.about_button:
- about();
- return true;
- case R.id.quit_button:
- quit();
- return true;
- default:
- return super.onOptionsItemSelected(item);
- }
- */
- return false;
- }
-
- private void quit() {
- finish();
- }
-
- private void about() {
- // Intent intent = new Intent(getView().getContext(), AboutActivity.class);
- try {
- Intent intent = new Intent();
- intent.setClassName(
- "jme3test.android",
- "jme3test.android.AboutActivity"
- );
- startActivity(intent);
- } catch (Exception exception) {
- logger.warning("exception: " + exception);
- exception.printStackTrace(System.err);
- }
- }
-
-
+ //buttonsContainer.addView(button);
+
+ button.setOnClickListener(
+ new View.OnClickListener() {
+
+ @Override
+ public void onClick(View view) {
+ Intent intent = new Intent(view.getContext(), AndroidActivity.class);
+ intent.putExtra(AndroidActivity.class.getName() + ".TEST_CLASS_NAME", finalClassName);
+ intent.putExtra(AndroidActivity.class.getName() + ".USE_VA", useVA);
+ startActivityForResult(intent, 0);
+ }
+ });
+ }
+ } catch (Exception exception) {
+ logger.warning("exception: " + exception);
+ exception.printStackTrace(System.err);
+ }
+ }
+
+ @Override
+ public void onDestroy() {
+ logger.info("onDestroy()");
+ super.onDestroy();
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ }
+
+ @Override
+ protected void onStart() {
+ super.onStart();
+ }
+
+ @Override
+ protected void onStop() {
+ super.onStop();
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ MenuInflater inflater = getMenuInflater();
+ //inflater.inflate(R.menu.options, menu);
+ return true;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ /*
+ switch (item.getItemId()) {
+ case R.id.about_button:
+ about();
+ return true;
+ case R.id.quit_button:
+ quit();
+ return true;
+ default:
+ return super.onOptionsItemSelected(item);
+ }
+ */
+ return false;
+ }
+
+ private void quit() {
+ finish();
+ }
+
+ private void about() {
+ // Intent intent = new Intent(getView().getContext(), AboutActivity.class);
+ try {
+ Intent intent = new Intent();
+ intent.setClassName(
+ "jme3test.android",
+ "jme3test.android.AboutActivity");
+ startActivity(intent);
+ } catch (Exception exception) {
+ logger.warning("exception: " + exception);
+ exception.printStackTrace(System.err);
+ }
+ }
}
-
* @author CW
*/
public final class Fixed {
- /**
- * Number of bits used for 'fraction'.
- */
- public static final int FIXED_POINT = 16;
- /**
- * Decimal one as represented by the Fixed class.
- */
- public static final int ONE = 1 << FIXED_POINT;
-
- /**
- * Half in fixed point.
- */
- public static final int HALF = ONE >> 1;
-
- /**
- * Quarter circle resolution for trig functions (should be a power of
- * two). This is the number of discrete steps in 90 degrees.
- */
- public static final int QUARTER_CIRCLE = 64;
-
- /**
- * Mask used to limit angles to one revolution. If a quarter circle is 64
- * (i.e. 90 degrees is broken into 64 steps) then the mask is 255.
- */
- public static final int FULL_CIRCLE_MASK = QUARTER_CIRCLE * 4 - 1;
-
- /**
- * The trig table is generated at a higher precision than the typical
- * 16.16 format used for the rest of the fixed point maths. The table
- * values are then shifted to match the actual fixed point used.
- */
- private static final int TABLE_SHIFT = 30;
-
- /**
- * Equivalent to: sin((2 * PI) / (QUARTER_CIRCLE * 4))
- * <p>
- * Note: if either QUARTER_CIRCLE or TABLE_SHIFT is changed this value
- * will need recalculating (put the above formular into a calculator set
- * radians, then shift the result by <code>TABLE_SHIFT</code>).
- */
- private static final int SIN_PRECALC = 26350943;
-
- /**
- * Equivalent to: cos((2 * PI) / (QUARTER_CIRCLE * 4)) * 2
- *
- * Note: if either QUARTER_CIRCLE or TABLE_SHIFT is changed this value
- * will need recalculating ((put the above formular into a calculator set
- * radians, then shift the result by <code>TABLE_SHIFT</code>).
- */
- private static final int COS_PRECALC = 2146836866;
-
- /**
- * One quarter sine wave as fixed point values.
- */
- private static final int[] SINE_TABLE = new int[QUARTER_CIRCLE + 1];
-
- /**
- * Scale value for indexing ATAN_TABLE[].
- */
- private static final int ATAN_SHIFT;
-
- /**
- * Reverse atan lookup table.
- */
- private static final byte[] ATAN_TABLE;
-
- /**
- * ATAN_TABLE.length
- */
- private static final int ATAN_TABLE_LEN;
-
- /*
- * Generates the tables and fills in any remaining static ints.
- */
- static {
- // Generate the sine table using recursive synthesis.
- SINE_TABLE[0] = 0;
- SINE_TABLE[1] = SIN_PRECALC;
- for (int n = 2; n < QUARTER_CIRCLE + 1; n++) {
- SINE_TABLE[n] = (int) (((long) SINE_TABLE[n - 1] * COS_PRECALC) >> TABLE_SHIFT) - SINE_TABLE[n - 2];
- }
- // Scale the values to the fixed point format used.
- for (int n = 0; n < QUARTER_CIRCLE + 1; n++) {
- SINE_TABLE[n] = SINE_TABLE[n] + (1 << (TABLE_SHIFT - FIXED_POINT - 1)) >> TABLE_SHIFT - FIXED_POINT;
- }
-
- // Calculate a shift used to scale atan lookups
- int rotl = 0;
- int tan0 = tan(0);
- int tan1 = tan(1);
- while (rotl < 32) {
- if ((tan1 >>= 1) > (tan0 >>= 1)) {
- rotl++;
- } else {
- break;
- }
- }
- ATAN_SHIFT = rotl;
- // Create the a table of tan values
- int[] lut = new int[QUARTER_CIRCLE];
- for (int n = 0; n < QUARTER_CIRCLE; n++) {
- lut[n] = tan(n) >> rotl;
- }
- ATAN_TABLE_LEN = lut[QUARTER_CIRCLE - 1];
- // Then from the tan values create a reverse lookup
- ATAN_TABLE = new byte[ATAN_TABLE_LEN];
- for (byte n = 0; n < QUARTER_CIRCLE - 1; n++) {
- int min = lut[n ];
- int max = lut[n + 1];
- for (int i = min; i < max; i++) {
- ATAN_TABLE[i] = n;
- }
- }
- }
-
- /**
- * How many decimal places to use when converting a fixed point value to
- * a decimal string.
- *
- * @see #toString
- */
- private static final int STRING_DECIMAL_PLACES = 2;
-
- /**
- * Value to add in order to round down a fixed point number when
- * converting to a string.
- */
- private static final int STRING_DECIMAL_PLACES_ROUND;
- static {
- int i = 10;
- for (int n = 1; n < STRING_DECIMAL_PLACES; n++) {
- i *= i;
- }
- if (STRING_DECIMAL_PLACES == 0) {
- STRING_DECIMAL_PLACES_ROUND = ONE / 2;
- } else {
- STRING_DECIMAL_PLACES_ROUND = ONE / (2 * i);
- }
- }
+ /**
+ * Number of bits used for 'fraction'.
+ */
+ public static final int FIXED_POINT = 16;
+ /**
+ * Decimal one as represented by the Fixed class.
+ */
+ public static final int ONE = 1 << FIXED_POINT;
+ /**
+ * Half in fixed point.
+ */
+ public static final int HALF = ONE >> 1;
+ /**
+ * Quarter circle resolution for trig functions (should be a power of
+ * two). This is the number of discrete steps in 90 degrees.
+ */
+ public static final int QUARTER_CIRCLE = 64;
+ /**
+ * Mask used to limit angles to one revolution. If a quarter circle is 64
+ * (i.e. 90 degrees is broken into 64 steps) then the mask is 255.
+ */
+ public static final int FULL_CIRCLE_MASK = QUARTER_CIRCLE * 4 - 1;
+ /**
+ * The trig table is generated at a higher precision than the typical
+ * 16.16 format used for the rest of the fixed point maths. The table
+ * values are then shifted to match the actual fixed point used.
+ */
+ private static final int TABLE_SHIFT = 30;
+ /**
+ * Equivalent to: sin((2 * PI) / (QUARTER_CIRCLE * 4))
+ * <p>
+ * Note: if either QUARTER_CIRCLE or TABLE_SHIFT is changed this value
+ * will need recalculating (put the above formular into a calculator set
+ * radians, then shift the result by <code>TABLE_SHIFT</code>).
+ */
+ private static final int SIN_PRECALC = 26350943;
+ /**
+ * Equivalent to: cos((2 * PI) / (QUARTER_CIRCLE * 4)) * 2
+ *
+ * Note: if either QUARTER_CIRCLE or TABLE_SHIFT is changed this value
+ * will need recalculating ((put the above formular into a calculator set
+ * radians, then shift the result by <code>TABLE_SHIFT</code>).
+ */
+ private static final int COS_PRECALC = 2146836866;
+ /**
+ * One quarter sine wave as fixed point values.
+ */
+ private static final int[] SINE_TABLE = new int[QUARTER_CIRCLE + 1];
+ /**
+ * Scale value for indexing ATAN_TABLE[].
+ */
+ private static final int ATAN_SHIFT;
+ /**
+ * Reverse atan lookup table.
+ */
+ private static final byte[] ATAN_TABLE;
+ /**
+ * ATAN_TABLE.length
+ */
+ private static final int ATAN_TABLE_LEN;
- /**
- * Random number generator. The standard <code>java.utll.Random</code> is
- * used since it is available to both J2ME and J2SE. If a guaranteed
- * sequence is required this would not be adequate.
- */
- private static Random rng = null;
+ /*
+ * Generates the tables and fills in any remaining static ints.
+ */
+ static {
+ // Generate the sine table using recursive synthesis.
+ SINE_TABLE[0] = 0;
+ SINE_TABLE[1] = SIN_PRECALC;
+ for (int n = 2; n < QUARTER_CIRCLE + 1; n++) {
+ SINE_TABLE[n] = (int) (((long) SINE_TABLE[n - 1] * COS_PRECALC) >> TABLE_SHIFT) - SINE_TABLE[n - 2];
+ }
+ // Scale the values to the fixed point format used.
+ for (int n = 0; n < QUARTER_CIRCLE + 1; n++) {
+ SINE_TABLE[n] = SINE_TABLE[n] + (1 << (TABLE_SHIFT - FIXED_POINT - 1)) >> TABLE_SHIFT - FIXED_POINT;
+ }
+
+ // Calculate a shift used to scale atan lookups
+ int rotl = 0;
+ int tan0 = tan(0);
+ int tan1 = tan(1);
+ while (rotl < 32) {
+ if ((tan1 >>= 1) > (tan0 >>= 1)) {
+ rotl++;
+ } else {
+ break;
+ }
+ }
+ ATAN_SHIFT = rotl;
+ // Create the a table of tan values
+ int[] lut = new int[QUARTER_CIRCLE];
+ for (int n = 0; n < QUARTER_CIRCLE; n++) {
+ lut[n] = tan(n) >> rotl;
+ }
+ ATAN_TABLE_LEN = lut[QUARTER_CIRCLE - 1];
+ // Then from the tan values create a reverse lookup
+ ATAN_TABLE = new byte[ATAN_TABLE_LEN];
+ for (byte n = 0; n < QUARTER_CIRCLE - 1; n++) {
+ int min = lut[n];
+ int max = lut[n + 1];
+ for (int i = min; i < max; i++) {
+ ATAN_TABLE[i] = n;
+ }
+ }
+ }
+ /**
+ * How many decimal places to use when converting a fixed point value to
+ * a decimal string.
+ *
+ * @see #toString
+ */
+ private static final int STRING_DECIMAL_PLACES = 2;
+ /**
+ * Value to add in order to round down a fixed point number when
+ * converting to a string.
+ */
+ private static final int STRING_DECIMAL_PLACES_ROUND;
+
+ static {
+ int i = 10;
+ for (int n = 1; n < STRING_DECIMAL_PLACES; n++) {
+ i *= i;
+ }
+ if (STRING_DECIMAL_PLACES == 0) {
+ STRING_DECIMAL_PLACES_ROUND = ONE / 2;
+ } else {
+ STRING_DECIMAL_PLACES_ROUND = ONE / (2 * i);
+ }
+ }
+ /**
+ * Random number generator. The standard <code>java.utll.Random</code> is
+ * used since it is available to both J2ME and J2SE. If a guaranteed
+ * sequence is required this would not be adequate.
+ */
+ private static Random rng = null;
- /**
- * Fixed can't be instantiated.
- */
- private Fixed() {}
+ /**
+ * Fixed can't be instantiated.
+ */
+ private Fixed() {
+ }
- /**
- * Returns an integer as a fixed point value.
- */
- public static int intToFixed(int n) {
- return n << FIXED_POINT;
- }
+ /**
+ * Returns an integer as a fixed point value.
+ */
+ public static int intToFixed(int n) {
+ return n << FIXED_POINT;
+ }
/**
* Returns a fixed point value as a float.
*/
public static float fixedToFloat(int i) {
float fp = i;
- fp = fp / ((float)ONE);
+ fp = fp / ((float) ONE);
return fp;
}
/**
* Returns a float as a fixed point value.
*/
- public static int floatToFixed(float fp){
+ public static int floatToFixed(float fp) {
return (int) (fp * ((float) ONE));
}
- /**
- * Converts a fixed point value into a decimal string.
- */
- public static String toString(int n) {
- StringBuffer sb = new StringBuffer(16);
- sb.append((n += STRING_DECIMAL_PLACES_ROUND) >> FIXED_POINT);
- sb.append('.');
- n &= ONE - 1;
- for (int i = 0; i < STRING_DECIMAL_PLACES; i++) {
- n *= 10;
- sb.append((n / ONE) % 10);
- }
- return sb.toString();
- }
+ /**
+ * Converts a fixed point value into a decimal string.
+ */
+ public static String toString(int n) {
+ StringBuffer sb = new StringBuffer(16);
+ sb.append((n += STRING_DECIMAL_PLACES_ROUND) >> FIXED_POINT);
+ sb.append('.');
+ n &= ONE - 1;
+ for (int i = 0; i < STRING_DECIMAL_PLACES; i++) {
+ n *= 10;
+ sb.append((n / ONE) % 10);
+ }
+ return sb.toString();
+ }
- /**
- * Multiplies two fixed point values and returns the result.
- */
- public static int mul(int a, int b) {
- return (int) ((long) a * (long) b >> FIXED_POINT);
- }
+ /**
+ * Multiplies two fixed point values and returns the result.
+ */
+ public static int mul(int a, int b) {
+ return (int) ((long) a * (long) b >> FIXED_POINT);
+ }
- /**
- * Divides two fixed point values and returns the result.
- */
- public static int div(int a, int b) {
- return (int) (((long) a << FIXED_POINT * 2) / (long) b >> FIXED_POINT);
- }
+ /**
+ * Divides two fixed point values and returns the result.
+ */
+ public static int div(int a, int b) {
+ return (int) (((long) a << FIXED_POINT * 2) / (long) b >> FIXED_POINT);
+ }
- /**
- * Sine of an angle.
- *
- * @see #QUARTER_CIRCLE
- */
- public static int sin(int n) {
- n &= FULL_CIRCLE_MASK;
- if (n < QUARTER_CIRCLE * 2) {
- if (n < QUARTER_CIRCLE) {
- return SINE_TABLE[n];
- } else {
- return SINE_TABLE[QUARTER_CIRCLE * 2 - n];
- }
- } else {
- if (n < QUARTER_CIRCLE * 3) {
- return -SINE_TABLE[n - QUARTER_CIRCLE * 2];
- } else {
- return -SINE_TABLE[QUARTER_CIRCLE * 4 - n];
- }
- }
- }
+ /**
+ * Sine of an angle.
+ *
+ * @see #QUARTER_CIRCLE
+ */
+ public static int sin(int n) {
+ n &= FULL_CIRCLE_MASK;
+ if (n < QUARTER_CIRCLE * 2) {
+ if (n < QUARTER_CIRCLE) {
+ return SINE_TABLE[n];
+ } else {
+ return SINE_TABLE[QUARTER_CIRCLE * 2 - n];
+ }
+ } else {
+ if (n < QUARTER_CIRCLE * 3) {
+ return -SINE_TABLE[n - QUARTER_CIRCLE * 2];
+ } else {
+ return -SINE_TABLE[QUARTER_CIRCLE * 4 - n];
+ }
+ }
+ }
- /**
- * Cosine of an angle.
- *
- * @see #QUARTER_CIRCLE
- */
- public static int cos(int n) {
- n &= FULL_CIRCLE_MASK;
- if (n < QUARTER_CIRCLE * 2) {
- if (n < QUARTER_CIRCLE) {
- return SINE_TABLE[QUARTER_CIRCLE - n];
- } else {
- return -SINE_TABLE[n - QUARTER_CIRCLE];
- }
- } else {
- if (n < QUARTER_CIRCLE * 3) {
- return -SINE_TABLE[QUARTER_CIRCLE * 3 - n];
- } else {
- return SINE_TABLE[n - QUARTER_CIRCLE * 3];
- }
- }
- }
+ /**
+ * Cosine of an angle.
+ *
+ * @see #QUARTER_CIRCLE
+ */
+ public static int cos(int n) {
+ n &= FULL_CIRCLE_MASK;
+ if (n < QUARTER_CIRCLE * 2) {
+ if (n < QUARTER_CIRCLE) {
+ return SINE_TABLE[QUARTER_CIRCLE - n];
+ } else {
+ return -SINE_TABLE[n - QUARTER_CIRCLE];
+ }
+ } else {
+ if (n < QUARTER_CIRCLE * 3) {
+ return -SINE_TABLE[QUARTER_CIRCLE * 3 - n];
+ } else {
+ return SINE_TABLE[n - QUARTER_CIRCLE * 3];
+ }
+ }
+ }
- /**
- * Tangent of an angle.
- *
- * @see #QUARTER_CIRCLE
- */
- public static int tan(int n) {
- return div(sin(n), cos(n));
- }
+ /**
+ * Tangent of an angle.
+ *
+ * @see #QUARTER_CIRCLE
+ */
+ public static int tan(int n) {
+ return div(sin(n), cos(n));
+ }
- /**
- * Returns the arc tangent of an angle.
- */
- public static int atan(int n) {
- n = n + (1 << (ATAN_SHIFT - 1)) >> ATAN_SHIFT;
- if (n < 0) {
- if (n <= -ATAN_TABLE_LEN) {
- return -(QUARTER_CIRCLE - 1);
- }
- return -ATAN_TABLE[-n];
- } else {
- if (n >= ATAN_TABLE_LEN) {
- return QUARTER_CIRCLE - 1;
- }
- return ATAN_TABLE[n];
- }
- }
+ /**
+ * Returns the arc tangent of an angle.
+ */
+ public static int atan(int n) {
+ n = n + (1 << (ATAN_SHIFT - 1)) >> ATAN_SHIFT;
+ if (n < 0) {
+ if (n <= -ATAN_TABLE_LEN) {
+ return -(QUARTER_CIRCLE - 1);
+ }
+ return -ATAN_TABLE[-n];
+ } else {
+ if (n >= ATAN_TABLE_LEN) {
+ return QUARTER_CIRCLE - 1;
+ }
+ return ATAN_TABLE[n];
+ }
+ }
- /**
- * Returns the polar angle of a rectangular coordinate.
- */
- public static int atan(int x, int y) {
- int n = atan(div(x, abs(y) + 1)); // kludge to prevent ArithmeticException
- if (y > 0) {
- return n;
- }
- if (y < 0) {
- if (x < 0) {
- return -QUARTER_CIRCLE * 2 - n;
- }
- if (x > 0) {
- return QUARTER_CIRCLE * 2 - n;
- }
- return QUARTER_CIRCLE * 2;
- }
- if (x > 0) {
- return QUARTER_CIRCLE;
- }
- return -QUARTER_CIRCLE;
- }
+ /**
+ * Returns the polar angle of a rectangular coordinate.
+ */
+ public static int atan(int x, int y) {
+ int n = atan(div(x, abs(y) + 1)); // kludge to prevent ArithmeticException
+ if (y > 0) {
+ return n;
+ }
+ if (y < 0) {
+ if (x < 0) {
+ return -QUARTER_CIRCLE * 2 - n;
+ }
+ if (x > 0) {
+ return QUARTER_CIRCLE * 2 - n;
+ }
+ return QUARTER_CIRCLE * 2;
+ }
+ if (x > 0) {
+ return QUARTER_CIRCLE;
+ }
+ return -QUARTER_CIRCLE;
+ }
- /**
- * Rough calculation of the hypotenuse. Whilst not accurate it is very fast.
- * <p>
- * Derived from a piece in Graphics Gems.
- */
- public static int hyp(int x1, int y1, int x2, int y2) {
- if ((x2 -= x1) < 0) {
- x2 = -x2;
- }
- if ((y2 -= y1) < 0) {
- y2 = -y2;
- }
- return x2 + y2 - (((x2 > y2) ? y2 : x2) >> 1);
- }
+ /**
+ * Rough calculation of the hypotenuse. Whilst not accurate it is very fast.
+ * <p>
+ * Derived from a piece in Graphics Gems.
+ */
+ public static int hyp(int x1, int y1, int x2, int y2) {
+ if ((x2 -= x1) < 0) {
+ x2 = -x2;
+ }
+ if ((y2 -= y1) < 0) {
+ y2 = -y2;
+ }
+ return x2 + y2 - (((x2 > y2) ? y2 : x2) >> 1);
+ }
- /**
- * Fixed point square root.
- * <p>
- * Derived from a 1993 Usenet algorithm posted by Christophe Meessen.
- */
- public static int sqrt(int n) {
- if (n <= 0) {
- return 0;
- }
- long sum = 0;
- int bit = 0x40000000;
- while (bit >= 0x100) { // lower values give more accurate results
- long tmp = sum | bit;
- if (n >= tmp) {
- n -= tmp;
- sum = tmp + bit;
- }
- bit >>= 1;
- n <<= 1;
- }
- return (int) (sum >> 16 - (FIXED_POINT / 2));
- }
+ /**
+ * Fixed point square root.
+ * <p>
+ * Derived from a 1993 Usenet algorithm posted by Christophe Meessen.
+ */
+ public static int sqrt(int n) {
+ if (n <= 0) {
+ return 0;
+ }
+ long sum = 0;
+ int bit = 0x40000000;
+ while (bit >= 0x100) { // lower values give more accurate results
+ long tmp = sum | bit;
+ if (n >= tmp) {
+ n -= tmp;
+ sum = tmp + bit;
+ }
+ bit >>= 1;
+ n <<= 1;
+ }
+ return (int) (sum >> 16 - (FIXED_POINT / 2));
+ }
- /**
- * Returns the absolute value.
- */
- public static int abs(int n) {
- return (n < 0) ? -n : n;
- }
+ /**
+ * Returns the absolute value.
+ */
+ public static int abs(int n) {
+ return (n < 0) ? -n : n;
+ }
- /**
- * Returns the sign of a value, -1 for negative numbers, otherwise 1.
- */
- public static int sgn(int n) {
- return (n < 0) ? -1 : 1;
- }
+ /**
+ * Returns the sign of a value, -1 for negative numbers, otherwise 1.
+ */
+ public static int sgn(int n) {
+ return (n < 0) ? -1 : 1;
+ }
- /**
- * Returns the minimum of two values.
- */
- public static int min(int a, int b) {
- return (a < b) ? a : b;
- }
+ /**
+ * Returns the minimum of two values.
+ */
+ public static int min(int a, int b) {
+ return (a < b) ? a : b;
+ }
- /**
- * Returns the maximum of two values.
- */
- public static int max(int a, int b) {
- return (a > b) ? a : b;
- }
+ /**
+ * Returns the maximum of two values.
+ */
+ public static int max(int a, int b) {
+ return (a > b) ? a : b;
+ }
- /**
- * Clamps the value n between min and max.
- */
- public static int clamp(int n, int min, int max) {
- return (n < min) ? min : (n > max) ? max : n;
- }
+ /**
+ * Clamps the value n between min and max.
+ */
+ public static int clamp(int n, int min, int max) {
+ return (n < min) ? min : (n > max) ? max : n;
+ }
- /**
- * Wraps the value n between 0 and the required limit.
- */
- public static int wrap(int n, int limit) {
- return ((n %= limit) < 0) ? limit + n : n;
- }
+ /**
+ * Wraps the value n between 0 and the required limit.
+ */
+ public static int wrap(int n, int limit) {
+ return ((n %= limit) < 0) ? limit + n : n;
+ }
- /**
- * Returns the nearest int to a fixed point value. Equivalent to <code>
- * Math.round()</code> in the standard library.
- */
- public static int round(int n) {
- return n + HALF >> FIXED_POINT;
- }
+ /**
+ * Returns the nearest int to a fixed point value. Equivalent to <code>
+ * Math.round()</code> in the standard library.
+ */
+ public static int round(int n) {
+ return n + HALF >> FIXED_POINT;
+ }
- /**
- * Returns the nearest int rounded down from a fixed point value.
- * Equivalent to <code>Math.floor()</code> in the standard library.
- */
- public static int floor(int n) {
- return n >> FIXED_POINT;
- }
+ /**
+ * Returns the nearest int rounded down from a fixed point value.
+ * Equivalent to <code>Math.floor()</code> in the standard library.
+ */
+ public static int floor(int n) {
+ return n >> FIXED_POINT;
+ }
- /**
- * Returns the nearest int rounded up from a fixed point value.
- * Equivalent to <code>Math.ceil()</code> in the standard library.
- */
- public static int ceil(int n) {
- return n + (ONE - 1) >> FIXED_POINT;
- }
+ /**
+ * Returns the nearest int rounded up from a fixed point value.
+ * Equivalent to <code>Math.ceil()</code> in the standard library.
+ */
+ public static int ceil(int n) {
+ return n + (ONE - 1) >> FIXED_POINT;
+ }
- /**
- * Returns a fixed point value greater than or equal to decimal 0.0 and
- * less than 1.0 (in 16.16 format this would be 0 to 65535 inclusive).
- */
- public static int rand() {
- if (rng == null) {
- rng = new Random();
- }
- return rng.nextInt() >>> (32 - FIXED_POINT);
- }
+ /**
+ * Returns a fixed point value greater than or equal to decimal 0.0 and
+ * less than 1.0 (in 16.16 format this would be 0 to 65535 inclusive).
+ */
+ public static int rand() {
+ if (rng == null) {
+ rng = new Random();
+ }
+ return rng.nextInt() >>> (32 - FIXED_POINT);
+ }
- /**
- * Returns a random number between 0 and <code>n</code> (exclusive).
- */
- public static int rand(int n) {
- return (rand() * n) >> FIXED_POINT;
- }
+ /**
+ * Returns a random number between 0 and <code>n</code> (exclusive).
+ */
+ public static int rand(int n) {
+ return (rand() * n) >> FIXED_POINT;
+ }
}
\ No newline at end of file
android:layout_height="fill_parent"
>
- <LinearLayout
+ <LinearLayout
android:id="@+id/buttonsContainer"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
- <TextView
+ <TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="copyright (c) 2009-2010 JMonkeyEngine"
/>
- <TextView
+ <TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="http://www.jmonkeyengine.org"
/>
- </LinearLayout>
+ </LinearLayout>
</LinearLayout>
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
-
- <LinearLayout
+ <LinearLayout
android:id="@+id/buttonsContainer"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- >
+ android:layout_height="fill_parent">
<!--
<Button
android:id="@+id/SimpleTextured"
android:layout_weight="1"
/>
-->
- </LinearLayout>
-
+ </LinearLayout>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
-
- <item
- android:id="@+id/about_button"
- android:title="@string/about"
+ <item
+ android:id="@+id/about_button"
+ android:title="@string/about"
/>
- <item
- android:id="@+id/quit_button"
- android:title="@string/quit"
+ <item
+ android:id="@+id/quit_button"
+ android:title="@string/quit"
/>
-
</menu>
<?xml version="1.0" encoding="utf-8"?>
<resources>
- <string name="app_name">JMEAndroidTest</string>
- <string name="about">About</string>
- <string name="quit">Quit</string>
+ <string name="app_name">JMEAndroidTest</string>
+ <string name="about">About</string>
+ <string name="quit">Quit</string>
</resources>
import com.jme3.input.MouseInput;
import com.jme3.input.TouchInput;
import com.jme3.renderer.Renderer;
-import com.jme3.system.JmeCanvasContext;
/**
* Represents a rendering context within the engine.
--- /dev/null
+package com.jme3.system;
+
+public enum Platform {
+
+ /**
+ * Microsoft Windows 32 bit
+ */
+ Windows32,
+
+ /**
+ * Microsoft Windows 64 bit
+ */
+ Windows64,
+
+ /**
+ * Linux 32 bit
+ */
+ Linux32,
+
+ /**
+ * Linux 64 bit
+ */
+ Linux64,
+
+ /**
+ * Apple Mac OS X 32 bit
+ */
+ MacOSX32,
+
+ /**
+ * Apple Mac OS X 64 bit
+ */
+ MacOSX64,
+
+ /**
+ * Apple Mac OS X 32 bit PowerPC
+ */
+ MacOSX_PPC32,
+
+ /**
+ * Apple Mac OS X 64 bit PowerPC
+ */
+ MacOSX_PPC64,
+
+ /**
+ * Android ARM5
+ */
+ Android_ARM5,
+
+ /**
+ * Android ARM6
+ */
+ Android_ARM6,
+
+ /**
+ * Android ARM7
+ */
+ Android_ARM7,
+
+ /**
+ * Android x86
+ */
+ Android_X86;
+
+}
\ No newline at end of file
import com.jme3.texture.Image.Format;
import com.jme3.texture.Texture;
import com.jme3.texture.TextureCubeMap;
-
+import java.util.ArrayList;
+
+/**
+ * <code>SkyFactory</code> is used to create jME {@link Spatial}s that can
+ * be attached to the scene to display a sky image in the background.
+ *
+ * @author Kirill Vainer
+ */
public class SkyFactory {
-
- public static Spatial createSky(AssetManager assetManager, Texture texture, Vector3f normalScale, boolean sphereMap){
- return createSky(assetManager, texture, normalScale, sphereMap, 10);
- }
- public static Spatial createSky(AssetManager assetManager, Texture texture, Vector3f normalScale, boolean sphereMap, int sphereRadius){
- if (texture == null)
+ /**
+ * Creates a sky using the given texture (cubemap or spheremap).
+ *
+ * @param assetManager The asset manager to use to load materials
+ * @param texture Texture to use for the sky
+ * @param normalScale The normal scale is multiplied by the 3D normal
+ * to get a texture coordinate. Use Vector3f.UNIT_XYZ to not apply
+ * and transformation to the normal.
+ * @param sphereMap The way the texture is used
+ * depends on this value:<br>
+ * <ul>
+ * <li>true: Its a Texture2D with the pixels arranged for
+ * <a href="http://en.wikipedia.org/wiki/Sphere_mapping">sphere mapping</a>.</li>
+ * <li>false: Its either a TextureCubeMap or Texture2D. If its a Texture2D
+ * then the image is taken from it and is inserted into a TextureCubeMap</li>
+ * </ul>
+ * @return A spatial representing the sky
+ */
+ public static Spatial createSky(AssetManager assetManager, Texture texture, Vector3f normalScale, boolean sphereMap) {
+ return createSky(assetManager, texture, normalScale, sphereMap, 10);
+ }
+
+ /**
+ * Creates a sky using the given texture (cubemap or spheremap).
+ *
+ * @param assetManager The asset manager to use to load materials
+ * @param texture Texture to use for the sky
+ * @param normalScale The normal scale is multiplied by the 3D normal
+ * to get a texture coordinate. Use Vector3f.UNIT_XYZ to not apply
+ * and transformation to the normal.
+ * @param sphereMap The way the texture is used
+ * depends on this value:<br>
+ * <ul>
+ * <li>true: Its a Texture2D with the pixels arranged for
+ * <a href="http://en.wikipedia.org/wiki/Sphere_mapping">sphere mapping</a>.</li>
+ * <li>false: Its either a TextureCubeMap or Texture2D. If its a Texture2D
+ * then the image is taken from it and is inserted into a TextureCubeMap</li>
+ * </ul>
+ * @param sphereRadius If specified, this will be the sky sphere's radius.
+ * This should be the camera's near plane for optimal quality.
+ * @return A spatial representing the sky
+ */
+ public static Spatial createSky(AssetManager assetManager, Texture texture, Vector3f normalScale, boolean sphereMap, int sphereRadius) {
+ if (texture == null) {
throw new IllegalArgumentException("texture cannot be null");
+ }
final Sphere sphereMesh = new Sphere(10, 10, sphereRadius, false, true);
-
+
Geometry sky = new Geometry("Sky", sphereMesh);
sky.setQueueBucket(Bucket.Sky);
sky.setCullHint(Spatial.CullHint.Never);
sky.setModelBound(new BoundingSphere(Float.POSITIVE_INFINITY, Vector3f.ZERO));
Material skyMat = new Material(assetManager, "Common/MatDefs/Misc/Sky.j3md");
-
+
skyMat.setVector3("NormalScale", normalScale);
- if (sphereMap){
+ if (sphereMap) {
skyMat.setBoolean("SphereMap", sphereMap);
- }else if (!(texture instanceof TextureCubeMap)){
+ } else if (!(texture instanceof TextureCubeMap)) {
// make sure its a cubemap
Image img = texture.getImage();
texture = new TextureCubeMap();
}
skyMat.setTexture("Texture", texture);
sky.setMaterial(skyMat);
-
+
return sky;
}
- private static void checkImage(Image image){
+ private static void checkImage(Image image) {
// if (image.getDepth() != 1)
// throw new IllegalArgumentException("3D/Array images not allowed");
- if (image.getWidth() != image.getHeight())
+ if (image.getWidth() != image.getHeight()) {
throw new IllegalArgumentException("Image width and height must be the same");
+ }
- if (image.getMultiSamples() != 1)
+ if (image.getMultiSamples() != 1) {
throw new IllegalArgumentException("Multisample textures not allowed");
+ }
}
- private static void checkImagesForCubeMap(Image ... images){
- if (images.length == 1) return;
+ private static void checkImagesForCubeMap(Image... images) {
+ if (images.length == 1) {
+ return;
+ }
Format fmt = images[0].getFormat();
int width = images[0].getWidth();
checkImage(images[0]);
- for (int i = 1; i < images.length; i++){
+ for (int i = 1; i < images.length; i++) {
Image image = images[i];
checkImage(images[i]);
- if (image.getFormat() != fmt) throw new IllegalArgumentException("Images must have same format");
- if (image.getWidth() != width) throw new IllegalArgumentException("Images must have same resolution");
- if (image.getData(0).capacity() != size) throw new IllegalArgumentException("Images must have same size");
+ if (image.getFormat() != fmt) {
+ throw new IllegalArgumentException("Images must have same format");
+ }
+ if (image.getWidth() != width) {
+ throw new IllegalArgumentException("Images must have same resolution");
+ }
+ if (image.getData(0).capacity() != size) {
+ throw new IllegalArgumentException("Images must have same size");
+ }
}
}
- public static Spatial createSky(AssetManager assetManager, Texture west, Texture east, Texture north, Texture south, Texture up, Texture down, Vector3f normalScale){
- return createSky(assetManager, west, east, north, south, up, down, normalScale, 10);
+ public static Spatial createSky(AssetManager assetManager, Texture west, Texture east, Texture north, Texture south, Texture up, Texture down, Vector3f normalScale) {
+ return createSky(assetManager, west, east, north, south, up, down, normalScale, 10);
}
-
- public static Spatial createSky(AssetManager assetManager, Texture west, Texture east, Texture north, Texture south, Texture up, Texture down, Vector3f normalScale, int sphereRadius){
+
+ public static Spatial createSky(AssetManager assetManager, Texture west, Texture east, Texture north, Texture south, Texture up, Texture down, Vector3f normalScale, int sphereRadius) {
final Sphere sphereMesh = new Sphere(10, 10, sphereRadius, false, true);
Geometry sky = new Geometry("Sky", sphereMesh);
sky.setQueueBucket(Bucket.Sky);
sky.setCullHint(Spatial.CullHint.Never);
sky.setModelBound(new BoundingSphere(Float.POSITIVE_INFINITY, Vector3f.ZERO));
- Image westImg = west.getImage();
- Image eastImg = east.getImage();
+ Image westImg = west.getImage();
+ Image eastImg = east.getImage();
Image northImg = north.getImage();
Image southImg = south.getImage();
- Image upImg = up.getImage();
- Image downImg = down.getImage();
+ Image upImg = up.getImage();
+ Image downImg = down.getImage();
checkImagesForCubeMap(westImg, eastImg, northImg, southImg, upImg, downImg);
Image cubeImage = new Image(westImg.getFormat(), westImg.getWidth(), westImg.getHeight(), null);
-
+
cubeImage.addData(westImg.getData(0));
cubeImage.addData(eastImg.getData(0));
-
+
cubeImage.addData(downImg.getData(0));
cubeImage.addData(upImg.getData(0));
cubeImage.addData(southImg.getData(0));
cubeImage.addData(northImg.getData(0));
+
+ if (westImg.getEfficentData() != null){
+ // also consilidate efficient data
+ ArrayList<Object> efficientData = new ArrayList<Object>(6);
+ efficientData.add(westImg.getEfficentData());
+ efficientData.add(eastImg.getEfficentData());
+ efficientData.add(downImg.getEfficentData());
+ efficientData.add(upImg.getEfficentData());
+ efficientData.add(southImg.getEfficentData());
+ efficientData.add(northImg.getEfficentData());
+ cubeImage.setEfficentData(efficientData);
+ }
TextureCubeMap cubeMap = new TextureCubeMap(cubeImage);
cubeMap.setAnisotropicFilter(0);
return sky;
}
- public static Spatial createSky(AssetManager assetManager, Texture west, Texture east, Texture north, Texture south, Texture up, Texture down){
+ public static Spatial createSky(AssetManager assetManager, Texture west, Texture east, Texture north, Texture south, Texture up, Texture down) {
return createSky(assetManager, west, east, north, south, up, down, Vector3f.UNIT_XYZ);
}
- public static Spatial createSky(AssetManager assetManager, Texture texture, boolean sphereMap){
+ public static Spatial createSky(AssetManager assetManager, Texture texture, boolean sphereMap) {
return createSky(assetManager, texture, Vector3f.UNIT_XYZ, sphereMap);
}
- public static Spatial createSky(AssetManager assetManager, String textureName, boolean sphereMap){
+ public static Spatial createSky(AssetManager assetManager, String textureName, boolean sphereMap) {
TextureKey key = new TextureKey(textureName, true);
key.setGenerateMips(true);
key.setAsCube(!sphereMap);
Texture tex = assetManager.loadTexture(key);
return createSky(assetManager, tex, sphereMap);
}
-
-
-
}
public class JmeSystem {
- public static enum Platform {
-
- /**
- * Microsoft Windows 32 bit
- */
- Windows32,
- /**
- * Microsoft Windows 64 bit
- */
- Windows64,
- /**
- * Linux 32 bit
- */
- Linux32,
- /**
- * Linux 64 bit
- */
- Linux64,
- /**
- * Apple Mac OS X 32 bit
- */
- MacOSX32,
- /**
- * Apple Mac OS X 64 bit
- */
- MacOSX64,
- /**
- * Apple Mac OS X 32 bit PowerPC
- */
- MacOSX_PPC32,
- /**
- * Apple Mac OS X 64 bit PowerPC
- */
- MacOSX_PPC64,
- }
private static final Logger logger = Logger.getLogger(JmeSystem.class.getName());
private static boolean initialized = false;
private static boolean lowPermissions = false;