split client and server 1

This commit is contained in:
Sen 2025-05-04 20:27:55 +02:00
parent 26a15a0b15
commit 2fa521c3d1
661 changed files with 3058 additions and 2826 deletions

View file

@ -1,7 +0,0 @@
package game.util;
import java.io.File;
public interface FileCallback {
void selected(File file);
}

View file

@ -1,7 +0,0 @@
package game.util;
import game.gui.element.Element;
public interface Formatter<T extends Element> {
String use(T elem);
}

View file

@ -0,0 +1,6 @@
package game.util;
public interface Identifyable
{
String getName();
}

View file

@ -0,0 +1,849 @@
/*
* Copyright (c) 2002-2008 LWJGL 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 'LWJGL' 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 game.util;
import java.io.Serializable;
import java.nio.FloatBuffer;
/**
* Holds a 4x4 float matrix.
*
* @author foo
*/
public class Matrix4f implements Serializable {
private static final long serialVersionUID = 1L;
public float m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33;
/**
* Construct a new matrix, initialized to the identity.
*/
public Matrix4f() {
super();
setIdentity();
}
public Matrix4f(final Matrix4f src) {
super();
load(src);
}
/**
* Returns a string representation of this matrix
*/
public String toString() {
StringBuilder buf = new StringBuilder();
buf.append(m00).append(' ').append(m10).append(' ').append(m20).append(' ').append(m30).append('\n');
buf.append(m01).append(' ').append(m11).append(' ').append(m21).append(' ').append(m31).append('\n');
buf.append(m02).append(' ').append(m12).append(' ').append(m22).append(' ').append(m32).append('\n');
buf.append(m03).append(' ').append(m13).append(' ').append(m23).append(' ').append(m33).append('\n');
return buf.toString();
}
/**
* Set this matrix to be the identity matrix.
* @return this
*/
public Matrix4f setIdentity() {
return setIdentity(this);
}
/**
* Set the given matrix to be the identity matrix.
* @param m The matrix to set to the identity
* @return m
*/
public static Matrix4f setIdentity(Matrix4f m) {
m.m00 = 1.0f;
m.m01 = 0.0f;
m.m02 = 0.0f;
m.m03 = 0.0f;
m.m10 = 0.0f;
m.m11 = 1.0f;
m.m12 = 0.0f;
m.m13 = 0.0f;
m.m20 = 0.0f;
m.m21 = 0.0f;
m.m22 = 1.0f;
m.m23 = 0.0f;
m.m30 = 0.0f;
m.m31 = 0.0f;
m.m32 = 0.0f;
m.m33 = 1.0f;
return m;
}
/**
* Set this matrix to 0.
* @return this
*/
public Matrix4f setZero() {
return setZero(this);
}
/**
* Set the given matrix to 0.
* @param m The matrix to set to 0
* @return m
*/
public static Matrix4f setZero(Matrix4f m) {
m.m00 = 0.0f;
m.m01 = 0.0f;
m.m02 = 0.0f;
m.m03 = 0.0f;
m.m10 = 0.0f;
m.m11 = 0.0f;
m.m12 = 0.0f;
m.m13 = 0.0f;
m.m20 = 0.0f;
m.m21 = 0.0f;
m.m22 = 0.0f;
m.m23 = 0.0f;
m.m30 = 0.0f;
m.m31 = 0.0f;
m.m32 = 0.0f;
m.m33 = 0.0f;
return m;
}
/**
* Load from another matrix4f
* @param src The source matrix
* @return this
*/
public Matrix4f load(Matrix4f src) {
return load(src, this);
}
/**
* Copy the source matrix to the destination matrix
* @param src The source matrix
* @param dest The destination matrix, or null of a new one is to be created
* @return The copied matrix
*/
public static Matrix4f load(Matrix4f src, Matrix4f dest) {
if (dest == null)
dest = new Matrix4f();
dest.m00 = src.m00;
dest.m01 = src.m01;
dest.m02 = src.m02;
dest.m03 = src.m03;
dest.m10 = src.m10;
dest.m11 = src.m11;
dest.m12 = src.m12;
dest.m13 = src.m13;
dest.m20 = src.m20;
dest.m21 = src.m21;
dest.m22 = src.m22;
dest.m23 = src.m23;
dest.m30 = src.m30;
dest.m31 = src.m31;
dest.m32 = src.m32;
dest.m33 = src.m33;
return dest;
}
/**
* Load from a float buffer. The buffer stores the matrix in column major
* (OpenGL) order.
*
* @param buf A float buffer to read from
* @return this
*/
public Matrix4f load(FloatBuffer buf) {
m00 = buf.get();
m01 = buf.get();
m02 = buf.get();
m03 = buf.get();
m10 = buf.get();
m11 = buf.get();
m12 = buf.get();
m13 = buf.get();
m20 = buf.get();
m21 = buf.get();
m22 = buf.get();
m23 = buf.get();
m30 = buf.get();
m31 = buf.get();
m32 = buf.get();
m33 = buf.get();
return this;
}
/**
* Load from a float buffer. The buffer stores the matrix in row major
* (maths) order.
*
* @param buf A float buffer to read from
* @return this
*/
public Matrix4f loadTranspose(FloatBuffer buf) {
m00 = buf.get();
m10 = buf.get();
m20 = buf.get();
m30 = buf.get();
m01 = buf.get();
m11 = buf.get();
m21 = buf.get();
m31 = buf.get();
m02 = buf.get();
m12 = buf.get();
m22 = buf.get();
m32 = buf.get();
m03 = buf.get();
m13 = buf.get();
m23 = buf.get();
m33 = buf.get();
return this;
}
/**
* Store this matrix in a float buffer. The matrix is stored in column
* major (openGL) order.
* @param buf The buffer to store this matrix in
*/
public Matrix4f store(FloatBuffer buf) {
buf.put(m00);
buf.put(m01);
buf.put(m02);
buf.put(m03);
buf.put(m10);
buf.put(m11);
buf.put(m12);
buf.put(m13);
buf.put(m20);
buf.put(m21);
buf.put(m22);
buf.put(m23);
buf.put(m30);
buf.put(m31);
buf.put(m32);
buf.put(m33);
return this;
}
/**
* Store this matrix in a float buffer. The matrix is stored in row
* major (maths) order.
* @param buf The buffer to store this matrix in
*/
public Matrix4f storeTranspose(FloatBuffer buf) {
buf.put(m00);
buf.put(m10);
buf.put(m20);
buf.put(m30);
buf.put(m01);
buf.put(m11);
buf.put(m21);
buf.put(m31);
buf.put(m02);
buf.put(m12);
buf.put(m22);
buf.put(m32);
buf.put(m03);
buf.put(m13);
buf.put(m23);
buf.put(m33);
return this;
}
/**
* Store the rotation portion of this matrix in a float buffer. The matrix is stored in column
* major (openGL) order.
* @param buf The buffer to store this matrix in
*/
public Matrix4f store3f(FloatBuffer buf) {
buf.put(m00);
buf.put(m01);
buf.put(m02);
buf.put(m10);
buf.put(m11);
buf.put(m12);
buf.put(m20);
buf.put(m21);
buf.put(m22);
return this;
}
/**
* Add two matrices together and place the result in a third matrix.
* @param left The left source matrix
* @param right The right source matrix
* @param dest The destination matrix, or null if a new one is to be created
* @return the destination matrix
*/
public static Matrix4f add(Matrix4f left, Matrix4f right, Matrix4f dest) {
if (dest == null)
dest = new Matrix4f();
dest.m00 = left.m00 + right.m00;
dest.m01 = left.m01 + right.m01;
dest.m02 = left.m02 + right.m02;
dest.m03 = left.m03 + right.m03;
dest.m10 = left.m10 + right.m10;
dest.m11 = left.m11 + right.m11;
dest.m12 = left.m12 + right.m12;
dest.m13 = left.m13 + right.m13;
dest.m20 = left.m20 + right.m20;
dest.m21 = left.m21 + right.m21;
dest.m22 = left.m22 + right.m22;
dest.m23 = left.m23 + right.m23;
dest.m30 = left.m30 + right.m30;
dest.m31 = left.m31 + right.m31;
dest.m32 = left.m32 + right.m32;
dest.m33 = left.m33 + right.m33;
return dest;
}
/**
* Subtract the right matrix from the left and place the result in a third matrix.
* @param left The left source matrix
* @param right The right source matrix
* @param dest The destination matrix, or null if a new one is to be created
* @return the destination matrix
*/
public static Matrix4f sub(Matrix4f left, Matrix4f right, Matrix4f dest) {
if (dest == null)
dest = new Matrix4f();
dest.m00 = left.m00 - right.m00;
dest.m01 = left.m01 - right.m01;
dest.m02 = left.m02 - right.m02;
dest.m03 = left.m03 - right.m03;
dest.m10 = left.m10 - right.m10;
dest.m11 = left.m11 - right.m11;
dest.m12 = left.m12 - right.m12;
dest.m13 = left.m13 - right.m13;
dest.m20 = left.m20 - right.m20;
dest.m21 = left.m21 - right.m21;
dest.m22 = left.m22 - right.m22;
dest.m23 = left.m23 - right.m23;
dest.m30 = left.m30 - right.m30;
dest.m31 = left.m31 - right.m31;
dest.m32 = left.m32 - right.m32;
dest.m33 = left.m33 - right.m33;
return dest;
}
/**
* Multiply the right matrix by the left and place the result in a third matrix.
* @param left The left source matrix
* @param right The right source matrix
* @param dest The destination matrix, or null if a new one is to be created
* @return the destination matrix
*/
public static Matrix4f mul(Matrix4f left, Matrix4f right, Matrix4f dest) {
if (dest == null)
dest = new Matrix4f();
float m00 = left.m00 * right.m00 + left.m10 * right.m01 + left.m20 * right.m02 + left.m30 * right.m03;
float m01 = left.m01 * right.m00 + left.m11 * right.m01 + left.m21 * right.m02 + left.m31 * right.m03;
float m02 = left.m02 * right.m00 + left.m12 * right.m01 + left.m22 * right.m02 + left.m32 * right.m03;
float m03 = left.m03 * right.m00 + left.m13 * right.m01 + left.m23 * right.m02 + left.m33 * right.m03;
float m10 = left.m00 * right.m10 + left.m10 * right.m11 + left.m20 * right.m12 + left.m30 * right.m13;
float m11 = left.m01 * right.m10 + left.m11 * right.m11 + left.m21 * right.m12 + left.m31 * right.m13;
float m12 = left.m02 * right.m10 + left.m12 * right.m11 + left.m22 * right.m12 + left.m32 * right.m13;
float m13 = left.m03 * right.m10 + left.m13 * right.m11 + left.m23 * right.m12 + left.m33 * right.m13;
float m20 = left.m00 * right.m20 + left.m10 * right.m21 + left.m20 * right.m22 + left.m30 * right.m23;
float m21 = left.m01 * right.m20 + left.m11 * right.m21 + left.m21 * right.m22 + left.m31 * right.m23;
float m22 = left.m02 * right.m20 + left.m12 * right.m21 + left.m22 * right.m22 + left.m32 * right.m23;
float m23 = left.m03 * right.m20 + left.m13 * right.m21 + left.m23 * right.m22 + left.m33 * right.m23;
float m30 = left.m00 * right.m30 + left.m10 * right.m31 + left.m20 * right.m32 + left.m30 * right.m33;
float m31 = left.m01 * right.m30 + left.m11 * right.m31 + left.m21 * right.m32 + left.m31 * right.m33;
float m32 = left.m02 * right.m30 + left.m12 * right.m31 + left.m22 * right.m32 + left.m32 * right.m33;
float m33 = left.m03 * right.m30 + left.m13 * right.m31 + left.m23 * right.m32 + left.m33 * right.m33;
dest.m00 = m00;
dest.m01 = m01;
dest.m02 = m02;
dest.m03 = m03;
dest.m10 = m10;
dest.m11 = m11;
dest.m12 = m12;
dest.m13 = m13;
dest.m20 = m20;
dest.m21 = m21;
dest.m22 = m22;
dest.m23 = m23;
dest.m30 = m30;
dest.m31 = m31;
dest.m32 = m32;
dest.m33 = m33;
return dest;
}
/**
* Transform a Vector by a matrix and return the result in a destination
* vector.
* @param left The left matrix
* @param right The right vector
* @param dest The destination vector, or null if a new one is to be created
* @return the destination vector
*/
public static Vector4f transform(Matrix4f left, Vector4f right, Vector4f dest) {
if (dest == null)
dest = new Vector4f();
float x = left.m00 * right.x + left.m10 * right.y + left.m20 * right.z + left.m30 * right.w;
float y = left.m01 * right.x + left.m11 * right.y + left.m21 * right.z + left.m31 * right.w;
float z = left.m02 * right.x + left.m12 * right.y + left.m22 * right.z + left.m32 * right.w;
float w = left.m03 * right.x + left.m13 * right.y + left.m23 * right.z + left.m33 * right.w;
dest.x = x;
dest.y = y;
dest.z = z;
dest.w = w;
return dest;
}
/**
* Transpose this matrix
* @return this
*/
public Matrix4f transpose() {
return transpose(this);
}
/**
* Translate this matrix
* @param vec The vector to translate by
* @return this
*/
// public Matrix4f translate(Vector2f vec) {
// return translate(vec, this);
// }
/**
* Translate this matrix
* @param vec The vector to translate by
* @return this
*/
public Matrix4f translate(Vector3f vec) {
return translate(vec, this);
}
/**
* Scales this matrix
* @param vec The vector to scale by
* @return this
*/
public Matrix4f scale(Vector3f vec) {
return scale(vec, this, this);
}
/**
* Scales the source matrix and put the result in the destination matrix
* @param vec The vector to scale by
* @param src The source matrix
* @param dest The destination matrix, or null if a new matrix is to be created
* @return The scaled matrix
*/
public static Matrix4f scale(Vector3f vec, Matrix4f src, Matrix4f dest) {
if (dest == null)
dest = new Matrix4f();
dest.m00 = src.m00 * vec.x;
dest.m01 = src.m01 * vec.x;
dest.m02 = src.m02 * vec.x;
dest.m03 = src.m03 * vec.x;
dest.m10 = src.m10 * vec.y;
dest.m11 = src.m11 * vec.y;
dest.m12 = src.m12 * vec.y;
dest.m13 = src.m13 * vec.y;
dest.m20 = src.m20 * vec.z;
dest.m21 = src.m21 * vec.z;
dest.m22 = src.m22 * vec.z;
dest.m23 = src.m23 * vec.z;
return dest;
}
/**
* Rotates the matrix around the given axis the specified angle
* @param angle the angle, in radians.
* @param axis The vector representing the rotation axis. Must be normalized.
* @return this
*/
public Matrix4f rotate(float angle, Vector3f axis) {
return rotate(angle, axis, this);
}
/**
* Rotates the matrix around the given axis the specified angle
* @param angle the angle, in radians.
* @param axis The vector representing the rotation axis. Must be normalized.
* @param dest The matrix to put the result, or null if a new matrix is to be created
* @return The rotated matrix
*/
public Matrix4f rotate(float angle, Vector3f axis, Matrix4f dest) {
return rotate(angle, axis, this, dest);
}
/**
* Rotates the source matrix around the given axis the specified angle and
* put the result in the destination matrix.
* @param angle the angle, in radians.
* @param axis The vector representing the rotation axis. Must be normalized.
* @param src The matrix to rotate
* @param dest The matrix to put the result, or null if a new matrix is to be created
* @return The rotated matrix
*/
public static Matrix4f rotate(float angle, Vector3f axis, Matrix4f src, Matrix4f dest) {
if (dest == null)
dest = new Matrix4f();
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;
float xz = axis.x*axis.z;
float xs = axis.x*s;
float ys = axis.y*s;
float zs = axis.z*s;
float f00 = axis.x*axis.x*oneminusc+c;
float f01 = xy*oneminusc+zs;
float f02 = xz*oneminusc-ys;
// n[3] not used
float f10 = xy*oneminusc-zs;
float f11 = axis.y*axis.y*oneminusc+c;
float f12 = yz*oneminusc+xs;
// n[7] not used
float f20 = xz*oneminusc+ys;
float f21 = yz*oneminusc-xs;
float f22 = axis.z*axis.z*oneminusc+c;
float t00 = src.m00 * f00 + src.m10 * f01 + src.m20 * f02;
float t01 = src.m01 * f00 + src.m11 * f01 + src.m21 * f02;
float t02 = src.m02 * f00 + src.m12 * f01 + src.m22 * f02;
float t03 = src.m03 * f00 + src.m13 * f01 + src.m23 * f02;
float t10 = src.m00 * f10 + src.m10 * f11 + src.m20 * f12;
float t11 = src.m01 * f10 + src.m11 * f11 + src.m21 * f12;
float t12 = src.m02 * f10 + src.m12 * f11 + src.m22 * f12;
float t13 = src.m03 * f10 + src.m13 * f11 + src.m23 * f12;
dest.m20 = src.m00 * f20 + src.m10 * f21 + src.m20 * f22;
dest.m21 = src.m01 * f20 + src.m11 * f21 + src.m21 * f22;
dest.m22 = src.m02 * f20 + src.m12 * f21 + src.m22 * f22;
dest.m23 = src.m03 * f20 + src.m13 * f21 + src.m23 * f22;
dest.m00 = t00;
dest.m01 = t01;
dest.m02 = t02;
dest.m03 = t03;
dest.m10 = t10;
dest.m11 = t11;
dest.m12 = t12;
dest.m13 = t13;
return dest;
}
/**
* Translate this matrix and stash the result in another matrix
* @param vec The vector to translate by
* @param dest The destination matrix or null if a new matrix is to be created
* @return the translated matrix
*/
public Matrix4f translate(Vector3f vec, Matrix4f dest) {
return translate(vec, this, dest);
}
/**
* Translate the source matrix and stash the result in the destination matrix
* @param vec The vector to translate by
* @param src The source matrix
* @param dest The destination matrix or null if a new matrix is to be created
* @return The translated matrix
*/
public static Matrix4f translate(Vector3f vec, Matrix4f src, Matrix4f dest) {
if (dest == null)
dest = new Matrix4f();
dest.m30 += src.m00 * vec.x + src.m10 * vec.y + src.m20 * vec.z;
dest.m31 += src.m01 * vec.x + src.m11 * vec.y + src.m21 * vec.z;
dest.m32 += src.m02 * vec.x + src.m12 * vec.y + src.m22 * vec.z;
dest.m33 += src.m03 * vec.x + src.m13 * vec.y + src.m23 * vec.z;
return dest;
}
/**
* Translate this matrix and stash the result in another matrix
* @param vec The vector to translate by
* @param dest The destination matrix or null if a new matrix is to be created
* @return the translated matrix
*/
// public Matrix4f translate(Vector2f vec, Matrix4f dest) {
// return translate(vec, this, dest);
// }
/**
* Translate the source matrix and stash the result in the destination matrix
* @param vec The vector to translate by
* @param src The source matrix
* @param dest The destination matrix or null if a new matrix is to be created
* @return The translated matrix
*/
// public static Matrix4f translate(Vector2f vec, Matrix4f src, Matrix4f dest) {
// if (dest == null)
// dest = new Matrix4f();
//
// dest.m30 += src.m00 * vec.x + src.m10 * vec.y;
// dest.m31 += src.m01 * vec.x + src.m11 * vec.y;
// dest.m32 += src.m02 * vec.x + src.m12 * vec.y;
// dest.m33 += src.m03 * vec.x + src.m13 * vec.y;
//
// return dest;
// }
/**
* Transpose this matrix and place the result in another matrix
* @param dest The destination matrix or null if a new matrix is to be created
* @return the transposed matrix
*/
public Matrix4f transpose(Matrix4f dest) {
return transpose(this, dest);
}
/**
* Transpose the source matrix and place the result in the destination matrix
* @param src The source matrix
* @param dest The destination matrix or null if a new matrix is to be created
* @return the transposed matrix
*/
public static Matrix4f transpose(Matrix4f src, Matrix4f dest) {
if (dest == null)
dest = new Matrix4f();
float m00 = src.m00;
float m01 = src.m10;
float m02 = src.m20;
float m03 = src.m30;
float m10 = src.m01;
float m11 = src.m11;
float m12 = src.m21;
float m13 = src.m31;
float m20 = src.m02;
float m21 = src.m12;
float m22 = src.m22;
float m23 = src.m32;
float m30 = src.m03;
float m31 = src.m13;
float m32 = src.m23;
float m33 = src.m33;
dest.m00 = m00;
dest.m01 = m01;
dest.m02 = m02;
dest.m03 = m03;
dest.m10 = m10;
dest.m11 = m11;
dest.m12 = m12;
dest.m13 = m13;
dest.m20 = m20;
dest.m21 = m21;
dest.m22 = m22;
dest.m23 = m23;
dest.m30 = m30;
dest.m31 = m31;
dest.m32 = m32;
dest.m33 = m33;
return dest;
}
/**
* @return the determinant of the matrix
*/
public float determinant() {
float f =
m00
* ((m11 * m22 * m33 + m12 * m23 * m31 + m13 * m21 * m32)
- m13 * m22 * m31
- m11 * m23 * m32
- m12 * m21 * m33);
f -= m01
* ((m10 * m22 * m33 + m12 * m23 * m30 + m13 * m20 * m32)
- m13 * m22 * m30
- m10 * m23 * m32
- m12 * m20 * m33);
f += m02
* ((m10 * m21 * m33 + m11 * m23 * m30 + m13 * m20 * m31)
- m13 * m21 * m30
- m10 * m23 * m31
- m11 * m20 * m33);
f -= m03
* ((m10 * m21 * m32 + m11 * m22 * m30 + m12 * m20 * m31)
- m12 * m21 * m30
- m10 * m22 * m31
- m11 * m20 * m32);
return f;
}
/**
* Calculate the determinant of a 3x3 matrix
* @return result
*/
private static float determinant3x3(float t00, float t01, float t02,
float t10, float t11, float t12,
float t20, float t21, float t22)
{
return t00 * (t11 * t22 - t12 * t21)
+ t01 * (t12 * t20 - t10 * t22)
+ t02 * (t10 * t21 - t11 * t20);
}
/**
* Invert this matrix
* @return this if successful, null otherwise
*/
public Matrix4f invert() {
return invert(this, this);
}
/**
* Invert the source matrix and put the result in the destination
* @param src The source matrix
* @param dest The destination matrix, or null if a new matrix is to be created
* @return The inverted matrix if successful, null otherwise
*/
public static Matrix4f invert(Matrix4f src, Matrix4f dest) {
float determinant = src.determinant();
if (determinant != 0) {
/*
* m00 m01 m02 m03
* m10 m11 m12 m13
* m20 m21 m22 m23
* m30 m31 m32 m33
*/
if (dest == null)
dest = new Matrix4f();
float determinant_inv = 1f/determinant;
// first row
float t00 = determinant3x3(src.m11, src.m12, src.m13, src.m21, src.m22, src.m23, src.m31, src.m32, src.m33);
float t01 = -determinant3x3(src.m10, src.m12, src.m13, src.m20, src.m22, src.m23, src.m30, src.m32, src.m33);
float t02 = determinant3x3(src.m10, src.m11, src.m13, src.m20, src.m21, src.m23, src.m30, src.m31, src.m33);
float t03 = -determinant3x3(src.m10, src.m11, src.m12, src.m20, src.m21, src.m22, src.m30, src.m31, src.m32);
// second row
float t10 = -determinant3x3(src.m01, src.m02, src.m03, src.m21, src.m22, src.m23, src.m31, src.m32, src.m33);
float t11 = determinant3x3(src.m00, src.m02, src.m03, src.m20, src.m22, src.m23, src.m30, src.m32, src.m33);
float t12 = -determinant3x3(src.m00, src.m01, src.m03, src.m20, src.m21, src.m23, src.m30, src.m31, src.m33);
float t13 = determinant3x3(src.m00, src.m01, src.m02, src.m20, src.m21, src.m22, src.m30, src.m31, src.m32);
// third row
float t20 = determinant3x3(src.m01, src.m02, src.m03, src.m11, src.m12, src.m13, src.m31, src.m32, src.m33);
float t21 = -determinant3x3(src.m00, src.m02, src.m03, src.m10, src.m12, src.m13, src.m30, src.m32, src.m33);
float t22 = determinant3x3(src.m00, src.m01, src.m03, src.m10, src.m11, src.m13, src.m30, src.m31, src.m33);
float t23 = -determinant3x3(src.m00, src.m01, src.m02, src.m10, src.m11, src.m12, src.m30, src.m31, src.m32);
// fourth row
float t30 = -determinant3x3(src.m01, src.m02, src.m03, src.m11, src.m12, src.m13, src.m21, src.m22, src.m23);
float t31 = determinant3x3(src.m00, src.m02, src.m03, src.m10, src.m12, src.m13, src.m20, src.m22, src.m23);
float t32 = -determinant3x3(src.m00, src.m01, src.m03, src.m10, src.m11, src.m13, src.m20, src.m21, src.m23);
float t33 = determinant3x3(src.m00, src.m01, src.m02, src.m10, src.m11, src.m12, src.m20, src.m21, src.m22);
// transpose and divide by the determinant
dest.m00 = t00*determinant_inv;
dest.m11 = t11*determinant_inv;
dest.m22 = t22*determinant_inv;
dest.m33 = t33*determinant_inv;
dest.m01 = t10*determinant_inv;
dest.m10 = t01*determinant_inv;
dest.m20 = t02*determinant_inv;
dest.m02 = t20*determinant_inv;
dest.m12 = t21*determinant_inv;
dest.m21 = t12*determinant_inv;
dest.m03 = t30*determinant_inv;
dest.m30 = t03*determinant_inv;
dest.m13 = t31*determinant_inv;
dest.m31 = t13*determinant_inv;
dest.m32 = t23*determinant_inv;
dest.m23 = t32*determinant_inv;
return dest;
} else
return null;
}
/**
* Negate this matrix
* @return this
*/
public Matrix4f negate() {
return negate(this);
}
/**
* Negate this matrix and place the result in a destination matrix.
* @param dest The destination matrix, or null if a new matrix is to be created
* @return the negated matrix
*/
public Matrix4f negate(Matrix4f dest) {
return negate(this, dest);
}
/**
* Negate this matrix and place the result in a destination matrix.
* @param src The source matrix
* @param dest The destination matrix, or null if a new matrix is to be created
* @return The negated matrix
*/
public static Matrix4f negate(Matrix4f src, Matrix4f dest) {
if (dest == null)
dest = new Matrix4f();
dest.m00 = -src.m00;
dest.m01 = -src.m01;
dest.m02 = -src.m02;
dest.m03 = -src.m03;
dest.m10 = -src.m10;
dest.m11 = -src.m11;
dest.m12 = -src.m12;
dest.m13 = -src.m13;
dest.m20 = -src.m20;
dest.m21 = -src.m21;
dest.m22 = -src.m22;
dest.m23 = -src.m23;
dest.m30 = -src.m30;
dest.m31 = -src.m31;
dest.m32 = -src.m32;
dest.m33 = -src.m33;
return dest;
}
}

