|
From: Caspian Rychlik-P. <ci...@us...> - 2003-03-21 17:06:01
|
Update of /cvsroot/java-game-lib/LWJGL/src/java/org/lwjgl In directory sc8-pr-cvs1:/tmp/cvs-serv27852/src/java/org/lwjgl Modified Files: Display.java Sys.java Math.java Log Message: New getPlatform() method added Index: Display.java CVS Browser: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/java-game-lib/LWJGL/src/java/org/lwjgl/Display.java =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/java/org/lwjgl/Display.java,v retrieving revision 1.18 retrieving revision 1.19 diff -u -d -r1.18 -r1.19 --- Display.java 19 Mar 2003 12:41:27 -0000 1.18 +++ Display.java 21 Mar 2003 17:05:55 -0000 1.19 @@ -63,6 +63,20 @@ /** Whether or not the display has been requested to shutdown by the user */ private static boolean closeRequested = false; + /* + * Platforms. This will let you determine which platform you are running + * on, which is handy to know for some GL context calls. + */ + + /** Windows platform */ + public static final int PLATFORM_WGL = 0; + + /** GLX (Linux/Unix) platform */ + public static final int PLATFORM_GLX = 1; + + /** MacOSX platform */ + public static final int PLATFORM_AGL = 2; + /** * No construction allowed. */ @@ -79,30 +93,30 @@ * @return an array of all display modes the system reckons it can handle. */ public static DisplayMode[] getAvailableDisplayModes() { - DisplayMode[] unfilteredModes = nGetAvailableDisplayModes(); + DisplayMode[] unfilteredModes = nGetAvailableDisplayModes(); - if (unfilteredModes == null) { - return new DisplayMode[0]; - } - - // We'll use a HashSet to filter out the duplicated modes - HashSet modes = new HashSet(unfilteredModes.length); - - modes.addAll(Arrays.asList(unfilteredModes)); - DisplayMode[] filteredModes = new DisplayMode[modes.size()]; - modes.toArray(filteredModes); - - if(Sys.DEBUG) { - System.out.println("Removed " + (unfilteredModes.length - filteredModes.length) + " duplicate displaymodes"); - } - - return filteredModes; + if (unfilteredModes == null) { + return new DisplayMode[0]; + } + + // We'll use a HashSet to filter out the duplicated modes + HashSet modes = new HashSet(unfilteredModes.length); + + modes.addAll(Arrays.asList(unfilteredModes)); + DisplayMode[] filteredModes = new DisplayMode[modes.size()]; + modes.toArray(filteredModes); + + if (Sys.DEBUG) { + System.out.println("Removed " + (unfilteredModes.length - filteredModes.length) + " duplicate displaymodes"); + } + + return filteredModes; } - - /** - * Native method for getting displaymodes - */ - public static native DisplayMode[] nGetAvailableDisplayModes(); + + /** + * Native method for getting displaymodes + */ + public static native DisplayMode[] nGetAvailableDisplayModes(); /** * Create a display with the specified display mode. If the display is @@ -118,13 +132,7 @@ * @throws Exception if the display mode could not be set * @see #destroy() */ - public static void create( - DisplayMode displayMode, - int alpha, - int depth, - int stencil, - boolean fullscreen, - String title) + public static void create(DisplayMode displayMode, int alpha, int depth, int stencil, boolean fullscreen, String title) throws Exception { if (created) { @@ -280,4 +288,16 @@ public static boolean isCloseRequested() { return closeRequested; } + + /** + * Returns the operating system windowing platform. This will be one of the + * constants defined above. There is no "unknown" platform; a native library port + * has to provide a unique platform number for this mechanism to work. If the LWJGL + * is ported to, say, QNX, we will have a PLATFORM_QNX at the ready. + * + * @return the windowing system + */ + public static native int getPlatform(); + + } Index: Sys.java CVS Browser: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/java-game-lib/LWJGL/src/java/org/lwjgl/Sys.java =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/java/org/lwjgl/Sys.java,v retrieving revision 1.15 retrieving revision 1.16 diff -u -d -r1.15 -r1.16 --- Sys.java 21 Mar 2003 16:57:40 -0000 1.15 +++ Sys.java 21 Mar 2003 17:05:56 -0000 1.16 @@ -101,20 +101,7 @@ } } - /* - * Platforms. This will let you determine which platform you are running - * on, which is handy to know for some GL calls. - */ - /** Windows platform */ - public static final int PLATFORM_WGL = 0; - - /** GLX (Linux/Unix) platform */ - public static final int PLATFORM_GLX = 1; - - /** MacOSX platform */ - public static final int PLATFORM_AGL = 2; - /** * @return the name of the native library to load */ @@ -223,14 +210,4 @@ */ public static native void alert(String title, String message); - /** - * Returns the operating system windowing platform. This will be one of the - * constants defined above. There is no "unknown" platform; a native library port - * has to provide a unique platform number for this mechanism to work. If the LWJGL - * is ported to, say, QNX, we will have a PLATFORM_QNX at the ready. - * - * @return the windowing system - */ - public static native int getPlatform(); - } Index: Math.java CVS Browser: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/java-game-lib/LWJGL/src/java/org/lwjgl/Math.java =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/java/org/lwjgl/Math.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- Math.java 21 Dec 2002 12:37:18 -0000 1.10 +++ Math.java 21 Mar 2003 17:05:56 -0000 1.11 @@ -32,6 +32,10 @@ package org.lwjgl; +import java.nio.*; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; + /** * $Id$ * @@ -790,13 +794,36 @@ return (float) java.lang.Math.toDegrees(java.lang.Math.atan(theta)); } + /* We use NIO to do our bit fiddling */ + private static final ByteBuffer sqrtByteBuf = ByteBuffer.allocate(4).order(ByteOrder.nativeOrder()); + private static final IntBuffer sqrtIntBuf = sqrtByteBuf.asIntBuffer(); + private static final FloatBuffer sqrtFloatBuf = sqrtByteBuf.asFloatBuffer(); + /** - * Return the square root of a value - * @param n the number for which you want the square root - * @return sqrt(n) + * Approximate inverse square root function (Newton-Raphson?). This is a very approximate + * root, accurate to maybe 1 or 2 dp. + * @param x + * @return ~x^0.5 */ - public static float sqrt(float n) { - return (float) java.lang.Math.sqrt(n); + public static float invsqrt(float x) { + float xhalf = 0.5f * x; + sqrtFloatBuf.put(0, x); + int i = sqrtIntBuf.get(0); + i = 0x5f375a86 - (i >> 1); + sqrtIntBuf.put(0, i); + x = sqrtFloatBuf.get(0); + x *= (1.5f - xhalf * x * x); // This line may be duplicated for more accuracy. + return x; + } + + /** + * Approximate square root function (Newton-Raphson?). This is a very approximate + * root, accurate to maybe 1 or 2 dp. + * @param x + * @return ~x^0.5 + */ + public static float sqrt(float x) { + return 1.0f / invsqrt(x); } /* @@ -1100,5 +1127,6 @@ ); } + } |