aboutsummaryrefslogtreecommitdiffstats
path: root/src/jake2/util
diff options
context:
space:
mode:
authorHolger Zickner <[email protected]>2004-07-08 15:58:48 +0000
committerHolger Zickner <[email protected]>2004-07-08 15:58:48 +0000
commit4f13ea26c4f47e54e66926f0700cf631e7bb3352 (patch)
treea9d434fc462417bb981b1565fd64cea5e7c82c15 /src/jake2/util
parent76839da3568e20f51220584d1fc92841b216505a (diff)
import of Jake2 version hannover
Diffstat (limited to 'src/jake2/util')
-rw-r--r--src/jake2/util/Lib.java38
-rw-r--r--src/jake2/util/Math3D.java67
2 files changed, 53 insertions, 52 deletions
diff --git a/src/jake2/util/Lib.java b/src/jake2/util/Lib.java
index 8ec58e1..bab5ff0 100644
--- a/src/jake2/util/Lib.java
+++ b/src/jake2/util/Lib.java
@@ -19,25 +19,18 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
// Created on 09.12.2003 by RST.
-// $Id: Lib.java,v 1.1 2004-07-07 19:59:52 hzi Exp $
+// $Id: Lib.java,v 1.2 2004-07-08 15:58:48 hzi Exp $
package jake2.util;
-import java.io.File;
-import java.io.IOException;
-import java.io.RandomAccessFile;
+import jake2.Globals;
+import jake2.qcommon.Com;
+import jake2.qcommon.FS;
+
+import java.io.*;
import java.nio.ByteBuffer;
-import java.text.BreakIterator;
import java.util.Arrays;
import java.util.StringTokenizer;
-import java.util.Vector;
-
-import jake2.*;
-import jake2.client.*;
-import jake2.game.*;
-import jake2.qcommon.*;
-import jake2.render.*;
-import jake2.server.*;
public class Lib {
@@ -86,19 +79,21 @@ public class Lib {
return Com.sprintf("%8.2f %8.2f %8.2f", new Vargs().add(v[0]).add(v[1]).add(v[2]));
}
public static short rand() {
- return (short) (Math.random() * 0x8000);
+ //return (short) (Math.random() * 0x8000);
+ return (short)Globals.rnd.nextInt(Short.MAX_VALUE+1);
}
public static float crandom() {
- return (float) (Math.random() - 0.5) * 2.0f;
+ return (Globals.rnd.nextFloat() - 0.5f) * 2.0f;
+ //return (float) (Math.random() - 0.5) * 2.0f;
}
public static float random() {
- return (float) Math.random();
+ return Globals.rnd.nextFloat();
}
public static float crand() {
- return (float) (Math.random() - 0.5) * 2.0f;
+ return (Globals.rnd.nextFloat() - 0.5f) * 2.0f;
}
public static float frand() {
- return (float) Math.random();
+ return Globals.rnd.nextFloat();
}
public static int strcmp(String in1, String in2) {
@@ -172,9 +167,9 @@ public class Lib {
return res;
}
- public static int strlen(String in) {
- return in.length();
- }
+// public static int strlen(String in) {
+// return in.length();
+// }
public static int strlen(char in[]) {
for (int i = 0; i < in.length; i++)
@@ -427,7 +422,6 @@ public class Lib {
catch (Exception e) {
return 1;
}
- return 0;
}
public static byte[] getIntBytes(int c) {
diff --git a/src/jake2/util/Math3D.java b/src/jake2/util/Math3D.java
index 117487c..6c607b3 100644
--- a/src/jake2/util/Math3D.java
+++ b/src/jake2/util/Math3D.java
@@ -19,7 +19,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
// Created on 09.12.2003 by RST.
-// $Id: Math3D.java,v 1.1 2004-07-07 19:59:53 hzi Exp $
+// $Id: Math3D.java,v 1.2 2004-07-08 15:58:48 hzi Exp $
package jake2.util;
@@ -29,10 +29,12 @@ import jake2.qcommon.Com;
public class Math3D extends Lib {
- public static void set(float v1[], float v2[])
- {
- for (int i=0; i < v1.length; i++)
- v1[i]=v2[i];
+ static final float shortratio = 360.0f / 65536.0f;
+ static final float piratio = (float)(Math.PI / 360.0);
+
+ public static void set(float v1[], float v2[]) {
+ for (int i = 0; i < v1.length; i++)
+ v1[i] = v2[i];
}
@@ -114,18 +116,18 @@ public class Math3D extends Lib {
}
return length;
}
- public static final float VectorNormalize2(float[] v, float[] to) {
- float length, ilength;
-
- length = VectorLength(v);
- if (length != 0.0f) {
- ilength = 1.0f / length;
- to[0] = v[0] * length;
- to[1] = v[1] * length;
- to[2] = v[2] * length;
- }
- return length;
- }
+// public static final float VectorNormalize2(float[] v, float[] to) {
+// float length, ilength;
+//
+// length = VectorLength(v);
+// if (length != 0.0f) {
+// ilength = 1.0f / length;
+// to[0] = v[0] * ilength;
+// to[1] = v[1] * ilength;
+// to[2] = v[2] * ilength;
+// }
+// return length;
+// }
public static final float VectorLength(float v[]) {
return (float) Math.sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
}
@@ -265,7 +267,7 @@ public class Math3D extends Lib {
public static float SHORT2ANGLE(int x) {
- return ((x) * (360.0f / 65536));
+ return (x * shortratio);
}
/*
@@ -450,13 +452,13 @@ public class Math3D extends Lib {
float angle;
float sr, sp, sy, cr, cp, cy;
- angle = (float) (angles[Defines.YAW] * (Math.PI * 2 / 360));
+ angle = (float) (angles[Defines.YAW] * (2.0f * piratio));
sy = (float) Math.sin(angle);
cy = (float) Math.cos(angle);
- angle = (float) (angles[Defines.PITCH] * (Math.PI * 2 / 360));
+ angle = (float) (angles[Defines.PITCH] * (2.0f * piratio));
sp = (float) Math.sin(angle);
cp = (float) Math.cos(angle);
- angle = (float) (angles[Defines.ROLL] * (Math.PI * 2 / 360));
+ angle = (float) (angles[Defines.ROLL] * (2.0f * piratio));
sr = (float) Math.sin(angle);
cr = (float) Math.cos(angle);
@@ -481,11 +483,16 @@ public class Math3D extends Lib {
m[0][0] = m[0][1] = m[0][2] = m[1][0] = m[1][1] = m[1][2] = m[2][0] = m[2][1] = m[2][2] = 0.0f;
}
- public static final void MatCopy(float src[][], float dst[][]) {
- for (int i = 0; i < 3; i++)
- {
- VectorCopy(src[i], dst[i]);
- }
+ private static final void MatCopy(float src[][], float dst[][]) {
+ dst[0][0]=src[0][0];
+ dst[0][1]=src[0][1];
+ dst[0][2]=src[0][2];
+ dst[1][0]=src[1][0];
+ dst[1][1]=src[1][1];
+ dst[1][2]=src[1][2];
+ dst[2][0]=src[2][0];
+ dst[2][1]=src[2][1];
+ dst[2][2]=src[2][2];
}
public static void G_ProjectSource(float[] point, float[] distance, float[] forward, float[] right, float[] result) {
@@ -526,13 +533,13 @@ public class Math3D extends Lib {
public static float anglemod(float a) {
- return (float) (360.0f / 65536) * ((int) (a * (65536 / 360.0f)) & 65535);
+ return (float) (shortratio) * ((int) (a / (shortratio)) & 65535);
}
public static int ANGLE2SHORT(float x) {
- return ((int) ((x) * 65536f / 360f) & 65535);
+ return ((int) ((x) / shortratio) & 65535);
}
@@ -553,11 +560,11 @@ public class Math3D extends Lib {
if (fov_x < 1.0f || fov_x > 179.0f)
Com.Error(Defines.ERR_DROP, "Bad fov: " + fov_x);
- x = width / Math.tan(fov_x / 360.0 * Math.PI);
+ x = width / Math.tan(fov_x * piratio);
a = Math.atan(height / x);
- a = a * 360 / Math.PI;
+ a = a / piratio;
return (float)a;
}