View file

@ -1,54 +0,0 @@
package game.util;
public enum PerfSection {
TIMING("Timing"),
INPUT("Input"),
TICK("Tick"),
UPDATE("Update"),
RENDER("Render"),
GUI("Gui"),
REST("Rest"),
SWAP("Swap"),
EVENTS("Events"),
WAIT("Wait");
private static PerfSection section;
private static int swap;
private static long start;
private static long total;
private final String name;
private long time;
private long[] last = new long[2];
private PerfSection(String name) {
this.name = name;
}
public void enter() {
this.time = Util.getTime();
if(section != null)
section.last[swap] = section.time = this.time - section.time;
section = this;
}
public String getName() {
return this.name;
}
public long getLast() {
return this.last[swap ^ 1];
}
public static void swap() {
long current = Util.getTime();
total = current - start;
start = current;
swap ^= 1;
}
public static long getTotal(boolean wait) {
return total - (wait ? 0L : WAIT.getLast());
}
}

View file

@ -1,321 +0,0 @@
package game.util;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import game.log.Log;
public abstract class SkinConverter {
private static BufferedImage convertSkin(BufferedImage image) {
BufferedImage img = new BufferedImage(64, 64, BufferedImage.TYPE_INT_ARGB);
Graphics graphics = img.getGraphics();
graphics.drawImage(image, 0, 0, null);
graphics.drawImage(img, 24, 48, 20, 52, 4, 16, 8, 20, null);
graphics.drawImage(img, 28, 48, 24, 52, 8, 16, 12, 20, null);
graphics.drawImage(img, 20, 52, 16, 64, 8, 20, 12, 32, null);
graphics.drawImage(img, 24, 52, 20, 64, 4, 20, 8, 32, null);
graphics.drawImage(img, 28, 52, 24, 64, 0, 20, 4, 32, null);
graphics.drawImage(img, 32, 52, 28, 64, 12, 20, 16, 32, null);
graphics.drawImage(img, 40, 48, 36, 52, 44, 16, 48, 20, null);
graphics.drawImage(img, 44, 48, 40, 52, 48, 16, 52, 20, null);
graphics.drawImage(img, 36, 52, 32, 64, 48, 20, 52, 32, null);
graphics.drawImage(img, 40, 52, 36, 64, 44, 20, 48, 32, null);
graphics.drawImage(img, 44, 52, 40, 64, 40, 20, 44, 32, null);
graphics.drawImage(img, 48, 52, 44, 64, 52, 20, 56, 32, null);
graphics.dispose();
return img;
}
private static BufferedImage convertSlim(BufferedImage image) {
BufferedImage img = new BufferedImage(64, 64, BufferedImage.TYPE_INT_ARGB);
Graphics2D graphics = img.createGraphics();
graphics.drawImage(image, 0, 0, null);
graphics.setBackground(new Color(0xffffffff, true));
graphics.clearRect(47, 16, 9, 16);
graphics.clearRect(37, 48, 11, 16);
graphics.setBackground(new Color(0x00000000, true));
graphics.clearRect(47, 32, 9, 16);
graphics.clearRect(53, 48, 11, 16);
graphics.drawImage(image, 47, 16, 48, 20, 46, 16, 47, 20, null); //
graphics.drawImage(image, 48, 16, 51, 20, 47, 16, 50, 20, null);
graphics.drawImage(image, 51, 16, 52, 20, 49, 16, 50, 20, null); //
graphics.drawImage(image, 47, 20, 48, 32, 46, 20, 47, 32, null); //
graphics.drawImage(image, 48, 20, 52, 32, 47, 20, 51, 32, null);
graphics.drawImage(image, 53, 20, 56, 32, 51, 20, 54, 32, null);
graphics.drawImage(image, 52, 20, 53, 32, 51, 20, 52, 32, null); //
graphics.drawImage(image, 47, 32, 48, 36, 46, 32, 47, 36, null); //
graphics.drawImage(image, 48, 32, 51, 36, 47, 32, 50, 36, null);
graphics.drawImage(image, 51, 32, 52, 36, 49, 32, 50, 36, null); //
graphics.drawImage(image, 47, 36, 48, 48, 46, 36, 47, 48, null); //
graphics.drawImage(image, 48, 36, 52, 48, 47, 36, 51, 48, null);
graphics.drawImage(image, 53, 36, 56, 48, 51, 36, 54, 48, null);
graphics.drawImage(image, 52, 36, 53, 48, 51, 36, 52, 48, null); //
graphics.drawImage(image, 37, 48, 40, 52, 36, 48, 39, 52, null);
graphics.drawImage(image, 41, 48, 44, 52, 39, 48, 42, 52, null);
graphics.drawImage(image, 40, 48, 41, 52, 39, 48, 40, 52, null); //
graphics.drawImage(image, 37, 52, 40, 64, 36, 52, 39, 64, null);
graphics.drawImage(image, 40, 52, 44, 64, 39, 52, 43, 64, null);
graphics.drawImage(image, 44, 52, 47, 64, 43, 52, 46, 64, null);
graphics.drawImage(image, 47, 52, 48, 64, 45, 52, 46, 64, null); //
graphics.drawImage(image, 53, 48, 56, 52, 52, 48, 55, 52, null);
graphics.drawImage(image, 57, 48, 60, 52, 55, 48, 58, 52, null);
graphics.drawImage(image, 56, 48, 57, 52, 55, 48, 56, 52, null); //
graphics.drawImage(image, 53, 52, 56, 64, 52, 52, 55, 64, null);
graphics.drawImage(image, 56, 52, 60, 64, 55, 52, 59, 64, null);
graphics.drawImage(image, 60, 52, 63, 64, 59, 52, 62, 64, null);
graphics.drawImage(image, 63, 52, 64, 64, 61, 52, 62, 64, null); //
graphics.dispose();
return img;
}
private static void copyData(int[] img1, int[] img2, int xo, int yo, int w, int h, boolean blank, boolean alpha) {
for(int y = yo; y < h+yo; y++) {
for(int x = xo; x < w+xo; x++) {
img2[y*64+x] = blank ? 0x00000000 : (img1[y*64+x] | (alpha ? 0x00000000 : 0xff000000));
}
}
}
private static void copyData(int[] img1, int[] img2, int xo, int yo, int w, int h, int xd, int yd) {
for(int y = 0; y < h; y++) {
for(int x = 0; x < w; x++) {
img2[(yd+y)*64+xd+x] = img1[(yo+y)*64+xo+x];
}
}
}
private static int[] filterImage(int[] img1, int[] img2) {
copyData(img1, img2, 0, 0, 8, 8, true, true);
copyData(img1, img2, 8, 0, 16, 8, false, false);
copyData(img1, img2, 24, 0, 8, 8, true, true);
copyData(img1, img2, 0, 8, 32, 8, false, false);
copyData(img1, img2, 32, 0, 8, 8, true, true);
copyData(img1, img2, 40, 0, 16, 8, false, true);
copyData(img1, img2, 56, 0, 8, 8, true, true);
copyData(img1, img2, 32, 8, 32, 8, false, true);
copyData(img1, img2, 0, 16, 4, 4, true, true);
copyData(img1, img2, 4, 16, 8, 4, false, false);
copyData(img1, img2, 12, 16, 8, 4, true, true);
copyData(img1, img2, 20, 16, 16, 4, false, false);
copyData(img1, img2, 36, 16, 8, 4, true, true);
copyData(img1, img2, 44, 16, 8, 4, false, false);
copyData(img1, img2, 52, 16, 4, 4, true, true);
copyData(img1, img2, 0, 20, 56, 12, false, false);
copyData(img1, img2, 56, 16, 8, 32, true, true);
copyData(img1, img2, 0, 32, 4, 4, true, true);
copyData(img1, img2, 4, 32, 8, 4, false, true);
copyData(img1, img2, 12, 32, 8, 4, true, true);
copyData(img1, img2, 20, 32, 16, 4, false, true);
copyData(img1, img2, 36, 32, 8, 4, true, true);
copyData(img1, img2, 44, 32, 8, 4, false, true);
copyData(img1, img2, 52, 32, 4, 4, true, true);
copyData(img1, img2, 0, 36, 56, 12, false, true);
copyData(img1, img2, 0, 48, 4, 4, true, true);
copyData(img1, img2, 4, 48, 8, 4, false, true);
copyData(img1, img2, 12, 48, 4, 4, true, true);
copyData(img1, img2, 0, 52, 16, 12, false, true);
copyData(img1, img2, 16, 48, 4, 4, true, true);
copyData(img1, img2, 20, 48, 8, 4, false, false);
copyData(img1, img2, 28, 48, 8, 4, true, true);
copyData(img1, img2, 36, 48, 8, 4, false, false);
copyData(img1, img2, 44, 48, 4, 4, true, true);
copyData(img1, img2, 16, 52, 32, 12, false, false);
copyData(img1, img2, 48, 48, 4, 4, true, true);
copyData(img1, img2, 52, 48, 8, 4, false, true);
copyData(img1, img2, 60, 48, 4, 4, true, true);
copyData(img1, img2, 48, 52, 16, 12, false, true);
return img2;
}
private static void relocateIntermediary(int[] img1, int[] img2) {
copyData(img1, img2, 0, 0, 64, 64, 0, 0);
copyData(img1, img2, 4, 16, 8, 4, 20, 48);
copyData(img1, img2, 44, 16, 8, 4, 4, 16);
copyData(img1, img2, 0, 20, 16, 12, 16, 52);
copyData(img1, img2, 40, 20, 16, 12, 0, 20);
copyData(img1, img2, 4, 32, 8, 4, 4, 48);
copyData(img1, img2, 44, 32, 8, 4, 4, 32);
copyData(img1, img2, 0, 36, 16, 12, 0, 52);
copyData(img1, img2, 40, 36, 16, 12, 0, 36);
copyData(img1, img2, 4, 48, 8, 4, 52, 48);
copyData(img1, img2, 20, 48, 8, 4, 36, 48);
copyData(img1, img2, 36, 48, 8, 4, 44, 16);
copyData(img1, img2, 52, 48, 8, 4, 44, 32);
copyData(img1, img2, 0, 52, 16, 12, 48, 52);
copyData(img1, img2, 16, 52, 16, 12, 32, 52);
copyData(img1, img2, 32, 52, 16, 12, 40, 20);
copyData(img1, img2, 48, 52, 16, 12, 40, 36);
}
public static boolean convertSkin(File source, File dir, boolean slim) {
BufferedImage img;
try {
img = ImageIO.read(source);
}
catch(IOException e) {
Log.JNI.error(e, "Konnte kein Bild von " + source + " laden");
return false;
}
if(img == null) {
Log.JNI.warn("Konnte kein Bild von " + source + " laden");
return false;
}
Log.JNI.info("Bild von " + source + " geladen");
if(img.getWidth() == 64 && img.getHeight() == 32) {
img = convertSkin(img);
Log.JNI.info("Skin " + source + " konvertiert");
}
else if(img.getWidth() != 64 || img.getHeight() != 64) {
Log.JNI.warn("Falsche Bildgröße von " + source + ": " + img.getWidth() + "x" + img.getHeight());
return false;
}
String name = source.getName();
int ext = name.lastIndexOf('.');
if(ext >= 0)
name = name.substring(0, ext);
if(name.isEmpty())
name = "skin";
if(slim) {
img = convertSlim(img);
Log.JNI.info("Skin " + source + " von 'Slim' konvertiert");
if(!name.startsWith("slim_"))
name = "slim_" + name;
}
File file = new File(dir, name + ".png");
int z = 1;
while(file.exists()) {
file = new File(dir, name + "_" + (++z) + ".png");
}
// Graphics2D g = img.createGraphics();
// g.setBackground(new Color(0x7fff00ff, true));
// g.clearRect(0, 0, 64, 64);
int[] data = img.getRGB(0, 0, 64, 64, new int[64*64], 0, 64);
int[] data2 = new int[data.length];
relocateIntermediary(data, data2);
data = data2;
filterImage(data, data);
img.setRGB(0, 0, 64, 64, data, 0, 64);
try {
ImageIO.write(img, "png", file);
}
catch(Exception e) {
Log.JNI.error(e, "Konnte Bild nicht speichern");
return false;
}
Log.JNI.info("Skin " + source + " gespeichert als " + file.getName());
return true;
}
// public static void main(String[] args) {
// if(args.length < 1) {
// System.err.println("Verwendung: SkinConverter [-s | -n | -i] <Skin-Datei | Ordner ...>");
// System.exit(1);
// }
// int n = 0;
// boolean slim = false;
//// boolean intermediary = false;
// for(String file : args) {
// if(file.equals("-s")) {
// slim = true;
// continue;
// }
//// else if(file.equals("-i")) {
//// intermediary = true;
//// continue;
//// }
// else if(file.equals("-n")) {
// slim = false;
//// intermediary = false;
// continue;
// }
// else if(new File(file).isDirectory()) {
// String[] files = new File(file).list();
// if(files != null && files.length > 0) {
// for(int z = 0; z < files.length; z++) {
// files[z] = file + File.separator + files[z];
// }
// if(slim) { // || intermediary) {
// String[] files2 = new String[files.length + /* (slim && intermediary ? 2 : */ 1]; // )];
// int pos = 0;
// if(slim)
// files2[pos++] = "-s";
//// if(intermediary)
//// files2[pos++] = "-i";
// System.arraycopy(files, 0, files2, pos, files.length);
// files = files2;
// }
// main(files);
// }
// continue;
// }
// else if(file.endsWith("-converted.png"))
// continue;
// String out = (file.endsWith(".png") ? file.substring(0, file.length() - 4) : file) + "-converted.png";
// BufferedImage img;
// try {
// img = ImageIO.read(new File(file));
// }
// catch(Exception e) {
// System.err.println("Konnte Bild '" + file + "' nicht laden");
// e.printStackTrace();
// continue;
// }
// if(img == null) {
// System.err.println("Konnte Bild '" + file + "' nicht öffnen");
// continue;
// }
// if(img.getWidth() == 64 && img.getHeight() == 32) {
// img = convertSkin(img);
// System.out.println("Skin '" + file + "' von 64x32 nach 64x64 konvertiert");
// }
// else if(img.getWidth() != 64 || img.getHeight() != 64) {
// System.err.println("Falsche Bildgröße für '" + file + "': " + img.getWidth() + "x" + img.getHeight());
// continue;
// }
// if(slim) {
// img = convertSlim(img);
// System.out.println("Skin '" + file + "' von 'Slim' nach 64x64/'Schlank' konvertiert");
// }
// int[] data = img.getRGB(0, 0, 64, 64, new int[64*64], 0, 64);
//// if(intermediary) {
// int[] data2 = new int[data.length];
// relocateIntermediary(data, data2);
// data = data2;
//// }
//// else {
// filterImage(data, data);
//// }
// img.setRGB(0, 0, 64, 64, data, 0, 64);
// try {
// ImageIO.write(img, "png", new File(out));
// }
// catch(Exception e) {
// System.err.println("Konnte Bild '" + out + "' nicht speichern");
// e.printStackTrace();
// continue;
// }
// System.out.println("Skin von '" + file + "' nach '" + out + "' konvertiert");
// n++;
// }
// if(n > 0)
// System.out.println(n + " Skins wurden konvertiert");
// }
}

