Removed Math class
This commit is contained in:
parent
2bd35dbe1d
commit
4b8611c4f6
|
@ -1,157 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2002 Lighweight Java Game Library Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'Light Weight Java Game Library' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.lwjgl;
|
||||
|
||||
import java.nio.*;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
/**
|
||||
* $Id$
|
||||
*
|
||||
* A floating point math library, with vector processing capabilities.
|
||||
* This class differs significantly from its java.lang.Math counterpart
|
||||
* in that it a) makes no claims about strict accuracy and b) uses degrees
|
||||
* rather than radians for its functions which are more friendly to use.
|
||||
*
|
||||
* @author cix_foo <cix_foo@users.sourceforge.net>
|
||||
* @version $Revision$
|
||||
*/
|
||||
public final class Math {
|
||||
|
||||
static {
|
||||
System.loadLibrary(Sys.getLibraryName());
|
||||
}
|
||||
|
||||
/** Floating point version of pi */
|
||||
public static final float PI = (float) java.lang.Math.PI;
|
||||
|
||||
/**
|
||||
* No constructor for Math.
|
||||
*/
|
||||
private Math() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the sine of theta
|
||||
*
|
||||
* @param theta angle in degrees
|
||||
* @return sin(theta)
|
||||
*/
|
||||
public static float sin(float theta) {
|
||||
return (float) java.lang.Math.sin(java.lang.Math.toRadians(theta));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the cosine of theta
|
||||
*
|
||||
* @param theta angle in degrees
|
||||
* @return cos(theta)
|
||||
*/
|
||||
public static float cos(float theta) {
|
||||
return (float) java.lang.Math.cos(java.lang.Math.toRadians(theta));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the tangent of theta
|
||||
*
|
||||
* @param theta angle in degrees
|
||||
* @return tan(theta)
|
||||
*/
|
||||
public static float tan(float theta) {
|
||||
return (float) java.lang.Math.tan(java.lang.Math.toRadians(theta));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the inverse sine of theta
|
||||
*
|
||||
* @param theta angle in degrees
|
||||
* @return asin(theta)
|
||||
*/
|
||||
public static float asin(float theta) {
|
||||
return (float) java.lang.Math.toDegrees(java.lang.Math.asin(theta));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the inverse cosine of theta
|
||||
*
|
||||
* @param theta angle in degrees
|
||||
* @return acos(theta)
|
||||
*/
|
||||
public static float acos(float theta) {
|
||||
return (float) java.lang.Math.toDegrees(java.lang.Math.acos(theta));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the inverse tangent of theta
|
||||
*
|
||||
* @param theta angle in degrees
|
||||
* @return atan(theta)
|
||||
*/
|
||||
public static float atan(float theta) {
|
||||
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();
|
||||
|
||||
/**
|
||||
* 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 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);
|
||||
}
|
||||
}
|
|
@ -89,7 +89,7 @@ public abstract class BaseAL {
|
|||
libname =
|
||||
(System.getProperty("os.name").toLowerCase().indexOf("windows") == -1)
|
||||
? "libopenal.so"
|
||||
: "OpenAL32.dll";
|
||||
: "lwjglaudio.dll";
|
||||
|
||||
// try to get path from JWS (if possible)
|
||||
String jwsLibname =
|
||||
|
|
|
@ -143,7 +143,8 @@ public interface GLConstants
|
|||
WGLMultisample,
|
||||
WGLPBuffer,
|
||||
WGLPixelFormat,
|
||||
WGLRenderTexture
|
||||
WGLRenderTexture,
|
||||
CoreGL14Constants
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
@ -52,6 +52,7 @@ import java.util.StringTokenizer;
|
|||
* @version $Revision$
|
||||
*/
|
||||
public class GLWindow extends Window {
|
||||
|
||||
/** Has the GL been created yet? */
|
||||
private boolean created;
|
||||
|
||||
|
|
|
@ -31,8 +31,6 @@
|
|||
*/
|
||||
package org.lwjgl.vector;
|
||||
|
||||
import org.lwjgl.Math;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.nio.FloatBuffer;
|
||||
|
||||
|
@ -494,8 +492,8 @@ public class Matrix4f extends Matrix implements Serializable {
|
|||
* @return this
|
||||
*/
|
||||
public Matrix4f rotate(float angle, Vector3f axis) {
|
||||
float c = Math.cos(angle);
|
||||
float s = Math.sin(angle);
|
||||
float c = (float) Math.cos(angle);
|
||||
float s = (float) Math.sin(angle);
|
||||
float oneminusc = 1.0f - c;
|
||||
float xy = axis.x*axis.y;
|
||||
float yz = axis.y*axis.z;
|
||||
|
@ -551,8 +549,8 @@ public class Matrix4f extends Matrix implements Serializable {
|
|||
dest = new Matrix4f();
|
||||
else if (dest == this)
|
||||
return rotate(angle, axis);
|
||||
float c = Math.cos(angle);
|
||||
float s = Math.sin(angle);
|
||||
float c = (float) Math.cos(angle);
|
||||
float s = (float) Math.sin(angle);
|
||||
float oneminusc = 1.0f - c;
|
||||
float xy = axis.x*axis.y;
|
||||
float yz = axis.y*axis.z;
|
||||
|
|
|
@ -34,8 +34,6 @@ package org.lwjgl.vector;
|
|||
import java.io.Serializable;
|
||||
import java.nio.FloatBuffer;
|
||||
|
||||
import org.lwjgl.Math;
|
||||
|
||||
/**
|
||||
* $Id$
|
||||
*
|
||||
|
@ -57,7 +55,7 @@ public abstract class Vector implements Serializable {
|
|||
* @return the length of the vector
|
||||
*/
|
||||
public final float length() {
|
||||
return Math.sqrt(lengthSquared());
|
||||
return (float) Math.sqrt(lengthSquared());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -34,8 +34,6 @@ package org.lwjgl.vector;
|
|||
import java.io.Serializable;
|
||||
import java.nio.FloatBuffer;
|
||||
|
||||
import org.lwjgl.Math;
|
||||
|
||||
/**
|
||||
* $Id$
|
||||
*
|
||||
|
@ -150,15 +148,6 @@ public class Vector2f extends Vector implements Serializable {
|
|||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the magnitude of of the vector
|
||||
* @return the magnitude of the vector
|
||||
*/
|
||||
public float magnitude()
|
||||
{
|
||||
return Math.sqrt( (x * x) + (y * y) );
|
||||
}
|
||||
|
||||
/**
|
||||
* The dot product of two vectors is calculated as
|
||||
* v1.x * v2.x + v1.y * v2.y + v1.z * v2.z
|
||||
|
@ -184,7 +173,7 @@ public class Vector2f extends Vector implements Serializable {
|
|||
dls = -1f;
|
||||
else if (dls > 1.0f)
|
||||
dls = 1.0f;
|
||||
return Math.acos(dls);
|
||||
return (float) Math.toDegrees(Math.acos(dls));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -34,8 +34,6 @@ package org.lwjgl.vector;
|
|||
import java.io.Serializable;
|
||||
import java.nio.FloatBuffer;
|
||||
|
||||
import org.lwjgl.Math;
|
||||
|
||||
/**
|
||||
* $Id$
|
||||
*
|
||||
|
@ -238,7 +236,7 @@ public class Vector3f extends Vector implements Serializable {
|
|||
dls = -1f;
|
||||
else if (dls > 1.0f)
|
||||
dls = 1.0f;
|
||||
return Math.acos(dls);
|
||||
return (float) Math.toDegrees(Math.acos(dls));
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
|
|
@ -34,8 +34,6 @@ package org.lwjgl.vector;
|
|||
import java.io.Serializable;
|
||||
import java.nio.FloatBuffer;
|
||||
|
||||
import org.lwjgl.Math;
|
||||
|
||||
/**
|
||||
* $Id$
|
||||
*
|
||||
|
@ -193,15 +191,6 @@ public class Vector4f extends Vector implements Serializable {
|
|||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the magnitude of of the vector
|
||||
* @return the magnitude of the vector
|
||||
*/
|
||||
public float magnitude()
|
||||
{
|
||||
return Math.sqrt( (x * x) + (y * y) + (z * z) + (w * w) );
|
||||
}
|
||||
|
||||
/**
|
||||
* The dot product of two vectors is calculated as
|
||||
* v1.x * v2.x + v1.y * v2.y + v1.z * v2.z + v1.w * v2.w
|
||||
|
@ -225,7 +214,7 @@ public class Vector4f extends Vector implements Serializable {
|
|||
dls = -1f;
|
||||
else if (dls > 1.0f)
|
||||
dls = 1.0f;
|
||||
return Math.acos(dls);
|
||||
return (float) Math.toDegrees(Math.acos(dls));
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
|
Loading…
Reference in New Issue