diff --git a/src/java/org/lwjgl/vector/ReadableVector.java b/src/java/org/lwjgl/vector/ReadableVector.java new file mode 100644 index 00000000..ba1e8dfd --- /dev/null +++ b/src/java/org/lwjgl/vector/ReadableVector.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2003 Shaven Puppy Ltd + * 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 'Shaven Puppy' 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.vector; + +import java.nio.FloatBuffer; + +/** + * @author foo + */ +public interface ReadableVector { + /** + * @return the length of the vector + */ + public float length(); + /** + * @return the length squared of the vector + */ + public float lengthSquared(); + /** + * Store this vector in a FloatBuffer + * @param buf The buffer to store it in, at the current position + * @return this + */ + public Vector store(FloatBuffer buf); +} \ No newline at end of file diff --git a/src/java/org/lwjgl/vector/ReadableVector2f.java b/src/java/org/lwjgl/vector/ReadableVector2f.java new file mode 100644 index 00000000..61e974b2 --- /dev/null +++ b/src/java/org/lwjgl/vector/ReadableVector2f.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2003 Shaven Puppy Ltd + * 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 'Shaven Puppy' 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.vector; + +/** + * @author foo + */ +public interface ReadableVector2f extends ReadableVector { + /** + * @return x + */ + public float getX(); + /** + * @return y + */ + public float getY(); +} \ No newline at end of file diff --git a/src/java/org/lwjgl/vector/ReadableVector3f.java b/src/java/org/lwjgl/vector/ReadableVector3f.java new file mode 100644 index 00000000..6f6902a6 --- /dev/null +++ b/src/java/org/lwjgl/vector/ReadableVector3f.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2003 Shaven Puppy Ltd + * 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 'Shaven Puppy' 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.vector; + +/** + * @author foo + */ +public interface ReadableVector3f extends ReadableVector2f { + /** + * @return z + */ + public float getZ(); +} \ No newline at end of file diff --git a/src/java/org/lwjgl/vector/ReadableVector4f.java b/src/java/org/lwjgl/vector/ReadableVector4f.java new file mode 100644 index 00000000..02f2350a --- /dev/null +++ b/src/java/org/lwjgl/vector/ReadableVector4f.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2003 Shaven Puppy Ltd + * 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 'Shaven Puppy' 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.vector; + +/** + * @author foo + */ +public interface ReadableVector4f extends ReadableVector3f { + + /** + * @return w + */ + public float getW(); + +} diff --git a/src/java/org/lwjgl/vector/Vector.java b/src/java/org/lwjgl/vector/Vector.java index 679f9221..f8ca851b 100644 --- a/src/java/org/lwjgl/vector/Vector.java +++ b/src/java/org/lwjgl/vector/Vector.java @@ -42,7 +42,7 @@ import java.nio.FloatBuffer; * @author cix_foo * @version $Revision$ */ -public abstract class Vector implements Serializable { +public abstract class Vector implements Serializable, ReadableVector { /** * Constructor for Vector. diff --git a/src/java/org/lwjgl/vector/Vector2f.java b/src/java/org/lwjgl/vector/Vector2f.java index e97d9eaf..845a666a 100644 --- a/src/java/org/lwjgl/vector/Vector2f.java +++ b/src/java/org/lwjgl/vector/Vector2f.java @@ -43,7 +43,7 @@ import java.nio.FloatBuffer; * @version $Revision$ */ -public class Vector2f extends Vector implements Serializable { +public class Vector2f extends Vector implements Serializable, ReadableVector2f { public float x, y; @@ -57,7 +57,7 @@ public class Vector2f extends Vector implements Serializable { /** * Constructor */ - public Vector2f(Vector2f src) { + public Vector2f(ReadableVector2f src) { set(src); } @@ -83,9 +83,9 @@ public class Vector2f extends Vector implements Serializable { * @param src The source vector * @return this */ - public Vector2f set(Vector2f src) { - x = src.x; - y = src.y; + public Vector2f set(ReadableVector2f src) { + x = src.getX(); + y = src.getY(); return this; } @@ -254,4 +254,35 @@ public class Vector2f extends Vector implements Serializable { 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; + } + } diff --git a/src/java/org/lwjgl/vector/Vector3f.java b/src/java/org/lwjgl/vector/Vector3f.java index 09526768..78fcb110 100644 --- a/src/java/org/lwjgl/vector/Vector3f.java +++ b/src/java/org/lwjgl/vector/Vector3f.java @@ -43,7 +43,7 @@ import java.nio.FloatBuffer; * @version $Revision$ */ -public class Vector3f extends Vector implements Serializable { +public class Vector3f extends Vector implements Serializable, ReadableVector3f { public float x, y, z; @@ -57,7 +57,7 @@ public class Vector3f extends Vector implements Serializable { /** * Constructor */ - public Vector3f(Vector3f src) { + public Vector3f(ReadableVector3f src) { set(src); } @@ -84,10 +84,10 @@ public class Vector3f extends Vector implements Serializable { * @param src The source vector * @return this */ - public Vector3f set(Vector3f src) { - x = src.x; - y = src.y; - z = src.z; + public Vector3f set(ReadableVector3f src) { + x = src.getX(); + y = src.getY(); + z = src.getZ(); return this; } @@ -290,5 +290,48 @@ public class Vector3f extends Vector implements Serializable { 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; + } } diff --git a/src/java/org/lwjgl/vector/Vector4f.java b/src/java/org/lwjgl/vector/Vector4f.java index 89b9844b..128bab17 100644 --- a/src/java/org/lwjgl/vector/Vector4f.java +++ b/src/java/org/lwjgl/vector/Vector4f.java @@ -43,7 +43,7 @@ import java.nio.FloatBuffer; * @version $Revision$ */ -public class Vector4f extends Vector implements Serializable { +public class Vector4f extends Vector implements Serializable, ReadableVector4f { public float x, y, z, w; @@ -57,7 +57,7 @@ public class Vector4f extends Vector implements Serializable { /** * Constructor */ - public Vector4f(Vector4f src) { + public Vector4f(ReadableVector4f src) { set(src); } @@ -85,11 +85,11 @@ public class Vector4f extends Vector implements Serializable { * @param src The source vector * @return this */ - public Vector4f set(Vector4f src) { - x = src.x; - y = src.y; - z = src.z; - w = src.w; + public Vector4f set(ReadableVector4f src) { + x = src.getX(); + y = src.getY(); + z = src.getZ(); + w = src.getW(); return this; } @@ -255,4 +255,66 @@ public class Vector4f extends Vector implements Serializable { 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; + } + + }