View file

@ -1,414 +0,0 @@
package game.util;
public abstract class Splashes {
public static final String[] SPLASHES = {
"Aus der TV-Werbung!",
"Toll!",
"0% pur!",
"Kann Nüsse enthalten!",
"Besser als Crysis!",
"Mehr Polygone!",
"Sexy!",
"Limitierte Edition!",
"Blinkende Buchstaben!",
"Erstellt von Notch!",
"Es ist hier!",
"Das Beste seiner Klasse!",
"Es ist vollendet!",
"Mehr oder weniger frei von Drachen!",
"Aufregung!",
"Weniger als -5 verkauft!",
"Einzigartig!",
"Einen Haufen Scheiße auf YouTube!",
"Indev!",
"Spinnen überall!",
"Schau es dir an!",
"Heilige Kuh, mann!",
"Es ist ein Spiel!",
"Hergestellt in Schweden!",
"Benutzt LWJGL!",
"Retikulierende Splinen!",
"Meine Kraft!",
"Hurraaa!",
"Einzelspieler!",
"Tastatur ist kompatibel!",
"Undokumentiert!",
"Barren!",
"Explodierende Sonnen!",
"Das ist ein Mond!",
"l33t!",
"Erschaffe!",
"Überlebe!",
"Verlies!",
"Exklusiv!",
"Die Knie der Biene!",
"Weg mit O.P.P.!",
"Mit Quellcode (mehr oder weniger)!",
"Mit Klasse(n)!",
"Wow!",
"Immer noch nicht auf Steam - und das ist auch gut so!",
"Oh, mann!",
"Grauenvolle Community!",
"Pixel!",
"Teetsuuuuoooo!",
"Kaaneeeedaaaa!",
"Jetzt ohne Schwierigkeit!",
"Verbessert!",
"9% frei von Bugs!",
"Schön!",
"13 Kräuter und Gewürze!",
"Fettfrei!",
"Absolut keine Memes!",
"Kostenlose Zähne!",
"Fragen Sie Ihnen Arzt oder Apotheker!",
"Alle Bergleute sind willkommen!",
"Cloud-Computing!",
"Legal in Finnland!",
"Schwer zu beschreiben!",
"Technisch gesehen gut!",
"Bringe den Speck nach Hause!",
"Indie!",
"GOTY!",
"Ceci n'est pas une title screen!",
"Euklidisch!",
"Jetzt in 3D!",
"Bietet Inspiration!",
"Herregud!",
"Komplexe Zellvorgänge!",
"Ja, Sir!",
"Von Cowboys gespielt!",
"OpenGL 1.5 oder höher!",
"Tausende von Farben!",
"Probiere es!",
"Age of Wonders ist besser!",
"Probiere die Pilzsuppe!",
"Sensationell!",
"Heiße Tamale, heiße heiße Tamale!",
"Spiele ihn runter, Klavierkatze!",
"Garantiert!",
"Makroskopisch!",
"Dann komm doch her!",
"Zufälliger Text!",
"Ruf deine Mutter an!",
"Monster-Streitigkeiten!",
"Von Melonen geliebt!",
"Ultimative Edition!",
"Merkwürdig!",
"Du hast einen nagelneuen Schlüssel bekommen!",
"Wasserfest!",
"Nicht brennbar!",
"Oha, du!",
"Alles inklusive!",
"Sag es deinen Freunden!",
"NP ist nicht in P!",
"Musik von C418 (DLC)!",
"Viel zu oft live gestreamt!",
"Heimgesucht!",
"Polynomial!",
"Terrestrisch!",
"Alles ist voller Zerstörung!",
"Voll mit Sternen, Planeten und Monden!",
"Wissenschaftlich!",
"Nicht so cool wie Spock!",
"Trage nix bei und höre weg!",
"Grabe niemals nach unten, wenn du keine Erze brauchst!",
"Mache nie Pause!",
"Nicht linear!",
"Han hat zuerst geschossen!",
"Schön dich zu sehen!",
"Eimer mit Lava!",
"Reite auf dem Schwein!",
"Größer als die Erde!",
"sqrt(-1)ch liebe dich!",
"Phobos-Anomalie!",
"Holz schlagen!",
"Von Klippen fallen!",
"0% Zucker!",
"150% hyperbol!",
"Synecdoche!",
"Lasst uns tanzne!",
"Geheeimes Freitags-Update!",
"Referenz-Implementation!",
"Frei mit zwei.. äähhh fünf Typen mit Essen!",
"Küsse den Himmel!",
"20 GOTO 10!",
"Verlet-Intregration!",
"Peter Griffin!",
"Verteile die Erde gut!",
"Cogito ergo sum!",
"4815162342 Zeilen Quellcode (287228 am 30.7.)!",
"Ein Skelett fiel heraus!",
"Das Werk von Notch!",
"Die Summe seiner Teile!",
"BTAF war mal gut!",
"Ich vermisse ADOM!",
"umop-apisdn!",
"GTX750Ti!",
"Bringe mir Mentos und Cola!",
"Finger-leckend!",
"Thematisch!",
"Pneumatisch!",
"Erhaben!",
"Achteckig!",
"Une baguette!",
"Gargamel spielt es!",
"Rita ist der neue beste Hund!",
"SWM für immer!",
"Repräsentiert Edsbyn!",
"Matt Damon!",
"Supercalifragilisticexpialidocious!",
"Vollende V's!",
"Kuh-Werkzeuge!",
"Doppelt gepuffert!",
"Fan-Fiction!",
"Flaxkikare!",
"Jason! Jason! Jason!",
"Heißer als die Sonne!",
"Internet-Funktionalität!",
"Autonom!",
"Engagiere!",
"Fantasie!",
"DRR! DRR! DRR!",
"Stoß es Wurzel runter!",
"Regionale Ressourcen!",
"Jaa, facepunch!",
"Jaa, somethingawful!",
"Jaa, /v/!",
"Jaa, tigsource!",
"Jaa, weinkraftforum!",
"Jaa, worldofweinkraft!",
"Buu, reddit!",
"Jaa, 2pp!",
"Goggle anllyticsed:DD :DDD:D!",
"Unterstützt jetzt äöü!",
"Gebt uns Gordon!",
"Gib deinem Kellner Trinkgeld!",
"Macht viel Spaß!",
"12345 ist ein schlechtes Passwort!",
"Stimme für Netz-Neutralität!",
"Lebt in einer Ananas unter dem Meer!",
"MAP11 hat zwei Namen!",
"Allmächtig!",
"Huch!",
"...!",
"Bienen, Bienen, Bienen, Bienen!",
"Jag känner en bot!",
"Dieser Text ist schwer bei der Standard-Auflösung zu lesen, aber auf 1080p ist es in Ordnung!",
"Haha, LOL!",
"Hampsterdance!",
"Schalter und Erze!",
"Menger-Schwamm!",
"idspispopd!",
"Eple (originale Version)!",
"So frisch, so sauber!",
"Schnell reagierende Portale!",
"Probiere den Warp aus!",
"Schaue nicht direkt auf die Bugs!",
"Oh, ok, NPCs!",
"Endlich mit Leitern!",
"Gruselig!",
"Spiele Minenkraft, schaue Topgear, bekomme Schwein!",
"Darüber gewittert!",
"Spring hoch, spring hoch, und komme runter!",
"Joel ist klasse!",
"Ein Rätsel, in einen Mythos verwoben!",
"Riesige Landeszüge voll mit TNT!",
"Willkommen zu deinem Ende! Muahahahahahaha!",
"Bleib ein Bisschen, bleib für immer!",
"Bleib ein Bisschen und höre zu!",
"Behandlung für Ihren Hautausschlag!",
"\"Autologisch\" ist!",
"Informationen wollen frei sein!",
"\"Fast nie\" ist ein interessantes Konzept!",
"Eine Menge Wahrheitigkeit!",
"Der TNT-Block ist ein Spion!",
"Turing-vollständig!",
"Es ist bahnbrechend!",
"Lasst unsere Schlachten beginnen!",
"Der Himmel ist die Grenze - oder auch nicht!",
"Jeb hat tolle Haare!",
"Ryan hat auch tolle Haare!",
"Gelegentliches Spielen!",
"Unbesiegt!",
"Ein Bisschen wie Lemmings!",
"Folge dem Zug, CJ!",
"Macht von Synergie Verwendung!",
"Diese Nachricht wird niemals als Splash-Text erscheinen, ist das nicht komisch?",
"DungeonQuest ist unfair!",
"0815!",
"666!",
"Geh zu den fernen Ländern und weiter!",
"Tyrion würde es lieben!",
"Probiere auch Stellaris!",
"Probiere auch Garry's Mod!",
"Probiere auch GZDoom!",
"Probiere auch OpenTTD!",
"Probiere auch Kaffee!",
"Probiere auch Vodka!",
"Probiere auch Tee!",
"Probiere auch Wasser!",
"Probiere auch Saft!",
"Das ist super!",
"Brot ist Schmerz!",
"Lese mehr Bücher!",
"Khaaaaaaaaan!",
"Weniger süchtig machend als TV Tropes!",
"Mehr süchtig machend als Limonade!",
"Größer als eine Brotkiste!",
"Millionen von Pfirsichen!",
"Fnord!",
"Dies ist meine echte Gestalt! Muahahahaha!",
"Habe Dre vollkommen vergessen!",
"Verschwende keine Zeit mit den Klonen!",
"Kürbiskopf!",
"Hobo humping slobo babe!",
"Erstellt von Jeb!",
"Hat kein Ende!",
"Endlich vollständig!",
"Voll mit Features!",
"Stiefel mit dem Fell!",
"Stop, hammertime!",
"Testificates!",
"Nicht konventionell!",
"Homeomorphisch zu einer 3-Kugel!",
"Vermeidet nicht doppelte Verneinung!",
"Platziere ALL die Blöcke!",
"Macht Walzen!",
"Erfüllt Erwartungen!",
"Spielen am PC seit 1873!",
"Ghoughpteighbteau tchoghs!",
"Deja vu!",
"Deja vu!",
"Hab deine Nase!",
"Haley liebt Elan!",
"Hat keine Angst vor der großen, schwarzen Fledermaus!",
"Benutzt nicht das U-Wort!",
"Nicht wirklich leicht!",
"Bis nächsten Freitag oder so!",
"Von den Straßen von Södermalm!",
"150 BPM für 400000 Minuten!",
"Technologisch!",
"Funk Soul Bruder!",
"Pumpa kungen!",
"Hallo Japan",
"Hallo Korea!",
"Hallo Wales!",
"Hallo Polen!",
"Hallo China",
"Hallo Russland!",
"Hallo Griechenland!",
"Mein Leben für Aiur!",
"Lenny lenny = new Lenny(\"(°^°)\");",
"Ich sehe dein Wortschatz hat sich verbessert!",
"Wer hat es dort hin getan?",
"Das kannst du nicht erklären! - Oder etwa doch??",
"if not ok then return end",
"Mehrfarbig!",
"FUNKY LOL",
"SOPA bedeutet LOSER in Schwedisch!",
"Große Spitze Zähne!",
"Mein Shizun bewacht das Tor!",
"Mmmph, mmph!",
"Füttere keine Avocados an Papageien!",
"Schwerter für alle!",
"Bitteee antworte meinem Tweet! (Nutzer wurde gebannt)",
".party()!",
"Nehme ihr Kissen!",
"Lege diesen Keks weg!",
"Extrem gruselig!",
"Ich habe einen Vorschlag.",
"Jetzt mit extra Sprengstoff!",
"Nicht kompatibel zu Java 6!",
"Oha.",
"HURNERJSGER?",
"Was'n los, Doc?",
"Enthält jetzt 0 zufällige tägliche Katzen!",
"Das ist Numberwang!",
"((pls rt)) -- Der Vogel ist tot!",
"Willst du meinem Server beitreten?",
"Mach einen großen Zaun drum herum! Oder du wirst v-",
"Lege eine Landmine drüber!",
"Eines Tages, irgendwann in der Zukunft, wird mein Werk zitiert werden!",
"Jetzt mit zusätzlichem Zeug!",
"Zusätzliche Dinge!",
"Hurra, Atombomben für alle!",
"So süß, wie ein schöner Bon-Bon!",
"Poppende Tags!",
"Sehr einflussreich in seinem Kreis!",
"Jetzt mit Mehrspieler!",
"Stehe aus deinem Grab auf!",
"Warnung! Ein großes Kampfschiff \"SHEN\" nähert sich schnell!",
"Der blaue Krieger hat das Essen beschossen!",
"Renn, Feigling! Ich hunger!",
"Geschmack ohne Würze!",
"Seltsam, aber nicht fremd!",
"Härter als Diamanten, Reich wie Creme!",
"Mach dich bereit zum Ruinieren!",
"Mach dich bereit zum Experimentieren!",
"Mach dich bereit zum Kollabieren!",
"Mach dich bereit zum Explodieren!",
"Mach dich bereit zum Implodieren!",
"Mach dich bereit zum Implizieren!",
"Es schwingt, es veräppelt!",
"Fahre Straßen entlang für Gold!",
"Nimm einen Schneebesen und haue ihn gegen eine Bratpfanne!",
"Bau mir einen Tisch, einen funkigen Tisch!",
"Nehm den Aufzug in die Hölle!",
"Hör auf vernünftig zu sein, das hier ist das Internet!",
"/give @a tnt 67108864 7",
"Das ist gut für 3D Realms.",
"Jeder Computer ist ein Laptop, wenn du tapfer genug bist!",
"Mach es alles, jede Sache!",
"Wo ist kein Licht, da kann Spinne!",
"GNU Terry Pratchett",
"Jetzt Java 8!",
"MeinKraft!",
"Immer noch zu viele Bugs!",
"Wird nicht laggen!",
"Er hat es ruiniert!",
"Maus nicht kompatibel!",
"OpenGL 2.0+ (definitiv nicht unterstützt)!",
"Keine Segfaults (nicht) möglich!",
"Keine Abstürze (un)möglich!",
"Alpha!",
"Enthält Bugs!",
"Enthält Mäuse!",
"Enthält Gewalt!",
"Grabe immer nach unten >:)>!",
"Weg mit O.O.P.!",
"Du hattest eine. aufgabe.",
"Spinnen können TNT1 A 0 sein!",
"RTFM!",
"Vorherrschaft des Imperiums!",
"Vorherrschaft der Eldar!",
"Vorherrschaft der Drukhari!",
"Vorherrschaft der Necrons!",
"Vorherrschaft der Orks!",
"Jeder Laptop ist ein Tablet, wenn du tapfer genug bist!",
"Jedes Handy ist ein Klapphandy, wenn du tapfer genug bist!",
"Quadcores altern wie feiner Wein (außer mit JS)!",
"Speicherzugriffsfehler (Speicherzug im Riff stehen geblieben)!",
"Eingedeutscht (naja fast)!",
"Ketzerei!",
"WAAAGH!",
"WAAAAGH!",
"WAAAAAGH!",
"WAAAAAAGH!",
"WAAAAAAAGH!",
"WAAAAAAAAGH!",
"WAAAAAAAAAGH!",
"WAAAAAAAAAAGH!",
"X ist nix!",
"Quadratisch, praktisch, gut!",
"Rund, unpraktisch, schlecht!",
"Verschreibungspflichtig!",
"Grüne, radioaktive Blöcke!",
"Blaue, nicht radioaktive Blöcke!",
"Exterminatus!",
"Nein! Doch! Ohh!",
"Eimer mit Wasser!",
"Hergestellt in Deutschland!",
"Hergestellt in China!",
"Jetzt mit Einzelspieler!"
};
}

View file

@ -1,30 +0,0 @@
package game.util;
public class Timing {
public static long tmr_timer;
public static long tmr_start;
public static long tmr_current;
public static long tmr_last;
public static long tmr_delta;
public static long tmr_update;
public static long tmr_frames;
public static long tmr_iters;
public static long tick_torun;
public static long tick_done;
public static long tick_total;
public static long tick_time;
public static long tick_stime;
public static long tick_ftime;
public static long tick_ttime;
public static long tick_update;
public static double tick_fraction;
public static float framerate;
public static float tickrate;
public static float fdelta;
public static int tickTarget;
public static int tickFrame;
}

View file

@ -10,7 +10,6 @@ import javax.swing.JOptionPane;
import game.collect.Lists;
import game.collect.Maps;
import game.log.Log;
import game.properties.IStringSerializable;
public abstract class Util {
private static long start = getTime();
@ -179,7 +178,7 @@ int utf_len(const char *str) {
}
public static <T extends Enum> T parseEnum(Class<T> clazz, String str) {
boolean name = IStringSerializable.class.isAssignableFrom(clazz);
boolean name = Identifyable.class.isAssignableFrom(clazz);
T[] values = clazz.getEnumConstants();
Integer value;
if((value = parseInt(str, 0)) != null && (value >= 0) && (value < values.length)) {
@ -189,7 +188,7 @@ int utf_len(const char *str) {
int max = 0;
T best = null;
for(int z = 0; z < values.length; z++) {
if((comp = compareLower(name ? ((IStringSerializable)values[z]).getName() : values[z].toString(), str)) > max) {
if((comp = compareLower(name ? ((Identifyable)values[z]).getName() : values[z].toString(), str)) > max) {
max = comp;
best = values[z];
}
@ -204,10 +203,10 @@ int utf_len(const char *str) {
for(Class<? extends Enum> clazz : enums) {
if(!base.isAssignableFrom(clazz))
throw new IllegalArgumentException("Klasse " + clazz.getSimpleName() + " ist nicht " + base.getSimpleName() + " untergeordnet");
boolean name = IStringSerializable.class.isAssignableFrom(clazz);
boolean name = Identifyable.class.isAssignableFrom(clazz);
Enum<?>[] values = clazz.getEnumConstants();
for(int z = 0; z < values.length; z++) {
if((comp = compareLower(name ? ((IStringSerializable)values[z]).getName() : values[z].toString(), str)) > max) {
if((comp = compareLower(name ? ((Identifyable)values[z]).getName() : values[z].toString(), str)) > max) {
max = comp;
best = (T)values[z];
}

View file

@ -0,0 +1,112 @@
/*
* Copyright (c) 2002-2008 LWJGL 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 'LWJGL' 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 game.util;
import java.io.Serializable;
import java.nio.FloatBuffer;
/**
*
* Base class for vectors.
*
* @author cix_foo <cix_foo@users.sourceforge.net>
* @version $Revision$
* $Id$
*/
public abstract class Vector implements Serializable {
/**
* Constructor for Vector.
*/
protected Vector() {
super();
}
/**
* @return the length of the vector
*/
public final float length() {
return (float) Math.sqrt(lengthSquared());
}
/**
* @return the length squared of the vector
*/
public abstract float lengthSquared();
/**
* Load this vector from a FloatBuffer
* @param buf The buffer to load it from, at the current position
* @return this
*/
public abstract Vector load(FloatBuffer buf);
/**
* Negate a vector
* @return this
*/
public abstract Vector negate();
/**
* Normalise this vector
* @return this
*/
public final Vector normalise() {
float len = length();
if (len != 0.0f) {
float l = 1.0f / len;
return scale(l);
} else
throw new IllegalStateException("Zero length vector");
}
/**
* Store this vector in a FloatBuffer
* @param buf The buffer to store it in, at the current position
* @return this
*/
public abstract Vector store(FloatBuffer buf);
/**
* Scale this vector
* @param scale The scale factor
* @return this
*/
public abstract Vector scale(float scale);
}

View file

@ -0,0 +1,358 @@
/*
* Copyright (c) 2002-2008 LWJGL 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 'LWJGL' 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 game.util;
import java.io.Serializable;
import java.nio.FloatBuffer;
/**
*
* Holds a 3-tuple vector.
*
* @author cix_foo <cix_foo@users.sourceforge.net>
* @version $Revision$
* $Id$
*/
public class Vector3f extends Vector implements Serializable {
private static final long serialVersionUID = 1L;
public float x, y, z;
/**
* Constructor for Vector3f.
*/
public Vector3f() {
super();
}
/**
* Constructor
*/
public Vector3f(Vector3f src) {
set(src);
}
/**
* Constructor
*/
public Vector3f(float x, float y, float z) {
set(x, y, z);
}
/* (non-Javadoc)
* @see org.lwjgl.util.vector.WritableVector2f#set(float, float)
*/
public void set(float x, float y) {
this.x = x;
this.y = y;
}
/* (non-Javadoc)
* @see org.lwjgl.util.vector.WritableVector3f#set(float, float, float)
*/
public void set(float x, float y, float z) {
this.x = x;
this.y = y;
this.z = z;
}
/**
* Load from another Vector3f
* @param src The source vector
* @return this
*/
public Vector3f set(Vector3f src) {
x = src.getX();
y = src.getY();
z = src.getZ();
return this;
}
/**
* @return the length squared of the vector
*/
public float lengthSquared() {
return x * x + y * y + z * z;
}
/**
* Translate a vector
* @param x The translation in x
* @param y the translation in y
* @return this
*/
public Vector3f translate(float x, float y, float z) {
this.x += x;
this.y += y;
this.z += z;
return this;
}
/**
* Add a vector to another vector and place the result in a destination
* vector.
* @param left The LHS vector
* @param right The RHS vector
* @param dest The destination vector, or null if a new vector is to be created
* @return the sum of left and right in dest
*/
public static Vector3f add(Vector3f left, Vector3f right, Vector3f dest) {
if (dest == null)
return new Vector3f(left.x + right.x, left.y + right.y, left.z + right.z);
else {
dest.set(left.x + right.x, left.y + right.y, left.z + right.z);
return dest;
}
}
/**
* Subtract a vector from another vector and place the result in a destination
* vector.
* @param left The LHS vector
* @param right The RHS vector
* @param dest The destination vector, or null if a new vector is to be created
* @return left minus right in dest
*/
public static Vector3f sub(Vector3f left, Vector3f right, Vector3f dest) {
if (dest == null)
return new Vector3f(left.x - right.x, left.y - right.y, left.z - right.z);
else {
dest.set(left.x - right.x, left.y - right.y, left.z - right.z);
return dest;
}
}
/**
* The cross product of two vectors.
*
* @param left The LHS vector
* @param right The RHS vector
* @param dest The destination result, or null if a new vector is to be created
* @return left cross right
*/
public static Vector3f cross(
Vector3f left,
Vector3f right,
Vector3f dest)
{
if (dest == null)
dest = new Vector3f();
dest.set(
left.y * right.z - left.z * right.y,
right.x * left.z - right.z * left.x,
left.x * right.y - left.y * right.x
);
return dest;
}
/**
* Negate a vector
* @return this
*/
public Vector negate() {
x = -x;
y = -y;
z = -z;
return this;
}
/**
* Negate a vector and place the result in a destination vector.
* @param dest The destination vector or null if a new vector is to be created
* @return the negated vector
*/
public Vector3f negate(Vector3f dest) {
if (dest == null)
dest = new Vector3f();
dest.x = -x;
dest.y = -y;
dest.z = -z;
return dest;
}
/**
* Normalise this vector and place the result in another vector.
* @param dest The destination vector, or null if a new vector is to be created
* @return the normalised vector
*/
public Vector3f normalise(Vector3f dest) {
float l = length();
if (dest == null)
dest = new Vector3f(x / l, y / l, z / l);
else
dest.set(x / l, y / l, z / l);
return dest;
}
/**
* The dot product of two vectors is calculated as
* v1.x * v2.x + v1.y * v2.y + v1.z * v2.z
* @param left The LHS vector
* @param right The RHS vector
* @return left dot right
*/
public static float dot(Vector3f left, Vector3f right) {
return left.x * right.x + left.y * right.y + left.z * right.z;
}
/**
* Calculate the angle between two vectors, in radians
* @param a A vector
* @param b The other vector
* @return the angle between the two vectors, in radians
*/
public static float angle(Vector3f a, Vector3f b) {
float dls = dot(a, b) / (a.length() * b.length());
if (dls < -1f)
dls = -1f;
else if (dls > 1.0f)
dls = 1.0f;
return (float)Math.acos(dls);
}
/* (non-Javadoc)
* @see org.lwjgl.vector.Vector#load(FloatBuffer)
*/
public Vector load(FloatBuffer buf) {
x = buf.get();
y = buf.get();
z = buf.get();
return this;
}
/* (non-Javadoc)
* @see org.lwjgl.vector.Vector#scale(float)
*/
public Vector scale(float scale) {
x *= scale;
y *= scale;
z *= scale;
return this;
}
/* (non-Javadoc)
* @see org.lwjgl.vector.Vector#store(FloatBuffer)
*/
public Vector store(FloatBuffer buf) {
buf.put(x);
buf.put(y);
buf.put(z);
return this;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
public String toString() {
StringBuilder sb = new StringBuilder(64);
sb.append("Vector3f[");
sb.append(x);
sb.append(", ");
sb.append(y);
sb.append(", ");
sb.append(z);
sb.append(']');
return sb.toString();
}
/**
* @return x
*/
public final float getX() {
return x;
}
/**
* @return y
*/
public final float getY() {
return y;
}
/**
* Set X
* @param x
*/
public final void setX(float x) {
this.x = x;
}
/**
* Set Y
* @param y
*/
public final void setY(float y) {
this.y = y;
}
/**
* Set Z
* @param z
*/
public void setZ(float z) {
this.z = z;
}
/* (Overrides)
* @see org.lwjgl.vector.ReadableVector3f#getZ()
*/
public float getZ() {
return z;
}
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null) return false;
if (getClass() != obj.getClass()) return false;
Vector3f other = (Vector3f)obj;
if (x == other.x && y == other.y && z == other.z) return true;
return false;
}
}

View file

@ -0,0 +1,349 @@
/*
* Copyright (c) 2002-2008 LWJGL 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 'LWJGL' 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 game.util;
import java.io.Serializable;
import java.nio.FloatBuffer;
/**
*
* Holds a 4-tuple vector.
*
* @author cix_foo <cix_foo@users.sourceforge.net>
* @version $Revision$
* $Id$
*/
public class Vector4f extends Vector implements Serializable {
private static final long serialVersionUID = 1L;
public float x, y, z, w;
/**
* Constructor for Vector4f.
*/
public Vector4f() {
super();
}
/**
* Constructor
*/
public Vector4f(Vector4f src) {
set(src);
}
/**
* Constructor
*/
public Vector4f(float x, float y, float z, float w) {
set(x, y, z, w);
}
/* (non-Javadoc)
* @see org.lwjgl.util.vector.WritableVector2f#set(float, float)
*/
public void set(float x, float y) {
this.x = x;
this.y = y;
}
/* (non-Javadoc)
* @see org.lwjgl.util.vector.WritableVector3f#set(float, float, float)
*/
public void set(float x, float y, float z) {
this.x = x;
this.y = y;
this.z = z;
}
/* (non-Javadoc)
* @see org.lwjgl.util.vector.WritableVector4f#set(float, float, float, float)
*/
public void set(float x, float y, float z, float w) {
this.x = x;
this.y = y;
this.z = z;
this.w = w;
}
/**
* Load from another Vector4f
* @param src The source vector
* @return this
*/
public Vector4f set(Vector4f src) {
x = src.getX();
y = src.getY();
z = src.getZ();
w = src.getW();
return this;
}
/**
* @return the length squared of the vector
*/
public float lengthSquared() {
return x * x + y * y + z * z + w * w;
}
/**
* Translate a vector
* @param x The translation in x
* @param y the translation in y
* @return this
*/
public Vector4f translate(float x, float y, float z, float w) {
this.x += x;
this.y += y;
this.z += z;
this.w += w;
return this;
}
/**
* Add a vector to another vector and place the result in a destination
* vector.
* @param left The LHS vector
* @param right The RHS vector
* @param dest The destination vector, or null if a new vector is to be created
* @return the sum of left and right in dest
*/
public static Vector4f add(Vector4f left, Vector4f right, Vector4f dest) {
if (dest == null)
return new Vector4f(left.x + right.x, left.y + right.y, left.z + right.z, left.w + right.w);
else {
dest.set(left.x + right.x, left.y + right.y, left.z + right.z, left.w + right.w);
return dest;
}
}
/**
* Subtract a vector from another vector and place the result in a destination
* vector.
* @param left The LHS vector
* @param right The RHS vector
* @param dest The destination vector, or null if a new vector is to be created
* @return left minus right in dest
*/
public static Vector4f sub(Vector4f left, Vector4f right, Vector4f dest) {
if (dest == null)
return new Vector4f(left.x - right.x, left.y - right.y, left.z - right.z, left.w - right.w);
else {
dest.set(left.x - right.x, left.y - right.y, left.z - right.z, left.w - right.w);
return dest;
}
}
/**
* Negate a vector
* @return this
*/
public Vector negate() {
x = -x;
y = -y;
z = -z;
w = -w;
return this;
}
/**
* Negate a vector and place the result in a destination vector.
* @param dest The destination vector or null if a new vector is to be created
* @return the negated vector
*/
public Vector4f negate(Vector4f dest) {
if (dest == null)
dest = new Vector4f();
dest.x = -x;
dest.y = -y;
dest.z = -z;
dest.w = -w;
return dest;
}
/**
* Normalise this vector and place the result in another vector.
* @param dest The destination vector, or null if a new vector is to be created
* @return the normalised vector
*/
public Vector4f normalise(Vector4f dest) {
float l = length();
if (dest == null)
dest = new Vector4f(x / l, y / l, z / l, w / l);
else
dest.set(x / l, y / l, z / l, w / l);
return dest;
}
/**
* 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
* @param left The LHS vector
* @param right The RHS vector
* @return left dot right
*/
public static float dot(Vector4f left, Vector4f right) {
return left.x * right.x + left.y * right.y + left.z * right.z + left.w * right.w;
}
/**
* Calculate the angle between two vectors, in radians
* @param a A vector
* @param b The other vector
* @return the angle between the two vectors, in radians
*/
public static float angle(Vector4f a, Vector4f b) {
float dls = dot(a, b) / (a.length() * b.length());
if (dls < -1f)
dls = -1f;
else if (dls > 1.0f)
dls = 1.0f;
return (float)Math.acos(dls);
}
/* (non-Javadoc)
* @see org.lwjgl.vector.Vector#load(FloatBuffer)
*/
public Vector load(FloatBuffer buf) {
x = buf.get();
y = buf.get();
z = buf.get();
w = buf.get();
return this;
}
/* (non-Javadoc)
* @see org.lwjgl.vector.Vector#scale(float)
*/
public Vector scale(float scale) {
x *= scale;
y *= scale;
z *= scale;
w *= scale;
return this;
}
/* (non-Javadoc)
* @see org.lwjgl.vector.Vector#store(FloatBuffer)
*/
public Vector store(FloatBuffer buf) {
buf.put(x);
buf.put(y);
buf.put(z);
buf.put(w);
return this;
}
public String toString() {
return "Vector4f: " + x + " " + y + " " + z + " " + w;
}
/**
* @return x
*/
public final float getX() {
return x;
}
/**
* @return y
*/
public final float getY() {
return y;
}
/**
* Set X
* @param x
*/
public final void setX(float x) {
this.x = x;
}
/**
* Set Y
* @param y
*/
public final void setY(float y) {
this.y = y;
}
/**
* Set Z
* @param z
*/
public void setZ(float z) {
this.z = z;
}
/* (Overrides)
* @see org.lwjgl.vector.ReadableVector3f#getZ()
*/
public float getZ() {
return z;
}
/**
* Set W
* @param w
*/
public void setW(float w) {
this.w = w;
}
/* (Overrides)
* @see org.lwjgl.vector.ReadableVector3f#getZ()
*/
public float getW() {
return w;
}
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null) return false;
if (getClass() != obj.getClass()) return false;
Vector4f other = (Vector4f)obj;
if (x == other.x && y == other.y && z == other.z && w == other.w) return true;
return false;
}
}