Started a rework.

-Upgraded: LWJGL3 to version 3.3.2
-Changed: Reworked to new formatting that i like.
-Started: New Gui System
This commit is contained in:
Speiger 2023-06-01 17:16:45 +02:00
parent 30b0cd7eb7
commit ba143d7d83
139 changed files with 3987 additions and 6859 deletions

View File

@ -1,4 +1,4 @@
org.gradle.jvmargs=-Xmx2G org.gradle.jvmargs=-Xmx2G
lwjglVersion = 3.2.4-SNAPSHOT lwjglVersion = 3.3.2
lwjglNatives = natives-windows lwjglNatives = natives-windows

View File

@ -14,10 +14,8 @@ public interface Vec
public Vec abs(); public Vec abs();
public Vec negate(); public Vec negate();
public Vec invert(); public Vec invert();
public Vec store(ByteBuffer buffer); public Vec store(ByteBuffer buffer);
public Vec load(ByteBuffer buffer); public Vec load(ByteBuffer buffer);
public boolean isMutable(); public boolean isMutable();
public Vec asMutable(); public Vec asMutable();
public Vec copyAsMutable(); public Vec copyAsMutable();

View File

@ -13,9 +13,4 @@ public class VectorUtil
float l3 = 1.0f - l1 - l2; float l3 = 1.0f - l1 - l2;
return l1 * p1.getY() + l2 * p2.getY() + l3 * p3.getY(); return l1 * p1.getY() + l2 * p2.getY() + l3 * p3.getY();
} }
public static float fma(float x, float y, float z)
{
return x * y + z;
}
} }

View File

@ -9,141 +9,120 @@ import speiger.src.coreengine.math.vector.ints.Vec2i;
import speiger.src.coreengine.math.vector.longs.Vec2l; import speiger.src.coreengine.math.vector.longs.Vec2l;
import speiger.src.coreengine.math.vector.shorts.Vec2s; import speiger.src.coreengine.math.vector.shorts.Vec2s;
public interface Vec2b extends Vecb {
public interface Vec2b extends Vecb
{
public static final Vec2b ZERO = of(); public static final Vec2b ZERO = of();
public static final Vec2b MINUS_ONE = of((byte)-1); public static final Vec2b MINUS_ONE = of((byte)-1);
public static final Vec2b ONE = of((byte)1); public static final Vec2b ONE = of((byte)1);
public static Vec2b mutable(){return new Vec2bMutable();} public static Vec2b mutable() { return new Vec2bMutable(); }
public static Vec2b mutable(byte value){return new Vec2bMutable(value);} public static Vec2b mutable(byte value) { return new Vec2bMutable(value); }
public static Vec2b mutable(byte x, byte y){return new Vec2bMutable(x, y);} public static Vec2b mutable(byte x, byte y) { return new Vec2bMutable(x, y); }
public static Vec2b mutable(Vec2b value){return mutable(value.getX(), value.getY());} public static Vec2b mutable(Vec2b value) { return mutable(value.getX(), value.getY()); }
public static Vec2b of(){return new Vec2bImmutable();} public static Vec2b of() { return new Vec2bImmutable(); }
public static Vec2b of(byte value){return new Vec2bImmutable(value);} public static Vec2b of(byte value) { return new Vec2bImmutable(value); }
public static Vec2b of(byte x, byte y){return new Vec2bImmutable(x, y);} public static Vec2b of(byte x, byte y) { return new Vec2bImmutable(x, y); }
public static Vec2b of(Vec2b value){return of(value.getX(), value.getY());} public static Vec2b of(Vec2b value) { return of(value.getX(), value.getY()); }
public byte getX(); public byte getX();
public byte getY(); public byte getY();
public Vec2b setX(byte x); public Vec2b setX(byte x);
public Vec2b setY(byte y); public Vec2b setY(byte y);
@Override @Override
public default byte[] asArray(){return new byte[]{getX(), getY()};} public default byte[] asArray() { return new byte[] {getX(), getY()}; }
@Override @Override
public Vec2b copy(); public Vec2b copy();
@Override @Override
public default Vec2b abs(){return set((byte)Math.abs(getX()), (byte)Math.abs(getY()));} public default Vec2b abs() { return set((byte)Math.abs(getX()), (byte)Math.abs(getY())); }
@Override @Override
public default Vec2b negate(){return set((byte)0, (byte)0);} public default Vec2b negate() { return set((byte)0, (byte)0); }
@Override @Override
public default Vec2b invert(){return set((byte)(-getX()), (byte)(-getY()));}; public default Vec2b invert() { return set((byte)(-getX()), (byte)(-getY())); };
@Override @Override
public default Vec2b add(byte value) {return add(value, value);} public default Vec2b add(byte value) { return add(value, value); }
public default Vec2b add(Vec2b value) {return add(value.getX(), value.getY());} public default Vec2b add(Vec2b value) { return add(value.getX(), value.getY()); }
public default Vec2b add(byte x, byte y) {return set((byte)(x + getX()), (byte)(y + getY()));} public default Vec2b add(byte x, byte y) { return set((byte)(x + getX()), (byte)(y + getY())); }
@Override @Override
public default Vec2b sub(byte value){return sub(value, value);} public default Vec2b sub(byte value) { return sub(value, value); }
public default Vec2b sub(Vec2b value){return sub(value.getX(), value.getY());} public default Vec2b sub(Vec2b value) { return sub(value.getX(), value.getY()); }
public default Vec2b sub(byte x, byte y) {return set((byte)(getX() - x), (byte)(getY() - y));} public default Vec2b sub(byte x, byte y) { return set((byte)(getX() - x), (byte)(getY() - y)); }
@Override @Override
public default Vec2b multiply(byte value){return multiply(value, value);} public default Vec2b multiply(byte value) { return multiply(value, value); }
public default Vec2b multiply(Vec2b value){return multiply(value.getX(), value.getY());} public default Vec2b multiply(Vec2b value) { return multiply(value.getX(), value.getY()); }
public default Vec2b multiply(byte x, byte y) {return set((byte)(x * getX()), (byte)(y * getY()));} public default Vec2b multiply(byte x, byte y) { return set((byte)(x * getX()), (byte)(y * getY())); }
@Override @Override
public default Vec2b devide(byte value){return devide(value, value);} public default Vec2b devide(byte value) { return devide(value, value); }
public default Vec2b devide(Vec2b value){return devide(value.getX(), value.getY());} public default Vec2b devide(Vec2b value) { return devide(value.getX(), value.getY()); }
public default Vec2b devide(byte x, byte y){return set((byte)(getX() / x), (byte)(getY() / y));} public default Vec2b devide(byte x, byte y) { return set((byte)(getX() / x), (byte)(getY() / y)); }
@Override @Override
public default Vec2b set(byte value){return set(value, value);}; public default Vec2b set(byte value) { return set(value, value); };
public default Vec2b set(Vec2b value){return set(value.getX(), value.getY());} public default Vec2b set(Vec2b value) { return set(value.getX(), value.getY()); }
public Vec2b set(byte x, byte y); public Vec2b set(byte x, byte y);
public default double distanceTo(Vec2b value) { return distanceTo(value.getX(), value.getY()); }
public default double distanceTo(Vec2b value){return distanceTo(value.getX(), value.getY());} public default double distanceTo(byte x, byte y) { return Math.sqrt(distanceToSquared(x, y)); }
public default double distanceTo(byte x, byte y){return Math.sqrt(distanceToSquared(x, y));} public default long distanceToSquared(Vec2b value) { return distanceToSquared(value.getX(), value.getY()); }
public default long distanceToSquared(byte x, byte y) {
public default long distanceToSquared(Vec2b value){return distanceToSquared(value.getX(), value.getY());}
public default long distanceToSquared(byte x, byte y)
{
long xPos = getX() - x; long xPos = getX() - x;
long yPos = getY() - y; long yPos = getY() - y;
return (xPos * xPos) + (yPos * yPos); return (xPos * xPos) + (yPos * yPos);
} }
@Override @Override
public default long lengthSquared() {return (getX() * getX()) + (getY() * getY());} public default long lengthSquared() { return (getX() * getX()) + (getY() * getY()); }
public default long dotProduct(Vec2b value) { return dotProduct(value.getX(), value.getY()); }
public default long dotProduct(Vec2b value){return dotProduct(value.getX(), value.getY());} public default long dotProduct(byte x, byte y) { return (getX() * x) + (getY() * y); }
public default long dotProduct(byte x, byte y){return (getX() * x) + (getY() * y);} public default Vec2b rotate(byte angle, Vec2b center) { return rotate(angle, center.getX(), center.getY()); }
public default Vec2b rotate(byte angle, byte x, byte y) {
public default Vec2b rotate(byte angle, Vec2b center){return rotate(angle, center.getX(), center.getY());}
public default Vec2b rotate(byte angle, byte x, byte y)
{
byte xPos = (byte)(getX() - x); byte xPos = (byte)(getX() - x);
byte yPos = (byte)(getY() - y); byte yPos = (byte)(getY() - y);
double cos = MathUtils.cos(angle); double cos = MathUtils.cos(angle);
double sin = MathUtils.sin(angle); double sin = MathUtils.sin(angle);
return set((byte)((xPos * cos) + (yPos * sin) + x), (byte)(-(xPos * sin) + (yPos * cos) + y)); return set((byte)((xPos * cos) + (yPos * sin) + x), (byte)(-(xPos * sin) + (yPos * cos) + y));
} }
public default Vec2b min(Vec2b other) {return min(other, this);} public default Vec2b min(Vec2b other) { return min(other, this); }
public default Vec2b min(Vec2b other, Vec2b result){return min(other.getX(), other.getY(), result);} public default Vec2b min(Vec2b other, Vec2b result) { return min(other.getX(), other.getY(), result); }
public default Vec2b min(byte x, byte y) {return min(x, y, this);} public default Vec2b min(byte x, byte y) { return min(x, y, this); }
public default Vec2b min(byte x, byte y, Vec2b result){return result.set((byte)Math.min(getX(), x), (byte)Math.min(getY(), y));} public default Vec2b min(byte x, byte y, Vec2b result) { return result.set((byte)Math.min(getX(), x), (byte)Math.min(getY(), y)); }
public default Vec2b max(Vec2b other) { return max(other, this); }
public default Vec2b max(Vec2b other) {return max(other, this);} public default Vec2b max(Vec2b other, Vec2b result) { return max(other.getX(), other.getY(), result); }
public default Vec2b max(Vec2b other, Vec2b result){return max(other.getX(), other.getY(), result);} public default Vec2b max(byte x, byte y) { return max(x, y, this); }
public default Vec2b max(byte x, byte y) {return max(x, y, this);} public default Vec2b max(byte x, byte y, Vec2b result) { return result.set((byte)Math.max(getX(), x), (byte)Math.max(getY(), y)); }
public default Vec2b max(byte x, byte y, Vec2b result){return result.set((byte)Math.max(getX(), x), (byte)Math.max(getY(), y));} public default Vec2b difference(Vec2b other) { return difference(other, this); }
public default Vec2b difference(Vec2b other, Vec2b result) { return difference(other.getX(), other.getY(), result); }
public default Vec2b difference(Vec2b other) {return difference(other, this);} public default Vec2b difference(byte x, byte y) { return difference(x, y, this); }
public default Vec2b difference(Vec2b other, Vec2b result){return difference(other.getX(), other.getY(), result);} public default Vec2b difference(byte x, byte y, Vec2b result) { return result.set((byte)(getX() - x), (byte)(getY() - y)); }
public default Vec2b difference(byte x, byte y) {return difference(x, y, this);}
public default Vec2b difference(byte x, byte y, Vec2b result){return result.set((byte)(getX() - x), (byte)(getY() - y));}
@Override @Override
public default Vec2b clamp(byte min, byte max){return clamp(min, max, ALL);} public default Vec2b clamp(byte min, byte max) { return clamp(min, max, ALL); }
public default Vec2b clamp(byte min, byte max, Vec2b result){return clamp(min, max, result, ALL);} public default Vec2b clamp(byte min, byte max, Vec2b result) { return clamp(min, max, result, ALL); }
@Override @Override
public default Vec2b clamp(byte min, byte max, int filter){return clamp(min, max, this, filter);} public default Vec2b clamp(byte min, byte max, int filter) { return clamp(min, max, this, filter); }
public default Vec2b clamp(byte min, byte max, Vec2b result, int filter){ return result.set((filter & X) == 0 ? getX() : MathUtils.clamp(min, max, getX()), (filter & Y) == 0 ? getY() : MathUtils.clamp(min, max, getY()));} public default Vec2b clamp(byte min, byte max, Vec2b result, int filter) { return result.set((filter & X) == 0 ? getX() : MathUtils.clamp(min, max, getX()), (filter & Y) == 0 ? getY() : MathUtils.clamp(min, max, getY())); }
@Override @Override
public default Vec2b store(ByteBuffer buffer) public default Vec2b store(ByteBuffer buffer) {
{
buffer.put(getX()).put(getY()); buffer.put(getX()).put(getY());
return this; return this;
} }
@Override
public default Vec2b load(ByteBuffer buffer) { return set(buffer.get(), buffer.get()); }
@Override @Override
public default Vec2b load(ByteBuffer buffer) public default Vec2s asShort() { return isMutable() ? Vec2s.mutable(getX(), getY()) : Vec2s.of(getX(), getY()); }
{
return set(buffer.get(), buffer.get());
}
@Override @Override
public default Vec2s asShort(){return isMutable() ? Vec2s.mutable(getX(), getY()) : Vec2s.of(getX(), getY());} public default Vec2i asInt() { return isMutable() ? Vec2i.mutable(getX(), getY()) : Vec2i.of(getX(), getY()); }
@Override @Override
public default Vec2i asInt(){return isMutable() ? Vec2i.mutable(getX(), getY()) : Vec2i.of(getX(), getY());} public default Vec2l asLong() { return isMutable() ? Vec2l.mutable(getX(), getY()) : Vec2l.of(getX(), getY()); }
@Override @Override
public default Vec2l asLong(){return isMutable() ? Vec2l.mutable(getX(), getY()) : Vec2l.of(getX(), getY());} public default Vec2f asFloat() { return isMutable() ? Vec2f.mutable(getX(), getY()) : Vec2f.of(getX(), getY()); }
@Override @Override
public default Vec2f asFloat() {return isMutable() ? Vec2f.mutable(getX(), getY()) : Vec2f.of(getX(), getY());} public default Vec2d asDouble() { return isMutable() ? Vec2d.mutable(getX(), getY()) : Vec2d.of(getX(), getY()); }
@Override @Override
public default Vec2d asDouble(){return isMutable() ? Vec2d.mutable(getX(), getY()) : Vec2d.of(getX(), getY());} public default Vec2b asMutable() { return isMutable() ? this : mutable(this); }
@Override @Override
public default Vec2b asMutable(){return isMutable() ? this : mutable(this);} public default Vec2b asImmutable() { return isMutable() ? of(this) : this; }
@Override @Override
public default Vec2b asImmutable(){return isMutable() ? of(this) : this;} public default Vec2b copyAsMutable() { return mutable(this); }
@Override @Override
public default Vec2b copyAsMutable(){return mutable(this);} public default Vec2b copyAsImmutable() { return of(this); }
@Override
public default Vec2b copyAsImmutable(){return of(this);}
} }

View File

@ -2,91 +2,50 @@ package speiger.src.coreengine.math.vector.bytes;
import java.util.Objects; import java.util.Objects;
public class Vec2bImmutable implements Vec2b public class Vec2bImmutable implements Vec2b {
{
final byte x; final byte x;
final byte y; final byte y;
public Vec2bImmutable() public Vec2bImmutable() {
{
x = 0; x = 0;
y = 0; y = 0;
} }
public Vec2bImmutable(byte value) public Vec2bImmutable(byte value) {
{
x = value; x = value;
y = value; y = value;
} }
public Vec2bImmutable(byte x, byte y) public Vec2bImmutable(byte x, byte y) {
{
this.x = x; this.x = x;
this.y = y; this.y = y;
} }
@Override
public boolean isMutable()
{
return false;
}
@Override @Override
public byte getX() public boolean isMutable() { return false; }
{
return x;
}
@Override @Override
public byte getY() public byte getX() { return x; }
{
return y;
}
@Override @Override
public Vec2b setX(byte x) public byte getY() { return y; }
{
return this.x == x ? this : Vec2b.of(x, y);
}
@Override @Override
public Vec2b setY(byte y) public Vec2b setX(byte x) { return this.x == x ? this : Vec2b.of(x, y); }
{
return this.y == y ? this : Vec2b.of(x, y);
}
@Override @Override
public Vec2b copy() public Vec2b setY(byte y) { return this.y == y ? this : Vec2b.of(x, y); }
{
return Vec2b.of(this);
}
@Override @Override
public Vec2b set(byte x, byte y) public Vec2b copy() { return Vec2b.of(this); }
{
return this.x == x && this.y == y ? this : Vec2b.of(x, y);
}
@Override @Override
public int hashCode() public Vec2b set(byte x, byte y) { return this.x == x && this.y == y ? this : Vec2b.of(x, y); }
{
return Objects.hash(x, y);
}
@Override @Override
public boolean equals(Object obj) public int hashCode() { return Objects.hash(x, y); }
{ @Override
if(obj instanceof Vec2b) public boolean equals(Object obj) {
{ if(obj instanceof Vec2b) {
Vec2b vec = (Vec2b)obj; Vec2b vec = (Vec2b)obj;
return vec.getX() == x && vec.getY() == y; return vec.getX() == x && vec.getY() == y;
} }
return false; return false;
} }
@Override @Override
public String toString() public String toString() { return "Vec2b[x="+x+", y="+y+"]"; }
{
return "Vec2b[x="+x+", y="+y+"]";
}
} }

View File

@ -2,93 +2,63 @@ package speiger.src.coreengine.math.vector.bytes;
import java.util.Objects; import java.util.Objects;
public class Vec2bMutable implements Vec2b public class Vec2bMutable implements Vec2b {
{
byte x; byte x;
byte y; byte y;
public Vec2bMutable() public Vec2bMutable() {}
{
}
public Vec2bMutable(byte value) public Vec2bMutable(byte value) {
{
x = value; x = value;
y = value; y = value;
} }
public Vec2bMutable(byte x, byte y) public Vec2bMutable(byte x, byte y) {
{
this.x = x; this.x = x;
this.y = y; this.y = y;
} }
@Override
public boolean isMutable()
{
return true;
}
@Override @Override
public byte getX() public boolean isMutable() { return true; }
{ @Override
return x; public byte getX() { return x; }
} @Override
public byte getY() { return y; }
@Override @Override
public byte getY() public Vec2b setX(byte x) {
{
return y;
}
@Override
public Vec2b setX(byte x)
{
this.x = x; this.x = x;
return this; return this;
} }
@Override @Override
public Vec2b setY(byte y) public Vec2b setY(byte y) {
{
this.y = y; this.y = y;
return this; return this;
} }
@Override @Override
public Vec2b copy() public Vec2b copy() { return Vec2b.mutable(this); }
{
return Vec2b.mutable(this);
}
@Override @Override
public Vec2b set(byte x, byte y) public Vec2b set(byte x, byte y) {
{
this.x = x; this.x = x;
this.y = y; this.y = y;
return this; return this;
} }
@Override @Override
public int hashCode() public int hashCode() { return Objects.hash(x, y); }
{
return Objects.hash(x, y);
}
@Override @Override
public boolean equals(Object obj) public boolean equals(Object obj) {
{ if(obj instanceof Vec2b) {
if(obj instanceof Vec2b)
{
Vec2b vec = (Vec2b)obj; Vec2b vec = (Vec2b)obj;
return vec.getX() == x && vec.getY() == y; return vec.getX() == x && vec.getY() == y;
} }
return false; return false;
} }
@Override @Override
public String toString() public String toString() { return "Vec2b[x="+x+", y="+y+"]"; }
{
return "Vec2b[x="+x+", y="+y+"]";
}
} }

View File

@ -9,21 +9,19 @@ import speiger.src.coreengine.math.vector.ints.Vec3i;
import speiger.src.coreengine.math.vector.longs.Vec3l; import speiger.src.coreengine.math.vector.longs.Vec3l;
import speiger.src.coreengine.math.vector.shorts.Vec3s; import speiger.src.coreengine.math.vector.shorts.Vec3s;
public interface Vec3b extends Vecb public interface Vec3b extends Vecb {
{
public static final Vec3b ZERO = of(); public static final Vec3b ZERO = of();
public static final Vec3b MINUS_ONE = of((byte)-1); public static final Vec3b MINUS_ONE = of((byte)-1);
public static final Vec3b ONE = of((byte)1); public static final Vec3b ONE = of((byte)1);
public static Vec3b mutable(){return new Vec3bMutable();} public static Vec3b mutable() { return new Vec3bMutable(); }
public static Vec3b mutable(byte value){return new Vec3bMutable(value);} public static Vec3b mutable(byte value) { return new Vec3bMutable(value); }
public static Vec3b mutable(byte x, byte y, byte z){return new Vec3bMutable(x, y, z);} public static Vec3b mutable(byte x, byte y, byte z) { return new Vec3bMutable(x, y, z); }
public static Vec3b mutable(Vec3b vec){return mutable(vec.getX(), vec.getY(), vec.getZ());} public static Vec3b mutable(Vec3b vec) { return mutable(vec.getX(), vec.getY(), vec.getZ()); }
public static Vec3b of() { return new Vec3bImmutable(); }
public static Vec3b of(){return new Vec3bImmutable();} public static Vec3b of(byte value) { return new Vec3bImmutable(value); }
public static Vec3b of(byte value){return new Vec3bImmutable(value);} public static Vec3b of(byte x, byte y, byte z) { return new Vec3bImmutable(x, y, z); }
public static Vec3b of(byte x, byte y, byte z){return new Vec3bImmutable(x, y, z);} public static Vec3b of(Vec3b vec) { return of(vec.getX(), vec.getY(), vec.getZ()); }
public static Vec3b of(Vec3b vec){return of(vec.getX(), vec.getY(), vec.getZ());}
public byte getX(); public byte getX();
public byte getY(); public byte getY();
@ -31,111 +29,95 @@ public interface Vec3b extends Vecb
public Vec3b setX(byte x); public Vec3b setX(byte x);
public Vec3b setY(byte y); public Vec3b setY(byte y);
public Vec3b setZ(byte z); public Vec3b setZ(byte z);
@Override
public default byte[] asArray(){return new byte[]{getX(), getY(), getZ()};}
@Override
public default byte[] asArray() { return new byte[] {getX(), getY(), getZ()}; }
@Override @Override
public Vec3b copy(); public Vec3b copy();
@Override @Override
public default Vec3b abs(){return set((byte)Math.abs(getX()), (byte)Math.abs(getY()), (byte)Math.abs(getZ()));} public default Vec3b abs() { return set((byte)Math.abs(getX()), (byte)Math.abs(getY()), (byte)Math.abs(getZ())); }
@Override @Override
public default Vec3b negate(){return set((byte)0, (byte)0, (byte)0);} public default Vec3b negate() { return set((byte)0, (byte)0, (byte)0); }
@Override @Override
public default Vec3b invert(){return set((byte)-getX(), (byte)-getY(), (byte)-getZ());} public default Vec3b invert() { return set((byte)-getX(), (byte)-getY(), (byte)-getZ()); }
@Override @Override
public default Vec3b add(byte value){return add(value, value, value);} public default Vec3b add(byte value) { return add(value, value, value); }
public default Vec3b add(Vec3b value){return add(value.getX(), value.getY(), value.getZ());} public default Vec3b add(Vec3b value) { return add(value.getX(), value.getY(), value.getZ()); }
public default Vec3b add(byte x, byte y, byte z){return set((byte)(getX() + x), (byte)(getY() + y), (byte)(getZ() + z));} public default Vec3b add(byte x, byte y, byte z) { return set((byte)(getX() + x), (byte)(getY() + y), (byte)(getZ() + z)); }
@Override @Override
public default Vec3b sub(byte value){return sub(value, value, value);} public default Vec3b sub(byte value) { return sub(value, value, value); }
public default Vec3b sub(Vec3b value){return sub(value.getX(), value.getY(), value.getZ());} public default Vec3b sub(Vec3b value) { return sub(value.getX(), value.getY(), value.getZ()); }
public default Vec3b sub(byte x, byte y, byte z){return set((byte)(getX() - x), (byte)(getY() - y), (byte)(getZ() - z));} public default Vec3b sub(byte x, byte y, byte z) { return set((byte)(getX() - x), (byte)(getY() - y), (byte)(getZ() - z)); }
@Override @Override
public default Vec3b multiply(byte value){return multiply(value, value, value);} public default Vec3b multiply(byte value) { return multiply(value, value, value); }
public default Vec3b multiply(Vec3b value){return multiply(value.getX(), value.getY(), value.getZ());} public default Vec3b multiply(Vec3b value) { return multiply(value.getX(), value.getY(), value.getZ()); }
public default Vec3b multiply(byte x, byte y, byte z){return set((byte)(getX() * x), (byte)(getY() * y), (byte)(getZ() * z));} public default Vec3b multiply(byte x, byte y, byte z) { return set((byte)(getX() * x), (byte)(getY() * y), (byte)(getZ() * z)); }
@Override @Override
public default Vec3b devide(byte value){return devide(value, value, value);} public default Vec3b devide(byte value) { return devide(value, value, value); }
public default Vec3b devide(Vec3b value){return devide(value.getX(), value.getY(), value.getZ());} public default Vec3b devide(Vec3b value) { return devide(value.getX(), value.getY(), value.getZ()); }
public default Vec3b devide(byte x, byte y, byte z){return set((byte)(getX() / x), (byte)(getY() / y), (byte)(getZ() / z));} public default Vec3b devide(byte x, byte y, byte z) { return set((byte)(getX() / x), (byte)(getY() / y), (byte)(getZ() / z)); }
@Override @Override
public default Vec3b set(byte value){return set(value, value, value);} public default Vec3b set(byte value) { return set(value, value, value); }
public default Vec3b set(Vec3b value){return set(value.getX(), value.getY(), value.getZ());} public default Vec3b set(Vec3b value) { return set(value.getX(), value.getY(), value.getZ()); }
public Vec3b set(byte x, byte y, byte z); public Vec3b set(byte x, byte y, byte z);
public default double distanceTo(Vec3b value) { return distanceTo(value.getX(), value.getY(), value.getZ()); }
public default double distanceTo(byte x, byte y, byte z) { return Math.sqrt(distanceToSquared(x, y, z)); }
public default long distanceToSquared(Vec3b value) { return distanceToSquared(value.getX(), value.getY(), value.getZ()); }
public default double distanceTo(Vec3b value){return distanceTo(value.getX(), value.getY(), value.getZ());} public default long distanceToSquared(byte x, byte y, byte z) {
public default double distanceTo(byte x, byte y, byte z){return Math.sqrt(distanceToSquared(x, y, z));}
public default long distanceToSquared(Vec3b value){return distanceToSquared(value.getX(), value.getY(), value.getZ());}
public default long distanceToSquared(byte x, byte y, byte z)
{
long xPos = getX() - x; long xPos = getX() - x;
long yPos = getY() - y; long yPos = getY() - y;
long zPos = getZ() - z; long zPos = getZ() - z;
return (xPos * xPos) + (yPos * yPos) + (zPos * zPos); return (xPos * xPos) + (yPos * yPos) + (zPos * zPos);
} }
@Override
public default long lengthSquared() {return (getX() * getX()) + (getY() * getY()) + (getZ() * getZ());}
public default long dotProduct(Vec3b value){return dotProduct(value.getX(), value.getY(), value.getZ());}
public default long dotProduct(byte x, byte y, byte z){return (getX() * x) + (getY() * y) + (getZ() * z);}
public default Vec3b min(Vec3b other) {return min(other, this);}
public default Vec3b min(Vec3b other, Vec3b result){return min(other.getX(), other.getY(), other.getZ(), result);}
public default Vec3b min(byte x, byte y, byte z) {return min(x, y, z, this);}
public default Vec3b min(byte x, byte y, byte z, Vec3b result){return result.set((byte)Math.min(getX(), x), (byte)Math.min(getY(), y), (byte)Math.min(getZ(), z));}
public default Vec3b max(Vec3b other) {return max(other, this);}
public default Vec3b max(Vec3b other, Vec3b result){return max(other.getX(), other.getY(), other.getZ(), result);}
public default Vec3b max(byte x, byte y, byte z) {return max(x, y, z, this);}
public default Vec3b max(byte x, byte y, byte z, Vec3b result){return result.set((byte)Math.max(getX(), x), (byte)Math.max(getY(), y), (byte)Math.max(getZ(), z));}
public default Vec3b difference(Vec3b other) {return difference(other, this);}
public default Vec3b difference(Vec3b other, Vec3b result){return difference(other.getX(), other.getY(), other.getZ(), result);}
public default Vec3b difference(byte x, byte y, byte z) {return difference(x, y, z, this);}
public default Vec3b difference(byte x, byte y, byte z, Vec3b result){return result.set((byte)(getX() - x), (byte)(getY() - y), (byte)(getZ() - z));}
@Override @Override
public default Vec3b clamp(byte min, byte max){return clamp(min, max, ALL);} public default long lengthSquared() { return (getX() * getX()) + (getY() * getY()) + (getZ() * getZ()); }
public default Vec3b clamp(byte min, byte max, Vec3b result){return clamp(min, max, result, ALL);} public default long dotProduct(Vec3b value) { return dotProduct(value.getX(), value.getY(), value.getZ()); }
public default long dotProduct(byte x, byte y, byte z) { return (getX() * x) + (getY() * y) + (getZ() * z); }
public default Vec3b min(Vec3b other) { return min(other, this); }
public default Vec3b min(Vec3b other, Vec3b result) { return min(other.getX(), other.getY(), other.getZ(), result); }
public default Vec3b min(byte x, byte y, byte z) { return min(x, y, z, this); }
public default Vec3b min(byte x, byte y, byte z, Vec3b result) { return result.set((byte)Math.min(getX(), x), (byte)Math.min(getY(), y), (byte)Math.min(getZ(), z)); }
public default Vec3b max(Vec3b other) { return max(other, this); }
public default Vec3b max(Vec3b other, Vec3b result) { return max(other.getX(), other.getY(), other.getZ(), result); }
public default Vec3b max(byte x, byte y, byte z) { return max(x, y, z, this); }
public default Vec3b max(byte x, byte y, byte z, Vec3b result) { return result.set((byte)Math.max(getX(), x), (byte)Math.max(getY(), y), (byte)Math.max(getZ(), z)); }
public default Vec3b difference(Vec3b other) { return difference(other, this); }
public default Vec3b difference(Vec3b other, Vec3b result) { return difference(other.getX(), other.getY(), other.getZ(), result); }
public default Vec3b difference(byte x, byte y, byte z) { return difference(x, y, z, this); }
public default Vec3b difference(byte x, byte y, byte z, Vec3b result) { return result.set((byte)(getX() - x), (byte)(getY() - y), (byte)(getZ() - z)); }
@Override @Override
public default Vec3b clamp(byte min, byte max, int filter){return clamp(min, max, this, filter);} public default Vec3b clamp(byte min, byte max) { return clamp(min, max, ALL); }
public default Vec3b clamp(byte min, byte max, Vec3b result, int filter){ return result.set((filter & X) == 0 ? getX() : MathUtils.clamp(min, max, getX()), (filter & Y) == 0 ? getY() : MathUtils.clamp(min, max, getY()), (filter & Z) == 0 ? getZ() : MathUtils.clamp(min, max, getZ()));} public default Vec3b clamp(byte min, byte max, Vec3b result) { return clamp(min, max, result, ALL); }
@Override
public default Vec3b clamp(byte min, byte max, int filter) { return clamp(min, max, this, filter); }
public default Vec3b clamp(byte min, byte max, Vec3b result, int filter) { return result.set((filter & X) == 0 ? getX() : MathUtils.clamp(min, max, getX()), (filter & Y) == 0 ? getY() : MathUtils.clamp(min, max, getY()), (filter & Z) == 0 ? getZ() : MathUtils.clamp(min, max, getZ())); }
@Override @Override
public default Vec3b store(ByteBuffer buffer) public default Vec3b store(ByteBuffer buffer) {
{
buffer.put(getX()).put(getY()).put(getZ()); buffer.put(getX()).put(getY()).put(getZ());
return this; return this;
} }
@Override @Override
public default Vec3b load(ByteBuffer buffer) public default Vec3b load(ByteBuffer buffer) { return set(buffer.get(), buffer.get(), buffer.get()); }
{
return set(buffer.get(), buffer.get(), buffer.get());
}
@Override @Override
public default Vec3s asShort(){return isMutable() ? Vec3s.mutable(getX(), getY(), getZ()) : Vec3s.of(getX(), getY(), getZ());} public default Vec3s asShort() { return isMutable() ? Vec3s.mutable(getX(), getY(), getZ()) : Vec3s.of(getX(), getY(), getZ()); }
@Override @Override
public default Vec3i asInt(){return isMutable() ? Vec3i.mutable(getX(), getY(), getZ()) : Vec3i.of(getX(), getY(), getZ());} public default Vec3i asInt() { return isMutable() ? Vec3i.mutable(getX(), getY(), getZ()) : Vec3i.of(getX(), getY(), getZ()); }
@Override @Override
public default Vec3l asLong(){return isMutable() ? Vec3l.mutable(getX(), getY(), getZ()) : Vec3l.of(getX(), getY(), getZ());} public default Vec3l asLong() { return isMutable() ? Vec3l.mutable(getX(), getY(), getZ()) : Vec3l.of(getX(), getY(), getZ()); }
@Override @Override
public default Vec3f asFloat() {return isMutable() ? Vec3f.mutable(getX(), getY(), getZ()) : Vec3f.of(getX(), getY(), getZ());} public default Vec3f asFloat() { return isMutable() ? Vec3f.mutable(getX(), getY(), getZ()) : Vec3f.of(getX(), getY(), getZ()); }
@Override @Override
public default Vec3d asDouble(){return isMutable() ? Vec3d.mutable(getX(), getY(), getZ()) : Vec3d.of(getX(), getY(), getZ());} public default Vec3d asDouble() { return isMutable() ? Vec3d.mutable(getX(), getY(), getZ()) : Vec3d.of(getX(), getY(), getZ()); }
@Override @Override
public default Vec3b asMutable(){return isMutable() ? this : mutable(this);} public default Vec3b asMutable() { return isMutable() ? this : mutable(this); }
@Override @Override
public default Vec3b asImmutable(){return isMutable() ? of(this) : this;} public default Vec3b asImmutable() { return isMutable() ? of(this) : this; }
@Override @Override
public default Vec3b copyAsMutable(){return mutable(this);} public default Vec3b copyAsMutable() { return mutable(this); }
@Override @Override
public default Vec3b copyAsImmutable(){return of(this);} public default Vec3b copyAsImmutable() { return of(this); }
} }

View File

@ -2,107 +2,58 @@ package speiger.src.coreengine.math.vector.bytes;
import java.util.Objects; import java.util.Objects;
public class Vec3bImmutable implements Vec3b public class Vec3bImmutable implements Vec3b {
{
final byte x; final byte x;
final byte y; final byte y;
final byte z; final byte z;
public Vec3bImmutable() public Vec3bImmutable() {
{
x = 0; x = 0;
y = 0; y = 0;
z = 0; z = 0;
} }
public Vec3bImmutable(byte value) public Vec3bImmutable(byte value) {
{
x = value; x = value;
y = value; y = value;
z = value; z = value;
} }
public Vec3bImmutable(byte x, byte y, byte z) public Vec3bImmutable(byte x, byte y, byte z) {
{
this.x = x; this.x = x;
this.y = y; this.y = y;
this.z = z; this.z = z;
} }
@Override
public boolean isMutable()
{
return false;
}
@Override @Override
public byte getX() public boolean isMutable() { return false; }
{
return x;
}
@Override @Override
public byte getY() public byte getX() { return x; }
{
return y;
}
@Override @Override
public byte getZ() public byte getY() { return y; }
{
return z;
}
@Override @Override
public Vec3b setX(byte x) public byte getZ() { return z; }
{
return this.x == x ? this : Vec3b.of(x, y, z);
}
@Override @Override
public Vec3b setY(byte y) public Vec3b setX(byte x) { return this.x == x ? this : Vec3b.of(x, y, z); }
{
return this.y == y ? this : Vec3b.of(x, y, z);
}
@Override @Override
public Vec3b setZ(byte z) public Vec3b setY(byte y) { return this.y == y ? this : Vec3b.of(x, y, z); }
{
return this.z == z ? this : Vec3b.of(x, y, z);
}
@Override @Override
public Vec3b copy() public Vec3b setZ(byte z) { return this.z == z ? this : Vec3b.of(x, y, z); }
{
return Vec3b.of(this);
}
@Override @Override
public Vec3b set(byte x, byte y, byte z) public Vec3b copy() { return Vec3b.of(this); }
{
return this.x == x && this.y == y && this.z == z ? this : Vec3b.of(x, y, z);
}
@Override @Override
public int hashCode() public Vec3b set(byte x, byte y, byte z) { return this.x == x && this.y == y && this.z == z ? this : Vec3b.of(x, y, z); }
{
return Objects.hash(x, y, z);
}
@Override @Override
public boolean equals(Object obj) public int hashCode() { return Objects.hash(x, y, z); }
{ @Override
if(obj instanceof Vec3b) public boolean equals(Object obj) {
{ if(obj instanceof Vec3b) {
Vec3b vec = (Vec3b)obj; Vec3b vec = (Vec3b)obj;
return vec.getX() == x && vec.getY() == y && vec.getZ() == z; return vec.getX() == x && vec.getY() == y && vec.getZ() == z;
} }
return false; return false;
} }
@Override @Override
public String toString() public String toString() { return "Vec3b[x="+x+", y="+y+", z="+z+"]"; }
{
return "Vec3b[x="+x+", y="+y+", z="+z+"]";
}
} }

View File

@ -2,84 +2,57 @@ package speiger.src.coreengine.math.vector.bytes;
import java.util.Objects; import java.util.Objects;
public class Vec3bMutable implements Vec3b public class Vec3bMutable implements Vec3b {
{
byte x; byte x;
byte y; byte y;
byte z; byte z;
public Vec3bMutable() public Vec3bMutable() {}
{
}
public Vec3bMutable(byte value) public Vec3bMutable(byte value) {
{
x = value; x = value;
y = value; y = value;
z = value; z = value;
} }
public Vec3bMutable(byte x, byte y, byte z) public Vec3bMutable(byte x, byte y, byte z) {
{
this.x = x; this.x = x;
this.y = y; this.y = y;
this.z = z; this.z = z;
} }
@Override
public boolean isMutable()
{
return true;
}
@Override @Override
public byte getX() public boolean isMutable() { return true; }
{ @Override
return x; public byte getX() { return x; }
} @Override
public byte getY() { return y; }
@Override
public byte getZ() { return z; }
@Override @Override
public byte getY() public Vec3b setX(byte x) {
{
return y;
}
@Override
public byte getZ()
{
return z;
}
@Override
public Vec3b setX(byte x)
{
this.x = x; this.x = x;
return this; return this;
} }
@Override @Override
public Vec3b setY(byte y) public Vec3b setY(byte y) {
{
this.y = y; this.y = y;
return this; return this;
} }
@Override @Override
public Vec3b setZ(byte z) public Vec3b setZ(byte z) {
{
this.z = z; this.z = z;
return this; return this;
} }
@Override @Override
public Vec3b copy() public Vec3b copy() { return Vec3b.mutable(this); }
{
return Vec3b.mutable(this);
}
@Override @Override
public Vec3b set(byte x, byte y, byte z) public Vec3b set(byte x, byte y, byte z) {
{
this.x = x; this.x = x;
this.y = y; this.y = y;
this.z = z; this.z = z;
@ -87,25 +60,17 @@ public class Vec3bMutable implements Vec3b
} }
@Override @Override
public int hashCode() public int hashCode() { return Objects.hash(x, y, z); }
{
return Objects.hash(x, y, z);
}
@Override @Override
public boolean equals(Object obj) public boolean equals(Object obj) {
{ if(obj instanceof Vec3b) {
if(obj instanceof Vec3b)
{
Vec3b vec = (Vec3b)obj; Vec3b vec = (Vec3b)obj;
return vec.getX() == x && vec.getY() == y && vec.getZ() == z; return vec.getX() == x && vec.getY() == y && vec.getZ() == z;
} }
return false; return false;
} }
@Override @Override
public String toString() public String toString() { return "Vec3b[x="+x+", y="+y+", z="+z+"]"; }
{
return "Vec3b[x="+x+", y="+y+", z="+z+"]";
}
} }

View File

@ -9,21 +9,19 @@ import speiger.src.coreengine.math.vector.ints.Vec4i;
import speiger.src.coreengine.math.vector.longs.Vec4l; import speiger.src.coreengine.math.vector.longs.Vec4l;
import speiger.src.coreengine.math.vector.shorts.Vec4s; import speiger.src.coreengine.math.vector.shorts.Vec4s;
public interface Vec4b extends Vecb public interface Vec4b extends Vecb {
{
public static final Vec4b ZERO = of(); public static final Vec4b ZERO = of();
public static final Vec4b MINUS_ONE = of((byte)-1); public static final Vec4b MINUS_ONE = of((byte)-1);
public static final Vec4b ONE = of((byte)1); public static final Vec4b ONE = of((byte)1);
public static Vec4b mutable(){return new Vec4bMutable();} public static Vec4b mutable() { return new Vec4bMutable(); }
public static Vec4b mutable(byte value){return new Vec4bMutable(value);} public static Vec4b mutable(byte value) { return new Vec4bMutable(value); }
public static Vec4b mutable(byte x, byte y, byte z, byte w){return new Vec4bMutable(x, y, z, w);} public static Vec4b mutable(byte x, byte y, byte z, byte w) { return new Vec4bMutable(x, y, z, w); }
public static Vec4b mutable(Vec4b vec){return mutable(vec.getX(), vec.getY(), vec.getZ(), vec.getW());} public static Vec4b mutable(Vec4b vec) { return mutable(vec.getX(), vec.getY(), vec.getZ(), vec.getW()); }
public static Vec4b of() { return new Vec4bImmutable(); }
public static Vec4b of(){return new Vec4bImmutable();} public static Vec4b of(byte value) { return new Vec4bImmutable(value); }
public static Vec4b of(byte value){return new Vec4bImmutable(value);} public static Vec4b of(byte x, byte y, byte z, byte w) { return new Vec4bImmutable(x, y, z, w); }
public static Vec4b of(byte x, byte y, byte z, byte w){return new Vec4bImmutable(x, y, z, w);} public static Vec4b of(Vec4b vec) { return of(vec.getX(), vec.getY(), vec.getZ(), vec.getW()); }
public static Vec4b of(Vec4b vec){return of(vec.getX(), vec.getY(), vec.getZ(), vec.getW());}
public byte getX(); public byte getX();
public byte getY(); public byte getY();
@ -33,113 +31,93 @@ public interface Vec4b extends Vecb
public Vec4b setY(byte y); public Vec4b setY(byte y);
public Vec4b setZ(byte z); public Vec4b setZ(byte z);
public Vec4b setW(byte w); public Vec4b setW(byte w);
@Override @Override
public default byte[] asArray(){return new byte[]{getX(), getY(), getZ(), getW()};} public default byte[] asArray() { return new byte[] {getX(), getY(), getZ(), getW()}; }
@Override @Override
public Vec4b copy(); public Vec4b copy();
@Override @Override
public default Vec4b abs(){return set((byte)Math.abs(getX()), (byte)Math.abs(getY()), (byte)Math.abs(getZ()), (byte)Math.abs(getW()));} public default Vec4b abs() { return set((byte)Math.abs(getX()), (byte)Math.abs(getY()), (byte)Math.abs(getZ()), (byte)Math.abs(getW())); }
@Override @Override
public default Vec4b negate(){return set((byte)0, (byte)0, (byte)0, (byte)0);} public default Vec4b negate() { return set((byte)0, (byte)0, (byte)0, (byte)0); }
@Override @Override
public default Vec4b invert(){return set((byte)-getX(), (byte)-getY(), (byte)-getZ(), (byte)-getW());} public default Vec4b invert() { return set((byte)-getX(), (byte)-getY(), (byte)-getZ(), (byte)-getW()); }
@Override @Override
public default Vec4b add(byte value){return add(value, value, value, value);} public default Vec4b add(byte value) { return add(value, value, value, value); }
public default Vec4b add(Vec4b value){return add(value.getX(), value.getY(), value.getZ(), value.getW());} public default Vec4b add(Vec4b value) { return add(value.getX(), value.getY(), value.getZ(), value.getW()); }
public default Vec4b add(byte x, byte y, byte z, byte w){return set((byte)(getX() + x), (byte)(getY() + y), (byte)(getZ() + z), (byte)(getW() + w));} public default Vec4b add(byte x, byte y, byte z, byte w) { return set((byte)(getX() + x), (byte)(getY() + y), (byte)(getZ() + z), (byte)(getW() + w)); }
@Override @Override
public default Vec4b sub(byte value){return sub(value, value, value, value);} public default Vec4b sub(byte value) { return sub(value, value, value, value); }
public default Vec4b sub(Vec4b value){return sub(value.getX(), value.getY(), value.getZ(), value.getW());} public default Vec4b sub(Vec4b value) { return sub(value.getX(), value.getY(), value.getZ(), value.getW()); }
public default Vec4b sub(byte x, byte y, byte z, byte w){return set((byte)(getX() - x), (byte)(getY() - y), (byte)(getZ() - z), (byte)(getW() - w));} public default Vec4b sub(byte x, byte y, byte z, byte w) { return set((byte)(getX() - x), (byte)(getY() - y), (byte)(getZ() - z), (byte)(getW() - w)); }
@Override @Override
public default Vec4b multiply(byte value){return multiply(value, value, value, value);} public default Vec4b multiply(byte value) { return multiply(value, value, value, value); }
public default Vec4b multiply(Vec4b value){return multiply(value.getX(), value.getY(), value.getZ(), value.getW());} public default Vec4b multiply(Vec4b value) { return multiply(value.getX(), value.getY(), value.getZ(), value.getW()); }
public default Vec4b multiply(byte x, byte y, byte z, byte w){return set((byte)(getX() * x), (byte)(getY() * y), (byte)(getZ() * z), (byte)(getW() * w));} public default Vec4b multiply(byte x, byte y, byte z, byte w) { return set((byte)(getX() * x), (byte)(getY() * y), (byte)(getZ() * z), (byte)(getW() * w)); }
@Override @Override
public default Vec4b devide(byte value){return devide(value, value, value, value);} public default Vec4b devide(byte value) { return devide(value, value, value, value); }
public default Vec4b devide(Vec4b value){return devide(value.getX(), value.getY(), value.getZ(), value.getW());} public default Vec4b devide(Vec4b value) { return devide(value.getX(), value.getY(), value.getZ(), value.getW()); }
public default Vec4b devide(byte x, byte y, byte z, byte w){return set((byte)(getX() / x), (byte)(getY() / y), (byte)(getZ() / z), (byte)(getW() / w));} public default Vec4b devide(byte x, byte y, byte z, byte w) { return set((byte)(getX() / x), (byte)(getY() / y), (byte)(getZ() / z), (byte)(getW() / w)); }
@Override @Override
public default Vec4b set(byte value){return set(value, value, value, value);} public default Vec4b set(byte value) { return set(value, value, value, value); }
public default Vec4b set(Vec4b value){return set(value.getX(), value.getY(), value.getZ(), value.getW());} public default Vec4b set(Vec4b value) { return set(value.getX(), value.getY(), value.getZ(), value.getW()); }
public Vec4b set(byte x, byte y, byte z, byte w); public Vec4b set(byte x, byte y, byte z, byte w);
public default double distanceTo(Vec4b value) { return distanceTo(value.getX(), value.getY(), value.getZ(), value.getW()); }
public default double distanceTo(Vec4b value){return distanceTo(value.getX(), value.getY(), value.getZ(), value.getW());} public default double distanceTo(byte x, byte y, byte z, byte w) { return Math.sqrt(distanceTo(x, y, z, w)); }
public default double distanceTo(byte x, byte y, byte z, byte w){return Math.sqrt(distanceTo(x, y, z, w));} public default long distanceToSquared(Vec4b value) { return distanceToSquared(value.getX(), value.getY(), value.getZ(), value.getW()); }
public default long distanceToSquared(byte x, byte y, byte z, byte w) {
public default long distanceToSquared(Vec4b value){return distanceToSquared(value.getX(), value.getY(), value.getZ(), value.getW());}
public default long distanceToSquared(byte x, byte y, byte z, byte w)
{
long xPos = getX() - x; long xPos = getX() - x;
long yPos = getY() - y; long yPos = getY() - y;
long zPos = getZ() - z; long zPos = getZ() - z;
long wPos = getW() - w; long wPos = getW() - w;
return (xPos * xPos) + (yPos * yPos) + (zPos * zPos) + (wPos * wPos); return (xPos * xPos) + (yPos * yPos) + (zPos * zPos) + (wPos * wPos);
} }
@Override
public default long lengthSquared() {return (getX() * getX()) + (getY() * getY()) + (getZ() * getZ()) + (getW() * getW());}
public default long dotProduct(Vec4b value){return dotProduct(value.getX(), value.getY(), value.getZ(), value.getW());}
public default long dotProduct(byte x, byte y, byte z, byte w){return (getX() * x) + (getY() * y) + (getZ() * z) + (getW() * w);};
public default Vec4b min(Vec4b other) {return min(other, this);}
public default Vec4b min(Vec4b other, Vec4b result){return min(other.getX(), other.getY(), other.getZ(), other.getW(), result);}
public default Vec4b min(byte x, byte y, byte z, byte w) {return min(x, y, z, w, this);}
public default Vec4b min(byte x, byte y, byte z, byte w, Vec4b result){return result.set((byte)Math.min(getX(), x), (byte)Math.min(getY(), y), (byte)Math.min(getZ(), z), (byte)Math.min(getW(), w));}
public default Vec4b max(Vec4b other) {return max(other, this);}
public default Vec4b max(Vec4b other, Vec4b result){return max(other.getX(), other.getY(), other.getZ(), other.getW(), result);}
public default Vec4b max(byte x, byte y, byte z, byte w) {return max(x, y, z, w, this);}
public default Vec4b max(byte x, byte y, byte z, byte w, Vec4b result){return result.set((byte)Math.max(getX(), x), (byte)Math.max(getY(), y), (byte)Math.max(getZ(), z), (byte)Math.max(getZ(), z));}
public default Vec4b difference(Vec4b other) {return difference(other, this);}
public default Vec4b difference(Vec4b other, Vec4b result){return difference(other.getX(), other.getY(), other.getZ(), other.getW(), result);}
public default Vec4b difference(byte x, byte y, byte z, byte w) {return difference(x, y, z, w, this);}
public default Vec4b difference(byte x, byte y, byte z, byte w, Vec4b result){return result.set((byte)(getX() - x), (byte)(getY() - y), (byte)(getZ() - z), (byte)(getW() - w));}
@Override @Override
public default Vec4b clamp(byte min, byte max){return clamp(min, max, ALL);} public default long lengthSquared() { return (getX() * getX()) + (getY() * getY()) + (getZ() * getZ()) + (getW() * getW()); }
public default Vec4b clamp(byte min, byte max, Vec4b result){return clamp(min, max, result, ALL);} public default long dotProduct(Vec4b value) { return dotProduct(value.getX(), value.getY(), value.getZ(), value.getW()); }
public default long dotProduct(byte x, byte y, byte z, byte w) { return (getX() * x) + (getY() * y) + (getZ() * z) + (getW() * w); };
public default Vec4b min(Vec4b other) { return min(other, this); }
public default Vec4b min(Vec4b other, Vec4b result) { return min(other.getX(), other.getY(), other.getZ(), other.getW(), result); }
public default Vec4b min(byte x, byte y, byte z, byte w) { return min(x, y, z, w, this); }
public default Vec4b min(byte x, byte y, byte z, byte w, Vec4b result) { return result.set((byte)Math.min(getX(), x), (byte)Math.min(getY(), y), (byte)Math.min(getZ(), z), (byte)Math.min(getW(), w)); }
public default Vec4b max(Vec4b other) { return max(other, this); }
public default Vec4b max(Vec4b other, Vec4b result) { return max(other.getX(), other.getY(), other.getZ(), other.getW(), result); }
public default Vec4b max(byte x, byte y, byte z, byte w) { return max(x, y, z, w, this); }
public default Vec4b max(byte x, byte y, byte z, byte w, Vec4b result) { return result.set((byte)Math.max(getX(), x), (byte)Math.max(getY(), y), (byte)Math.max(getZ(), z), (byte)Math.max(getZ(), z)); }
public default Vec4b difference(Vec4b other) { return difference(other, this); }
public default Vec4b difference(Vec4b other, Vec4b result) { return difference(other.getX(), other.getY(), other.getZ(), other.getW(), result); }
public default Vec4b difference(byte x, byte y, byte z, byte w) { return difference(x, y, z, w, this); }
public default Vec4b difference(byte x, byte y, byte z, byte w, Vec4b result) { return result.set((byte)(getX() - x), (byte)(getY() - y), (byte)(getZ() - z), (byte)(getW() - w)); }
@Override @Override
public default Vec4b clamp(byte min, byte max, int filter){return clamp(min, max, this, filter);} public default Vec4b clamp(byte min, byte max) { return clamp(min, max, ALL); }
public default Vec4b clamp(byte min, byte max, Vec4b result, int filter){ return result.set((filter & X) == 0 ? getX() : MathUtils.clamp(min, max, getX()), (filter & Y) == 0 ? getY() : MathUtils.clamp(min, max, getY()), (filter & Z) == 0 ? getZ() : MathUtils.clamp(min, max, getZ()), (filter & W) == 0 ? getW() : MathUtils.clamp(min, max, getW()));} public default Vec4b clamp(byte min, byte max, Vec4b result) { return clamp(min, max, result, ALL); }
@Override @Override
public default Vec4b store(ByteBuffer buffer) public default Vec4b clamp(byte min, byte max, int filter) { return clamp(min, max, this, filter); }
{ public default Vec4b clamp(byte min, byte max, Vec4b result, int filter) { return result.set((filter & X) == 0 ? getX() : MathUtils.clamp(min, max, getX()), (filter & Y) == 0 ? getY() : MathUtils.clamp(min, max, getY()), (filter & Z) == 0 ? getZ() : MathUtils.clamp(min, max, getZ()), (filter & W) == 0 ? getW() : MathUtils.clamp(min, max, getW())); }
@Override
public default Vec4b store(ByteBuffer buffer) {
buffer.put(getX()).put(getY()).put(getZ()).put(getW()); buffer.put(getX()).put(getY()).put(getZ()).put(getW());
return this; return this;
} }
@Override @Override
public default Vec4b load(ByteBuffer buffer) public default Vec4b load(ByteBuffer buffer) { return set(buffer.get(), buffer.get(), buffer.get(), buffer.get()); }
{
return set(buffer.get(), buffer.get(), buffer.get(), buffer.get());
}
@Override @Override
public default Vec4s asShort(){return isMutable() ? Vec4s.mutable(getX(), getY(), getZ(), getW()) : Vec4s.of(getX(), getY(), getZ(), getW());} public default Vec4s asShort() { return isMutable() ? Vec4s.mutable(getX(), getY(), getZ(), getW()) : Vec4s.of(getX(), getY(), getZ(), getW()); }
@Override @Override
public default Vec4i asInt(){return isMutable() ? Vec4i.mutable(getX(), getY(), getZ(), getW()) : Vec4i.of(getX(), getY(), getZ(), getW());} public default Vec4i asInt() { return isMutable() ? Vec4i.mutable(getX(), getY(), getZ(), getW()) : Vec4i.of(getX(), getY(), getZ(), getW()); }
@Override @Override
public default Vec4l asLong(){return isMutable() ? Vec4l.mutable(getX(), getY(), getZ(), getW()) : Vec4l.of(getX(), getY(), getZ(), getW());} public default Vec4l asLong() { return isMutable() ? Vec4l.mutable(getX(), getY(), getZ(), getW()) : Vec4l.of(getX(), getY(), getZ(), getW()); }
@Override @Override
public default Vec4f asFloat() {return isMutable() ? Vec4f.mutable(getX(), getY(), getZ(), getW()) : Vec4f.of(getX(), getY(), getZ(), getW());} public default Vec4f asFloat() { return isMutable() ? Vec4f.mutable(getX(), getY(), getZ(), getW()) : Vec4f.of(getX(), getY(), getZ(), getW()); }
@Override @Override
public default Vec4d asDouble(){return isMutable() ? Vec4d.mutable(getX(), getY(), getZ(), getW()) : Vec4d.of(getX(), getY(), getZ(), getW());} public default Vec4d asDouble() {return isMutable() ? Vec4d.mutable(getX(), getY(), getZ(), getW()) : Vec4d.of(getX(), getY(), getZ(), getW()); }
@Override @Override
public default Vec4b asMutable(){return isMutable() ? this : mutable(this);} public default Vec4b asMutable() { return isMutable() ? this : mutable(this); }
@Override @Override
public default Vec4b asImmutable(){return isMutable() ? of(this) : this;} public default Vec4b asImmutable() { return isMutable() ? of(this) : this; }
@Override @Override
public default Vec4b copyAsMutable(){return mutable(this);} public default Vec4b copyAsMutable() { return mutable(this); }
@Override @Override
public default Vec4b copyAsImmutable(){return of(this);} public default Vec4b copyAsImmutable() { return of(this); }
} }

View File

@ -2,114 +2,61 @@ package speiger.src.coreengine.math.vector.bytes;
import java.util.Objects; import java.util.Objects;
public class Vec4bImmutable implements Vec4b public class Vec4bImmutable implements Vec4b {
{
final byte x; final byte x;
final byte y; final byte y;
final byte z; final byte z;
final byte w; final byte w;
public Vec4bImmutable() public Vec4bImmutable() {
{
x = 0; x = 0;
y = 0; y = 0;
z = 0; z = 0;
w = 0; w = 0;
} }
public Vec4bImmutable(byte value) public Vec4bImmutable(byte value) {
{
x = value; x = value;
y = value; y = value;
z = value; z = value;
w = value; w = value;
} }
public Vec4bImmutable(byte x, byte y, byte z, byte w) public Vec4bImmutable(byte x, byte y, byte z, byte w) {
{
this.x = x; this.x = x;
this.y = y; this.y = y;
this.z = z; this.z = z;
this.w = w; this.w = w;
} }
@Override
public boolean isMutable()
{
return false;
}
@Override @Override
public byte getX() public boolean isMutable() { return false; }
{ @Override
return x; public byte getX() { return x; }
} @Override
public byte getY() { return y; }
@Override
public byte getZ() { return z; }
@Override
public byte getW() { return w; }
@Override
public Vec4b setX(byte x) { return this.x == x ? this : Vec4b.of(x, y, z, w); }
@Override
public Vec4b setY(byte y) { return this.y == y ? this : Vec4b.of(x, y, z, w); }
@Override
public Vec4b setZ(byte z) { return this.z == z ? this : Vec4b.of(x, y, z, w); }
@Override
public Vec4b setW(byte w) { return this.w == w ? this : Vec4b.of(x, y, z, w); }
@Override
public Vec4b copy() { return Vec4b.of(this); }
@Override
public Vec4b set(byte x, byte y, byte z, byte w) { return this.x == x && this.y == y && this.z == z && this.w == w ? this : Vec4b.of(x, y, z, w); }
@Override
public int hashCode() { return Objects.hash(x, y, z, w); }
@Override @Override
public byte getY() public boolean equals(Object obj) {
{ if(obj instanceof Vec4b) {
return y;
}
@Override
public byte getZ()
{
return z;
}
@Override
public byte getW()
{
return w;
}
@Override
public Vec4b setX(byte x)
{
return this.x == x ? this : Vec4b.of(x, y, z, w);
}
@Override
public Vec4b setY(byte y)
{
return this.y == y ? this : Vec4b.of(x, y, z, w);
}
@Override
public Vec4b setZ(byte z)
{
return this.z == z ? this : Vec4b.of(x, y, z, w);
}
@Override
public Vec4b setW(byte w)
{
return this.w == w ? this : Vec4b.of(x, y, z, w);
}
@Override
public Vec4b copy()
{
return Vec4b.of(this);
}
@Override
public Vec4b set(byte x, byte y, byte z, byte w)
{
return this.x == x && this.y == y && this.z == z && this.w == w ? this : Vec4b.of(x, y, z, w);
}
@Override
public int hashCode()
{
return Objects.hash(x, y, z, w);
}
@Override
public boolean equals(Object obj)
{
if(obj instanceof Vec4b)
{
Vec4b vec = (Vec4b)obj; Vec4b vec = (Vec4b)obj;
return vec.getX() == x && vec.getY() == y && vec.getZ() == z && vec.getW() == w; return vec.getX() == x && vec.getY() == y && vec.getZ() == z && vec.getW() == w;
} }
@ -117,8 +64,5 @@ public class Vec4bImmutable implements Vec4b
} }
@Override @Override
public String toString() public String toString() { return "Vec4b[x="+x+", y="+y+", z="+z+", w="+w+"]"; }
{
return "Vec4b[x="+x+", y="+y+", z="+z+", w="+w+"]";
}
} }

View File

@ -2,100 +2,68 @@ package speiger.src.coreengine.math.vector.bytes;
import java.util.Objects; import java.util.Objects;
public class Vec4bMutable implements Vec4b public class Vec4bMutable implements Vec4b {
{
byte x; byte x;
byte y; byte y;
byte z; byte z;
byte w; byte w;
public Vec4bMutable() public Vec4bMutable() {}
{
}
public Vec4bMutable(byte value) public Vec4bMutable(byte value) {
{
x = value; x = value;
y = value; y = value;
z = value; z = value;
w = value; w = value;
} }
public Vec4bMutable(byte x, byte y, byte z, byte w) public Vec4bMutable(byte x, byte y, byte z, byte w) {
{
this.x = x; this.x = x;
this.y = y; this.y = y;
this.z = z; this.z = z;
this.w = w; this.w = w;
} }
@Override
public boolean isMutable()
{
return true;
}
@Override @Override
public byte getX() public boolean isMutable() { return true; }
{ @Override
return x; public byte getX() { return x; }
} @Override
public byte getY() { return y; }
@Override
public byte getZ() { return z; }
@Override
public byte getW() { return w; }
@Override @Override
public byte getY() public Vec4b setX(byte x) {
{
return y;
}
@Override
public byte getZ()
{
return z;
}
@Override
public byte getW()
{
return w;
}
@Override
public Vec4b setX(byte x)
{
this.x = x; this.x = x;
return this; return this;
} }
@Override @Override
public Vec4b setY(byte y) public Vec4b setY(byte y) {
{
this.y = y; this.y = y;
return this; return this;
} }
@Override @Override
public Vec4b setZ(byte z) public Vec4b setZ(byte z) {
{
this.z = z; this.z = z;
return this; return this;
} }
@Override @Override
public Vec4b setW(byte w) public Vec4b setW(byte w) {
{
this.w = w; this.w = w;
return this; return this;
} }
@Override @Override
public Vec4b copy() public Vec4b copy() { return Vec4b.mutable(this); }
{
return Vec4b.mutable(this);
}
@Override @Override
public Vec4b set(byte x, byte y, byte z, byte w) public Vec4b set(byte x, byte y, byte z, byte w) {
{
this.x = x; this.x = x;
this.y = y; this.y = y;
this.z = z; this.z = z;
@ -104,16 +72,11 @@ public class Vec4bMutable implements Vec4b
} }
@Override @Override
public int hashCode() public int hashCode() { return Objects.hash(x, y, z, w); }
{
return Objects.hash(x, y, z, w);
}
@Override @Override
public boolean equals(Object obj) public boolean equals(Object obj) {
{ if(obj instanceof Vec4b) {
if(obj instanceof Vec4b)
{
Vec4b vec = (Vec4b)obj; Vec4b vec = (Vec4b)obj;
return vec.getX() == x && vec.getY() == y && vec.getZ() == z && vec.getW() == w; return vec.getX() == x && vec.getY() == y && vec.getZ() == z && vec.getW() == w;
} }
@ -121,9 +84,6 @@ public class Vec4bMutable implements Vec4b
} }
@Override @Override
public String toString() public String toString() { return "Vec4b[x="+x+", y="+y+", z="+z+", w="+w+"]"; }
{
return "Vec4b[x="+x+", y="+y+", z="+z+", w="+w+"]";
}
} }

View File

@ -7,8 +7,7 @@ import speiger.src.coreengine.math.vector.ints.Veci;
import speiger.src.coreengine.math.vector.longs.Vecl; import speiger.src.coreengine.math.vector.longs.Vecl;
import speiger.src.coreengine.math.vector.shorts.Vecs; import speiger.src.coreengine.math.vector.shorts.Vecs;
public interface Vecb extends Vec public interface Vecb extends Vec {
{
public Vecb set(byte value); public Vecb set(byte value);
public Vecb add(byte value); public Vecb add(byte value);
public Vecb sub(byte value); public Vecb sub(byte value);
@ -16,10 +15,8 @@ public interface Vecb extends Vec
public Vecb devide(byte value); public Vecb devide(byte value);
public Vecb clamp(byte min, byte max); public Vecb clamp(byte min, byte max);
public Vecb clamp(byte min, byte max, int filter); public Vecb clamp(byte min, byte max, int filter);
public long lengthSquared(); public long lengthSquared();
public default double length(){return Math.sqrt(lengthSquared());} public default double length() { return Math.sqrt(lengthSquared()); }
public byte[] asArray(); public byte[] asArray();
public Vecs asShort(); public Vecs asShort();
public Veci asInt(); public Veci asInt();

View File

@ -10,178 +10,147 @@ import speiger.src.coreengine.math.vector.ints.Vec2i;
import speiger.src.coreengine.math.vector.longs.Vec2l; import speiger.src.coreengine.math.vector.longs.Vec2l;
import speiger.src.coreengine.math.vector.shorts.Vec2s; import speiger.src.coreengine.math.vector.shorts.Vec2s;
public interface Vec2d extends Vecd public interface Vec2d extends Vecd {
{
public static final Vec2d ZERO = of(); public static final Vec2d ZERO = of();
public static final Vec2d MINUS_ONE = of(-1D); public static final Vec2d MINUS_ONE = of(-1D);
public static final Vec2d ONE = of(1D); public static final Vec2d ONE = of(1D);
public static Vec2d mutable(){return new Vec2dMutable();} public static Vec2d mutable() { return new Vec2dMutable(); }
public static Vec2d mutable(double value){return new Vec2dMutable(value);} public static Vec2d mutable(double value) { return new Vec2dMutable(value); }
public static Vec2d mutable(double x, double y){return new Vec2dMutable(x, y);} public static Vec2d mutable(double x, double y) { return new Vec2dMutable(x, y); }
public static Vec2d mutable(Vec2d value){return mutable(value.getX(), value.getY());} public static Vec2d mutable(Vec2d value) { return mutable(value.getX(), value.getY()); }
public static Vec2d of() { return new Vec2dImmutable(); }
public static Vec2d of(){return new Vec2dImmutable();} public static Vec2d of(double value) { return new Vec2dImmutable(value); }
public static Vec2d of(double value){return new Vec2dImmutable(value);} public static Vec2d of(double x, double y) { return new Vec2dImmutable(x, y); }
public static Vec2d of(double x, double y){return new Vec2dImmutable(x, y);} public static Vec2d of(Vec2d value) { return of(value.getX(), value.getY()); }
public static Vec2d of(Vec2d value){return of(value.getX(), value.getY());}
public double getX(); public double getX();
public double getY(); public double getY();
public Vec2d setX(double x); public Vec2d setX(double x);
public Vec2d setY(double y); public Vec2d setY(double y);
@Override @Override
public default double[] asArray(){return new double[]{getX(), getY()};} public default double[] asArray() { return new double[] {getX(), getY()}; }
@Override @Override
public Vec2d copy(); public Vec2d copy();
@Override @Override
public default Vec2d abs(){return set(Math.abs(getX()), Math.abs(getY()));} public default Vec2d abs() { return set(Math.abs(getX()), Math.abs(getY())); }
@Override @Override
public default Vec2d negate(){return set(0D, 0D);} public default Vec2d negate() { return set(0D, 0D); }
@Override @Override
public default Vec2d invert(){return set(-getX(), -getY());}; public default Vec2d invert() { return set(-getX(), -getY()); };
public default Vec2d normalize() public default Vec2d normalize() {
{
double l = length(); double l = length();
return l == 0D ? this : multiply(1D / l); return l == 0D ? this : multiply(1D / l);
} }
@Override @Override
public default Vec2d add(double value) {return add(value, value);} public default Vec2d add(double value) { return add(value, value); }
public default Vec2d add(Vec2d value) {return add(value.getX(), value.getY());} public default Vec2d add(Vec2d value) { return add(value.getX(), value.getY()); }
public default Vec2d add(double x, double y) {return set(x + getX(), y + getY());} public default Vec2d add(double x, double y) { return set(x + getX(), y + getY()); }
@Override @Override
public default Vec2d sub(double value){return sub(value, value);} public default Vec2d sub(double value) { return sub(value, value); }
public default Vec2d sub(Vec2d value){return sub(value.getX(), value.getY());} public default Vec2d sub(Vec2d value) { return sub(value.getX(), value.getY()); }
public default Vec2d sub(double x, double y) {return set(getX() - x, getY() - y);} public default Vec2d sub(double x, double y) { return set(getX() - x, getY() - y); }
@Override @Override
public default Vec2d multiply(double value){return multiply(value, value);} public default Vec2d multiply(double value) { return multiply(value, value); }
public default Vec2d multiply(Vec2d value){return multiply(value.getX(), value.getY());} public default Vec2d multiply(Vec2d value) { return multiply(value.getX(), value.getY()); }
public default Vec2d multiply(double x, double y) {return set(x * getX(), y * getY());} public default Vec2d multiply(double x, double y) { return set(x * getX(), y * getY()); }
@Override @Override
public default Vec2d devide(double value){return devide(value, value);} public default Vec2d devide(double value) { return devide(value, value); }
public default Vec2d devide(Vec2d value){return devide(value.getX(), value.getY());} public default Vec2d devide(Vec2d value) { return devide(value.getX(), value.getY()); }
public default Vec2d devide(double x, double y){return set(getX() / x, getY() / y);} public default Vec2d devide(double x, double y) { return set(getX() / x, getY() / y); }
@Override @Override
public default Vec2d set(double value){return set(value, value);}; public default Vec2d set(double value) { return set(value, value); };
public default Vec2d set(Vec2d value){return set(value.getX(), value.getY());} public default Vec2d set(Vec2d value) { return set(value.getX(), value.getY()); }
public Vec2d set(double x, double y); public Vec2d set(double x, double y);
public default double distanceTo(Vec2d value){return distanceTo(value.getX(), value.getY());} public default double distanceTo(Vec2d value) { return distanceTo(value.getX(), value.getY()); }
public default double distanceTo(double x, double y){return Math.sqrt(distanceToSquared(x, y));} public default double distanceTo(double x, double y) { return Math.sqrt(distanceToSquared(x, y)); }
public default double distanceToSquared(Vec2d value) { return distanceToSquared(value.getX(), value.getY()); }
public default double distanceToSquared(Vec2d value){return distanceToSquared(value.getX(), value.getY());} public default double distanceToSquared(double x, double y) {
public default double distanceToSquared(double x, double y)
{
double xPos = getX() - x; double xPos = getX() - x;
double yPos = getY() - y; double yPos = getY() - y;
return (xPos * xPos) + (yPos * yPos); return (xPos * xPos) + (yPos * yPos);
} }
@Override @Override
public default double lengthSquared() {return (getX() * getX()) + (getY() * getY());} public default double lengthSquared() { return (getX() * getX()) + (getY() * getY()); }
public default double dotProduct(Vec2d value) { return dotProduct(value.getX(), value.getY()); }
public default double dotProduct(Vec2d value){return dotProduct(value.getX(), value.getY());} public default double dotProduct(double x, double y) { return (getX() * x) + (getY() * y); }
public default double dotProduct(double x, double y){return (getX() * x) + (getY() * y);} public default Vec2d lerp(Vec2d value, float progress, Vec2d result) { return lerp(value.getX(), value.getY(), progress, result); }
public default Vec2d lerp(double x, double y, float progress, Vec2d result) { return result.set(MathUtils.lerp(getX(), x, progress), MathUtils.lerp(getY(), y, progress)); };
public default Vec2d lerp(Vec2d value, float progress, Vec2d result){return lerp(value.getX(), value.getY(), progress, result);} public default double angle(Vec2d value) { return angle(value.getX(), value.getY()); }
public default Vec2d lerp(double x, double y, float progress, Vec2d result){return result.set(MathUtils.lerp(getX(), x, progress), MathUtils.lerp(getY(), y, progress));}; public default double angle(double x, double y) { return (float)Math.atan2((getX() * y) - (getY() * x), (getX() * x) + (getY() * y)); }
public default double directionAngle(Vec2d value) { return directionAngle(value.getX(), value.getY()); }
public default double angle(Vec2d value){return angle(value.getX(), value.getY());} public default double directionAngle(double x, double y) { return (float)(-Math.toDegrees(Math.atan2(getX() - x, getY() - y)) % 360D); }
public default double angle(double x, double y){return (float)Math.atan2((getX() * y) - (getY() * x), (getX() * x) + (getY() * y));} public default Vec2d reflect(Vec2d value) { return reflect(value.getX(), value.getY(), this); }
public default Vec2d reflect(double x, double y) { return reflect(x, y, this); };
public default double directionAngle(Vec2d value){return directionAngle(value.getX(), value.getY());} public default Vec2d reflect(Vec2d value, Vec2d result) { return reflect(value.getX(), value.getY(), result); }
public default double directionAngle(double x, double y){return (float)(-Math.toDegrees(Math.atan2(getX() - x, getY() - y)) % 360D);} public default Vec2d reflect(double x, double y, Vec2d result) {
public default Vec2d reflect(Vec2d value){return reflect(value.getX(), value.getY(), this);}
public default Vec2d reflect(double x, double y){return reflect(x, y, this);};
public default Vec2d reflect(Vec2d value, Vec2d result){return reflect(value.getX(), value.getY(), result);}
public default Vec2d reflect(double x, double y, Vec2d result)
{
double dot = dotProduct(x, y); double dot = dotProduct(x, y);
double x2 = (float)((dot + dot) * x); double x2 = (float)((dot + dot) * x);
double y2 = (float)((dot + dot) * y); double y2 = (float)((dot + dot) * y);
return result.set(getX() - x2, getY() - y2); return result.set(getX() - x2, getY() - y2);
} }
public default Vec2d rotate(double angle, Vec2d center){return rotate(angle, center.getX(), center.getY());} public default Vec2d rotate(double angle, Vec2d center) { return rotate(angle, center.getX(), center.getY()); }
public default Vec2d rotate(double angle, double x, double y) public default Vec2d rotate(double angle, double x, double y) {
{
double xPos = getX() - x; double xPos = getX() - x;
double yPos = getY() - y; double yPos = getY() - y;
double cos = MathUtils.cos(angle); double cos = MathUtils.cos(angle);
double sin = MathUtils.sin(angle); double sin = MathUtils.sin(angle);
return set((float)((xPos * cos) + (yPos * sin) + x), (float)(-(xPos * sin) + (yPos * cos) + y)); return set((float)((xPos * cos) + (yPos * sin) + x), (float)(-(xPos * sin) + (yPos * cos) + y));
} }
public default Vec2d min(Vec2d other) {return min(other, this);} public default Vec2d min(Vec2d other) { return min(other, this); }
public default Vec2d min(Vec2d other, Vec2d result){return min(other.getX(), other.getY(), result);} public default Vec2d min(Vec2d other, Vec2d result) { return min(other.getX(), other.getY(), result); }
public default Vec2d min(double x, double y) {return min(x, y, this);} public default Vec2d min(double x, double y) { return min(x, y, this); }
public default Vec2d min(double x, double y, Vec2d result){return result.set(Math.min(getX(), x), Math.min(getY(), y));} public default Vec2d min(double x, double y, Vec2d result) { return result.set(Math.min(getX(), x), Math.min(getY(), y)); }
public default Vec2d max(Vec2d other) { return max(other, this); }
public default Vec2d max(Vec2d other) {return max(other, this);} public default Vec2d max(Vec2d other, Vec2d result) { return max(other.getX(), other.getY(), result); }
public default Vec2d max(Vec2d other, Vec2d result){return max(other.getX(), other.getY(), result);} public default Vec2d max(double x, double y) { return max(x, y, this); }
public default Vec2d max(double x, double y) {return max(x, y, this);} public default Vec2d max(double x, double y, Vec2d result) { return result.set(Math.max(getX(), x), Math.max(getY(), y)); }
public default Vec2d max(double x, double y, Vec2d result){return result.set(Math.max(getX(), x), Math.max(getY(), y));} public default Vec2d difference(Vec2d other) { return difference(other, this); }
public default Vec2d difference(Vec2d other, Vec2d result) { return difference(other.getX(), other.getY(), result); }
public default Vec2d difference(Vec2d other) {return difference(other, this);} public default Vec2d difference(double x, double y) { return difference(x, y, this); }
public default Vec2d difference(Vec2d other, Vec2d result){return difference(other.getX(), other.getY(), result);} public default Vec2d difference(double x, double y, Vec2d result) { return result.set(getX() - x, getY() - y); }
public default Vec2d difference(double x, double y) {return difference(x, y, this);} @Override
public default Vec2d difference(double x, double y, Vec2d result){return result.set(getX() - x, getY() - y);} public default Vec2d clamp(double min, double max) { return clamp(min, max, ALL); }
public default Vec2d clamp(double min, double max, Vec2d result) { return clamp(min, max, result, ALL); }
@Override
public default Vec2d clamp(double min, double max, int filter) { return clamp(min, max, this, filter); }
public default Vec2d clamp(double min, double max, Vec2d result, int filter) { return result.set((filter & X) == 0 ? getX() : MathUtils.clamp(min, max, getX()), (filter & Y) == 0 ? getY() : MathUtils.clamp(min, max, getY())); }
@Override @Override
public default Vec2d clamp(double min, double max){return clamp(min, max, ALL);} public default Vec2d store(ByteBuffer buffer) {
public default Vec2d clamp(double min, double max, Vec2d result){return clamp(min, max, result, ALL);}
@Override
public default Vec2d clamp(double min, double max, int filter){return clamp(min, max, this, filter);}
public default Vec2d clamp(double min, double max, Vec2d result, int filter){ return result.set((filter & X) == 0 ? getX() : MathUtils.clamp(min, max, getX()), (filter & Y) == 0 ? getY() : MathUtils.clamp(min, max, getY()));}
@Override
public default Vec2d store(ByteBuffer buffer)
{
buffer.putDouble(getX()).putDouble(getY()); buffer.putDouble(getX()).putDouble(getY());
return this; return this;
} }
@Override @Override
public default Vec2d load(ByteBuffer buffer) public default Vec2d load(ByteBuffer buffer) { return set(buffer.getDouble(), buffer.getDouble()); }
{
return set(buffer.getDouble(), buffer.getDouble());
}
@Override @Override
public default Vec2d store(DoubleBuffer buffer) public default Vec2d store(DoubleBuffer buffer) {
{
buffer.put(getX()).put(getY()); buffer.put(getX()).put(getY());
return this; return this;
} }
@Override @Override
public default Vec2d load(DoubleBuffer buffer) public default Vec2d load(DoubleBuffer buffer) { return set(buffer.get(), buffer.get()); }
{
return set(buffer.get(), buffer.get());
}
@Override @Override
public default Vec2b asByte(){return isMutable() ? Vec2b.mutable((byte)MathUtils.floor(getX()), (byte)MathUtils.floor(getY())) : Vec2b.of((byte)MathUtils.floor(getX()), (byte)MathUtils.floor(getY()));} public default Vec2b asByte() { return isMutable() ? Vec2b.mutable((byte)MathUtils.floor(getX()), (byte)MathUtils.floor(getY())) : Vec2b.of((byte)MathUtils.floor(getX()), (byte)MathUtils.floor(getY())); }
@Override @Override
public default Vec2s asShort(){return isMutable() ? Vec2s.mutable((short)MathUtils.floor(getX()), (short)MathUtils.floor(getY())) : Vec2s.of((short)MathUtils.floor(getX()), (short)MathUtils.floor(getY()));} public default Vec2s asShort() { return isMutable() ? Vec2s.mutable((short)MathUtils.floor(getX()), (short)MathUtils.floor(getY())) : Vec2s.of((short)MathUtils.floor(getX()), (short)MathUtils.floor(getY())); }
@Override @Override
public default Vec2i asInt(){return isMutable() ? Vec2i.mutable(MathUtils.floor(getX()), MathUtils.floor(getY())) : Vec2i.of(MathUtils.floor(getX()), MathUtils.floor(getY()));} public default Vec2i asInt() { return isMutable() ? Vec2i.mutable(MathUtils.floor(getX()), MathUtils.floor(getY())) : Vec2i.of(MathUtils.floor(getX()), MathUtils.floor(getY())); }
@Override @Override
public default Vec2l asLong() {return isMutable() ? Vec2l.mutable(MathUtils.floor(getX()), MathUtils.floor(getY())) : Vec2l.of(MathUtils.floor(getX()), MathUtils.floor(getY()));} public default Vec2l asLong() { return isMutable() ? Vec2l.mutable(MathUtils.floor(getX()), MathUtils.floor(getY())) : Vec2l.of(MathUtils.floor(getX()), MathUtils.floor(getY())); }
@Override @Override
public default Vec2f asFloat(){return isMutable() ? Vec2f.mutable((float)getX(), (float)getY()) : Vec2f.of((float)getX(), (float)getY());} public default Vec2f asFloat() { return isMutable() ? Vec2f.mutable((float)getX(), (float)getY()) : Vec2f.of((float)getX(), (float)getY()); }
@Override @Override
public default Vec2d asMutable(){return isMutable() ? this : mutable(this);} public default Vec2d asMutable() { return isMutable() ? this : mutable(this); }
@Override @Override
public default Vec2d asImmutable(){return isMutable() ? of(this) : this;} public default Vec2d asImmutable() { return isMutable() ? of(this) : this; }
@Override @Override
public default Vec2d copyAsMutable(){return mutable(this);} public default Vec2d copyAsMutable() { return mutable(this); }
@Override @Override
public default Vec2d copyAsImmutable(){return of(this);} public default Vec2d copyAsImmutable() { return of(this); }
} }

View File

@ -2,91 +2,51 @@ package speiger.src.coreengine.math.vector.doubles;
import java.util.Objects; import java.util.Objects;
public class Vec2dImmutable implements Vec2d public class Vec2dImmutable implements Vec2d {
{
final double x; final double x;
final double y; final double y;
public Vec2dImmutable() public Vec2dImmutable() {
{
x = 0D; x = 0D;
y = 0D; y = 0D;
} }
public Vec2dImmutable(double value) public Vec2dImmutable(double value) {
{
x = value; x = value;
y = value; y = value;
} }
public Vec2dImmutable(double x, double y) public Vec2dImmutable(double x, double y) {
{
this.x = x; this.x = x;
this.y = y; this.y = y;
} }
@Override
public boolean isMutable()
{
return false;
}
@Override @Override
public double getX() public boolean isMutable() { return false; }
{ @Override
return x; public double getX() { return x; }
} @Override
public double getY() { return y; }
@Override
public Vec2d setX(double x) { return this.x == x ? this : Vec2d.of(x, y); }
@Override
public Vec2d setY(double y) { return this.y == y ? this : Vec2d.of(x, y); }
@Override
public Vec2d copy() { return Vec2d.of(this); }
@Override
public Vec2d set(double x, double y) { return this.x == x && this.y == y ? this : Vec2d.of(x, y); }
@Override
public int hashCode() { return Objects.hash(x, y); }
@Override @Override
public double getY() public boolean equals(Object obj) {
{ if(obj instanceof Vec2d) {
return y;
}
@Override
public Vec2d setX(double x)
{
return this.x == x ? this : Vec2d.of(x, y);
}
@Override
public Vec2d setY(double y)
{
return this.y == y ? this : Vec2d.of(x, y);
}
@Override
public Vec2d copy()
{
return Vec2d.of(this);
}
@Override
public Vec2d set(double x, double y)
{
return this.x == x && this.y == y ? this : Vec2d.of(x, y);
}
@Override
public int hashCode()
{
return Objects.hash(x, y);
}
@Override
public boolean equals(Object obj)
{
if(obj instanceof Vec2d)
{
Vec2d vec = (Vec2d)obj; Vec2d vec = (Vec2d)obj;
return vec.getX() == x && vec.getY() == y; return vec.getX() == x && vec.getY() == y;
} }
return false; return false;
} }
@Override @Override
public String toString() public String toString() { return "Vec2d[x="+x+", y="+y+"]"; }
{
return "Vec2d[x="+x+", y="+y+"]";
}
} }

View File

@ -2,95 +2,66 @@ package speiger.src.coreengine.math.vector.doubles;
import java.util.Objects; import java.util.Objects;
public class Vec2dMutable implements Vec2d public class Vec2dMutable implements Vec2d {
{
double x; double x;
double y; double y;
public Vec2dMutable() public Vec2dMutable() {
{
x = 0D; x = 0D;
y = 0D; y = 0D;
} }
public Vec2dMutable(double value) public Vec2dMutable(double value) {
{
x = value; x = value;
y = value; y = value;
} }
public Vec2dMutable(double x, double y) public Vec2dMutable(double x, double y) {
{
this.x = x; this.x = x;
this.y = y; this.y = y;
} }
@Override @Override
public boolean isMutable() public boolean isMutable() { return true; }
{ @Override
return true; public double getX() { return x; }
} @Override
public double getY() { return y; }
@Override @Override
public double getX() public Vec2d setX(double x) {
{
return x;
}
@Override
public double getY()
{
return y;
}
@Override
public Vec2d setX(double x)
{
this.x = x; this.x = x;
return this; return this;
} }
@Override @Override
public Vec2d setY(double y) public Vec2d setY(double y) {
{
this.y = y; this.y = y;
return this; return this;
} }
@Override @Override
public Vec2d copy() public Vec2d copy() { return Vec2d.mutable(this); }
{
return Vec2d.mutable(this);
}
@Override @Override
public Vec2d set(double x, double y) public Vec2d set(double x, double y) {
{
this.x = x; this.x = x;
this.y = y; this.y = y;
return this; return this;
} }
@Override @Override
public int hashCode() public int hashCode() { return Objects.hash(x, y); }
{
return Objects.hash(x, y);
}
@Override @Override
public boolean equals(Object obj) public boolean equals(Object obj) {
{ if(obj instanceof Vec2d) {
if(obj instanceof Vec2d)
{
Vec2d vec = (Vec2d)obj; Vec2d vec = (Vec2d)obj;
return vec.getX() == x && vec.getY() == y; return vec.getX() == x && vec.getY() == y;
} }
return false; return false;
} }
@Override @Override
public String toString() public String toString() { return "Vec2d[x="+x+", y="+y+"]"; }
{
return "Vec2d[x="+x+", y="+y+"]";
}
} }

View File

@ -10,21 +10,26 @@ import speiger.src.coreengine.math.vector.ints.Vec3i;
import speiger.src.coreengine.math.vector.longs.Vec3l; import speiger.src.coreengine.math.vector.longs.Vec3l;
import speiger.src.coreengine.math.vector.shorts.Vec3s; import speiger.src.coreengine.math.vector.shorts.Vec3s;
public interface Vec3d extends Vecd public interface Vec3d extends Vecd {
{
public static final Vec3d ZERO = of(); public static final Vec3d ZERO = of();
public static final Vec3d MINUS_ONE = of(-1D); public static final Vec3d MINUS_ONE = of(-1D);
public static final Vec3d ONE = of(1D); public static final Vec3d ONE = of(1D);
public static Vec3d mutable(){return new Vec3dMutable();} public static Vec3d mutable() { return new Vec3dMutable(); }
public static Vec3d mutable(double value){return new Vec3dMutable(value);}
public static Vec3d mutable(double x, double y, double z){return new Vec3dMutable(x, y, z);}
public static Vec3d mutable(Vec3d vec){return mutable(vec.getX(), vec.getY(), vec.getZ());}
public static Vec3d of(){return new Vec3dImmutable();} public static Vec3d mutable(double value) { return new Vec3dMutable(value); }
public static Vec3d of(double value){return new Vec3dImmutable(value);}
public static Vec3d of(double x, double y, double z){return new Vec3dImmutable(x, y, z);} public static Vec3d mutable(double x, double y, double z) { return new Vec3dMutable(x, y, z); }
public static Vec3d of(Vec3d vec){return of(vec.getX(), vec.getY(), vec.getZ());}
public static Vec3d mutable(Vec3d vec) { return mutable(vec.getX(), vec.getY(), vec.getZ()); }
public static Vec3d of() { return new Vec3dImmutable(); }
public static Vec3d of(double value) { return new Vec3dImmutable(value); }
public static Vec3d of(double x, double y, double z) { return new Vec3dImmutable(x, y, z); }
public static Vec3d of(Vec3d vec) { return of(vec.getX(), vec.getY(), vec.getZ()); }
public double getX(); public double getX();
public double getY(); public double getY();
@ -32,127 +37,209 @@ public interface Vec3d extends Vecd
public Vec3d setX(double x); public Vec3d setX(double x);
public Vec3d setY(double y); public Vec3d setY(double y);
public Vec3d setZ(double z); public Vec3d setZ(double z);
@Override @Override
public default double[] asArray(){return new double[]{getX(), getY(), getZ()};} public default double[] asArray() { return new double[] {getX(), getY(), getZ()}; }
@Override @Override
public Vec3d copy(); public Vec3d copy();
@Override @Override
public default Vec3d abs(){return set(Math.abs(getX()), Math.abs(getY()), Math.abs(getZ()));} public default Vec3d abs() { return set(Math.abs(getX()), Math.abs(getY()), Math.abs(getZ())); }
@Override @Override
public default Vec3d negate(){return set(0D, 0D, 0D);} public default Vec3d negate() { return set(0D, 0D, 0D); }
@Override @Override
public default Vec3d invert(){return set(-getX(), -getY(), -getZ());} public default Vec3d invert() { return set(-getX(), -getY(), -getZ()); }
public default Vec3d normalize()
{ public default Vec3d normalize() {
double l = length(); double l = length();
return l == 0D ? this : multiply(1.0D / l); return l == 0D ? this : multiply(1.0D / l);
} }
@Override
public default Vec3d add(double value){return add(value, value, value);}
public default Vec3d add(Vec3d value){return add(value.getX(), value.getY(), value.getZ());}
public default Vec3d add(double x, double y, double z){return set(getX() + x, getY() + y, getZ() + z);}
@Override
public default Vec3d sub(double value){return sub(value, value, value);}
public default Vec3d sub(Vec3d value){return sub(value.getX(), value.getY(), value.getZ());}
public default Vec3d sub(double x, double y, double z){return set(getX() - x, getY() - y, getZ() - z);}
@Override @Override
public default Vec3d multiply(double value){return multiply(value, value, value);} public default Vec3d add(double value) { return add(value, value, value); }
public default Vec3d multiply(Vec3d value){return multiply(value.getX(), value.getY(), value.getZ());}
public default Vec3d multiply(double x, double y, double z){return set(getX() * x, getY() * y, getZ() * z);} public default Vec3d add(Vec3d value) { return add(value.getX(), value.getY(), value.getZ()); }
@Override public default Vec3d add(double x, double y, double z) {
public default Vec3d devide(double value){return devide(value, value, value);} return set(getX() + x, getY() + y, getZ() + z);
public default Vec3d devide(Vec3d value){return devide(value.getX(), value.getY(), value.getZ());} }
public default Vec3d devide(double x, double y, double z){return set(getX() / x, getY() / y, getZ() / z);}
@Override @Override
public default Vec3d set(double value){return set(value, value, value);} public default Vec3d sub(double value) { return sub(value, value, value); }
public default Vec3d set(Vec3d value){return set(value.getX(), value.getY(), value.getZ());}
public default Vec3d sub(Vec3d value) { return sub(value.getX(), value.getY(), value.getZ()); }
public default Vec3d sub(double x, double y, double z) {
return set(getX() - x, getY() - y, getZ() - z);
}
@Override
public default Vec3d multiply(double value) { return multiply(value, value, value); }
public default Vec3d multiply(Vec3d value) {
return multiply(value.getX(), value.getY(), value.getZ());
}
public default Vec3d multiply(double x, double y, double z) {
return set(getX() * x, getY() * y, getZ() * z);
}
@Override
public default Vec3d devide(double value) { return devide(value, value, value); }
public default Vec3d devide(Vec3d value) {
return devide(value.getX(), value.getY(), value.getZ());
}
public default Vec3d devide(double x, double y, double z) {
return set(getX() / x, getY() / y, getZ() / z);
}
@Override
public default Vec3d set(double value) { return set(value, value, value); }
public default Vec3d set(Vec3d value) { return set(value.getX(), value.getY(), value.getZ()); }
public Vec3d set(double x, double y, double z); public Vec3d set(double x, double y, double z);
public default double distanceTo(Vec3d value){return distanceTo(value.getX(), value.getY(), value.getZ());} public default double distanceTo(Vec3d value) {
public default double distanceTo(double x, double y, double z){return Math.sqrt(distanceToSquared(x, y, z));} return distanceTo(value.getX(), value.getY(), value.getZ());
}
public default double distanceToSquared(Vec3d value){return distanceToSquared(value.getX(), value.getY(), value.getZ());} public default double distanceTo(double x, double y, double z) {
public default double distanceToSquared(double x, double y, double z) return Math.sqrt(distanceToSquared(x, y, z));
{ }
public default double distanceToSquared(Vec3d value) {
return distanceToSquared(value.getX(), value.getY(), value.getZ());
}
public default double distanceToSquared(double x, double y, double z) {
double xPos = getX() - x; double xPos = getX() - x;
double yPos = getY() - y; double yPos = getY() - y;
double zPos = getZ() - z; double zPos = getZ() - z;
return (xPos * xPos) + (yPos * yPos) + (zPos * zPos); return (xPos * xPos) + (yPos * yPos) + (zPos * zPos);
} }
@Override @Override
public default double lengthSquared() {return (getX() * getX()) + (getY() * getY()) + (getZ() * getZ());} public default double lengthSquared() {
return (getX() * getX()) + (getY() * getY()) + (getZ() * getZ());
}
public default double dotProduct(Vec3d value){return dotProduct(value.getX(), value.getY(), value.getZ());} public default double dotProduct(Vec3d value) {
public default double dotProduct(double x, double y, double z){return (getX() * x) + (getY() * y) + (getZ() * z);} return dotProduct(value.getX(), value.getY(), value.getZ());
}
public default Vec3d lerp(Vec3d value, float progress, Vec3d result){return lerp(value.getX(), value.getY(), value.getZ(), progress, result);} public default double dotProduct(double x, double y, double z) {
public default Vec3d lerp(double x, double y, double z, float progress, Vec3d result){return result.set(MathUtils.lerp(getX(), x, progress), MathUtils.lerp(getY(), y, progress), MathUtils.lerp(getZ(), z, progress));} return (getX() * x) + (getY() * y) + (getZ() * z);
}
public default double angle(Vec3d value){return angle(value.getX(), value.getY(), value.getZ());} public default Vec3d lerp(Vec3d value, float progress, Vec3d result) {
public default double angle(double x, double y, double z){return Math.acos(MathUtils.clamp(-1, 1, angleCos(x, y, z)));} return lerp(value.getX(), value.getY(), value.getZ(), progress, result);
}
public default double angleCos(Vec3d value){return angleCos(value.getX(), value.getY(), value.getZ());} public default Vec3d lerp(double x, double y, double z, float progress, Vec3d result) {
public default double angleCos(double x, double y, double z) return result.set(MathUtils.lerp(getX(), x, progress), MathUtils.lerp(getY(), y, progress), MathUtils.lerp(getZ(), z, progress));
{ }
public default double angle(Vec3d value) {
return angle(value.getX(), value.getY(), value.getZ());
}
public default double angle(double x, double y, double z) {
return Math.acos(MathUtils.clamp(-1, 1, angleCos(x, y, z)));
}
public default double angleCos(Vec3d value) {
return angleCos(value.getX(), value.getY(), value.getZ());
}
public default double angleCos(double x, double y, double z) {
double myLength = (getX() * getX()) + (getY() * getY()) + (getZ() * getZ()); double myLength = (getX() * getX()) + (getY() * getY()) + (getZ() * getZ());
double otherLength = (x * x) + (y * y) + (z * z); double otherLength = (x * x) + (y * y) + (z * z);
double dot = (getX() * x) + (getY() * y) + (getZ() * z); double dot = (getX() * x) + (getY() * y) + (getZ() * z);
return dot / (Math.sqrt(myLength * otherLength)); return dot / (Math.sqrt(myLength * otherLength));
} }
public default Vec3d crossProduct(Vec3d value){return crossProduct(value.getX(), value.getY(), value.getZ(), this);} public default Vec3d crossProduct(Vec3d value) {
public default Vec3d crossProduct(Vec3d value, Vec3d result){return crossProduct(value.getX(), value.getY(), value.getZ(), result);} return crossProduct(value.getX(), value.getY(), value.getZ(), this);
public default Vec3d crossProduct(double x, double y, double z){return crossProduct(x, y, z, this);} }
public default Vec3d crossProduct(double x, double y, double z, Vec3d result){return result.set((getY() * z) - (getZ() * y), (getZ() * x) - (getX() * z), (getX() * y) - (getY() * x));}
public default Vec3d reflect(Vec3d value){return reflect(value.getX(), value.getY(), value.getZ(), this);} public default Vec3d crossProduct(Vec3d value, Vec3d result) {
public default Vec3d reflect(Vec3d value, Vec3d result){return reflect(value.getX(), value.getY(), value.getZ(), result);} return crossProduct(value.getX(), value.getY(), value.getZ(), result);
public default Vec3d reflect(double x, double y, double z){return reflect(x, y, z, this);} }
public default Vec3d reflect(double x, double y, double z, Vec3d result)
{ public default Vec3d crossProduct(double x, double y, double z) {
return crossProduct(x, y, z, this);
}
public default Vec3d crossProduct(double x, double y, double z, Vec3d result) {
return result.set((getY() * z) - (getZ() * y), (getZ() * x) - (getX() * z), (getX() * y) - (getY() * x));
}
public default Vec3d reflect(Vec3d value) {
return reflect(value.getX(), value.getY(), value.getZ(), this);
}
public default Vec3d reflect(Vec3d value, Vec3d result) {
return reflect(value.getX(), value.getY(), value.getZ(), result);
}
public default Vec3d reflect(double x, double y, double z) { return reflect(x, y, z, this); }
public default Vec3d reflect(double x, double y, double z, Vec3d result) {
double dot = dotProduct(x, y, z) * 2D; double dot = dotProduct(x, y, z) * 2D;
return result.set(getX() - dot * x, getY() - dot * y, getZ() - dot * z); return result.set(getX() - dot * x, getY() - dot * y, getZ() - dot * z);
} }
public default Vec3d rotate(double angle, Vec3d axis){return rotate(angle, axis.getX(), axis.getY(), axis.getZ());} public default Vec3d rotate(double angle, Vec3d axis) {
public default Vec3d rotate(double angle, Vec3d axis, Vec3d result){return rotate(angle, axis.getX(), axis.getY(), axis.getZ(), result);} return rotate(angle, axis.getX(), axis.getY(), axis.getZ());
public default Vec3d rotate(double angle, double x, double y, double z){return rotate(angle, x, y, z, this);} }
public default Vec3d rotate(double angle, double x, double y, double z, Vec3d result)
{ public default Vec3d rotate(double angle, Vec3d axis, Vec3d result) {
return rotate(angle, axis.getX(), axis.getY(), axis.getZ(), result);
}
public default Vec3d rotate(double angle, double x, double y, double z) {
return rotate(angle, x, y, z, this);
}
public default Vec3d rotate(double angle, double x, double y, double z, Vec3d result) {
double cos = MathUtils.cos(angle); double cos = MathUtils.cos(angle);
double sin = MathUtils.sin(angle); double sin = MathUtils.sin(angle);
double dot = dotProduct(x, y, z); double dot = dotProduct(x, y, z);
double xPos = x * dot * (1D - cos) + (getX() * cos) + (-z * getY() + y * getZ()) * sin; double xPos = x * dot * (1D - cos) + (getX() * cos) + (-z * getY() + y * getZ()) * sin;
double yPos = y * dot * (1D - cos) + (getY() * cos) + (z * getX() - x * getZ()) * sin; double yPos = y * dot * (1D - cos) + (getY() * cos) + (z * getX() - x * getZ()) * sin;
double zPos = z * dot * (1D - cos) + (getZ() * cos) + (-y * getX() + x * getY()) * sin; double zPos = z * dot * (1D - cos) + (getZ() * cos) + (-y * getX() + x * getY()) * sin;
return result.set(xPos, yPos, zPos); return result.set(xPos, yPos, zPos);
} }
public default Vec3d rotateX(double angle){return rotateX(angle, this);}
public default Vec3d rotateX(double angle, Vec3d result) public default Vec3d rotateX(double angle) { return rotateX(angle, this); }
{
public default Vec3d rotateX(double angle, Vec3d result) {
double cos = MathUtils.cos(angle); double cos = MathUtils.cos(angle);
double sin = MathUtils.sin(angle); double sin = MathUtils.sin(angle);
double y = getY() * cos + getZ() * sin; double y = getY() * cos + getZ() * sin;
double z = getZ() * cos - getY() * sin; double z = getZ() * cos - getY() * sin;
return result.set(getX(), y, z); return result.set(getX(), y, z);
} }
public default Vec3d rotateY(double angle){return rotateY(angle, this);}
public default Vec3d rotateY(double angle, Vec3d result) public default Vec3d rotateY(double angle) { return rotateY(angle, this); }
{
public default Vec3d rotateY(double angle, Vec3d result) {
double cos = MathUtils.cos(angle); double cos = MathUtils.cos(angle);
double sin = MathUtils.sin(angle); double sin = MathUtils.sin(angle);
double x = getX() * cos + getZ() * sin; double x = getX() * cos + getZ() * sin;
double z = getZ() * cos - getX() * sin; double z = getZ() * cos - getX() * sin;
return result.set(x, getY(), z); return result.set(x, getY(), z);
} }
public default Vec3d rotateZ(double angle){return rotateZ(angle, this);}
public default Vec3d rotateZ(double angle, Vec3d result) public default Vec3d rotateZ(double angle) { return rotateZ(angle, this); }
{
public default Vec3d rotateZ(double angle, Vec3d result) {
double cos = MathUtils.cos(angle); double cos = MathUtils.cos(angle);
double sin = MathUtils.sin(angle); double sin = MathUtils.sin(angle);
double x = cos * getX() - sin * getY(); double x = cos * getX() - sin * getY();
@ -160,82 +247,129 @@ public interface Vec3d extends Vecd
return result.set(x, y, getZ()); return result.set(x, y, getZ());
} }
public default Vec3d smoothStep(Vec3d value, float progress, Vec3d result){return smoothStep(value.getX(), value.getY(), value.getZ(), progress, result);} public default Vec3d smoothStep(Vec3d value, float progress, Vec3d result) {
public default Vec3d smoothStep(double x, double y, double z, float progress, Vec3d result) return smoothStep(value.getX(), value.getY(), value.getZ(), progress, result);
{ }
double t2 = progress * progress;
double t3 = t2 * progress; public default Vec3d smoothStep(double x, double y, double z, float progress, Vec3d result) {
double xPos = ((getX() + getX() - x - x) * t3 + (3.0D * x - 3.0D * getX()) * t2 + getX() * progress + getX()); double t2 = progress * progress;
double yPos = ((getY() + getY() - y - y) * t3 + (3.0D * y - 3.0D * getY()) * t2 + getY() * progress + getY()); double t3 = t2 * progress;
double zPos = ((getZ() + getZ() - z - z) * t3 + (3.0D * z - 3.0D * getZ()) * t2 + getZ() * progress + getZ()); double xPos = ((getX() + getX() - x - x) * t3 + (3.0D * x - 3.0D * getX()) * t2 + getX() * progress + getX());
double yPos = ((getY() + getY() - y - y) * t3 + (3.0D * y - 3.0D * getY()) * t2 + getY() * progress + getY());
double zPos = ((getZ() + getZ() - z - z) * t3 + (3.0D * z - 3.0D * getZ()) * t2 + getZ() * progress + getZ());
return result.set(xPos, yPos, zPos); return result.set(xPos, yPos, zPos);
} }
public default Vec3d min(Vec3d other) {return min(other, this);}
public default Vec3d min(Vec3d other, Vec3d result){return min(other.getX(), other.getY(), other.getZ(), result);}
public default Vec3d min(double x, double y, double z) {return min(x, y, z, this);}
public default Vec3d min(double x, double y, double z, Vec3d result){return result.set(Math.min(getX(), x), Math.min(getY(), y), Math.min(getZ(), z));}
public default Vec3d max(Vec3d other) {return max(other, this);} public default Vec3d min(Vec3d other) { return min(other, this); }
public default Vec3d max(Vec3d other, Vec3d result){return max(other.getX(), other.getY(), other.getZ(), result);}
public default Vec3d max(double x, double y, double z) {return max(x, y, z, this);}
public default Vec3d max(double x, double y, double z, Vec3d result){return result.set(Math.max(getX(), x), Math.max(getY(), y), Math.max(getZ(), z));}
public default Vec3d difference(Vec3d other) {return difference(other, this);} public default Vec3d min(Vec3d other, Vec3d result) {
public default Vec3d difference(Vec3d other, Vec3d result){return difference(other.getX(), other.getY(), other.getZ(), result);} return min(other.getX(), other.getY(), other.getZ(), result);
public default Vec3d difference(double x, double y, double z) {return difference(x, y, z, this);} }
public default Vec3d difference(double x, double y, double z, Vec3d result){return result.set(getX() - x, getY() - y, getZ() - z);}
public default Vec3d min(double x, double y, double z) { return min(x, y, z, this); }
public default Vec3d min(double x, double y, double z, Vec3d result) {
return result.set(Math.min(getX(), x), Math.min(getY(), y), Math.min(getZ(), z));
}
public default Vec3d max(Vec3d other) { return max(other, this); }
public default Vec3d max(Vec3d other, Vec3d result) {
return max(other.getX(), other.getY(), other.getZ(), result);
}
public default Vec3d max(double x, double y, double z) { return max(x, y, z, this); }
public default Vec3d max(double x, double y, double z, Vec3d result) {
return result.set(Math.max(getX(), x), Math.max(getY(), y), Math.max(getZ(), z));
}
public default Vec3d difference(Vec3d other) { return difference(other, this); }
public default Vec3d difference(Vec3d other, Vec3d result) {
return difference(other.getX(), other.getY(), other.getZ(), result);
}
public default Vec3d difference(double x, double y, double z) {
return difference(x, y, z, this);
}
public default Vec3d difference(double x, double y, double z, Vec3d result) {
return result.set(getX() - x, getY() - y, getZ() - z);
}
@Override @Override
public default Vec3d clamp(double min, double max){return clamp(min, max, ALL);} public default Vec3d clamp(double min, double max) { return clamp(min, max, ALL); }
public default Vec3d clamp(double min, double max, Vec3d result){return clamp(min, max, result, ALL);}
@Override public default Vec3d clamp(double min, double max, Vec3d result) {
public default Vec3d clamp(double min, double max, int filter){return clamp(min, max, this, filter);} return clamp(min, max, result, ALL);
public default Vec3d clamp(double min, double max, Vec3d result, int filter){ return result.set((filter & X) == 0 ? getX() : MathUtils.clamp(min, max, getX()), (filter & Y) == 0 ? getY() : MathUtils.clamp(min, max, getY()), (filter & Z) == 0 ? getZ() : MathUtils.clamp(min, max, getZ()));} }
@Override @Override
public default Vec3d store(ByteBuffer buffer) public default Vec3d clamp(double min, double max, int filter) {
{ return clamp(min, max, this, filter);
}
public default Vec3d clamp(double min, double max, Vec3d result, int filter) {
return result.set((filter & X) == 0 ? getX() : MathUtils.clamp(min, max, getX()), (filter & Y) == 0 ? getY() : MathUtils.clamp(min, max, getY()), (filter & Z) == 0 ? getZ() : MathUtils.clamp(min, max, getZ()));
}
@Override
public default Vec3d store(ByteBuffer buffer) {
buffer.putDouble(getX()).putDouble(getY()).putDouble(getZ()); buffer.putDouble(getX()).putDouble(getY()).putDouble(getZ());
return this; return this;
} }
@Override @Override
public default Vec3d load(ByteBuffer buffer) public default Vec3d load(ByteBuffer buffer) {
{
return set(buffer.getDouble(), buffer.getDouble(), buffer.getDouble()); return set(buffer.getDouble(), buffer.getDouble(), buffer.getDouble());
} }
@Override @Override
public default Vec3d store(DoubleBuffer buffer) public default Vec3d store(DoubleBuffer buffer) {
{
buffer.put(getX()).put(getY()).put(getZ()); buffer.put(getX()).put(getY()).put(getZ());
return this; return this;
} }
@Override @Override
public default Vec3d load(DoubleBuffer buffer) public default Vec3d load(DoubleBuffer buffer) {
{
return set(buffer.get(), buffer.get(), buffer.get()); return set(buffer.get(), buffer.get(), buffer.get());
} }
@Override @Override
public default Vec3b asByte(){return isMutable() ? Vec3b.mutable((byte)MathUtils.floor(getX()), (byte)MathUtils.floor(getY()), (byte)MathUtils.floor(getZ())) : Vec3b.of((byte)MathUtils.floor(getX()), (byte)MathUtils.floor(getY()), (byte)MathUtils.floor(getZ()));} public default Vec3b asByte() {
@Override return isMutable() ? Vec3b.mutable((byte)MathUtils.floor(getX()), (byte)MathUtils.floor(getY()), (byte)MathUtils.floor(getZ())) : Vec3b.of((byte)MathUtils.floor(getX()), (byte)MathUtils.floor(getY()), (byte)MathUtils.floor(getZ()));
public default Vec3s asShort(){return isMutable() ? Vec3s.mutable((short)MathUtils.floor(getX()), (short)MathUtils.floor(getY()), (short)MathUtils.floor(getZ())) : Vec3s.of((short)MathUtils.floor(getX()), (short)MathUtils.floor(getY()), (short)MathUtils.floor(getZ()));} }
@Override
public default Vec3i asInt(){return isMutable() ? Vec3i.mutable(MathUtils.floor(getX()), MathUtils.floor(getY()), MathUtils.floor(getZ())) : Vec3i.of(MathUtils.floor(getX()), MathUtils.floor(getY()), MathUtils.floor(getZ()));}
@Override
public default Vec3l asLong() {return isMutable() ? Vec3l.mutable(MathUtils.floor(getX()), MathUtils.floor(getY()), MathUtils.floor(getZ())) : Vec3l.of(MathUtils.floor(getX()), MathUtils.floor(getY()), MathUtils.floor(getZ()));}
@Override
public default Vec3f asFloat(){return isMutable() ? Vec3f.mutable((float)getX(), (float)getY(), (float)getZ()) : Vec3f.of((float)getX(), (float)getY(), (float)getZ());}
@Override @Override
public default Vec3d asMutable(){return isMutable() ? this : mutable(this);} public default Vec3s asShort() {
return isMutable() ? Vec3s.mutable((short)MathUtils.floor(getX()), (short)MathUtils.floor(getY()), (short)MathUtils.floor(getZ())) : Vec3s.of((short)MathUtils.floor(getX()), (short)MathUtils.floor(getY()), (short)MathUtils.floor(getZ()));
}
@Override @Override
public default Vec3d asImmutable(){return isMutable() ? of(this) : this;} public default Vec3i asInt() {
return isMutable() ? Vec3i.mutable(MathUtils.floor(getX()), MathUtils.floor(getY()), MathUtils.floor(getZ())) : Vec3i.of(MathUtils.floor(getX()), MathUtils.floor(getY()), MathUtils.floor(getZ()));
}
@Override @Override
public default Vec3d copyAsMutable(){return mutable(this);} public default Vec3l asLong() {
return isMutable() ? Vec3l.mutable(MathUtils.floor(getX()), MathUtils.floor(getY()), MathUtils.floor(getZ())) : Vec3l.of(MathUtils.floor(getX()), MathUtils.floor(getY()), MathUtils.floor(getZ()));
}
@Override @Override
public default Vec3d copyAsImmutable(){return of(this);} public default Vec3f asFloat() {
return isMutable() ? Vec3f.mutable((float)getX(), (float)getY(), (float)getZ()) : Vec3f.of((float)getX(), (float)getY(), (float)getZ());
}
@Override
public default Vec3d asMutable() { return isMutable() ? this : mutable(this); }
@Override
public default Vec3d asImmutable() { return isMutable() ? of(this) : this; }
@Override
public default Vec3d copyAsMutable() { return mutable(this); }
@Override
public default Vec3d copyAsImmutable() { return of(this); }
} }

View File

@ -2,107 +2,59 @@ package speiger.src.coreengine.math.vector.doubles;
import java.util.Objects; import java.util.Objects;
public class Vec3dImmutable implements Vec3d public class Vec3dImmutable implements Vec3d {
{
final double x; final double x;
final double y; final double y;
final double z; final double z;
public Vec3dImmutable() public Vec3dImmutable() {
{
x = 0; x = 0;
y = 0; y = 0;
z = 0; z = 0;
} }
public Vec3dImmutable(double value) public Vec3dImmutable(double value) {
{
x = value; x = value;
y = value; y = value;
z = value; z = value;
} }
public Vec3dImmutable(double x, double y, double z) public Vec3dImmutable(double x, double y, double z) {
{
this.x = x; this.x = x;
this.y = y; this.y = y;
this.z = z; this.z = z;
} }
@Override
public boolean isMutable()
{
return false;
}
@Override @Override
public double getX() public boolean isMutable() { return false; }
{ @Override
return x; public double getX() { return x; }
} @Override
public double getY() { return y; }
@Override
public double getZ() { return z; }
@Override
public Vec3d setX(double x) { return this.x == x ? this : Vec3d.of(x, y, z); }
@Override
public Vec3d setY(double y) { return this.y == y ? this : Vec3d.of(x, y, z); }
@Override
public Vec3d setZ(double z) { return this.z == z ? this : Vec3d.of(x, y, z); }
@Override
public Vec3d copy() { return Vec3d.of(this); }
@Override
public Vec3d set(double x, double y, double z) { return this.x == x && this.y == y && this.z == z ? this : Vec3d.of(x, y, z); }
@Override
public int hashCode() { return Objects.hash(x, y, z); }
@Override @Override
public double getY() public boolean equals(Object obj) {
{ if(obj instanceof Vec3d) {
return y;
}
@Override
public double getZ()
{
return z;
}
@Override
public Vec3d setX(double x)
{
return this.x == x ? this : Vec3d.of(x, y, z);
}
@Override
public Vec3d setY(double y)
{
return this.y == y ? this : Vec3d.of(x, y, z);
}
@Override
public Vec3d setZ(double z)
{
return this.z == z ? this : Vec3d.of(x, y, z);
}
@Override
public Vec3d copy()
{
return Vec3d.of(this);
}
@Override
public Vec3d set(double x, double y, double z)
{
return this.x == x && this.y == y && this.z == z ? this : Vec3d.of(x, y, z);
}
@Override
public int hashCode()
{
return Objects.hash(x, y, z);
}
@Override
public boolean equals(Object obj)
{
if(obj instanceof Vec3d)
{
Vec3d vec = (Vec3d)obj; Vec3d vec = (Vec3d)obj;
return vec.getX() == x && vec.getY() == y && vec.getZ() == z; return vec.getX() == x && vec.getY() == y && vec.getZ() == z;
} }
return false; return false;
} }
@Override @Override
public String toString() public String toString() { return "Vec3d[x="+x+", y="+y+", z="+z+"]"; }
{
return "Vec3d[x="+x+", y="+y+", z="+z+"]";
}
} }

View File

@ -2,87 +2,61 @@ package speiger.src.coreengine.math.vector.doubles;
import java.util.Objects; import java.util.Objects;
public class Vec3dMutable implements Vec3d public class Vec3dMutable implements Vec3d {
{
double x; double x;
double y; double y;
double z; double z;
public Vec3dMutable() public Vec3dMutable() {
{
x = 0; x = 0;
y = 0; y = 0;
z = 0; z = 0;
} }
public Vec3dMutable(double value) public Vec3dMutable(double value) {
{
x = value; x = value;
y = value; y = value;
z = value; z = value;
} }
public Vec3dMutable(double x, double y, double z) public Vec3dMutable(double x, double y, double z) {
{
this.x = x; this.x = x;
this.y = y; this.y = y;
this.z = z; this.z = z;
} }
@Override @Override
public boolean isMutable() public boolean isMutable() { return true; }
{ @Override
return true; public double getX() { return x; }
} @Override
public double getY() { return y; }
@Override
public double getZ() { return z; }
@Override @Override
public double getX() public Vec3d setX(double x) {
{
return x;
}
@Override
public double getY()
{
return y;
}
@Override
public double getZ()
{
return z;
}
@Override
public Vec3d setX(double x)
{
this.x = x; this.x = x;
return this; return this;
} }
@Override @Override
public Vec3d setY(double y) public Vec3d setY(double y) {
{
this.y = y; this.y = y;
return this; return this;
} }
@Override @Override
public Vec3d setZ(double z) public Vec3d setZ(double z) {
{
this.z = z; this.z = z;
return this; return this;
} }
@Override @Override
public Vec3d copy() public Vec3d copy() { return Vec3d.mutable(this); }
{
return Vec3d.mutable(this);
}
@Override @Override
public Vec3d set(double x, double y, double z) public Vec3d set(double x, double y, double z) {
{
this.x = x; this.x = x;
this.y = y; this.y = y;
this.z = z; this.z = z;
@ -90,25 +64,17 @@ public class Vec3dMutable implements Vec3d
} }
@Override @Override
public int hashCode() public int hashCode() { return Objects.hash(x, y, z); }
{
return Objects.hash(x, y, z);
}
@Override @Override
public boolean equals(Object obj) public boolean equals(Object obj) {
{ if(obj instanceof Vec3d) {
if(obj instanceof Vec3d)
{
Vec3d vec = (Vec3d)obj; Vec3d vec = (Vec3d)obj;
return vec.getX() == x && vec.getY() == y && vec.getZ() == z; return vec.getX() == x && vec.getY() == y && vec.getZ() == z;
} }
return false; return false;
} }
@Override @Override
public String toString() public String toString() { return "Vec3d[x="+x+", y="+y+", z="+z+"]"; }
{
return "Vec3d[x="+x+", y="+y+", z="+z+"]";
}
} }

View File

@ -10,21 +10,19 @@ import speiger.src.coreengine.math.vector.ints.Vec4i;
import speiger.src.coreengine.math.vector.longs.Vec4l; import speiger.src.coreengine.math.vector.longs.Vec4l;
import speiger.src.coreengine.math.vector.shorts.Vec4s; import speiger.src.coreengine.math.vector.shorts.Vec4s;
public interface Vec4d extends Vecd public interface Vec4d extends Vecd {
{
public static final Vec4d ZERO = of(); public static final Vec4d ZERO = of();
public static final Vec4d MINUS_ONE = of(-1D); public static final Vec4d MINUS_ONE = of(-1D);
public static final Vec4d ONE = of(1D); public static final Vec4d ONE = of(1D);
public static Vec4d mutable(){return new Vec4dMutable();} public static Vec4d mutable() { return new Vec4dMutable(); }
public static Vec4d mutable(double value){return new Vec4dMutable(value);} public static Vec4d mutable(double value) { return new Vec4dMutable(value); }
public static Vec4d mutable(double x, double y, double z, double w){return new Vec4dMutable(x, y, z, w);} public static Vec4d mutable(double x, double y, double z, double w) { return new Vec4dMutable(x, y, z, w); }
public static Vec4d mutable(Vec4d vec){return mutable(vec.getX(), vec.getY(), vec.getZ(), vec.getW());} public static Vec4d mutable(Vec4d vec) { return mutable(vec.getX(), vec.getY(), vec.getZ(), vec.getW()); }
public static Vec4d of() { return new Vec4dImmutable(); }
public static Vec4d of(){return new Vec4dImmutable();} public static Vec4d of(double value) { return new Vec4dImmutable(value); }
public static Vec4d of(double value){return new Vec4dImmutable(value);} public static Vec4d of(double x, double y, double z, double w) { return new Vec4dImmutable(x, y, z, w); }
public static Vec4d of(double x, double y, double z, double w){return new Vec4dImmutable(x, y, z, w);} public static Vec4d of(Vec4d vec) { return of(vec.getX(), vec.getY(), vec.getZ(), vec.getW()); }
public static Vec4d of(Vec4d vec){return of(vec.getX(), vec.getY(), vec.getZ(), vec.getW());}
public double getX(); public double getX();
public double getY(); public double getY();
@ -34,114 +32,100 @@ public interface Vec4d extends Vecd
public Vec4d setY(double y); public Vec4d setY(double y);
public Vec4d setZ(double z); public Vec4d setZ(double z);
public Vec4d setW(double w); public Vec4d setW(double w);
@Override @Override
public default double[] asArray(){return new double[]{getX(), getY(), getZ(), getW()};} public default double[] asArray() { return new double[] {getX(), getY(), getZ(), getW()}; }
@Override @Override
public Vec4d copy(); public Vec4d copy();
@Override @Override
public default Vec4d abs(){return set(Math.abs(getX()), Math.abs(getY()), Math.abs(getZ()), Math.abs(getW()));} public default Vec4d abs() { return set(Math.abs(getX()), Math.abs(getY()), Math.abs(getZ()), Math.abs(getW())); }
@Override @Override
public default Vec4d negate(){return set(0D, 0D, 0D, 0D);} public default Vec4d negate() { return set(0D, 0D, 0D, 0D); }
@Override @Override
public default Vec4d invert(){return set(-getX(), -getY(), -getZ(), -getW());} public default Vec4d invert() { return set(-getX(), -getY(), -getZ(), -getW()); }
public default Vec4d normalize() public default Vec4d normalize() {
{
double l = length(); double l = length();
return l == 0D ? this : multiply(1.0D / l); return l == 0D ? this : multiply(1.0D / l);
} }
public default Vec4d normalize3D() {
public default Vec4d normalize3D()
{
double value = (getX() * getX()) + (getY() * getY()) + (getZ() * getZ()); double value = (getX() * getX()) + (getY() * getY()) + (getZ() * getZ());
return value == 0D ? this : multiply(1D / value); return value == 0D ? this : multiply(1D / value);
} }
@Override @Override
public default Vec4d add(double value){return add(value, value, value, value);} public default Vec4d add(double value) { return add(value, value, value, value); }
public default Vec4d add(Vec4d value){return add(value.getX(), value.getY(), value.getZ(), value.getW());} public default Vec4d add(Vec4d value) { return add(value.getX(), value.getY(), value.getZ(), value.getW()); }
public default Vec4d add(double x, double y, double z, double w){return set(getX() + x, getY() + y, getZ() + z, getW() + w);} public default Vec4d add(double x, double y, double z, double w) { return set(getX() + x, getY() + y, getZ() + z, getW() + w); }
@Override @Override
public default Vec4d sub(double value){return sub(value, value, value, value);} public default Vec4d sub(double value) { return sub(value, value, value, value); }
public default Vec4d sub(Vec4d value){return sub(value.getX(), value.getY(), value.getZ(), value.getW());} public default Vec4d sub(Vec4d value) { return sub(value.getX(), value.getY(), value.getZ(), value.getW()); }
public default Vec4d sub(double x, double y, double z, double w){return set(getX() - x, getY() - y, getZ() - z, getW() - w);} public default Vec4d sub(double x, double y, double z, double w) { return set(getX() - x, getY() - y, getZ() - z, getW() - w); }
@Override @Override
public default Vec4d multiply(double value){return multiply(value, value, value, value);} public default Vec4d multiply(double value) { return multiply(value, value, value, value); }
public default Vec4d multiply(Vec4d value){return multiply(value.getX(), value.getY(), value.getZ(), value.getW());} public default Vec4d multiply(Vec4d value) { return multiply(value.getX(), value.getY(), value.getZ(), value.getW()); }
public default Vec4d multiply(double x, double y, double z, double w){return set(getX() * x, getY() * y, getZ() * z, getW() * w);} public default Vec4d multiply(double x, double y, double z, double w) { return set(getX() * x, getY() * y, getZ() * z, getW() * w); }
@Override @Override
public default Vec4d devide(double value){return devide(value, value, value, value);} public default Vec4d devide(double value) { return devide(value, value, value, value); }
public default Vec4d devide(Vec4d value){return devide(value.getX(), value.getY(), value.getZ(), value.getW());} public default Vec4d devide(Vec4d value) { return devide(value.getX(), value.getY(), value.getZ(), value.getW()); }
public default Vec4d devide(double x, double y, double z, double w){return set(getX() / x, getY() / y, getZ() / z, getW() / w);} public default Vec4d devide(double x, double y, double z, double w) { return set(getX() / x, getY() / y, getZ() / z, getW() / w); }
@Override @Override
public default Vec4d set(double value){return set(value, value, value, value);} public default Vec4d set(double value) { return set(value, value, value, value); }
public default Vec4d set(Vec4d value){return set(value.getX(), value.getY(), value.getZ(), value.getW());} public default Vec4d set(Vec4d value) { return set(value.getX(), value.getY(), value.getZ(), value.getW()); }
public Vec4d set(double x, double y, double z, double w); public Vec4d set(double x, double y, double z, double w);
public default double distanceTo(Vec4d value){return distanceTo(value.getX(), value.getY(), value.getZ(), value.getW());} public default double distanceTo(Vec4d value) { return distanceTo(value.getX(), value.getY(), value.getZ(), value.getW()); }
public default double distanceTo(double x, double y, double z, double w){return Math.sqrt(distanceTo(x, y, z, w));} public default double distanceTo(double x, double y, double z, double w) { return Math.sqrt(distanceTo(x, y, z, w)); }
public default double distanceToSquared(Vec4d value) { return distanceToSquared(value.getX(), value.getY(), value.getZ(), value.getW()); }
public default double distanceToSquared(Vec4d value){return distanceToSquared(value.getX(), value.getY(), value.getZ(), value.getW());} public default double distanceToSquared(double x, double y, double z, double w) {
public default double distanceToSquared(double x, double y, double z, double w)
{
double xPos = getX() - x; double xPos = getX() - x;
double yPos = getY() - y; double yPos = getY() - y;
double zPos = getZ() - z; double zPos = getZ() - z;
double wPos = getW() - w; double wPos = getW() - w;
return (xPos * xPos) + (yPos * yPos) + (zPos * zPos) + (wPos * wPos); return (xPos * xPos) + (yPos * yPos) + (zPos * zPos) + (wPos * wPos);
} }
@Override @Override
public default double lengthSquared() {return (getX() * getX()) + (getY() * getY()) + (getZ() * getZ()) + (getW() * getW());} public default double lengthSquared() { return (getX() * getX()) + (getY() * getY()) + (getZ() * getZ()) + (getW() * getW()); }
public default double dotProduct(Vec4d value) { return dotProduct(value.getX(), value.getY(), value.getZ(), value.getW()); }
public default double dotProduct(Vec4d value){return dotProduct(value.getX(), value.getY(), value.getZ(), value.getW());} public default double dotProduct(double x, double y, double z, double w) { return (getX() * x) + (getY() * y) + (getZ() * z) + (getW() * w); };
public default double dotProduct(double x, double y, double z, double w){return (getX() * x) + (getY() * y) + (getZ() * z) + (getW() * w);}; public default Vec4d lerp(Vec4d value, float progress, Vec4d result) { return lerp(value.getX(), value.getY(), value.getZ(), value.getW(), progress, result); }
public default Vec4d lerp(double x, double y, double z, double w, float progress, Vec4d result) { return result.set(MathUtils.lerp(getX(), x, progress), MathUtils.lerp(getY(), y, progress), MathUtils.lerp(getZ(), z, progress), MathUtils.lerp(getW(), w, progress)); }
public default Vec4d lerp(Vec4d value, float progress, Vec4d result){return lerp(value.getX(), value.getY(), value.getZ(), value.getW(), progress, result);} public default double angle(Vec4d value) { return angle(value.getX(), value.getY(), value.getZ(), value.getW()); }
public default Vec4d lerp(double x, double y, double z, double w, float progress, Vec4d result){return result.set(MathUtils.lerp(getX(), x, progress), MathUtils.lerp(getY(), y, progress), MathUtils.lerp(getZ(), z, progress), MathUtils.lerp(getW(), w, progress));} public default double angle(double x, double y, double z, double w) { return Math.acos(MathUtils.clamp(-1D, 1D, angleCos(x, y, z, w))); }
public default double angleCos(Vec4d value) { return angleCos(value.getX(), value.getY(), value.getZ(), value.getW()); }
public default double angle(Vec4d value){return angle(value.getX(), value.getY(), value.getZ(), value.getW());} public default double angleCos(double x, double y, double z, double w) { return dotProduct(x, y, z, w) / Math.sqrt(lengthSquared() * (x * x) + (y * y) + (z * z) + (w * w)); }
public default double angle(double x, double y, double z, double w){return Math.acos(MathUtils.clamp(-1D, 1D, angleCos(x, y, z, w)));} public default Vec4d rotate(double angle, Vec4d axis) { return rotate(angle, axis.getX(), axis.getY(), axis.getZ(), axis.getW()); }
public default Vec4d rotate(double angle, Vec4d axis, Vec4d result) { return rotate(angle, axis.getX(), axis.getY(), axis.getZ(), axis.getW(), result); }
public default double angleCos(Vec4d value){return angleCos(value.getX(), value.getY(), value.getZ(), value.getW());} public default Vec4d rotate(double angle, double x, double y, double z, double w) { return rotate(angle, x, y, z, w, this); }
public default double angleCos(double x, double y, double z, double w){return dotProduct(x, y, z, w) / Math.sqrt(lengthSquared() * (x * x) + (y * y) + (z * z) + (w * w));} public default Vec4d rotate(double angle, double x, double y, double z, double w, Vec4d result) {
public default Vec4d rotate(double angle, Vec4d axis){return rotate(angle, axis.getX(), axis.getY(), axis.getZ(), axis.getW());}
public default Vec4d rotate(double angle, Vec4d axis, Vec4d result){return rotate(angle, axis.getX(), axis.getY(), axis.getZ(), axis.getW(), result);}
public default Vec4d rotate(double angle, double x, double y, double z, double w){return rotate(angle, x, y, z, w, this);}
public default Vec4d rotate(double angle, double x, double y, double z, double w, Vec4d result)
{
double cos = MathUtils.cos(angle); double cos = MathUtils.cos(angle);
double sin = MathUtils.sin(angle); double sin = MathUtils.sin(angle);
double dot = dotProduct(x, y, z, w); double dot = dotProduct(x, y, z, w);
double xPos = x * dot * (1D - cos) + (getX() * cos) + (-z * getY() + y * getZ()) * sin; double xPos = x * dot * (1D - cos) + (getX() * cos) + (-z * getY() + y * getZ()) * sin;
double yPos = y * dot * (1D - cos) + (getY() * cos) + (z * getX() - x * getZ()) * sin; double yPos = y * dot * (1D - cos) + (getY() * cos) + (z * getX() - x * getZ()) * sin;
double zPos = z * dot * (1D - cos) + (getZ() * cos) + (-y * getX() + x * getY()) * sin; double zPos = z * dot * (1D - cos) + (getZ() * cos) + (-y * getX() + x * getY()) * sin;
return result.set(xPos, yPos, zPos, getW()); return result.set(xPos, yPos, zPos, getW());
} }
public default Vec4d rotateX(double angle){return rotateX(angle, this);}
public default Vec4d rotateX(double angle, Vec4d result) public default Vec4d rotateX(double angle) { return rotateX(angle, this); }
{ public default Vec4d rotateX(double angle, Vec4d result) {
double cos = MathUtils.cos(angle); double cos = MathUtils.cos(angle);
double sin = MathUtils.sin(angle); double sin = MathUtils.sin(angle);
double y = getY() * cos + getZ() * sin; double y = getY() * cos + getZ() * sin;
double z = getZ() * cos - getY() * sin; double z = getZ() * cos - getY() * sin;
return result.set(getX(), y, z, getW()); return result.set(getX(), y, z, getW());
} }
public default Vec4d rotateY(double angle){return rotateY(angle, this);}
public default Vec4d rotateY(double angle, Vec4d result) public default Vec4d rotateY(double angle) { return rotateY(angle, this); }
{ public default Vec4d rotateY(double angle, Vec4d result) {
double cos = MathUtils.cos(angle); double cos = MathUtils.cos(angle);
double sin = MathUtils.sin(angle); double sin = MathUtils.sin(angle);
double x = getX() * cos + getZ() * sin; double x = getX() * cos + getZ() * sin;
double z = getZ() * cos - getX() * sin; double z = getZ() * cos - getX() * sin;
return result.set(x, getY(), z, getW()); return result.set(x, getY(), z, getW());
} }
public default Vec4d rotateZ(double angle){return rotateZ(angle, this);}
public default Vec4d rotateZ(double angle, Vec4d result) public default Vec4d rotateZ(double angle) { return rotateZ(angle, this); }
{ public default Vec4d rotateZ(double angle, Vec4d result) {
double cos = MathUtils.cos(angle); double cos = MathUtils.cos(angle);
double sin = MathUtils.sin(angle); double sin = MathUtils.sin(angle);
double x = cos * getX() - sin * getY(); double x = cos * getX() - sin * getY();
@ -149,83 +133,69 @@ public interface Vec4d extends Vecd
return result.set(x, y, getZ(), getW()); return result.set(x, y, getZ(), getW());
} }
public default Vec4d smoothStep(Vec4d value, float progress, Vec4d result){return smoothStep(value.getX(), value.getY(), value.getZ(), value.getW(), progress, result);} public default Vec4d smoothStep(Vec4d value, float progress, Vec4d result) { return smoothStep(value.getX(), value.getY(), value.getZ(), value.getW(), progress, result); }
public default Vec4d smoothStep(double x, double y, double z, double w, float progress, Vec4d result) public default Vec4d smoothStep(double x, double y, double z, double w, float progress, Vec4d result) {
{ double t2 = progress * progress;
double t2 = progress * progress; double t3 = t2 * progress;
double t3 = t2 * progress; double xPos = ((getX() + getX() - x - x) * t3 + (3.0D * x - 3.0D * getX()) * t2 + getX() * progress + getX());
double xPos = ((getX() + getX() - x - x) * t3 + (3.0D * x - 3.0D * getX()) * t2 + getX() * progress + getX()); double yPos = ((getY() + getY() - y - y) * t3 + (3.0D * y - 3.0D * getY()) * t2 + getY() * progress + getY());
double yPos = ((getY() + getY() - y - y) * t3 + (3.0D * y - 3.0D * getY()) * t2 + getY() * progress + getY()); double zPos = ((getZ() + getZ() - z - z) * t3 + (3.0D * z - 3.0D * getZ()) * t2 + getZ() * progress + getZ());
double zPos = ((getZ() + getZ() - z - z) * t3 + (3.0D * z - 3.0D * getZ()) * t2 + getZ() * progress + getZ()); double wPos = ((getW() + getW() - w - w) * t3 + (3.0D * w - 3.0D * getW()) * t2 + getW() * progress + getW());
double wPos = ((getW() + getW() - w - w) * t3 + (3.0D * w - 3.0D * getW()) * t2 + getW() * progress + getW());
return result.set(xPos, yPos, zPos, wPos); return result.set(xPos, yPos, zPos, wPos);
} }
public default Vec4d min(Vec4d other) {return min(other, this);} public default Vec4d min(Vec4d other) { return min(other, this); }
public default Vec4d min(Vec4d other, Vec4d result){return min(other.getX(), other.getY(), other.getZ(), other.getW(), result);} public default Vec4d min(Vec4d other, Vec4d result) { return min(other.getX(), other.getY(), other.getZ(), other.getW(), result); }
public default Vec4d min(double x, double y, double z, double w) {return min(x, y, z, w, this);} public default Vec4d min(double x, double y, double z, double w) { return min(x, y, z, w, this); }
public default Vec4d min(double x, double y, double z, double w, Vec4d result){return result.set(Math.min(getX(), x), Math.min(getY(), y), Math.min(getZ(), z), Math.min(getW(), w));} public default Vec4d min(double x, double y, double z, double w, Vec4d result) { return result.set(Math.min(getX(), x), Math.min(getY(), y), Math.min(getZ(), z), Math.min(getW(), w)); }
public default Vec4d max(Vec4d other) { return max(other, this); }
public default Vec4d max(Vec4d other) {return max(other, this);} public default Vec4d max(Vec4d other, Vec4d result) { return max(other.getX(), other.getY(), other.getZ(), other.getW(), result); }
public default Vec4d max(Vec4d other, Vec4d result){return max(other.getX(), other.getY(), other.getZ(), other.getW(), result);} public default Vec4d max(double x, double y, double z, double w) { return max(x, y, z, w, this); }
public default Vec4d max(double x, double y, double z, double w) {return max(x, y, z, w, this);} public default Vec4d max(double x, double y, double z, double w, Vec4d result) { return result.set(Math.max(getX(), x), Math.max(getY(), y), Math.max(getZ(), z), Math.max(getZ(), z)); }
public default Vec4d max(double x, double y, double z, double w, Vec4d result){return result.set(Math.max(getX(), x), Math.max(getY(), y), Math.max(getZ(), z), Math.max(getZ(), z));} public default Vec4d difference(Vec4d other) { return difference(other, this); }
public default Vec4d difference(Vec4d other, Vec4d result) { return difference(other.getX(), other.getY(), other.getZ(), other.getW(), result); }
public default Vec4d difference(Vec4d other) {return difference(other, this);} public default Vec4d difference(double x, double y, double z, double w) { return difference(x, y, z, w, this); }
public default Vec4d difference(Vec4d other, Vec4d result){return difference(other.getX(), other.getY(), other.getZ(), other.getW(), result);} public default Vec4d difference(double x, double y, double z, double w, Vec4d result) { return result.set(getX() - x, getY() - y, getZ() - z, getW() - w); }
public default Vec4d difference(double x, double y, double z, double w) {return difference(x, y, z, w, this);} @Override
public default Vec4d difference(double x, double y, double z, double w, Vec4d result){return result.set(getX() - x, getY() - y, getZ() - z, getW() - w);} public default Vec4d clamp(double min, double max) { return clamp(min, max, ALL); }
public default Vec4d clamp(double min, double max, Vec4d result) { return clamp(min, max, result, ALL); }
@Override
public default Vec4d clamp(double min, double max, int filter) { return clamp(min, max, this, filter); }
public default Vec4d clamp(double min, double max, Vec4d result, int filter) { return result.set((filter & X) == 0 ? getX() : MathUtils.clamp(min, max, getX()), (filter & Y) == 0 ? getY() : MathUtils.clamp(min, max, getY()), (filter & Z) == 0 ? getZ() : MathUtils.clamp(min, max, getZ()), (filter & W) == 0 ? getW() : MathUtils.clamp(min, max, getW())); }
@Override @Override
public default Vec4d clamp(double min, double max){return clamp(min, max, ALL);} public default Vec4d store(ByteBuffer buffer) {
public default Vec4d clamp(double min, double max, Vec4d result){return clamp(min, max, result, ALL);}
@Override
public default Vec4d clamp(double min, double max, int filter){return clamp(min, max, this, filter);}
public default Vec4d clamp(double min, double max, Vec4d result, int filter){ return result.set((filter & X) == 0 ? getX() : MathUtils.clamp(min, max, getX()), (filter & Y) == 0 ? getY() : MathUtils.clamp(min, max, getY()), (filter & Z) == 0 ? getZ() : MathUtils.clamp(min, max, getZ()), (filter & W) == 0 ? getW() : MathUtils.clamp(min, max, getW()));}
@Override
public default Vec4d store(ByteBuffer buffer)
{
buffer.putDouble(getX()).putDouble(getY()).putDouble(getZ()).putDouble(getW()); buffer.putDouble(getX()).putDouble(getY()).putDouble(getZ()).putDouble(getW());
return this; return this;
} }
@Override @Override
public default Vec4d load(ByteBuffer buffer) public default Vec4d load(ByteBuffer buffer) { return set(buffer.getDouble(), buffer.getDouble(), buffer.getDouble(), buffer.getDouble()); }
{
return set(buffer.getDouble(), buffer.getDouble(), buffer.getDouble(), buffer.getDouble());
}
@Override @Override
public default Vec4d store(DoubleBuffer buffer) public default Vec4d store(DoubleBuffer buffer) {
{
buffer.put(getX()).put(getY()).put(getZ()).put(getW()); buffer.put(getX()).put(getY()).put(getZ()).put(getW());
return this; return this;
} }
@Override @Override
public default Vec4d load(DoubleBuffer buffer) public default Vec4d load(DoubleBuffer buffer) { return set(buffer.get(), buffer.get(), buffer.get(), buffer.get()); }
{
return set(buffer.get(), buffer.get(), buffer.get(), buffer.get());
}
@Override @Override
public default Vec4b asByte(){return isMutable() ? Vec4b.mutable((byte)MathUtils.floor(getX()), (byte)MathUtils.floor(getY()), (byte)MathUtils.floor(getZ()), (byte)MathUtils.floor(getW())) : Vec4b.of((byte)MathUtils.floor(getX()), (byte)MathUtils.floor(getY()), (byte)MathUtils.floor(getZ()), (byte)MathUtils.floor(getW()));} public default Vec4b asByte() { return isMutable() ? Vec4b.mutable((byte)MathUtils.floor(getX()), (byte)MathUtils.floor(getY()), (byte)MathUtils.floor(getZ()), (byte)MathUtils.floor(getW())) : Vec4b.of((byte)MathUtils.floor(getX()), (byte)MathUtils.floor(getY()), (byte)MathUtils.floor(getZ()), (byte)MathUtils.floor(getW())); }
@Override @Override
public default Vec4s asShort(){return isMutable() ? Vec4s.mutable((short)MathUtils.floor(getX()), (short)MathUtils.floor(getY()), (short)MathUtils.floor(getZ()), (short)MathUtils.floor(getW())) : Vec4s.of((short)MathUtils.floor(getX()), (short)MathUtils.floor(getY()), (short)MathUtils.floor(getZ()), (short)MathUtils.floor(getW()));} public default Vec4s asShort() { return isMutable() ? Vec4s.mutable((short)MathUtils.floor(getX()), (short)MathUtils.floor(getY()), (short)MathUtils.floor(getZ()), (short)MathUtils.floor(getW())) : Vec4s.of((short)MathUtils.floor(getX()), (short)MathUtils.floor(getY()), (short)MathUtils.floor(getZ()), (short)MathUtils.floor(getW())); }
@Override @Override
public default Vec4i asInt(){return isMutable() ? Vec4i.mutable(MathUtils.floor(getX()), MathUtils.floor(getY()), MathUtils.floor(getZ()), MathUtils.floor(getW())) : Vec4i.of(MathUtils.floor(getX()), MathUtils.floor(getY()), MathUtils.floor(getZ()), MathUtils.floor(getW()));} public default Vec4i asInt() { return isMutable() ? Vec4i.mutable(MathUtils.floor(getX()), MathUtils.floor(getY()), MathUtils.floor(getZ()), MathUtils.floor(getW())) : Vec4i.of(MathUtils.floor(getX()), MathUtils.floor(getY()), MathUtils.floor(getZ()), MathUtils.floor(getW())); }
@Override @Override
public default Vec4l asLong() {return isMutable() ? Vec4l.mutable(MathUtils.floor(getX()), MathUtils.floor(getY()), MathUtils.floor(getZ()), MathUtils.floor(getW())) : Vec4l.of(MathUtils.floor(getX()), MathUtils.floor(getY()), MathUtils.floor(getZ()), MathUtils.floor(getW()));} public default Vec4l asLong() { return isMutable() ? Vec4l.mutable(MathUtils.floor(getX()), MathUtils.floor(getY()), MathUtils.floor(getZ()), MathUtils.floor(getW())) : Vec4l.of(MathUtils.floor(getX()), MathUtils.floor(getY()), MathUtils.floor(getZ()), MathUtils.floor(getW())); }
@Override @Override
public default Vec4f asFloat(){return isMutable() ? Vec4f.mutable((float)getX(), (float)getY(), (float)getZ(), (float)getW()) : Vec4f.of((float)getX(), (float)getY(), (float)getZ(), (float)getW());} public default Vec4f asFloat() { return isMutable() ? Vec4f.mutable((float)getX(), (float)getY(), (float)getZ(), (float)getW()) : Vec4f.of((float)getX(), (float)getY(), (float)getZ(), (float)getW()); }
@Override @Override
public default Vec4d asMutable(){return isMutable() ? this : mutable(this);} public default Vec4d asMutable() { return isMutable() ? this : mutable(this); }
@Override @Override
public default Vec4d asImmutable(){return isMutable() ? of(this) : this;} public default Vec4d asImmutable() { return isMutable() ? of(this) : this; }
@Override @Override
public default Vec4d copyAsMutable(){return mutable(this);} public default Vec4d copyAsMutable() { return mutable(this); }
@Override @Override
public default Vec4d copyAsImmutable(){return of(this);} public default Vec4d copyAsImmutable() { return of(this); }
} }

View File

@ -2,123 +2,71 @@ package speiger.src.coreengine.math.vector.doubles;
import java.util.Objects; import java.util.Objects;
public class Vec4dImmutable implements Vec4d public class Vec4dImmutable implements Vec4d {
{
final double x; final double x;
final double y; final double y;
final double z; final double z;
final double w; final double w;
public Vec4dImmutable() public Vec4dImmutable() {
{
x = 0; x = 0;
y = 0; y = 0;
z = 0; z = 0;
w = 0; w = 0;
} }
public Vec4dImmutable(double value) public Vec4dImmutable(double value) {
{
x = value; x = value;
y = value; y = value;
z = value; z = value;
w = value; w = value;
} }
public Vec4dImmutable(double x, double y, double z, double w) public Vec4dImmutable(double x, double y, double z, double w) {
{
this.x = x; this.x = x;
this.y = y; this.y = y;
this.z = z; this.z = z;
this.w = w; this.w = w;
} }
@Override @Override
public boolean isMutable() public boolean isMutable() { return false; }
{
return false;
}
@Override @Override
public double getX() public double getX() { return x; }
{
return x;
}
@Override @Override
public double getY() public double getY() { return y; }
{
return y;
}
@Override @Override
public double getZ() public double getZ() { return z; }
{
return z;
}
@Override @Override
public double getW() public double getW() { return w; }
{
return w;
}
@Override @Override
public Vec4d setX(double x) public Vec4d setX(double x) { return this.x == x ? this : Vec4d.of(x, y, z, w); }
{
return this.x == x ? this : Vec4d.of(x, y, z, w);
}
@Override @Override
public Vec4d setY(double y) public Vec4d setY(double y) { return this.y == y ? this : Vec4d.of(x, y, z, w); }
{
return this.y == y ? this : Vec4d.of(x, y, z, w);
}
@Override @Override
public Vec4d setZ(double z) public Vec4d setZ(double z) { return this.z == z ? this : Vec4d.of(x, y, z, w); }
{
return this.z == z ? this : Vec4d.of(x, y, z, w);
}
@Override @Override
public Vec4d setW(double w) public Vec4d setW(double w) { return this.w == w ? this : Vec4d.of(x, y, z, w); }
{
return this.w == w ? this : Vec4d.of(x, y, z, w);
}
@Override @Override
public Vec4d copy() public Vec4d copy() { return Vec4d.of(this); }
{
return Vec4d.of(this);
}
@Override @Override
public Vec4d set(double x, double y, double z, double w) public Vec4d set(double x, double y, double z, double w) {
{
return this.x == x && this.y == y && this.z == z && this.w == w ? this : Vec4d.of(x, y, z, w); return this.x == x && this.y == y && this.z == z && this.w == w ? this : Vec4d.of(x, y, z, w);
} }
@Override @Override
public int hashCode() public int hashCode() { return Objects.hash(x, y, z, w); }
{
return Objects.hash(x, y, z, w);
}
@Override @Override
public boolean equals(Object obj) public boolean equals(Object obj) {
{ if(obj instanceof Vec4d) {
if(obj instanceof Vec4d)
{
Vec4d vec = (Vec4d)obj; Vec4d vec = (Vec4d)obj;
return vec.getX() == x && vec.getY() == y && vec.getZ() == z && vec.getW() == w; return vec.getX() == x && vec.getY() == y && vec.getZ() == z && vec.getW() == w;
} }
return false; return false;
} }
@Override @Override
public String toString() public String toString() { return "Vec4d[x="+x+", y="+y+", z="+z+", w="+w+"]"; }
{
return "Vec4d[x="+x+", y="+y+", z="+z+", w="+w+"]";
}
} }

View File

@ -2,100 +2,68 @@ package speiger.src.coreengine.math.vector.doubles;
import java.util.Objects; import java.util.Objects;
public class Vec4dMutable implements Vec4d public class Vec4dMutable implements Vec4d {
{
double x; double x;
double y; double y;
double z; double z;
double w; double w;
public Vec4dMutable() public Vec4dMutable() {}
{
}
public Vec4dMutable(double value) public Vec4dMutable(double value) {
{
x = value; x = value;
y = value; y = value;
z = value; z = value;
w = value; w = value;
} }
public Vec4dMutable(double x, double y, double z, double w) public Vec4dMutable(double x, double y, double z, double w) {
{
this.x = x; this.x = x;
this.y = y; this.y = y;
this.z = z; this.z = z;
this.w = w; this.w = w;
} }
@Override
public boolean isMutable()
{
return true;
}
@Override @Override
public double getX() public boolean isMutable() { return true; }
{ @Override
return x; public double getX() { return x; }
} @Override
public double getY() { return y; }
@Override
public double getZ() { return z; }
@Override
public double getW() { return w; }
@Override @Override
public double getY() public Vec4d setX(double x) {
{
return y;
}
@Override
public double getZ()
{
return z;
}
@Override
public double getW()
{
return w;
}
@Override
public Vec4d setX(double x)
{
this.x = x; this.x = x;
return this; return this;
} }
@Override @Override
public Vec4d setY(double y) public Vec4d setY(double y) {
{
this.y = y; this.y = y;
return this; return this;
} }
@Override @Override
public Vec4d setZ(double z) public Vec4d setZ(double z) {
{
this.z = z; this.z = z;
return this; return this;
} }
@Override @Override
public Vec4d setW(double w) public Vec4d setW(double w) {
{
this.w = w; this.w = w;
return this; return this;
} }
@Override @Override
public Vec4d copy() public Vec4d copy() { return Vec4d.mutable(this); }
{
return Vec4d.mutable(this);
}
@Override @Override
public Vec4d set(double x, double y, double z, double w) public Vec4d set(double x, double y, double z, double w) {
{
this.x = x; this.x = x;
this.y = y; this.y = y;
this.z = z; this.z = z;
@ -104,16 +72,11 @@ public class Vec4dMutable implements Vec4d
} }
@Override @Override
public int hashCode() public int hashCode() { return Objects.hash(x, y, z, w); }
{
return Objects.hash(x, y, z, w);
}
@Override @Override
public boolean equals(Object obj) public boolean equals(Object obj) {
{ if(obj instanceof Vec4d) {
if(obj instanceof Vec4d)
{
Vec4d vec = (Vec4d)obj; Vec4d vec = (Vec4d)obj;
return vec.getX() == x && vec.getY() == y && vec.getZ() == z && vec.getW() == w; return vec.getX() == x && vec.getY() == y && vec.getZ() == z && vec.getW() == w;
} }
@ -121,8 +84,5 @@ public class Vec4dMutable implements Vec4d
} }
@Override @Override
public String toString() public String toString() { return "Vec4d[x="+x+", y="+y+", z="+z+", w="+w+"]"; }
{
return "Vec4d[x="+x+", y="+y+", z="+z+", w="+w+"]";
}
} }

View File

@ -9,8 +9,7 @@ import speiger.src.coreengine.math.vector.ints.Veci;
import speiger.src.coreengine.math.vector.longs.Vecl; import speiger.src.coreengine.math.vector.longs.Vecl;
import speiger.src.coreengine.math.vector.shorts.Vecs; import speiger.src.coreengine.math.vector.shorts.Vecs;
public interface Vecd extends Vec public interface Vecd extends Vec {
{
public Vecd set(double value); public Vecd set(double value);
public Vecd add(double value); public Vecd add(double value);
public Vecd sub(double value); public Vecd sub(double value);
@ -19,12 +18,10 @@ public interface Vecd extends Vec
public Vecd clamp(double min, double max); public Vecd clamp(double min, double max);
public Vecd clamp(double min, double max, int filter); public Vecd clamp(double min, double max, int filter);
public double lengthSquared(); public double lengthSquared();
public default double length(){return Math.sqrt(lengthSquared());} public default double length() { return Math.sqrt(lengthSquared()); }
public Vecd store(DoubleBuffer buffer); public Vecd store(DoubleBuffer buffer);
public Vecd load(DoubleBuffer buffer); public Vecd load(DoubleBuffer buffer);
public double[] asArray(); public double[] asArray();
public Vecb asByte(); public Vecb asByte();
public Vecs asShort(); public Vecs asShort();
public Veci asInt(); public Veci asInt();

View File

@ -10,178 +10,148 @@ import speiger.src.coreengine.math.vector.ints.Vec2i;
import speiger.src.coreengine.math.vector.longs.Vec2l; import speiger.src.coreengine.math.vector.longs.Vec2l;
import speiger.src.coreengine.math.vector.shorts.Vec2s; import speiger.src.coreengine.math.vector.shorts.Vec2s;
public interface Vec2f extends Vecf public interface Vec2f extends Vecf {
{
public static final Vec2f ZERO = of(); public static final Vec2f ZERO = of();
public static final Vec2f MINUS_ONE = of(-1F); public static final Vec2f MINUS_ONE = of(-1F);
public static final Vec2f ONE = of(1F); public static final Vec2f ONE = of(1F);
public static Vec2f mutable(){return new Vec2fMutable();} public static Vec2f mutable() { return new Vec2fMutable(); }
public static Vec2f mutable(float value){return new Vec2fMutable(value);} public static Vec2f mutable(float value) { return new Vec2fMutable(value); }
public static Vec2f mutable(float x, float y){return new Vec2fMutable(x, y);} public static Vec2f mutable(float x, float y) { return new Vec2fMutable(x, y); }
public static Vec2f mutable(Vec2f value){return mutable(value.getX(), value.getY());} public static Vec2f mutable(Vec2f value) { return mutable(value.getX(), value.getY()); }
public static Vec2f of() { return new Vec2fImmutable(); }
public static Vec2f of(){return new Vec2fImmutable();} public static Vec2f of(float value) { return new Vec2fImmutable(value); }
public static Vec2f of(float value){return new Vec2fImmutable(value);} public static Vec2f of(float x, float y) { return new Vec2fImmutable(x, y); }
public static Vec2f of(float x, float y){return new Vec2fImmutable(x, y);} public static Vec2f of(Vec2f value) { return of(value.getX(), value.getY()); }
public static Vec2f of(Vec2f value){return of(value.getX(), value.getY());}
public float getX(); public float getX();
public float getY(); public float getY();
public Vec2f setX(float x); public Vec2f setX(float x);
public Vec2f setY(float y); public Vec2f setY(float y);
@Override @Override
public default float[] asArray(){return new float[]{getX(), getY()};} public default float[] asArray() { return new float[] {getX(), getY()}; }
@Override @Override
public Vec2f copy(); public Vec2f copy();
@Override @Override
public default Vec2f abs(){return set(Math.abs(getX()), Math.abs(getY()));} public default Vec2f abs() { return set(Math.abs(getX()), Math.abs(getY())); }
@Override @Override
public default Vec2f negate(){return set(0F, 0F);} public default Vec2f negate() { return set(0F, 0F); }
@Override @Override
public default Vec2f invert(){return set(-getX(), -getY());}; public default Vec2f invert() { return set(-getX(), -getY()); };
public default Vec2f normalize() public default Vec2f normalize() {
{
float l = length(); float l = length();
return l == 0F ? this : multiply(1F / l); return l == 0F ? this : multiply(1F / l);
} }
@Override @Override
public default Vec2f add(float value) {return add(value, value);} public default Vec2f add(float value) { return add(value, value); }
public default Vec2f add(Vec2f value) {return add(value.getX(), value.getY());} public default Vec2f add(Vec2f value) { return add(value.getX(), value.getY()); }
public default Vec2f add(float x, float y) {return set(x + getX(), y + getY());} public default Vec2f add(float x, float y) { return set(x + getX(), y + getY()); }
@Override @Override
public default Vec2f sub(float value){return sub(value, value);} public default Vec2f sub(float value) { return sub(value, value); }
public default Vec2f sub(Vec2f value){return sub(value.getX(), value.getY());} public default Vec2f sub(Vec2f value) { return sub(value.getX(), value.getY()); }
public default Vec2f sub(float x, float y) {return set(getX() - x, getY() - y);} public default Vec2f sub(float x, float y) { return set(getX() - x, getY() - y); }
@Override @Override
public default Vec2f multiply(float value){return multiply(value, value);} public default Vec2f multiply(float value) { return multiply(value, value); }
public default Vec2f multiply(Vec2f value){return multiply(value.getX(), value.getY());} public default Vec2f multiply(Vec2f value) { return multiply(value.getX(), value.getY()); }
public default Vec2f multiply(float x, float y) {return set(x * getX(), y * getY());} public default Vec2f multiply(float x, float y) { return set(x * getX(), y * getY()); }
@Override @Override
public default Vec2f devide(float value){return devide(value, value);} public default Vec2f devide(float value) { return devide(value, value); }
public default Vec2f devide(Vec2f value){return devide(value.getX(), value.getY());} public default Vec2f devide(Vec2f value) { return devide(value.getX(), value.getY()); }
public default Vec2f devide(float x, float y){return set(getX() / x, getY() / y);} public default Vec2f devide(float x, float y) { return set(getX() / x, getY() / y); }
@Override @Override
public default Vec2f set(float value){return set(value, value);}; public default Vec2f set(float value) { return set(value, value); };
public default Vec2f set(Vec2f value){return set(value.getX(), value.getY());} public default Vec2f set(Vec2f value) { return set(value.getX(), value.getY()); }
public Vec2f set(float x, float y); public Vec2f set(float x, float y);
public default double distanceTo(Vec2f value) { return distanceTo(value.getX(), value.getY()); }
public default double distanceTo(Vec2f value){return distanceTo(value.getX(), value.getY());} public default double distanceTo(float x, float y) { return Math.sqrt(distanceToSquared(x, y)); }
public default double distanceTo(float x, float y){return Math.sqrt(distanceToSquared(x, y));} public default double distanceToSquared(Vec2f value) { return distanceToSquared(value.getX(), value.getY()); }
public default double distanceToSquared(float x, float y) {
public default double distanceToSquared(Vec2f value){return distanceToSquared(value.getX(), value.getY());}
public default double distanceToSquared(float x, float y)
{
double xPos = getX() - x; double xPos = getX() - x;
double yPos = getY() - y; double yPos = getY() - y;
return (xPos * xPos) + (yPos * yPos); return (xPos * xPos) + (yPos * yPos);
} }
@Override @Override
public default float lengthSquared() {return (getX() * getX()) + (getY() * getY());} public default float lengthSquared() { return (getX() * getX()) + (getY() * getY()); }
public default double dotProduct(Vec2f value) { return dotProduct(value.getX(), value.getY()); }
public default double dotProduct(Vec2f value){return dotProduct(value.getX(), value.getY());} public default double dotProduct(float x, float y) { return (getX() * x) + (getY() * y); }
public default double dotProduct(float x, float y){return (getX() * x) + (getY() * y);} public default Vec2f lerp(Vec2f value, float progress, Vec2f result) { return lerp(value.getX(), value.getY(), progress, result); }
public default Vec2f lerp(float x, float y, float progress, Vec2f result) { return result.set(MathUtils.lerp(getX(), x, progress), MathUtils.lerp(getY(), y, progress)); };
public default Vec2f lerp(Vec2f value, float progress, Vec2f result){return lerp(value.getX(), value.getY(), progress, result);} public default float angle(Vec2f value) { return angle(value.getX(), value.getY()); }
public default Vec2f lerp(float x, float y, float progress, Vec2f result){return result.set(MathUtils.lerp(getX(), x, progress), MathUtils.lerp(getY(), y, progress));}; public default float angle(float x, float y) { return (float)Math.atan2((getX() * y) - (getY() * x), (getX() * x) + (getY() * y)); }
public default float directionAngle(Vec2f value) { return directionAngle(value.getX(), value.getY()); }
public default float angle(Vec2f value){return angle(value.getX(), value.getY());} public default float directionAngle(float x, float y) { return (float)(-Math.toDegrees(Math.atan2(getX() - x, getY() - y)) % 360D); }
public default float angle(float x, float y){return (float)Math.atan2((getX() * y) - (getY() * x), (getX() * x) + (getY() * y));} public default Vec2f reflect(Vec2f value) { return reflect(value.getX(), value.getY(), this); }
public default Vec2f reflect(float x, float y) { return reflect(x, y, this); };
public default float directionAngle(Vec2f value){return directionAngle(value.getX(), value.getY());} public default Vec2f reflect(Vec2f value, Vec2f result) { return reflect(value.getX(), value.getY(), result); }
public default float directionAngle(float x, float y){return (float)(-Math.toDegrees(Math.atan2(getX() - x, getY() - y)) % 360D);} public default Vec2f reflect(float x, float y, Vec2f result) {
public default Vec2f reflect(Vec2f value){return reflect(value.getX(), value.getY(), this);}
public default Vec2f reflect(float x, float y){return reflect(x, y, this);};
public default Vec2f reflect(Vec2f value, Vec2f result){return reflect(value.getX(), value.getY(), result);}
public default Vec2f reflect(float x, float y, Vec2f result)
{
double dot = dotProduct(x, y); double dot = dotProduct(x, y);
float x2 = (float)((dot + dot) * x); float x2 = (float)((dot + dot) * x);
float y2 = (float)((dot + dot) * y); float y2 = (float)((dot + dot) * y);
return result.set(getX() - x2, getY() - y2); return result.set(getX() - x2, getY() - y2);
} }
public default Vec2f rotate(float angle, Vec2f center){return rotate(angle, center.getX(), center.getY());} public default Vec2f rotate(float angle, Vec2f center) { return rotate(angle, center.getX(), center.getY()); }
public default Vec2f rotate(float angle, float x, float y) public default Vec2f rotate(float angle, float x, float y) {
{
float xPos = getX() - x; float xPos = getX() - x;
float yPos = getY() - y; float yPos = getY() - y;
double cos = MathUtils.cos(angle); double cos = MathUtils.cos(angle);
double sin = MathUtils.sin(angle); double sin = MathUtils.sin(angle);
return set((float)((xPos * cos) + (yPos * sin) + x), (float)(-(xPos * sin) + (yPos * cos) + y)); return set((float)((xPos * cos) + (yPos * sin) + x), (float)(-(xPos * sin) + (yPos * cos) + y));
} }
public default Vec2f min(Vec2f other) {return min(other, this);} public default Vec2f min(Vec2f other) { return min(other, this); }
public default Vec2f min(Vec2f other, Vec2f result){return min(other.getX(), other.getY(), result);} public default Vec2f min(Vec2f other, Vec2f result) { return min(other.getX(), other.getY(), result); }
public default Vec2f min(float x, float y) {return min(x, y, this);} public default Vec2f min(float x, float y) { return min(x, y, this); }
public default Vec2f min(float x, float y, Vec2f result){return result.set(Math.min(getX(), x), Math.min(getY(), y));} public default Vec2f min(float x, float y, Vec2f result) { return result.set(Math.min(getX(), x), Math.min(getY(), y)); }
public default Vec2f max(Vec2f other) { return max(other, this); }
public default Vec2f max(Vec2f other) {return max(other, this);} public default Vec2f max(Vec2f other, Vec2f result) { return max(other.getX(), other.getY(), result); }
public default Vec2f max(Vec2f other, Vec2f result){return max(other.getX(), other.getY(), result);} public default Vec2f max(float x, float y) { return max(x, y, this); }
public default Vec2f max(float x, float y) {return max(x, y, this);} public default Vec2f max(float x, float y, Vec2f result) { return result.set(Math.max(getX(), x), Math.max(getY(), y)); }
public default Vec2f max(float x, float y, Vec2f result){return result.set(Math.max(getX(), x), Math.max(getY(), y));} public default Vec2f difference(Vec2f other) { return difference(other, this); }
public default Vec2f difference(Vec2f other, Vec2f result) { return difference(other.getX(), other.getY(), result); }
public default Vec2f difference(Vec2f other) {return difference(other, this);} public default Vec2f difference(float x, float y) { return difference(x, y, this); }
public default Vec2f difference(Vec2f other, Vec2f result){return difference(other.getX(), other.getY(), result);} public default Vec2f difference(float x, float y, Vec2f result) { return result.set(getX() - x, getY() - y); }
public default Vec2f difference(float x, float y) {return difference(x, y, this);}
public default Vec2f difference(float x, float y, Vec2f result){return result.set(getX() - x, getY() - y);}
@Override @Override
public default Vec2f clamp(float min, float max){return clamp(min, max, ALL);} public default Vec2f clamp(float min, float max) { return clamp(min, max, ALL); }
public default Vec2f clamp(float min, float max, Vec2f result){return clamp(min, max, result, ALL);} public default Vec2f clamp(float min, float max, Vec2f result) { return clamp(min, max, result, ALL); }
@Override @Override
public default Vec2f clamp(float min, float max, int filter){return clamp(min, max, this, filter);} public default Vec2f clamp(float min, float max, int filter) { return clamp(min, max, this, filter); }
public default Vec2f clamp(float min, float max, Vec2f result, int filter){ return result.set((filter & X) == 0 ? getX() : MathUtils.clamp(min, max, getX()), (filter & Y) == 0 ? getY() : MathUtils.clamp(min, max, getY()));} public default Vec2f clamp(float min, float max, Vec2f result, int filter) { return result.set((filter & X) == 0 ? getX() : MathUtils.clamp(min, max, getX()), (filter & Y) == 0 ? getY() : MathUtils.clamp(min, max, getY())); }
@Override @Override
public default Vec2f store(ByteBuffer buffer) public default Vec2f store(ByteBuffer buffer) {
{
buffer.putFloat(getX()).putFloat(getY()); buffer.putFloat(getX()).putFloat(getY());
return this; return this;
} }
@Override @Override
public default Vec2f load(ByteBuffer buffer) public default Vec2f load(ByteBuffer buffer) { return set(buffer.getFloat(), buffer.getFloat()); }
{
return set(buffer.getFloat(), buffer.getFloat());
}
@Override @Override
public default Vec2f store(FloatBuffer buffer) public default Vec2f store(FloatBuffer buffer) {
{
buffer.put(getX()).put(getY()); buffer.put(getX()).put(getY());
return this; return this;
} }
@Override @Override
public default Vec2f load(FloatBuffer buffer) public default Vec2f load(FloatBuffer buffer) { return set(buffer.get(), buffer.get()); }
{
return set(buffer.get(), buffer.get());
}
@Override @Override
public default Vec2b asByte(){return isMutable() ? Vec2b.mutable((byte)MathUtils.floor(getX()), (byte)MathUtils.floor(getY())) : Vec2b.of((byte)MathUtils.floor(getX()), (byte)MathUtils.floor(getY()));} public default Vec2b asByte() { return isMutable() ? Vec2b.mutable((byte)MathUtils.floor(getX()), (byte)MathUtils.floor(getY())) : Vec2b.of((byte)MathUtils.floor(getX()), (byte)MathUtils.floor(getY())); }
@Override @Override
public default Vec2s asShort(){return isMutable() ? Vec2s.mutable((short)MathUtils.floor(getX()), (short)MathUtils.floor(getY())) : Vec2s.of((short)MathUtils.floor(getX()), (short)MathUtils.floor(getY()));} public default Vec2s asShort() { return isMutable() ? Vec2s.mutable((short)MathUtils.floor(getX()), (short)MathUtils.floor(getY())) : Vec2s.of((short)MathUtils.floor(getX()), (short)MathUtils.floor(getY())); }
@Override @Override
public default Vec2i asInt(){return isMutable() ? Vec2i.mutable(MathUtils.floor(getX()), MathUtils.floor(getY())) : Vec2i.of(MathUtils.floor(getX()), MathUtils.floor(getY()));} public default Vec2i asInt() { return isMutable() ? Vec2i.mutable(MathUtils.floor(getX()), MathUtils.floor(getY())) : Vec2i.of(MathUtils.floor(getX()), MathUtils.floor(getY())); }
@Override @Override
public default Vec2l asLong() {return isMutable() ? Vec2l.mutable(MathUtils.floor(getX()), MathUtils.floor(getY())) : Vec2l.of(MathUtils.floor(getX()), MathUtils.floor(getY()));} public default Vec2l asLong() { return isMutable() ? Vec2l.mutable(MathUtils.floor(getX()), MathUtils.floor(getY())) : Vec2l.of(MathUtils.floor(getX()), MathUtils.floor(getY())); }
@Override @Override
public default Vec2d asDouble(){return isMutable() ? Vec2d.mutable(getX(), getY()) : Vec2d.of(getX(), getY());} public default Vec2d asDouble() { return isMutable() ? Vec2d.mutable(getX(), getY()) : Vec2d.of(getX(), getY()); }
@Override @Override
public default Vec2f asMutable(){return isMutable() ? this : mutable(this);} public default Vec2f asMutable() { return isMutable() ? this : mutable(this); }
@Override @Override
public default Vec2f asImmutable(){return isMutable() ? of(this) : this;} public default Vec2f asImmutable() { return isMutable() ? of(this) : this; }
@Override @Override
public default Vec2f copyAsMutable(){return mutable(this);} public default Vec2f copyAsMutable() { return mutable(this); }
@Override @Override
public default Vec2f copyAsImmutable(){return of(this);} public default Vec2f copyAsImmutable() { return of(this); }
} }

View File

@ -2,91 +2,52 @@ package speiger.src.coreengine.math.vector.floats;
import java.util.Objects; import java.util.Objects;
public class Vec2fImmutable implements Vec2f public class Vec2fImmutable implements Vec2f {
{
final float x; final float x;
final float y; final float y;
public Vec2fImmutable() public Vec2fImmutable() {
{
x = 0F; x = 0F;
y = 0F; y = 0F;
} }
public Vec2fImmutable(float value) public Vec2fImmutable(float value) {
{
x = value; x = value;
y = value; y = value;
} }
public Vec2fImmutable(float x, float y) public Vec2fImmutable(float x, float y) {
{
this.x = x; this.x = x;
this.y = y; this.y = y;
} }
@Override @Override
public boolean isMutable() public boolean isMutable() { return false; }
{ @Override
return false; public float getX() { return x; }
} @Override
public float getY() { return y; }
@Override
public Vec2f setX(float x) { return this.x == x ? this : Vec2f.of(x, y); }
@Override
public Vec2f setY(float y) { return this.y == y ? this : Vec2f.of(x, y); }
@Override
public Vec2f copy() { return Vec2f.of(x, y); }
@Override
public Vec2f set(float x, float y) { return this.x == x && this.y == y ? this : Vec2f.of(x, y); }
@Override @Override
public float getX() public int hashCode() { return Objects.hash(x, y); }
{
return x;
}
@Override @Override
public float getY() public boolean equals(Object obj) {
{ if(obj instanceof Vec2f) {
return y;
}
@Override
public Vec2f setX(float x)
{
return this.x == x ? this : Vec2f.of(x, y);
}
@Override
public Vec2f setY(float y)
{
return this.y == y ? this : Vec2f.of(x, y);
}
@Override
public Vec2f copy()
{
return Vec2f.of(x, y);
}
@Override
public Vec2f set(float x, float y)
{
return this.x == x && this.y == y ? this : Vec2f.of(x, y);
}
@Override
public int hashCode()
{
return Objects.hash(x, y);
}
@Override
public boolean equals(Object obj)
{
if(obj instanceof Vec2f)
{
Vec2f vec = (Vec2f)obj; Vec2f vec = (Vec2f)obj;
return vec.getX() == x && vec.getY() == y; return vec.getX() == x && vec.getY() == y;
} }
return false; return false;
} }
@Override @Override
public String toString() public String toString() { return "Vec2f[x="+x+", y="+y+"]"; }
{
return "Vec2f[x="+x+", y="+y+"]";
}
} }

View File

@ -2,93 +2,63 @@ package speiger.src.coreengine.math.vector.floats;
import java.util.Objects; import java.util.Objects;
public class Vec2fMutable implements Vec2f public class Vec2fMutable implements Vec2f {
{
float x; float x;
float y; float y;
public Vec2fMutable() public Vec2fMutable() {}
{
}
public Vec2fMutable(float value) public Vec2fMutable(float value) {
{
x = value; x = value;
y = value; y = value;
} }
public Vec2fMutable(float x, float y) public Vec2fMutable(float x, float y) {
{
this.x = x; this.x = x;
this.y = y; this.y = y;
} }
@Override @Override
public boolean isMutable() public boolean isMutable() { return true; }
{ @Override
return true; public float getX() { return x; }
} @Override
public float getY() { return y; }
@Override @Override
public float getX() public Vec2f setX(float x) {
{
return x;
}
@Override
public float getY()
{
return y;
}
@Override
public Vec2f setX(float x)
{
this.x = x; this.x = x;
return this; return this;
} }
@Override @Override
public Vec2f setY(float y) public Vec2f setY(float y) {
{
this.y = y; this.y = y;
return this; return this;
} }
@Override @Override
public Vec2f copy() public Vec2f copy() { return Vec2f.mutable(this); }
{
return Vec2f.mutable(this);
}
@Override @Override
public Vec2f set(float x, float y) public Vec2f set(float x, float y) {
{
this.x = x; this.x = x;
this.y = y; this.y = y;
return this; return this;
} }
@Override @Override
public int hashCode() public int hashCode() { return Objects.hash(x, y); }
{
return Objects.hash(x, y);
}
@Override @Override
public boolean equals(Object obj) public boolean equals(Object obj) {
{ if(obj instanceof Vec2f) {
if(obj instanceof Vec2f)
{
Vec2f vec = (Vec2f)obj; Vec2f vec = (Vec2f)obj;
return vec.getX() == x && vec.getY() == y; return vec.getX() == x && vec.getY() == y;
} }
return false; return false;
} }
@Override @Override
public String toString() public String toString() { return "Vec2f[x="+x+", y="+y+"]"; }
{
return "Vec2f[x="+x+", y="+y+"]";
}
} }

View File

@ -10,21 +10,19 @@ import speiger.src.coreengine.math.vector.ints.Vec3i;
import speiger.src.coreengine.math.vector.longs.Vec3l; import speiger.src.coreengine.math.vector.longs.Vec3l;
import speiger.src.coreengine.math.vector.shorts.Vec3s; import speiger.src.coreengine.math.vector.shorts.Vec3s;
public interface Vec3f extends Vecf public interface Vec3f extends Vecf {
{
public static final Vec3f ZERO = of(); public static final Vec3f ZERO = of();
public static final Vec3f MINUS_ONE = of(-1F); public static final Vec3f MINUS_ONE = of(-1F);
public static final Vec3f ONE = of(1F); public static final Vec3f ONE = of(1F);
public static Vec3f mutable(){return new Vec3fMutable();} public static Vec3f mutable() { return new Vec3fMutable(); }
public static Vec3f mutable(float value){return new Vec3fMutable(value);} public static Vec3f mutable(float value) { return new Vec3fMutable(value); }
public static Vec3f mutable(float x, float y, float z){return new Vec3fMutable(x, y, z);} public static Vec3f mutable(float x, float y, float z) { return new Vec3fMutable(x, y, z); }
public static Vec3f mutable(Vec3f vec){return mutable(vec.getX(), vec.getY(), vec.getZ());} public static Vec3f mutable(Vec3f vec) { return mutable(vec.getX(), vec.getY(), vec.getZ()); }
public static Vec3f of() { return new Vec3fImmutable(); }
public static Vec3f of(){return new Vec3fImmutable();} public static Vec3f of(float value) { return new Vec3fImmutable(value); }
public static Vec3f of(float value){return new Vec3fImmutable(value);} public static Vec3f of(float x, float y, float z) { return new Vec3fImmutable(x, y, z); }
public static Vec3f of(float x, float y, float z){return new Vec3fImmutable(x, y, z);} public static Vec3f of(Vec3f vec) { return of(vec.getX(), vec.getY(), vec.getZ()); }
public static Vec3f of(Vec3f vec){return of(vec.getX(), vec.getY(), vec.getZ());}
public float getX(); public float getX();
public float getY(); public float getY();
@ -32,127 +30,113 @@ public interface Vec3f extends Vecf
public Vec3f setX(float x); public Vec3f setX(float x);
public Vec3f setY(float y); public Vec3f setY(float y);
public Vec3f setZ(float z); public Vec3f setZ(float z);
@Override
public default float[] asArray(){return new float[]{getX(), getY(), getZ()};}
@Override
public default float[] asArray() { return new float[] {getX(), getY(), getZ()}; }
@Override @Override
public Vec3f copy(); public Vec3f copy();
@Override @Override
public default Vec3f abs(){return set(Math.abs(getX()), Math.abs(getY()), Math.abs(getZ()));} public default Vec3f abs() { return set(Math.abs(getX()), Math.abs(getY()), Math.abs(getZ())); }
@Override @Override
public default Vec3f negate(){return set(0F, 0F, 0F);} public default Vec3f negate() { return set(0F, 0F, 0F); }
@Override @Override
public default Vec3f invert(){return set(-getX(), -getY(), -getZ());} public default Vec3f invert() { return set(-getX(), -getY(), -getZ()); }
public default Vec3f normalize() public default Vec3f normalize() {
{
float l = length(); float l = length();
return l == 0F ? this : multiply(1.0F / l); return l == 0F ? this : multiply(1.0F / l);
} }
@Override
public default Vec3f add(float value){return add(value, value, value);}
public default Vec3f add(Vec3f value){return add(value.getX(), value.getY(), value.getZ());}
public default Vec3f add(float x, float y, float z){return set(getX() + x, getY() + y, getZ() + z);}
@Override
public default Vec3f sub(float value){return sub(value, value, value);}
public default Vec3f sub(Vec3f value){return sub(value.getX(), value.getY(), value.getZ());}
public default Vec3f sub(float x, float y, float z){return set(getX() - x, getY() - y, getZ() - z);}
@Override @Override
public default Vec3f multiply(float value){return multiply(value, value, value);} public default Vec3f add(float value) { return add(value, value, value); }
public default Vec3f multiply(Vec3f value){return multiply(value.getX(), value.getY(), value.getZ());} public default Vec3f add(Vec3f value) { return add(value.getX(), value.getY(), value.getZ()); }
public default Vec3f multiply(float x, float y, float z){return set(getX() * x, getY() * y, getZ() * z);} public default Vec3f add(float x, float y, float z) { return set(getX() + x, getY() + y, getZ() + z); }
@Override @Override
public default Vec3f devide(float value){return devide(value, value, value);} public default Vec3f sub(float value) { return sub(value, value, value); }
public default Vec3f devide(Vec3f value){return devide(value.getX(), value.getY(), value.getZ());} public default Vec3f sub(Vec3f value) { return sub(value.getX(), value.getY(), value.getZ()); }
public default Vec3f devide(float x, float y, float z){return set(getX() / x, getY() / y, getZ() / z);} public default Vec3f sub(float x, float y, float z) { return set(getX() - x, getY() - y, getZ() - z); }
@Override @Override
public default Vec3f set(float value){return set(value, value, value);} public default Vec3f multiply(float value) { return multiply(value, value, value); }
public default Vec3f set(Vec3f value){return set(value.getX(), value.getY(), value.getZ());} public default Vec3f multiply(Vec3f value) { return multiply(value.getX(), value.getY(), value.getZ()); }
public default Vec3f multiply(float x, float y, float z) { return set(getX() * x, getY() * y, getZ() * z); }
@Override
public default Vec3f devide(float value) { return devide(value, value, value); }
public default Vec3f devide(Vec3f value) { return devide(value.getX(), value.getY(), value.getZ()); }
public default Vec3f devide(float x, float y, float z) { return set(getX() / x, getY() / y, getZ() / z); }
@Override
public default Vec3f set(float value) { return set(value, value, value); }
public default Vec3f set(Vec3f value) { return set(value.getX(), value.getY(), value.getZ()); }
public Vec3f set(float x, float y, float z); public Vec3f set(float x, float y, float z);
public default double distanceTo(Vec3f value) { return distanceTo(value.getX(), value.getY(), value.getZ()); }
public default double distanceTo(Vec3f value){return distanceTo(value.getX(), value.getY(), value.getZ());} public default double distanceTo(float x, float y, float z) { return Math.sqrt(distanceToSquared(x, y, z)); }
public default double distanceTo(float x, float y, float z){return Math.sqrt(distanceToSquared(x, y, z));} public default double distanceToSquared(Vec3f value) { return distanceToSquared(value.getX(), value.getY(), value.getZ()); }
public default double distanceToSquared(float x, float y, float z) {
public default double distanceToSquared(Vec3f value){return distanceToSquared(value.getX(), value.getY(), value.getZ());}
public default double distanceToSquared(float x, float y, float z)
{
double xPos = getX() - x; double xPos = getX() - x;
double yPos = getY() - y; double yPos = getY() - y;
double zPos = getZ() - z; double zPos = getZ() - z;
return (xPos * xPos) + (yPos * yPos) + (zPos * zPos); return (xPos * xPos) + (yPos * yPos) + (zPos * zPos);
} }
@Override @Override
public default float lengthSquared() {return (getX() * getX()) + (getY() * getY()) + (getZ() * getZ());} public default float lengthSquared() { return (getX() * getX()) + (getY() * getY()) + (getZ() * getZ()); }
public default double dotProduct(Vec3f value) { return dotProduct(value.getX(), value.getY(), value.getZ()); }
public default double dotProduct(Vec3f value){return dotProduct(value.getX(), value.getY(), value.getZ());} public default double dotProduct(float x, float y, float z) { return (getX() * x) + (getY() * y) + (getZ() * z); }
public default double dotProduct(float x, float y, float z){return (getX() * x) + (getY() * y) + (getZ() * z);} public default Vec3f lerp(Vec3f value, float progress, Vec3f result) { return lerp(value.getX(), value.getY(), value.getZ(), progress, result); }
public default Vec3f lerp(float x, float y, float z, float progress, Vec3f result) { return result.set(MathUtils.lerp(getX(), x, progress), MathUtils.lerp(getY(), y, progress), MathUtils.lerp(getZ(), z, progress)); }
public default Vec3f lerp(Vec3f value, float progress, Vec3f result){return lerp(value.getX(), value.getY(), value.getZ(), progress, result);} public default float angle(Vec3f value) { return angle(value.getX(), value.getY(), value.getZ()); }
public default Vec3f lerp(float x, float y, float z, float progress, Vec3f result){return result.set(MathUtils.lerp(getX(), x, progress), MathUtils.lerp(getY(), y, progress), MathUtils.lerp(getZ(), z, progress));} public default float angle(float x, float y, float z) { return (float)Math.acos(MathUtils.clamp(-1, 1, angleCos(x, y, z))); }
public default float angleCos(Vec3f value) { return angleCos(value.getX(), value.getY(), value.getZ()); }
public default float angle(Vec3f value){return angle(value.getX(), value.getY(), value.getZ());} public default float angleCos(float x, float y, float z) {
public default float angle(float x, float y, float z){return (float)Math.acos(MathUtils.clamp(-1, 1, angleCos(x, y, z)));}
public default float angleCos(Vec3f value){return angleCos(value.getX(), value.getY(), value.getZ());}
public default float angleCos(float x, float y, float z)
{
double myLength = (getX() * getX()) + (getY() * getY()) + (getZ() * getZ()); double myLength = (getX() * getX()) + (getY() * getY()) + (getZ() * getZ());
double otherLength = (x * x) + (y * y) + (z * z); double otherLength = (x * x) + (y * y) + (z * z);
float dot = (getX() * x) + (getY() * y) + (getZ() * z); float dot = (getX() * x) + (getY() * y) + (getZ() * z);
return dot / (float)(Math.sqrt(myLength * otherLength)); return dot / (float)(Math.sqrt(myLength * otherLength));
} }
public default Vec3f crossProduct(Vec3f value){return crossProduct(value.getX(), value.getY(), value.getZ(), this);} public default Vec3f crossProduct(Vec3f value) { return crossProduct(value.getX(), value.getY(), value.getZ(), this); }
public default Vec3f crossProduct(Vec3f value, Vec3f result){return crossProduct(value.getX(), value.getY(), value.getZ(), result);} public default Vec3f crossProduct(Vec3f value, Vec3f result) { return crossProduct(value.getX(), value.getY(), value.getZ(), result); }
public default Vec3f crossProduct(float x, float y, float z){return crossProduct(x, y, z, this);} public default Vec3f crossProduct(float x, float y, float z) { return crossProduct(x, y, z, this); }
public default Vec3f crossProduct(float x, float y, float z, Vec3f result){return result.set((getY() * z) - (getZ() * y), (getZ() * x) - (getX() * z), (getX() * y) - (getY() * x));} public default Vec3f crossProduct(float x, float y, float z, Vec3f result) { return result.set((getY() * z) - (getZ() * y), (getZ() * x) - (getX() * z), (getX() * y) - (getY() * x)); }
public default Vec3f reflect(Vec3f value) { return reflect(value.getX(), value.getY(), value.getZ(), this); }
public default Vec3f reflect(Vec3f value){return reflect(value.getX(), value.getY(), value.getZ(), this);} public default Vec3f reflect(Vec3f value, Vec3f result) { return reflect(value.getX(), value.getY(), value.getZ(), result); }
public default Vec3f reflect(Vec3f value, Vec3f result){return reflect(value.getX(), value.getY(), value.getZ(), result);} public default Vec3f reflect(float x, float y, float z) { return reflect(x, y, z, this); }
public default Vec3f reflect(float x, float y, float z){return reflect(x, y, z, this);} public default Vec3f reflect(float x, float y, float z, Vec3f result) {
public default Vec3f reflect(float x, float y, float z, Vec3f result)
{
double dot = dotProduct(x, y, z) * 2D; double dot = dotProduct(x, y, z) * 2D;
return result.set(getX() - (float)(dot * x), getY() - (float)(dot * y), getZ() - (float)(dot * z)); return result.set(getX() - (float)(dot * x), getY() - (float)(dot * y), getZ() - (float)(dot * z));
} }
public default Vec3f rotate(float angle, Vec3f axis){return rotate(angle, axis.getX(), axis.getY(), axis.getZ());} public default Vec3f rotate(float angle, Vec3f axis) { return rotate(angle, axis.getX(), axis.getY(), axis.getZ()); }
public default Vec3f rotate(float angle, Vec3f axis, Vec3f result){return rotate(angle, axis.getX(), axis.getY(), axis.getZ(), result);} public default Vec3f rotate(float angle, Vec3f axis, Vec3f result) { return rotate(angle, axis.getX(), axis.getY(), axis.getZ(), result); }
public default Vec3f rotate(float angle, float x, float y, float z){return rotate(angle, x, y, z, this);} public default Vec3f rotate(float angle, float x, float y, float z) { return rotate(angle, x, y, z, this); }
public default Vec3f rotate(float angle, float x, float y, float z, Vec3f result) public default Vec3f rotate(float angle, float x, float y, float z, Vec3f result) {
{
double cos = MathUtils.cos(angle); double cos = MathUtils.cos(angle);
double sin = MathUtils.sin(angle); double sin = MathUtils.sin(angle);
double dot = dotProduct(x, y, z); double dot = dotProduct(x, y, z);
double xPos = x * dot * (1D - cos) + (getX() * cos) + (-z * getY() + y * getZ()) * sin; double xPos = x * dot * (1D - cos) + (getX() * cos) + (-z * getY() + y * getZ()) * sin;
double yPos = y * dot * (1D - cos) + (getY() * cos) + (z * getX() - x * getZ()) * sin; double yPos = y * dot * (1D - cos) + (getY() * cos) + (z * getX() - x * getZ()) * sin;
double zPos = z * dot * (1D - cos) + (getZ() * cos) + (-y * getX() + x * getY()) * sin; double zPos = z * dot * (1D - cos) + (getZ() * cos) + (-y * getX() + x * getY()) * sin;
return result.set((float)xPos, (float)yPos, (float)zPos); return result.set((float)xPos, (float)yPos, (float)zPos);
} }
public default Vec3f rotateX(float angle){return rotateX(angle, this);}
public default Vec3f rotateX(float angle, Vec3f result) public default Vec3f rotateX(float angle) { return rotateX(angle, this); }
{ public default Vec3f rotateX(float angle, Vec3f result) {
double cos = MathUtils.cos(angle); double cos = MathUtils.cos(angle);
double sin = MathUtils.sin(angle); double sin = MathUtils.sin(angle);
double y = getY() * cos + getZ() * sin; double y = getY() * cos + getZ() * sin;
double z = getZ() * cos - getY() * sin; double z = getZ() * cos - getY() * sin;
return result.set(getX(), (float)y, (float)z); return result.set(getX(), (float)y, (float)z);
} }
public default Vec3f rotateY(float angle){return rotateY(angle, this);}
public default Vec3f rotateY(float angle, Vec3f result) public default Vec3f rotateY(float angle) { return rotateY(angle, this); }
{ public default Vec3f rotateY(float angle, Vec3f result) {
double cos = MathUtils.cos(angle); double cos = MathUtils.cos(angle);
double sin = MathUtils.sin(angle); double sin = MathUtils.sin(angle);
double x = getX() * cos + getZ() * sin; double x = getX() * cos + getZ() * sin;
double z = getZ() * cos - getX() * sin; double z = getZ() * cos - getX() * sin;
return result.set((float)x, getY(), (float)z); return result.set((float)x, getY(), (float)z);
} }
public default Vec3f rotateZ(float angle){return rotateZ(angle, this);}
public default Vec3f rotateZ(float angle, Vec3f result) public default Vec3f rotateZ(float angle) { return rotateZ(angle, this); }
{ public default Vec3f rotateZ(float angle, Vec3f result) {
double cos = MathUtils.cos(angle); double cos = MathUtils.cos(angle);
double sin = MathUtils.sin(angle); double sin = MathUtils.sin(angle);
double x = cos * getX() - sin * getY(); double x = cos * getX() - sin * getY();
@ -160,83 +144,68 @@ public interface Vec3f extends Vecf
return result.set((float)x, (float)y, getZ()); return result.set((float)x, (float)y, getZ());
} }
public default Vec3f smoothStep(Vec3f value, float progress, Vec3f result){return smoothStep(value.getX(), value.getY(), value.getZ(), progress, result);} public default Vec3f smoothStep(Vec3f value, float progress, Vec3f result) { return smoothStep(value.getX(), value.getY(), value.getZ(), progress, result); }
public default Vec3f smoothStep(float x, float y, float z, float progress, Vec3f result) public default Vec3f smoothStep(float x, float y, float z, float progress, Vec3f result) {
{ float t2 = progress * progress;
float t2 = progress * progress; float t3 = t2 * progress;
float t3 = t2 * progress; float xPos = ((getX() + getX() - x - x) * t3 + (3.0F * x - 3.0F * getX()) * t2 + getX() * progress + getX());
float xPos = ((getX() + getX() - x - x) * t3 + (3.0F * x - 3.0F * getX()) * t2 + getX() * progress + getX()); float yPos = ((getY() + getY() - y - y) * t3 + (3.0F * y - 3.0F * getY()) * t2 + getY() * progress + getY());
float yPos = ((getY() + getY() - y - y) * t3 + (3.0F * y - 3.0F * getY()) * t2 + getY() * progress + getY()); float zPos = ((getZ() + getZ() - z - z) * t3 + (3.0F * z - 3.0F * getZ()) * t2 + getZ() * progress + getZ());
float zPos = ((getZ() + getZ() - z - z) * t3 + (3.0F * z - 3.0F * getZ()) * t2 + getZ() * progress + getZ());
return result.set(xPos, yPos, zPos); return result.set(xPos, yPos, zPos);
} }
public default Vec3f min(Vec3f other) {return min(other, this);}
public default Vec3f min(Vec3f other, Vec3f result){return min(other.getX(), other.getY(), other.getZ(), result);}
public default Vec3f min(float x, float y, float z) {return min(x, y, z, this);}
public default Vec3f min(float x, float y, float z, Vec3f result){return result.set(Math.min(getX(), x), Math.min(getY(), y), Math.min(getZ(), z));}
public default Vec3f max(Vec3f other) {return max(other, this);} public default Vec3f min(Vec3f other) { return min(other, this); }
public default Vec3f max(Vec3f other, Vec3f result){return max(other.getX(), other.getY(), other.getZ(), result);} public default Vec3f min(Vec3f other, Vec3f result) { return min(other.getX(), other.getY(), other.getZ(), result); }
public default Vec3f max(float x, float y, float z) {return max(x, y, z, this);} public default Vec3f min(float x, float y, float z) { return min(x, y, z, this); }
public default Vec3f max(float x, float y, float z, Vec3f result){return result.set(Math.max(getX(), x), Math.max(getY(), y), Math.max(getZ(), z));} public default Vec3f min(float x, float y, float z, Vec3f result) { return result.set(Math.min(getX(), x), Math.min(getY(), y), Math.min(getZ(), z)); }
public default Vec3f max(Vec3f other) { return max(other, this); }
public default Vec3f difference(Vec3f other) {return difference(other, this);} public default Vec3f max(Vec3f other, Vec3f result) { return max(other.getX(), other.getY(), other.getZ(), result); }
public default Vec3f difference(Vec3f other, Vec3f result){return difference(other.getX(), other.getY(), other.getZ(), result);} public default Vec3f max(float x, float y, float z) { return max(x, y, z, this); }
public default Vec3f difference(float x, float y, float z) {return difference(x, y, z, this);} public default Vec3f max(float x, float y, float z, Vec3f result) { return result.set(Math.max(getX(), x), Math.max(getY(), y), Math.max(getZ(), z)); }
public default Vec3f difference(float x, float y, float z, Vec3f result){return result.set(getX() - x, getY() - y, getZ() - z);} public default Vec3f difference(Vec3f other) { return difference(other, this); }
public default Vec3f difference(Vec3f other, Vec3f result) { return difference(other.getX(), other.getY(), other.getZ(), result); }
public default Vec3f difference(float x, float y, float z) { return difference(x, y, z, this); }
public default Vec3f difference(float x, float y, float z, Vec3f result) { return result.set(getX() - x, getY() - y, getZ() - z); }
@Override
public default Vec3f clamp(float min, float max) { return clamp(min, max, ALL); }
public default Vec3f clamp(float min, float max, Vec3f result) { return clamp(min, max, result, ALL); }
@Override
public default Vec3f clamp(float min, float max, int filter) { return clamp(min, max, this, filter); }
public default Vec3f clamp(float min, float max, Vec3f result, int filter) { return result.set((filter & X) == 0 ? getX() : MathUtils.clamp(min, max, getX()), (filter & Y) == 0 ? getY() : MathUtils.clamp(min, max, getY()), (filter & Z) == 0 ? getZ() : MathUtils.clamp(min, max, getZ())); }
@Override @Override
public default Vec3f clamp(float min, float max){return clamp(min, max, ALL);} public default Vec3f store(ByteBuffer buffer) {
public default Vec3f clamp(float min, float max, Vec3f result){return clamp(min, max, result, ALL);}
@Override
public default Vec3f clamp(float min, float max, int filter){return clamp(min, max, this, filter);}
public default Vec3f clamp(float min, float max, Vec3f result, int filter){ return result.set((filter & X) == 0 ? getX() : MathUtils.clamp(min, max, getX()), (filter & Y) == 0 ? getY() : MathUtils.clamp(min, max, getY()), (filter & Z) == 0 ? getZ() : MathUtils.clamp(min, max, getZ()));}
@Override
public default Vec3f store(ByteBuffer buffer)
{
buffer.putFloat(getX()).putFloat(getY()).putFloat(getZ()); buffer.putFloat(getX()).putFloat(getY()).putFloat(getZ());
return this; return this;
} }
@Override @Override
public default Vec3f load(ByteBuffer buffer) public default Vec3f load(ByteBuffer buffer) { return set(buffer.getFloat(), buffer.getFloat(), buffer.getFloat()); }
{
return set(buffer.getFloat(), buffer.getFloat(), buffer.getFloat());
}
@Override @Override
public default Vec3f store(FloatBuffer buffer) public default Vec3f store(FloatBuffer buffer) {
{
buffer.put(getX()).put(getY()).put(getZ()); buffer.put(getX()).put(getY()).put(getZ());
return this; return this;
} }
@Override @Override
public default Vec3f load(FloatBuffer buffer) public default Vec3f load(FloatBuffer buffer) { return set(buffer.get(), buffer.get(), buffer.get()); }
{
return set(buffer.get(), buffer.get(), buffer.get());
}
@Override @Override
public default Vec3b asByte(){return isMutable() ? Vec3b.mutable((byte)MathUtils.floor(getX()), (byte)MathUtils.floor(getY()), (byte)MathUtils.floor(getZ())) : Vec3b.of((byte)MathUtils.floor(getX()), (byte)MathUtils.floor(getY()), (byte)MathUtils.floor(getZ()));} public default Vec3b asByte() { return isMutable() ? Vec3b.mutable((byte)MathUtils.floor(getX()), (byte)MathUtils.floor(getY()), (byte)MathUtils.floor(getZ())) : Vec3b.of((byte)MathUtils.floor(getX()), (byte)MathUtils.floor(getY()), (byte)MathUtils.floor(getZ())); }
@Override @Override
public default Vec3s asShort(){return isMutable() ? Vec3s.mutable((short)MathUtils.floor(getX()), (short)MathUtils.floor(getY()), (short)MathUtils.floor(getZ())) : Vec3s.of((short)MathUtils.floor(getX()), (short)MathUtils.floor(getY()), (short)MathUtils.floor(getZ()));} public default Vec3s asShort() { return isMutable() ? Vec3s.mutable((short)MathUtils.floor(getX()), (short)MathUtils.floor(getY()), (short)MathUtils.floor(getZ())) : Vec3s.of((short)MathUtils.floor(getX()), (short)MathUtils.floor(getY()), (short)MathUtils.floor(getZ())); }
@Override @Override
public default Vec3i asInt(){return isMutable() ? Vec3i.mutable(MathUtils.floor(getX()), MathUtils.floor(getY()), MathUtils.floor(getZ())) : Vec3i.of(MathUtils.floor(getX()), MathUtils.floor(getY()), MathUtils.floor(getZ()));} public default Vec3i asInt() { return isMutable() ? Vec3i.mutable(MathUtils.floor(getX()), MathUtils.floor(getY()), MathUtils.floor(getZ())) : Vec3i.of(MathUtils.floor(getX()), MathUtils.floor(getY()), MathUtils.floor(getZ())); }
@Override @Override
public default Vec3l asLong() {return isMutable() ? Vec3l.mutable(MathUtils.floor(getX()), MathUtils.floor(getY()), MathUtils.floor(getZ())) : Vec3l.of(MathUtils.floor(getX()), MathUtils.floor(getY()), MathUtils.floor(getZ()));} public default Vec3l asLong() { return isMutable() ? Vec3l.mutable(MathUtils.floor(getX()), MathUtils.floor(getY()), MathUtils.floor(getZ())) : Vec3l.of(MathUtils.floor(getX()), MathUtils.floor(getY()), MathUtils.floor(getZ())); }
@Override @Override
public default Vec3d asDouble(){return isMutable() ? Vec3d.mutable(getX(), getY(), getZ()) : Vec3d.of(getX(), getY(), getZ());} public default Vec3d asDouble() { return isMutable() ? Vec3d.mutable(getX(), getY(), getZ()) : Vec3d.of(getX(), getY(), getZ()); }
@Override @Override
public default Vec3f asMutable(){return isMutable() ? this : mutable(this);} public default Vec3f asMutable() { return isMutable() ? this : mutable(this); }
@Override @Override
public default Vec3f asImmutable(){return isMutable() ? of(this) : this;} public default Vec3f asImmutable() { return isMutable() ? of(this) : this; }
@Override @Override
public default Vec3f copyAsMutable(){return mutable(this);} public default Vec3f copyAsMutable() { return mutable(this); }
@Override @Override
public default Vec3f copyAsImmutable(){return of(this);} public default Vec3f copyAsImmutable() { return of(this); }
} }

View File

@ -2,107 +2,60 @@ package speiger.src.coreengine.math.vector.floats;
import java.util.Objects; import java.util.Objects;
public class Vec3fImmutable implements Vec3f public class Vec3fImmutable implements Vec3f {
{
final float x; final float x;
final float y; final float y;
final float z; final float z;
public Vec3fImmutable() public Vec3fImmutable() {
{
x = 0F; x = 0F;
y = 0F; y = 0F;
z = 0F; z = 0F;
} }
public Vec3fImmutable(float value) public Vec3fImmutable(float value) {
{
x = value; x = value;
y = value; y = value;
z = value; z = value;
} }
public Vec3fImmutable(float x, float y, float z) public Vec3fImmutable(float x, float y, float z) {
{
this.x = x; this.x = x;
this.y = y; this.y = y;
this.z = z; this.z = z;
} }
@Override
public boolean isMutable()
{
return false;
}
@Override @Override
public float getX() public boolean isMutable() { return false; }
{ @Override
return x; public float getX() { return x; }
} @Override
public float getY() { return y; }
@Override
public float getZ() { return z; }
@Override
public Vec3f setX(float x) { return this.x == x ? this : Vec3f.of(x, y, z); }
@Override
public Vec3f setY(float y) { return this.y == y ? this : Vec3f.of(x, y, z); }
@Override
public Vec3f setZ(float z) { return this.z == z ? this : Vec3f.of(x, y, z); }
@Override
public Vec3f copy() { return Vec3f.of(this); }
@Override
public Vec3f set(float x, float y, float z) { return this.x == x && this.y == y && this.z == z ? this : Vec3f.of(x, y, z); }
@Override @Override
public float getY() public int hashCode() { return Objects.hash(x, y, z); }
{
return y;
}
@Override @Override
public float getZ() public boolean equals(Object obj) {
{ if(obj instanceof Vec3f) {
return z;
}
@Override
public Vec3f setX(float x)
{
return this.x == x ? this : Vec3f.of(x, y, z);
}
@Override
public Vec3f setY(float y)
{
return this.y == y ? this : Vec3f.of(x, y, z);
}
@Override
public Vec3f setZ(float z)
{
return this.z == z ? this : Vec3f.of(x, y, z);
}
@Override
public Vec3f copy()
{
return Vec3f.of(this);
}
@Override
public Vec3f set(float x, float y, float z)
{
return this.x == x && this.y == y && this.z == z ? this : Vec3f.of(x, y, z);
}
@Override
public int hashCode()
{
return Objects.hash(x, y, z);
}
@Override
public boolean equals(Object obj)
{
if(obj instanceof Vec3f)
{
Vec3f vec = (Vec3f)obj; Vec3f vec = (Vec3f)obj;
return vec.getX() == x && vec.getY() == y && vec.getZ() == z; return vec.getX() == x && vec.getY() == y && vec.getZ() == z;
} }
return false; return false;
} }
@Override @Override
public String toString() public String toString() { return "Vec3f[x="+x+", y="+y+", z="+z+"]"; }
{
return "Vec3f[x="+x+", y="+y+", z="+z+"]";
}
} }

View File

@ -2,84 +2,57 @@ package speiger.src.coreengine.math.vector.floats;
import java.util.Objects; import java.util.Objects;
public class Vec3fMutable implements Vec3f public class Vec3fMutable implements Vec3f {
{
float x; float x;
float y; float y;
float z; float z;
public Vec3fMutable() public Vec3fMutable() {}
{
}
public Vec3fMutable(float value) public Vec3fMutable(float value) {
{
x = value; x = value;
y = value; y = value;
z = value; z = value;
} }
public Vec3fMutable(float x, float y, float z) public Vec3fMutable(float x, float y, float z) {
{
this.x = x; this.x = x;
this.y = y; this.y = y;
this.z = z; this.z = z;
} }
@Override @Override
public boolean isMutable() public boolean isMutable() { return true; }
{ @Override
return true; public float getX() { return x; }
} @Override
public float getY() { return y; }
@Override
public float getZ() { return z; }
@Override @Override
public float getX() public Vec3f setX(float x) {
{
return x;
}
@Override
public float getY()
{
return y;
}
@Override
public float getZ()
{
return z;
}
@Override
public Vec3f setX(float x)
{
this.x = x; this.x = x;
return this; return this;
} }
@Override @Override
public Vec3f setY(float y) public Vec3f setY(float y) {
{
this.y = y; this.y = y;
return this; return this;
} }
@Override @Override
public Vec3f setZ(float z) public Vec3f setZ(float z) {
{
this.z = z; this.z = z;
return this; return this;
} }
@Override @Override
public Vec3f copy() public Vec3f copy() { return Vec3f.mutable(this); }
{
return Vec3f.mutable(this);
}
@Override @Override
public Vec3f set(float x, float y, float z) public Vec3f set(float x, float y, float z) {
{
this.x = x; this.x = x;
this.y = y; this.y = y;
this.z = z; this.z = z;
@ -87,25 +60,17 @@ public class Vec3fMutable implements Vec3f
} }
@Override @Override
public int hashCode() public int hashCode() { return Objects.hash(x, y, z); }
{
return Objects.hash(x, y, z);
}
@Override @Override
public boolean equals(Object obj) public boolean equals(Object obj) {
{ if(obj instanceof Vec3f) {
if(obj instanceof Vec3f)
{
Vec3f vec = (Vec3f)obj; Vec3f vec = (Vec3f)obj;
return vec.getX() == x && vec.getY() == y && vec.getZ() == z; return vec.getX() == x && vec.getY() == y && vec.getZ() == z;
} }
return false; return false;
} }
@Override @Override
public String toString() public String toString() { return "Vec3f[x="+x+", y="+y+", z="+z+"]"; }
{
return "Vec3f[x="+x+", y="+y+", z="+z+"]";
}
} }

View File

@ -10,21 +10,19 @@ import speiger.src.coreengine.math.vector.ints.Vec4i;
import speiger.src.coreengine.math.vector.longs.Vec4l; import speiger.src.coreengine.math.vector.longs.Vec4l;
import speiger.src.coreengine.math.vector.shorts.Vec4s; import speiger.src.coreengine.math.vector.shorts.Vec4s;
public interface Vec4f extends Vecf public interface Vec4f extends Vecf {
{
public static final Vec4f ZERO = of(); public static final Vec4f ZERO = of();
public static final Vec4f MINUS_ONE = of(-1F); public static final Vec4f MINUS_ONE = of(-1F);
public static final Vec4f ONE = of(1F); public static final Vec4f ONE = of(1F);
public static Vec4f mutable(){return new Vec4fMutable();} public static Vec4f mutable() { return new Vec4fMutable(); }
public static Vec4f mutable(float value){return new Vec4fMutable(value);} public static Vec4f mutable(float value) { return new Vec4fMutable(value); }
public static Vec4f mutable(float x, float y, float z, float w){return new Vec4fMutable(x, y, z, w);} public static Vec4f mutable(float x, float y, float z, float w) { return new Vec4fMutable(x, y, z, w); }
public static Vec4f mutable(Vec4f vec){return mutable(vec.getX(), vec.getY(), vec.getZ(), vec.getW());} public static Vec4f mutable(Vec4f vec) { return mutable(vec.getX(), vec.getY(), vec.getZ(), vec.getW()); }
public static Vec4f of() { return new Vec4fImmutable(); }
public static Vec4f of(){return new Vec4fImmutable();} public static Vec4f of(float value) { return new Vec4fImmutable(value); }
public static Vec4f of(float value){return new Vec4fImmutable(value);} public static Vec4f of(float x, float y, float z, float w) { return new Vec4fImmutable(x, y, z, w); }
public static Vec4f of(float x, float y, float z, float w){return new Vec4fImmutable(x, y, z, w);} public static Vec4f of(Vec4f vec) { return of(vec.getX(), vec.getY(), vec.getZ(), vec.getW()); }
public static Vec4f of(Vec4f vec){return of(vec.getX(), vec.getY(), vec.getZ(), vec.getW());}
public float getX(); public float getX();
public float getY(); public float getY();
@ -34,114 +32,101 @@ public interface Vec4f extends Vecf
public Vec4f setY(float y); public Vec4f setY(float y);
public Vec4f setZ(float z); public Vec4f setZ(float z);
public Vec4f setW(float w); public Vec4f setW(float w);
@Override @Override
public default float[] asArray(){return new float[]{getX(), getY(), getZ(), getW()};} public default float[] asArray() { return new float[] {getX(), getY(), getZ(), getW()}; }
@Override @Override
public Vec4f copy(); public Vec4f copy();
@Override @Override
public default Vec4f abs(){return set(Math.abs(getX()), Math.abs(getY()), Math.abs(getZ()), Math.abs(getW()));} public default Vec4f abs() { return set(Math.abs(getX()), Math.abs(getY()), Math.abs(getZ()), Math.abs(getW())); }
@Override @Override
public default Vec4f negate(){return set(0F, 0F, 0F, 0F);} public default Vec4f negate() { return set(0F, 0F, 0F, 0F); }
@Override @Override
public default Vec4f invert(){return set(-getX(), -getY(), -getZ(), -getW());} public default Vec4f invert() { return set(-getX(), -getY(), -getZ(), -getW()); }
public default Vec4f normalize() public default Vec4f normalize() {
{
float l = length(); float l = length();
return l == 0F ? this : multiply(1.0F / l); return l == 0F ? this : multiply(1.0F / l);
} }
public default Vec4f normalize3D() public default Vec4f normalize3D() {
{
float value = (getX() * getX()) + (getY() * getY()) + (getZ() * getZ()); float value = (getX() * getX()) + (getY() * getY()) + (getZ() * getZ());
return value == 0F ? this : multiply(1F / value); return value == 0F ? this : multiply(1F / value);
} }
@Override @Override
public default Vec4f add(float value){return add(value, value, value, value);} public default Vec4f add(float value) { return add(value, value, value, value); }
public default Vec4f add(Vec4f value){return add(value.getX(), value.getY(), value.getZ(), value.getW());} public default Vec4f add(Vec4f value) { return add(value.getX(), value.getY(), value.getZ(), value.getW()); }
public default Vec4f add(float x, float y, float z, float w){return set(getX() + x, getY() + y, getZ() + z, getW() + w);} public default Vec4f add(float x, float y, float z, float w) { return set(getX() + x, getY() + y, getZ() + z, getW() + w); }
@Override @Override
public default Vec4f sub(float value){return sub(value, value, value, value);} public default Vec4f sub(float value) { return sub(value, value, value, value); }
public default Vec4f sub(Vec4f value){return sub(value.getX(), value.getY(), value.getZ(), value.getW());} public default Vec4f sub(Vec4f value) { return sub(value.getX(), value.getY(), value.getZ(), value.getW()); }
public default Vec4f sub(float x, float y, float z, float w){return set(getX() - x, getY() - y, getZ() - z, getW() - w);} public default Vec4f sub(float x, float y, float z, float w) { return set(getX() - x, getY() - y, getZ() - z, getW() - w); }
@Override @Override
public default Vec4f multiply(float value){return multiply(value, value, value, value);} public default Vec4f multiply(float value) { return multiply(value, value, value, value); }
public default Vec4f multiply(Vec4f value){return multiply(value.getX(), value.getY(), value.getZ(), value.getW());} public default Vec4f multiply(Vec4f value) { return multiply(value.getX(), value.getY(), value.getZ(), value.getW()); }
public default Vec4f multiply(float x, float y, float z, float w){return set(getX() * x, getY() * y, getZ() * z, getW() * w);} public default Vec4f multiply(float x, float y, float z, float w) { return set(getX() * x, getY() * y, getZ() * z, getW() * w); }
@Override @Override
public default Vec4f devide(float value){return devide(value, value, value, value);} public default Vec4f devide(float value) { return devide(value, value, value, value); }
public default Vec4f devide(Vec4f value){return devide(value.getX(), value.getY(), value.getZ(), value.getW());} public default Vec4f devide(Vec4f value) { return devide(value.getX(), value.getY(), value.getZ(), value.getW()); }
public default Vec4f devide(float x, float y, float z, float w){return set(getX() / x, getY() / y, getZ() / z, getW() / w);} public default Vec4f devide(float x, float y, float z, float w) { return set(getX() / x, getY() / y, getZ() / z, getW() / w); }
@Override @Override
public default Vec4f set(float value){return set(value, value, value, value);} public default Vec4f set(float value) { return set(value, value, value, value); }
public default Vec4f set(Vec4f value){return set(value.getX(), value.getY(), value.getZ(), value.getW());} public default Vec4f set(Vec4f value) { return set(value.getX(), value.getY(), value.getZ(), value.getW()); }
public Vec4f set(float x, float y, float z, float w); public Vec4f set(float x, float y, float z, float w);
public default double distanceTo(Vec4f value) { return distanceTo(value.getX(), value.getY(), value.getZ(), value.getW()); }
public default double distanceTo(Vec4f value){return distanceTo(value.getX(), value.getY(), value.getZ(), value.getW());} public default double distanceTo(float x, float y, float z, float w) { return Math.sqrt(distanceTo(x, y, z, w)); }
public default double distanceTo(float x, float y, float z, float w){return Math.sqrt(distanceTo(x, y, z, w));} public default double distanceToSquared(Vec4f value) { return distanceToSquared(value.getX(), value.getY(), value.getZ(), value.getW()); }
public default double distanceToSquared(float x, float y, float z, float w) {
public default double distanceToSquared(Vec4f value){return distanceToSquared(value.getX(), value.getY(), value.getZ(), value.getW());}
public default double distanceToSquared(float x, float y, float z, float w)
{
double xPos = getX() - x; double xPos = getX() - x;
double yPos = getY() - y; double yPos = getY() - y;
double zPos = getZ() - z; double zPos = getZ() - z;
double wPos = getW() - w; double wPos = getW() - w;
return (xPos * xPos) + (yPos * yPos) + (zPos * zPos) + (wPos * wPos); return (xPos * xPos) + (yPos * yPos) + (zPos * zPos) + (wPos * wPos);
} }
@Override @Override
public default float lengthSquared() {return (getX() * getX()) + (getY() * getY()) + (getZ() * getZ()) + (getW() * getW());} public default float lengthSquared() { return (getX() * getX()) + (getY() * getY()) + (getZ() * getZ()) + (getW() * getW()); }
public default double dotProduct(Vec4f value) { return dotProduct(value.getX(), value.getY(), value.getZ(), value.getW()); }
public default double dotProduct(Vec4f value){return dotProduct(value.getX(), value.getY(), value.getZ(), value.getW());} public default double dotProduct(float x, float y, float z, float w) { return (getX() * x) + (getY() * y) + (getZ() * z) + (getW() * w); };
public default double dotProduct(float x, float y, float z, float w){return (getX() * x) + (getY() * y) + (getZ() * z) + (getW() * w);}; public default Vec4f lerp(Vec4f value, float progress, Vec4f result) { return lerp(value.getX(), value.getY(), value.getZ(), value.getW(), progress, result); }
public default Vec4f lerp(float x, float y, float z, float w, float progress, Vec4f result) { return result.set(MathUtils.lerp(getX(), x, progress), MathUtils.lerp(getY(), y, progress), MathUtils.lerp(getZ(), z, progress), MathUtils.lerp(getW(), w, progress)); }
public default Vec4f lerp(Vec4f value, float progress, Vec4f result){return lerp(value.getX(), value.getY(), value.getZ(), value.getW(), progress, result);} public default float angle(Vec4f value) { return angle(value.getX(), value.getY(), value.getZ(), value.getW()); }
public default Vec4f lerp(float x, float y, float z, float w, float progress, Vec4f result){return result.set(MathUtils.lerp(getX(), x, progress), MathUtils.lerp(getY(), y, progress), MathUtils.lerp(getZ(), z, progress), MathUtils.lerp(getW(), w, progress));} public default float angle(float x, float y, float z, float w) { return (float)Math.acos(MathUtils.clamp(-1F, 1F, angleCos(x, y, z, w))); }
public default float angleCos(Vec4f value) { return angleCos(value.getX(), value.getY(), value.getZ(), value.getW()); }
public default float angle(Vec4f value){return angle(value.getX(), value.getY(), value.getZ(), value.getW());} public default float angleCos(float x, float y, float z, float w) { return (float)(dotProduct(x, y, z, w) / Math.sqrt(lengthSquared() * (x * x) + (y * y) + (z * z) + (w * w))); }
public default float angle(float x, float y, float z, float w){return (float)Math.acos(MathUtils.clamp(-1F, 1F, angleCos(x, y, z, w)));} public default Vec4f rotate(float angle, Vec4f axis) { return rotate(angle, axis.getX(), axis.getY(), axis.getZ(), axis.getW()); }
public default Vec4f rotate(float angle, Vec4f axis, Vec4f result) { return rotate(angle, axis.getX(), axis.getY(), axis.getZ(), axis.getW(), result); }
public default float angleCos(Vec4f value){return angleCos(value.getX(), value.getY(), value.getZ(), value.getW());} public default Vec4f rotate(float angle, float x, float y, float z, float w) { return rotate(angle, x, y, z, w, this); }
public default float angleCos(float x, float y, float z, float w){return (float)(dotProduct(x, y, z, w) / Math.sqrt(lengthSquared() * (x * x) + (y * y) + (z * z) + (w * w)));} public default Vec4f rotate(float angle, float x, float y, float z, float w, Vec4f result) {
public default Vec4f rotate(float angle, Vec4f axis){return rotate(angle, axis.getX(), axis.getY(), axis.getZ(), axis.getW());}
public default Vec4f rotate(float angle, Vec4f axis, Vec4f result){return rotate(angle, axis.getX(), axis.getY(), axis.getZ(), axis.getW(), result);}
public default Vec4f rotate(float angle, float x, float y, float z, float w){return rotate(angle, x, y, z, w, this);}
public default Vec4f rotate(float angle, float x, float y, float z, float w, Vec4f result)
{
double cos = MathUtils.cos(angle); double cos = MathUtils.cos(angle);
double sin = MathUtils.sin(angle); double sin = MathUtils.sin(angle);
double dot = dotProduct(x, y, z, w); double dot = dotProduct(x, y, z, w);
double xPos = x * dot * (1D - cos) + (getX() * cos) + (-z * getY() + y * getZ()) * sin; double xPos = x * dot * (1D - cos) + (getX() * cos) + (-z * getY() + y * getZ()) * sin;
double yPos = y * dot * (1D - cos) + (getY() * cos) + (z * getX() - x * getZ()) * sin; double yPos = y * dot * (1D - cos) + (getY() * cos) + (z * getX() - x * getZ()) * sin;
double zPos = z * dot * (1D - cos) + (getZ() * cos) + (-y * getX() + x * getY()) * sin; double zPos = z * dot * (1D - cos) + (getZ() * cos) + (-y * getX() + x * getY()) * sin;
return result.set((float)xPos, (float)yPos, (float)zPos, getW()); return result.set((float)xPos, (float)yPos, (float)zPos, getW());
} }
public default Vec4f rotateX(float angle){return rotateX(angle, this);}
public default Vec4f rotateX(float angle, Vec4f result) public default Vec4f rotateX(float angle) { return rotateX(angle, this); }
{ public default Vec4f rotateX(float angle, Vec4f result) {
double cos = MathUtils.cos(angle); double cos = MathUtils.cos(angle);
double sin = MathUtils.sin(angle); double sin = MathUtils.sin(angle);
double y = getY() * cos + getZ() * sin; double y = getY() * cos + getZ() * sin;
double z = getZ() * cos - getY() * sin; double z = getZ() * cos - getY() * sin;
return result.set(getX(), (float)y, (float)z, getW()); return result.set(getX(), (float)y, (float)z, getW());
} }
public default Vec4f rotateY(float angle){return rotateY(angle, this);}
public default Vec4f rotateY(float angle, Vec4f result) public default Vec4f rotateY(float angle) { return rotateY(angle, this); }
{ public default Vec4f rotateY(float angle, Vec4f result) {
double cos = MathUtils.cos(angle); double cos = MathUtils.cos(angle);
double sin = MathUtils.sin(angle); double sin = MathUtils.sin(angle);
double x = getX() * cos + getZ() * sin; double x = getX() * cos + getZ() * sin;
double z = getZ() * cos - getX() * sin; double z = getZ() * cos - getX() * sin;
return result.set((float)x, getY(), (float)z, getW()); return result.set((float)x, getY(), (float)z, getW());
} }
public default Vec4f rotateZ(float angle){return rotateZ(angle, this);}
public default Vec4f rotateZ(float angle, Vec4f result) public default Vec4f rotateZ(float angle) { return rotateZ(angle, this); }
{ public default Vec4f rotateZ(float angle, Vec4f result) {
double cos = MathUtils.cos(angle); double cos = MathUtils.cos(angle);
double sin = MathUtils.sin(angle); double sin = MathUtils.sin(angle);
double x = cos * getX() - sin * getY(); double x = cos * getX() - sin * getY();
@ -149,84 +134,70 @@ public interface Vec4f extends Vecf
return result.set((float)x, (float)y, getZ(), getW()); return result.set((float)x, (float)y, getZ(), getW());
} }
public default Vec4f smoothStep(Vec4f value, float progress, Vec4f result){return smoothStep(value.getX(), value.getY(), value.getZ(), value.getW(), progress, result);} public default Vec4f smoothStep(Vec4f value, float progress, Vec4f result) { return smoothStep(value.getX(), value.getY(), value.getZ(), value.getW(), progress, result); }
public default Vec4f smoothStep(float x, float y, float z, float w, float progress, Vec4f result) public default Vec4f smoothStep(float x, float y, float z, float w, float progress, Vec4f result) {
{ float t2 = progress * progress;
float t2 = progress * progress; float t3 = t2 * progress;
float t3 = t2 * progress; float xPos = ((getX() + getX() - x - x) * t3 + (3.0F * x - 3.0F * getX()) * t2 + getX() * progress + getX());
float xPos = ((getX() + getX() - x - x) * t3 + (3.0F * x - 3.0F * getX()) * t2 + getX() * progress + getX()); float yPos = ((getY() + getY() - y - y) * t3 + (3.0F * y - 3.0F * getY()) * t2 + getY() * progress + getY());
float yPos = ((getY() + getY() - y - y) * t3 + (3.0F * y - 3.0F * getY()) * t2 + getY() * progress + getY()); float zPos = ((getZ() + getZ() - z - z) * t3 + (3.0F * z - 3.0F * getZ()) * t2 + getZ() * progress + getZ());
float zPos = ((getZ() + getZ() - z - z) * t3 + (3.0F * z - 3.0F * getZ()) * t2 + getZ() * progress + getZ()); float wPos = ((getW() + getW() - w - w) * t3 + (3.0F * w - 3.0F * getW()) * t2 + getW() * progress + getW());
float wPos = ((getW() + getW() - w - w) * t3 + (3.0F * w - 3.0F * getW()) * t2 + getW() * progress + getW());
return result.set(xPos, yPos, zPos, wPos); return result.set(xPos, yPos, zPos, wPos);
} }
public default Vec4f min(Vec4f other) {return min(other, this);} public default Vec4f min(Vec4f other) { return min(other, this); }
public default Vec4f min(Vec4f other, Vec4f result){return min(other.getX(), other.getY(), other.getZ(), other.getW(), result);} public default Vec4f min(Vec4f other, Vec4f result) { return min(other.getX(), other.getY(), other.getZ(), other.getW(), result); }
public default Vec4f min(float x, float y, float z, float w) {return min(x, y, z, w, this);} public default Vec4f min(float x, float y, float z, float w) { return min(x, y, z, w, this); }
public default Vec4f min(float x, float y, float z, float w, Vec4f result){return result.set(Math.min(getX(), x), Math.min(getY(), y), Math.min(getZ(), z), Math.min(getW(), w));} public default Vec4f min(float x, float y, float z, float w, Vec4f result) { return result.set(Math.min(getX(), x), Math.min(getY(), y), Math.min(getZ(), z), Math.min(getW(), w)); }
public default Vec4f max(Vec4f other) { return max(other, this); }
public default Vec4f max(Vec4f other) {return max(other, this);} public default Vec4f max(Vec4f other, Vec4f result) { return max(other.getX(), other.getY(), other.getZ(), other.getW(), result); }
public default Vec4f max(Vec4f other, Vec4f result){return max(other.getX(), other.getY(), other.getZ(), other.getW(), result);} public default Vec4f max(float x, float y, float z, float w) { return max(x, y, z, w, this); }
public default Vec4f max(float x, float y, float z, float w) {return max(x, y, z, w, this);} public default Vec4f max(float x, float y, float z, float w, Vec4f result) { return result.set(Math.max(getX(), x), Math.max(getY(), y), Math.max(getZ(), z), Math.max(getZ(), z)); }
public default Vec4f max(float x, float y, float z, float w, Vec4f result){return result.set(Math.max(getX(), x), Math.max(getY(), y), Math.max(getZ(), z), Math.max(getZ(), z));} public default Vec4f difference(Vec4f other) { return difference(other, this); }
public default Vec4f difference(Vec4f other, Vec4f result) { return difference(other.getX(), other.getY(), other.getZ(), other.getW(), result); }
public default Vec4f difference(Vec4f other) {return difference(other, this);} public default Vec4f difference(float x, float y, float z, float w) { return difference(x, y, z, w, this); }
public default Vec4f difference(Vec4f other, Vec4f result){return difference(other.getX(), other.getY(), other.getZ(), other.getW(), result);} public default Vec4f difference(float x, float y, float z, float w, Vec4f result) { return result.set(getX() - x, getY() - y, getZ() - z, getW() - w); }
public default Vec4f difference(float x, float y, float z, float w) {return difference(x, y, z, w, this);} @Override
public default Vec4f difference(float x, float y, float z, float w, Vec4f result){return result.set(getX() - x, getY() - y, getZ() - z, getW() - w);} public default Vec4f clamp(float min, float max) { return clamp(min, max, ALL); }
public default Vec4f clamp(float min, float max, Vec4f result) { return clamp(min, max, result, ALL); }
@Override
public default Vec4f clamp(float min, float max, int filter) { return clamp(min, max, this, filter); }
public default Vec4f clamp(float min, float max, Vec4f result, int filter) { return result.set((filter & X) == 0 ? getX() : MathUtils.clamp(min, max, getX()), (filter & Y) == 0 ? getY() : MathUtils.clamp(min, max, getY()), (filter & Z) == 0 ? getZ() : MathUtils.clamp(min, max, getZ()), (filter & W) == 0 ? getW() : MathUtils.clamp(min, max, getW())); }
@Override @Override
public default Vec4f clamp(float min, float max){return clamp(min, max, ALL);} public default Vec4f store(ByteBuffer buffer) {
public default Vec4f clamp(float min, float max, Vec4f result){return clamp(min, max, result, ALL);}
@Override
public default Vec4f clamp(float min, float max, int filter){return clamp(min, max, this, filter);}
public default Vec4f clamp(float min, float max, Vec4f result, int filter){ return result.set((filter & X) == 0 ? getX() : MathUtils.clamp(min, max, getX()), (filter & Y) == 0 ? getY() : MathUtils.clamp(min, max, getY()), (filter & Z) == 0 ? getZ() : MathUtils.clamp(min, max, getZ()), (filter & W) == 0 ? getW() : MathUtils.clamp(min, max, getW()));}
@Override
public default Vec4f store(ByteBuffer buffer)
{
buffer.putFloat(getX()).putFloat(getY()).putFloat(getZ()).putFloat(getW()); buffer.putFloat(getX()).putFloat(getY()).putFloat(getZ()).putFloat(getW());
return this; return this;
} }
@Override @Override
public default Vec4f load(ByteBuffer buffer) public default Vec4f load(ByteBuffer buffer) { return set(buffer.getFloat(), buffer.getFloat(), buffer.getFloat(), buffer.getFloat()); }
{
return set(buffer.getFloat(), buffer.getFloat(), buffer.getFloat(), buffer.getFloat());
}
@Override @Override
public default Vec4f store(FloatBuffer buffer) public default Vec4f store(FloatBuffer buffer) {
{
buffer.put(getX()).put(getY()).put(getZ()).put(getW()); buffer.put(getX()).put(getY()).put(getZ()).put(getW());
return this; return this;
} }
@Override @Override
public default Vec4f load(FloatBuffer buffer) public default Vec4f load(FloatBuffer buffer) { return set(buffer.get(), buffer.get(), buffer.get(), buffer.get()); }
{
return set(buffer.get(), buffer.get(), buffer.get(), buffer.get());
}
@Override @Override
public default Vec4b asByte(){return isMutable() ? Vec4b.mutable((byte)MathUtils.floor(getX()), (byte)MathUtils.floor(getY()), (byte)MathUtils.floor(getZ()), (byte)MathUtils.floor(getW())) : Vec4b.of((byte)MathUtils.floor(getX()), (byte)MathUtils.floor(getY()), (byte)MathUtils.floor(getZ()), (byte)MathUtils.floor(getW()));} public default Vec4b asByte() { return isMutable() ? Vec4b.mutable((byte)MathUtils.floor(getX()), (byte)MathUtils.floor(getY()), (byte)MathUtils.floor(getZ()), (byte)MathUtils.floor(getW())) : Vec4b.of((byte)MathUtils.floor(getX()), (byte)MathUtils.floor(getY()), (byte)MathUtils.floor(getZ()), (byte)MathUtils.floor(getW())); }
@Override @Override
public default Vec4s asShort(){return isMutable() ? Vec4s.mutable((short)MathUtils.floor(getX()), (short)MathUtils.floor(getY()), (short)MathUtils.floor(getZ()), (short)MathUtils.floor(getW())) : Vec4s.of((short)MathUtils.floor(getX()), (short)MathUtils.floor(getY()), (short)MathUtils.floor(getZ()), (short)MathUtils.floor(getW()));} public default Vec4s asShort() { return isMutable() ? Vec4s.mutable((short)MathUtils.floor(getX()), (short)MathUtils.floor(getY()), (short)MathUtils.floor(getZ()), (short)MathUtils.floor(getW())) : Vec4s.of((short)MathUtils.floor(getX()), (short)MathUtils.floor(getY()), (short)MathUtils.floor(getZ()), (short)MathUtils.floor(getW())); }
@Override @Override
public default Vec4i asInt(){return isMutable() ? Vec4i.mutable(MathUtils.floor(getX()), MathUtils.floor(getY()), MathUtils.floor(getZ()), MathUtils.floor(getW())) : Vec4i.of(MathUtils.floor(getX()), MathUtils.floor(getY()), MathUtils.floor(getZ()), MathUtils.floor(getW()));} public default Vec4i asInt() { return isMutable() ? Vec4i.mutable(MathUtils.floor(getX()), MathUtils.floor(getY()), MathUtils.floor(getZ()), MathUtils.floor(getW())) : Vec4i.of(MathUtils.floor(getX()), MathUtils.floor(getY()), MathUtils.floor(getZ()), MathUtils.floor(getW())); }
@Override @Override
public default Vec4l asLong() {return isMutable() ? Vec4l.mutable(MathUtils.floor(getX()), MathUtils.floor(getY()), MathUtils.floor(getZ()), MathUtils.floor(getW())) : Vec4l.of(MathUtils.floor(getX()), MathUtils.floor(getY()), MathUtils.floor(getZ()), MathUtils.floor(getW()));} public default Vec4l asLong() { return isMutable() ? Vec4l.mutable(MathUtils.floor(getX()), MathUtils.floor(getY()), MathUtils.floor(getZ()), MathUtils.floor(getW())) : Vec4l.of(MathUtils.floor(getX()), MathUtils.floor(getY()), MathUtils.floor(getZ()), MathUtils.floor(getW())); }
@Override @Override
public default Vec4d asDouble(){return isMutable() ? Vec4d.mutable(getX(), getY(), getZ(), getW()) : Vec4d.of(getX(), getY(), getZ(), getW());} public default Vec4d asDouble() { return isMutable() ? Vec4d.mutable(getX(), getY(), getZ(), getW()) : Vec4d.of(getX(), getY(), getZ(), getW()); }
@Override @Override
public default Vec4f asMutable(){return isMutable() ? this : mutable(this);} public default Vec4f asMutable() { return isMutable() ? this : mutable(this); }
@Override @Override
public default Vec4f asImmutable(){return isMutable() ? of(this) : this;} public default Vec4f asImmutable() { return isMutable() ? of(this) : this; }
@Override @Override
public default Vec4f copyAsMutable(){return mutable(this);} public default Vec4f copyAsMutable() { return mutable(this); }
@Override @Override
public default Vec4f copyAsImmutable(){return of(this);} public default Vec4f copyAsImmutable() { return of(this); }
} }

View File

@ -2,114 +2,61 @@ package speiger.src.coreengine.math.vector.floats;
import java.util.Objects; import java.util.Objects;
public class Vec4fImmutable implements Vec4f public class Vec4fImmutable implements Vec4f {
{
final float x; final float x;
final float y; final float y;
final float z; final float z;
final float w; final float w;
public Vec4fImmutable() public Vec4fImmutable() {
{
x = 0; x = 0;
y = 0; y = 0;
z = 0; z = 0;
w = 0; w = 0;
} }
public Vec4fImmutable(float value) public Vec4fImmutable(float value) {
{
x = value; x = value;
y = value; y = value;
z = value; z = value;
w = value; w = value;
} }
public Vec4fImmutable(float x, float y, float z, float w) public Vec4fImmutable(float x, float y, float z, float w) {
{
this.x = x; this.x = x;
this.y = y; this.y = y;
this.z = z; this.z = z;
this.w = w; this.w = w;
} }
@Override
public boolean isMutable()
{
return false;
}
@Override @Override
public float getX() public boolean isMutable() { return false; }
{ @Override
return x; public float getX() { return x; }
} @Override
public float getY() { return y; }
@Override
public float getZ() { return z; }
@Override
public float getW() { return w; }
@Override
public Vec4f setX(float x) { return this.x == x ? this : Vec4f.of(x, y, z, w); }
@Override
public Vec4f setY(float y) { return this.y == y ? this : Vec4f.of(x, y, z, w); }
@Override
public Vec4f setZ(float z) { return this.z == z ? this : Vec4f.of(x, y, z, w); }
@Override
public Vec4f setW(float w) { return this.w == w ? this : Vec4f.of(x, y, z, w); }
@Override
public Vec4f copy() { return Vec4f.of(this); }
@Override
public Vec4f set(float x, float y, float z, float w) { return this.x == x && this.y == y && this.z == z && this.w == w ? this : Vec4f.of(x, y, z, w); }
@Override
public int hashCode() { return Objects.hash(x, y, z, w); }
@Override @Override
public float getY() public boolean equals(Object obj) {
{ if(obj instanceof Vec4f) {
return y;
}
@Override
public float getZ()
{
return z;
}
@Override
public float getW()
{
return w;
}
@Override
public Vec4f setX(float x)
{
return this.x == x ? this : Vec4f.of(x, y, z, w);
}
@Override
public Vec4f setY(float y)
{
return this.y == y ? this : Vec4f.of(x, y, z, w);
}
@Override
public Vec4f setZ(float z)
{
return this.z == z ? this : Vec4f.of(x, y, z, w);
}
@Override
public Vec4f setW(float w)
{
return this.w == w ? this : Vec4f.of(x, y, z, w);
}
@Override
public Vec4f copy()
{
return Vec4f.of(this);
}
@Override
public Vec4f set(float x, float y, float z, float w)
{
return this.x == x && this.y == y && this.z == z && this.w == w ? this : Vec4f.of(x, y, z, w);
}
@Override
public int hashCode()
{
return Objects.hash(x, y, z, w);
}
@Override
public boolean equals(Object obj)
{
if(obj instanceof Vec4f)
{
Vec4f vec = (Vec4f)obj; Vec4f vec = (Vec4f)obj;
return vec.getX() == x && vec.getY() == y && vec.getZ() == z && vec.getW() == w; return vec.getX() == x && vec.getY() == y && vec.getZ() == z && vec.getW() == w;
} }
@ -117,8 +64,5 @@ public class Vec4fImmutable implements Vec4f
} }
@Override @Override
public String toString() public String toString() { return "Vec4f[x="+x+", y="+y+", z="+z+", w="+w+"]"; }
{
return "Vec4f[x="+x+", y="+y+", z="+z+", w="+w+"]";
}
} }

View File

@ -2,31 +2,27 @@ package speiger.src.coreengine.math.vector.floats;
import java.util.Objects; import java.util.Objects;
public class Vec4fMutable implements Vec4f public class Vec4fMutable implements Vec4f {
{
float x; float x;
float y; float y;
float z; float z;
float w; float w;
public Vec4fMutable() public Vec4fMutable() {
{
x = 0; x = 0;
y = 0; y = 0;
z = 0; z = 0;
w = 0; w = 0;
} }
public Vec4fMutable(float value) public Vec4fMutable(float value) {
{
x = value; x = value;
y = value; y = value;
z = value; z = value;
w = value; w = value;
} }
public Vec4fMutable(float x, float y, float z, float w) public Vec4fMutable(float x, float y, float z, float w) {
{
this.x = x; this.x = x;
this.y = y; this.y = y;
this.z = z; this.z = z;
@ -34,72 +30,45 @@ public class Vec4fMutable implements Vec4f
} }
@Override @Override
public boolean isMutable() public boolean isMutable() { return true; }
{ @Override
return true; public float getX() { return x; }
} @Override
public float getY() { return y; }
@Override
public float getZ() { return z; }
@Override
public float getW() { return w; }
@Override @Override
public float getX() public Vec4f setX(float x) {
{
return x;
}
@Override
public float getY()
{
return y;
}
@Override
public float getZ()
{
return z;
}
@Override
public float getW()
{
return w;
}
@Override
public Vec4f setX(float x)
{
this.x = x; this.x = x;
return this; return this;
} }
@Override @Override
public Vec4f setY(float y) public Vec4f setY(float y) {
{
this.y = y; this.y = y;
return this; return this;
} }
@Override @Override
public Vec4f setZ(float z) public Vec4f setZ(float z) {
{
this.z = z; this.z = z;
return this; return this;
} }
@Override @Override
public Vec4f setW(float w) public Vec4f setW(float w) {
{
this.w = w; this.w = w;
return this; return this;
} }
@Override @Override
public Vec4f copy() public Vec4f copy() { return Vec4f.mutable(this); }
{
return Vec4f.mutable(this);
}
@Override @Override
public Vec4f set(float x, float y, float z, float w) public Vec4f set(float x, float y, float z, float w) {
{
this.x = x; this.x = x;
this.y = y; this.y = y;
this.z = z; this.z = z;
@ -108,16 +77,11 @@ public class Vec4fMutable implements Vec4f
} }
@Override @Override
public int hashCode() public int hashCode() { return Objects.hash(x, y, z, w); }
{
return Objects.hash(x, y, z, w);
}
@Override @Override
public boolean equals(Object obj) public boolean equals(Object obj) {
{ if(obj instanceof Vec4f) {
if(obj instanceof Vec4f)
{
Vec4f vec = (Vec4f)obj; Vec4f vec = (Vec4f)obj;
return vec.getX() == x && vec.getY() == y && vec.getZ() == z && vec.getW() == w; return vec.getX() == x && vec.getY() == y && vec.getZ() == z && vec.getW() == w;
} }
@ -125,8 +89,5 @@ public class Vec4fMutable implements Vec4f
} }
@Override @Override
public String toString() public String toString() { return "Vec4f[x="+x+", y="+y+", z="+z+", w="+w+"]"; }
{
return "Vec4f[x="+x+", y="+y+", z="+z+", w="+w+"]";
}
} }

View File

@ -9,8 +9,7 @@ import speiger.src.coreengine.math.vector.ints.Veci;
import speiger.src.coreengine.math.vector.longs.Vecl; import speiger.src.coreengine.math.vector.longs.Vecl;
import speiger.src.coreengine.math.vector.shorts.Vecs; import speiger.src.coreengine.math.vector.shorts.Vecs;
public interface Vecf extends Vec public interface Vecf extends Vec {
{
public Vecf set(float value); public Vecf set(float value);
public Vecf add(float value); public Vecf add(float value);
public Vecf sub(float value); public Vecf sub(float value);
@ -18,14 +17,11 @@ public interface Vecf extends Vec
public Vecf devide(float value); public Vecf devide(float value);
public Vecf clamp(float min, float max); public Vecf clamp(float min, float max);
public Vecf clamp(float min, float max, int filter); public Vecf clamp(float min, float max, int filter);
public float lengthSquared(); public float lengthSquared();
public default float length(){return (float)Math.sqrt(lengthSquared());} public default float length() { return (float)Math.sqrt(lengthSquared()); }
public Vecf store(FloatBuffer buffer); public Vecf store(FloatBuffer buffer);
public Vecf load(FloatBuffer buffer); public Vecf load(FloatBuffer buffer);
public float[] asArray(); public float[] asArray();
public Vecb asByte(); public Vecb asByte();
public Vecs asShort(); public Vecs asShort();
public Veci asInt(); public Veci asInt();

View File

@ -10,154 +10,129 @@ import speiger.src.coreengine.math.vector.floats.Vec2f;
import speiger.src.coreengine.math.vector.longs.Vec2l; import speiger.src.coreengine.math.vector.longs.Vec2l;
import speiger.src.coreengine.math.vector.shorts.Vec2s; import speiger.src.coreengine.math.vector.shorts.Vec2s;
public interface Vec2i extends Veci public interface Vec2i extends Veci {
{
public static final Vec2i ZERO = of(); public static final Vec2i ZERO = of();
public static final Vec2i MINUS_ONE = of(-1); public static final Vec2i MINUS_ONE = of(-1);
public static final Vec2i ONE = of(1); public static final Vec2i ONE = of(1);
public static Vec2i mutable(){return new Vec2iMutable();} public static Vec2i mutable() { return new Vec2iMutable(); }
public static Vec2i mutable(int value){return new Vec2iMutable(value);} public static Vec2i mutable(int value) { return new Vec2iMutable(value); }
public static Vec2i mutable(int x, int y){return new Vec2iMutable(x, y);} public static Vec2i mutable(int x, int y) { return new Vec2iMutable(x, y); }
public static Vec2i mutable(Vec2i value){return mutable(value.getX(), value.getY());} public static Vec2i mutable(Vec2i value) { return mutable(value.getX(), value.getY()); }
public static Vec2i of() { return new Vec2iImmutable(); }
public static Vec2i of(){return new Vec2iImmutable();} public static Vec2i of(int value) { return new Vec2iImmutable(value); }
public static Vec2i of(int value){return new Vec2iImmutable(value);} public static Vec2i of(int x, int y) { return new Vec2iImmutable(x, y); }
public static Vec2i of(int x, int y){return new Vec2iImmutable(x, y);} public static Vec2i of(Vec2i value) { return of(value.getX(), value.getY()); }
public static Vec2i of(Vec2i value){return of(value.getX(), value.getY());}
public int getX(); public int getX();
public int getY(); public int getY();
public Vec2i setX(int x); public Vec2i setX(int x);
public Vec2i setY(int y); public Vec2i setY(int y);
@Override @Override
public default int[] asArray(){return new int[]{getX(), getY()};} public default int[] asArray() { return new int[] {getX(), getY()}; }
@Override @Override
public Vec2i copy(); public Vec2i copy();
@Override @Override
public default Vec2i abs(){return set(Math.abs(getX()), Math.abs(getY()));} public default Vec2i abs() { return set(Math.abs(getX()), Math.abs(getY())); }
@Override @Override
public default Vec2i negate(){return set(0, 0);} public default Vec2i negate() { return set(0, 0); }
@Override @Override
public default Vec2i invert(){return set(-getX(), -getY());}; public default Vec2i invert() { return set(-getX(), -getY()); };
@Override @Override
public default Vec2i add(int value) {return add(value, value);} public default Vec2i add(int value) { return add(value, value); }
public default Vec2i add(Vec2i value) {return add(value.getX(), value.getY());} public default Vec2i add(Vec2i value) { return add(value.getX(), value.getY()); }
public default Vec2i add(int x, int y) {return set(x + getX(), y + getY());} public default Vec2i add(int x, int y) { return set(x + getX(), y + getY()); }
@Override @Override
public default Vec2i sub(int value){return sub(value, value);} public default Vec2i sub(int value) { return sub(value, value); }
public default Vec2i sub(Vec2i value){return sub(value.getX(), value.getY());} public default Vec2i sub(Vec2i value) { return sub(value.getX(), value.getY()); }
public default Vec2i sub(int x, int y) {return set(getX() - x, getY() - y);} public default Vec2i sub(int x, int y) { return set(getX() - x, getY() - y); }
@Override @Override
public default Vec2i multiply(int value){return multiply(value, value);} public default Vec2i multiply(int value) { return multiply(value, value); }
public default Vec2i multiply(Vec2i value){return multiply(value.getX(), value.getY());} public default Vec2i multiply(Vec2i value) { return multiply(value.getX(), value.getY()); }
public default Vec2i multiply(int x, int y) {return set(x * getX(), y * getY());} public default Vec2i multiply(int x, int y) { return set(x * getX(), y * getY()); }
@Override @Override
public default Vec2i devide(int value){return devide(value, value);} public default Vec2i devide(int value) { return devide(value, value); }
public default Vec2i devide(Vec2i value){return devide(value.getX(), value.getY());} public default Vec2i devide(Vec2i value) { return devide(value.getX(), value.getY()); }
public default Vec2i devide(int x, int y){return set(getX() / x, getY() / y);} public default Vec2i devide(int x, int y) { return set(getX() / x, getY() / y); }
@Override @Override
public default Vec2i set(int value){return set(value, value);}; public default Vec2i set(int value) { return set(value, value); };
public default Vec2i set(Vec2i value){return set(value.getX(), value.getY());} public default Vec2i set(Vec2i value) { return set(value.getX(), value.getY()); }
public Vec2i set(int x, int y); public Vec2i set(int x, int y);
public default double distanceTo(Vec2i value) { return distanceTo(value.getX(), value.getY()); }
public default double distanceTo(Vec2i value){return distanceTo(value.getX(), value.getY());} public default double distanceTo(int x, int y) { return Math.sqrt(distanceToSquared(x, y)); }
public default double distanceTo(int x, int y){return Math.sqrt(distanceToSquared(x, y));} public default long distanceToSquared(Vec2i value) { return distanceToSquared(value.getX(), value.getY()); }
public default long distanceToSquared(int x, int y) {
public default long distanceToSquared(Vec2i value){return distanceToSquared(value.getX(), value.getY());}
public default long distanceToSquared(int x, int y)
{
long xPos = getX() - x; long xPos = getX() - x;
long yPos = getY() - y; long yPos = getY() - y;
return (xPos * xPos) + (yPos * yPos); return (xPos * xPos) + (yPos * yPos);
} }
@Override @Override
public default long lengthSquared() {return (getX() * getX()) + (getY() * getY());} public default long lengthSquared() { return (getX() * getX()) + (getY() * getY()); }
public default long dotProduct(Vec2i value) { return dotProduct(value.getX(), value.getY()); }
public default long dotProduct(Vec2i value){return dotProduct(value.getX(), value.getY());} public default long dotProduct(int x, int y) { return (getX() * x) + (getY() * y); }
public default long dotProduct(int x, int y){return (getX() * x) + (getY() * y);} public default Vec2i rotate(int angle, Vec2i center) { return rotate(angle, center.getX(), center.getY()); }
public default Vec2i rotate(int angle, int x, int y) {
public default Vec2i rotate(int angle, Vec2i center){return rotate(angle, center.getX(), center.getY());}
public default Vec2i rotate(int angle, int x, int y)
{
int xPos = getX() - x; int xPos = getX() - x;
int yPos = getY() - y; int yPos = getY() - y;
double cos = MathUtils.cos(angle); double cos = MathUtils.cos(angle);
double sin = MathUtils.sin(angle); double sin = MathUtils.sin(angle);
return set((int)((xPos * cos) + (yPos * sin) + x), (int)(-(xPos * sin) + (yPos * cos) + y)); return set((int)((xPos * cos) + (yPos * sin) + x), (int)(-(xPos * sin) + (yPos * cos) + y));
} }
public default Vec2i min(Vec2i other) {return min(other, this);} public default Vec2i min(Vec2i other) { return min(other, this); }
public default Vec2i min(Vec2i other, Vec2i result){return min(other.getX(), other.getY(), result);} public default Vec2i min(Vec2i other, Vec2i result) { return min(other.getX(), other.getY(), result); }
public default Vec2i min(int x, int y) {return min(x, y, this);} public default Vec2i min(int x, int y) { return min(x, y, this); }
public default Vec2i min(int x, int y, Vec2i result){return result.set(Math.min(getX(), x), Math.min(getY(), y));} public default Vec2i min(int x, int y, Vec2i result) { return result.set(Math.min(getX(), x), Math.min(getY(), y)); }
public default Vec2i max(Vec2i other) { return max(other, this); }
public default Vec2i max(Vec2i other) {return max(other, this);} public default Vec2i max(Vec2i other, Vec2i result) { return max(other.getX(), other.getY(), result); }
public default Vec2i max(Vec2i other, Vec2i result){return max(other.getX(), other.getY(), result);} public default Vec2i max(int x, int y) { return max(x, y, this); }
public default Vec2i max(int x, int y) {return max(x, y, this);} public default Vec2i max(int x, int y, Vec2i result) { return result.set(Math.max(getX(), x), Math.max(getY(), y)); }
public default Vec2i max(int x, int y, Vec2i result){return result.set(Math.max(getX(), x), Math.max(getY(), y));} public default Vec2i difference(Vec2i other) { return difference(other, this); }
public default Vec2i difference(Vec2i other, Vec2i result) { return difference(other.getX(), other.getY(), result); }
public default Vec2i difference(Vec2i other) {return difference(other, this);} public default Vec2i difference(int x, int y) { return difference(x, y, this); }
public default Vec2i difference(Vec2i other, Vec2i result){return difference(other.getX(), other.getY(), result);} public default Vec2i difference(int x, int y, Vec2i result) { return result.set(getX() - x, getY() - y); }
public default Vec2i difference(int x, int y) {return difference(x, y, this);} @Override
public default Vec2i difference(int x, int y, Vec2i result){return result.set(getX() - x, getY() - y);} public default Vec2i clamp(int min, int max) { return clamp(min, max, ALL); }
public default Vec2i clamp(int min, int max, Vec2i result) { return clamp(min, max, result, ALL); }
@Override
public default Vec2i clamp(int min, int max, int filter) { return clamp(min, max, this, filter); }
public default Vec2i clamp(int min, int max, Vec2i result, int filter) { return result.set((filter & X) == 0 ? getX() : MathUtils.clamp(min, max, getX()), (filter & Y) == 0 ? getY() : MathUtils.clamp(min, max, getY())); }
@Override @Override
public default Vec2i clamp(int min, int max){return clamp(min, max, ALL);} public default Vec2i store(ByteBuffer buffer) {
public default Vec2i clamp(int min, int max, Vec2i result){return clamp(min, max, result, ALL);}
@Override
public default Vec2i clamp(int min, int max, int filter){return clamp(min, max, this, filter);}
public default Vec2i clamp(int min, int max, Vec2i result, int filter){return result.set((filter & X) == 0 ? getX() : MathUtils.clamp(min, max, getX()), (filter & Y) == 0 ? getY() : MathUtils.clamp(min, max, getY()));}
@Override
public default Vec2i store(ByteBuffer buffer)
{
buffer.putInt(getX()).putInt(getY()); buffer.putInt(getX()).putInt(getY());
return this; return this;
} }
@Override @Override
public default Vec2i load(ByteBuffer buffer) public default Vec2i load(ByteBuffer buffer) { return set(buffer.getInt(), buffer.getInt()); }
{
return set(buffer.getInt(), buffer.getInt());
}
@Override @Override
public default Vec2i store(IntBuffer buffer) public default Vec2i store(IntBuffer buffer) {
{
buffer.put(getX()).put(getY()); buffer.put(getX()).put(getY());
return this; return this;
} }
@Override @Override
public default Vec2i load(IntBuffer buffer) public default Vec2i load(IntBuffer buffer) { return set(buffer.get(), buffer.get()); }
{
return set(buffer.get(), buffer.get());
}
@Override @Override
public default Vec2b asByte(){return isMutable() ? Vec2b.mutable((byte)getX(), (byte)getY()) : Vec2b.of((byte)getX(), (byte)getY());} public default Vec2b asByte() { return isMutable() ? Vec2b.mutable((byte)getX(), (byte)getY()) : Vec2b.of((byte)getX(), (byte)getY()); }
@Override @Override
public default Vec2s asShort(){return isMutable() ? Vec2s.mutable((short)getX(), (short)getY()) : Vec2s.of((short)getX(), (short)getY());} public default Vec2s asShort() { return isMutable() ? Vec2s.mutable((short)getX(), (short)getY()) : Vec2s.of((short)getX(), (short)getY()); }
@Override @Override
public default Vec2l asLong(){return isMutable() ? Vec2l.mutable(getX(), getY()) : Vec2l.of(getX(), getY());} public default Vec2l asLong() { return isMutable() ? Vec2l.mutable(getX(), getY()) : Vec2l.of(getX(), getY()); }
@Override @Override
public default Vec2f asFloat() {return isMutable() ? Vec2f.mutable(getX(), getY()) : Vec2f.of(getX(), getY());} public default Vec2f asFloat() { return isMutable() ? Vec2f.mutable(getX(), getY()) : Vec2f.of(getX(), getY()); }
@Override @Override
public default Vec2d asDouble(){return isMutable() ? Vec2d.mutable(getX(), getY()) : Vec2d.of(getX(), getY());} public default Vec2d asDouble() { return isMutable() ? Vec2d.mutable(getX(), getY()) : Vec2d.of(getX(), getY()); }
@Override @Override
public default Vec2i asMutable(){return isMutable() ? this : mutable(this);} public default Vec2i asMutable() { return isMutable() ? this : mutable(this); }
@Override @Override
public default Vec2i asImmutable(){return isMutable() ? of(this) : this;} public default Vec2i asImmutable() { return isMutable() ? of(this) : this; }
@Override @Override
public default Vec2i copyAsMutable(){return mutable(this);} public default Vec2i copyAsMutable() { return mutable(this); }
@Override @Override
public default Vec2i copyAsImmutable(){return of(this);} public default Vec2i copyAsImmutable() { return of(this); }
} }

View File

@ -2,91 +2,51 @@ package speiger.src.coreengine.math.vector.ints;
import java.util.Objects; import java.util.Objects;
public class Vec2iImmutable implements Vec2i public class Vec2iImmutable implements Vec2i {
{
final int x; final int x;
final int y; final int y;
public Vec2iImmutable() public Vec2iImmutable() {
{
x = 0; x = 0;
y = 0; y = 0;
} }
public Vec2iImmutable(int value) public Vec2iImmutable(int value) {
{
x = value; x = value;
y = value; y = value;
} }
public Vec2iImmutable(int x, int y) public Vec2iImmutable(int x, int y) {
{
this.x = x; this.x = x;
this.y = y; this.y = y;
} }
@Override
public boolean isMutable()
{
return false;
}
@Override @Override
public int getX() public boolean isMutable() { return false; }
{ @Override
return x; public int getX() { return x; }
} @Override
public int getY() { return y; }
@Override
public Vec2i setX(int x) { return this.x == x ? this : Vec2i.of(x, y); }
@Override
public Vec2i setY(int y) { return this.y == y ? this : Vec2i.of(x, y); }
@Override
public Vec2i copy() { return Vec2i.of(this); }
@Override
public Vec2i set(int x, int y) { return this.x == x && this.y == y ? this : Vec2i.of(x, y); }
@Override
public int hashCode() { return Objects.hash(x, y); }
@Override @Override
public int getY() public boolean equals(Object obj) {
{ if(obj instanceof Vec2i) {
return y;
}
@Override
public Vec2i setX(int x)
{
return this.x == x ? this : Vec2i.of(x, y);
}
@Override
public Vec2i setY(int y)
{
return this.y == y ? this : Vec2i.of(x, y);
}
@Override
public Vec2i copy()
{
return Vec2i.of(this);
}
@Override
public Vec2i set(int x, int y)
{
return this.x == x && this.y == y ? this : Vec2i.of(x, y);
}
@Override
public int hashCode()
{
return Objects.hash(x, y);
}
@Override
public boolean equals(Object obj)
{
if(obj instanceof Vec2i)
{
Vec2i vec = (Vec2i)obj; Vec2i vec = (Vec2i)obj;
return vec.getX() == x && vec.getY() == y; return vec.getX() == x && vec.getY() == y;
} }
return false; return false;
} }
@Override @Override
public String toString() public String toString() { return "Vec2i[x="+x+", y="+y+"]"; }
{
return "Vec2i[x="+x+", y="+y+"]";
}
} }

View File

@ -2,93 +2,63 @@ package speiger.src.coreengine.math.vector.ints;
import java.util.Objects; import java.util.Objects;
public class Vec2iMutable implements Vec2i public class Vec2iMutable implements Vec2i {
{
int x; int x;
int y; int y;
public Vec2iMutable() public Vec2iMutable() {}
{
}
public Vec2iMutable(int value) public Vec2iMutable(int value) {
{
x = value; x = value;
y = value; y = value;
} }
public Vec2iMutable(int x, int y) public Vec2iMutable(int x, int y) {
{
this.x = x; this.x = x;
this.y = y; this.y = y;
} }
@Override
public boolean isMutable()
{
return true;
}
@Override @Override
public int getX() public boolean isMutable() { return true; }
{ @Override
return x; public int getX() { return x; }
} @Override
public int getY() { return y; }
@Override @Override
public int getY() public Vec2i setX(int x) {
{
return y;
}
@Override
public Vec2i setX(int x)
{
this.x = x; this.x = x;
return this; return this;
} }
@Override @Override
public Vec2i setY(int y) public Vec2i setY(int y) {
{
this.y = y; this.y = y;
return this; return this;
} }
@Override @Override
public Vec2i copy() public Vec2i copy() { return Vec2i.mutable(this); }
{
return Vec2i.mutable(this);
}
@Override @Override
public Vec2i set(int x, int y) public Vec2i set(int x, int y) {
{
this.x = x; this.x = x;
this.y = y; this.y = y;
return this; return this;
} }
@Override @Override
public int hashCode() public int hashCode() { return Objects.hash(x, y); }
{
return Objects.hash(x, y);
}
@Override @Override
public boolean equals(Object obj) public boolean equals(Object obj) {
{ if(obj instanceof Vec2i) {
if(obj instanceof Vec2i)
{
Vec2i vec = (Vec2i)obj; Vec2i vec = (Vec2i)obj;
return vec.getX() == x && vec.getY() == y; return vec.getX() == x && vec.getY() == y;
} }
return false; return false;
} }
@Override @Override
public String toString() public String toString() { return "Vec2i[x="+x+", y="+y+"]"; }
{
return "Vec2i[x="+x+", y="+y+"]";
}
} }

View File

@ -10,22 +10,19 @@ import speiger.src.coreengine.math.vector.floats.Vec3f;
import speiger.src.coreengine.math.vector.longs.Vec3l; import speiger.src.coreengine.math.vector.longs.Vec3l;
import speiger.src.coreengine.math.vector.shorts.Vec3s; import speiger.src.coreengine.math.vector.shorts.Vec3s;
public interface Vec3i extends Veci {
public interface Vec3i extends Veci
{
public static final Vec3i ZERO = of(); public static final Vec3i ZERO = of();
public static final Vec3i MINUS_ONE = of(-1); public static final Vec3i MINUS_ONE = of(-1);
public static final Vec3i ONE = of(1); public static final Vec3i ONE = of(1);
public static Vec3i mutable(){return new Vec3iMutable();} public static Vec3i mutable() { return new Vec3iMutable(); }
public static Vec3i mutable(int value){return new Vec3iMutable(value);} public static Vec3i mutable(int value) { return new Vec3iMutable(value); }
public static Vec3i mutable(int x, int y, int z){return new Vec3iMutable(x, y, z);} public static Vec3i mutable(int x, int y, int z) { return new Vec3iMutable(x, y, z); }
public static Vec3i mutable(Vec3i vec){return mutable(vec.getX(), vec.getY(), vec.getZ());} public static Vec3i mutable(Vec3i vec) { return mutable(vec.getX(), vec.getY(), vec.getZ()); }
public static Vec3i of() { return new Vec3iImmutable(); }
public static Vec3i of(){return new Vec3iImmutable();} public static Vec3i of(int value) { return new Vec3iImmutable(value); }
public static Vec3i of(int value){return new Vec3iImmutable(value);} public static Vec3i of(int x, int y, int z) { return new Vec3iImmutable(x, y, z); }
public static Vec3i of(int x, int y, int z){return new Vec3iImmutable(x, y, z);} public static Vec3i of(Vec3i vec) { return of(vec.getX(), vec.getY(), vec.getZ()); }
public static Vec3i of(Vec3i vec){return of(vec.getX(), vec.getY(), vec.getZ());}
public int getX(); public int getX();
public int getY(); public int getY();
@ -33,125 +30,103 @@ public interface Vec3i extends Veci
public Vec3i setX(int x); public Vec3i setX(int x);
public Vec3i setY(int y); public Vec3i setY(int y);
public Vec3i setZ(int z); public Vec3i setZ(int z);
@Override
public default int[] asArray(){return new int[]{getX(), getY(), getZ()};}
@Override
public default int[] asArray() { return new int[] {getX(), getY(), getZ()}; }
@Override @Override
public Vec3i copy(); public Vec3i copy();
@Override @Override
public default Vec3i abs(){return set(Math.abs(getX()), Math.abs(getY()), Math.abs(getZ()));} public default Vec3i abs() { return set(Math.abs(getX()), Math.abs(getY()), Math.abs(getZ())); }
@Override @Override
public default Vec3i negate(){return set(0, 0, 0);} public default Vec3i negate() { return set(0, 0, 0); }
@Override @Override
public default Vec3i invert(){return set(-getX(), -getY(), -getZ());} public default Vec3i invert() { return set(-getX(), -getY(), -getZ()); }
@Override @Override
public default Vec3i add(int value){return add(value, value, value);} public default Vec3i add(int value) { return add(value, value, value); }
public default Vec3i add(Vec3i value){return add(value.getX(), value.getY(), value.getZ());} public default Vec3i add(Vec3i value) { return add(value.getX(), value.getY(), value.getZ()); }
public default Vec3i add(int x, int y, int z){return set(getX() + x, getY() + y, getZ() + z);} public default Vec3i add(int x, int y, int z) { return set(getX() + x, getY() + y, getZ() + z); }
@Override @Override
public default Vec3i sub(int value){return sub(value, value, value);} public default Vec3i sub(int value) { return sub(value, value, value); }
public default Vec3i sub(Vec3i value){return sub(value.getX(), value.getY(), value.getZ());} public default Vec3i sub(Vec3i value) { return sub(value.getX(), value.getY(), value.getZ()); }
public default Vec3i sub(int x, int y, int z){return set(getX() - x, getY() - y, getZ() - z);} public default Vec3i sub(int x, int y, int z) { return set(getX() - x, getY() - y, getZ() - z); }
@Override @Override
public default Vec3i multiply(int value){return multiply(value, value, value);} public default Vec3i multiply(int value) { return multiply(value, value, value); }
public default Vec3i multiply(Vec3i value){return multiply(value.getX(), value.getY(), value.getZ());} public default Vec3i multiply(Vec3i value) { return multiply(value.getX(), value.getY(), value.getZ()); }
public default Vec3i multiply(int x, int y, int z){return set(getX() * x, getY() * y, getZ() * z);} public default Vec3i multiply(int x, int y, int z) { return set(getX() * x, getY() * y, getZ() * z); }
@Override @Override
public default Vec3i devide(int value){return devide(value, value, value);} public default Vec3i devide(int value) { return devide(value, value, value); }
public default Vec3i devide(Vec3i value){return devide(value.getX(), value.getY(), value.getZ());} public default Vec3i devide(Vec3i value) { return devide(value.getX(), value.getY(), value.getZ()); }
public default Vec3i devide(int x, int y, int z){return set(getX() / x, getY() / y, getZ() / z);} public default Vec3i devide(int x, int y, int z) { return set(getX() / x, getY() / y, getZ() / z); }
@Override @Override
public default Vec3i set(int value){return set(value, value, value);} public default Vec3i set(int value) { return set(value, value, value); }
public default Vec3i set(Vec3i value){return set(value.getX(), value.getY(), value.getZ());} public default Vec3i set(Vec3i value) { return set(value.getX(), value.getY(), value.getZ()); }
public Vec3i set(int x, int y, int z); public Vec3i set(int x, int y, int z);
public default double distanceTo(Vec3i value) { return distanceTo(value.getX(), value.getY(), value.getZ()); }
public default double distanceTo(Vec3i value){return distanceTo(value.getX(), value.getY(), value.getZ());} public default double distanceTo(int x, int y, int z) { return Math.sqrt(distanceToSquared(x, y, z)); }
public default double distanceTo(int x, int y, int z){return Math.sqrt(distanceToSquared(x, y, z));} public default long distanceToSquared(Vec3i value) { return distanceToSquared(value.getX(), value.getY(), value.getZ()); }
public default long distanceToSquared(int x, int y, int z) {
public default long distanceToSquared(Vec3i value){return distanceToSquared(value.getX(), value.getY(), value.getZ());}
public default long distanceToSquared(int x, int y, int z)
{
long xPos = getX() - x; long xPos = getX() - x;
long yPos = getY() - y; long yPos = getY() - y;
long zPos = getZ() - z; long zPos = getZ() - z;
return (xPos * xPos) + (yPos * yPos) + (zPos * zPos); return (xPos * xPos) + (yPos * yPos) + (zPos * zPos);
} }
@Override
public default long lengthSquared() {return (getX() * getX()) + (getY() * getY()) + (getZ() * getZ());}
public default long dotProduct(Vec3i value){return dotProduct(value.getX(), value.getY(), value.getZ());}
public default long dotProduct(int x, int y, int z){return (getX() * x) + (getY() * y) + (getZ() * z);}
public default Vec3i min(Vec3i other) {return min(other, this);}
public default Vec3i min(Vec3i other, Vec3i result){return min(other.getX(), other.getY(), other.getZ(), result);}
public default Vec3i min(int x, int y, int z) {return min(x, y, z, this);}
public default Vec3i min(int x, int y, int z, Vec3i result){return result.set(Math.min(getX(), x), Math.min(getY(), y), Math.min(getZ(), z));}
public default Vec3i max(Vec3i other) {return max(other, this);}
public default Vec3i max(Vec3i other, Vec3i result){return max(other.getX(), other.getY(), other.getZ(), result);}
public default Vec3i max(int x, int y, int z) {return max(x, y, z, this);}
public default Vec3i max(int x, int y, int z, Vec3i result){return result.set(Math.max(getX(), x), Math.max(getY(), y), Math.max(getZ(), z));}
public default Vec3i difference(Vec3i other) {return difference(other, this);}
public default Vec3i difference(Vec3i other, Vec3i result){return difference(other.getX(), other.getY(), other.getZ(), result);}
public default Vec3i difference(int x, int y, int z) {return difference(x, y, z, this);}
public default Vec3i difference(int x, int y, int z, Vec3i result){return result.set(getX() - x, getY() - y, getZ() - z);}
@Override @Override
public default Vec3i clamp(int min, int max){return clamp(min, max, ALL);} public default long lengthSquared() { return (getX() * getX()) + (getY() * getY()) + (getZ() * getZ()); }
public default Vec3i clamp(int min, int max, Vec3i result){return clamp(min, max, result, ALL);} public default long dotProduct(Vec3i value) { return dotProduct(value.getX(), value.getY(), value.getZ()); }
public default long dotProduct(int x, int y, int z) { return (getX() * x) + (getY() * y) + (getZ() * z); }
public default Vec3i min(Vec3i other) { return min(other, this); }
public default Vec3i min(Vec3i other, Vec3i result) { return min(other.getX(), other.getY(), other.getZ(), result); }
public default Vec3i min(int x, int y, int z) { return min(x, y, z, this); }
public default Vec3i min(int x, int y, int z, Vec3i result) { return result.set(Math.min(getX(), x), Math.min(getY(), y), Math.min(getZ(), z)); }
public default Vec3i max(Vec3i other) { return max(other, this); }
public default Vec3i max(Vec3i other, Vec3i result) { return max(other.getX(), other.getY(), other.getZ(), result); }
public default Vec3i max(int x, int y, int z) { return max(x, y, z, this); }
public default Vec3i max(int x, int y, int z, Vec3i result) { return result.set(Math.max(getX(), x), Math.max(getY(), y), Math.max(getZ(), z)); }
public default Vec3i difference(Vec3i other) { return difference(other, this); }
public default Vec3i difference(Vec3i other, Vec3i result) { return difference(other.getX(), other.getY(), other.getZ(), result); }
public default Vec3i difference(int x, int y, int z) { return difference(x, y, z, this); }
public default Vec3i difference(int x, int y, int z, Vec3i result) { return result.set(getX() - x, getY() - y, getZ() - z); }
@Override @Override
public default Vec3i clamp(int min, int max, int filter){return clamp(min, max, this, filter);} public default Vec3i clamp(int min, int max) { return clamp(min, max, ALL); }
public default Vec3i clamp(int min, int max, Vec3i result, int filter){ return result.set((filter & X) == 0 ? getX() : MathUtils.clamp(min, max, getX()), (filter & Y) == 0 ? getY() : MathUtils.clamp(min, max, getY()), (filter & Z) == 0 ? getZ() : MathUtils.clamp(min, max, getZ()));} public default Vec3i clamp(int min, int max, Vec3i result) { return clamp(min, max, result, ALL); }
@Override
public default Vec3i clamp(int min, int max, int filter) { return clamp(min, max, this, filter); }
public default Vec3i clamp(int min, int max, Vec3i result, int filter) { return result.set((filter & X) == 0 ? getX() : MathUtils.clamp(min, max, getX()), (filter & Y) == 0 ? getY() : MathUtils.clamp(min, max, getY()), (filter & Z) == 0 ? getZ() : MathUtils.clamp(min, max, getZ())); }
@Override @Override
public default Vec3i store(ByteBuffer buffer) public default Vec3i store(ByteBuffer buffer) {
{
buffer.putInt(getX()).putInt(getY()).putInt(getZ()); buffer.putInt(getX()).putInt(getY()).putInt(getZ());
return this; return this;
} }
@Override @Override
public default Vec3i load(ByteBuffer buffer) public default Vec3i load(ByteBuffer buffer) { return set(buffer.getInt(), buffer.getInt(), buffer.getInt()); }
{
return set(buffer.getInt(), buffer.getInt(), buffer.getInt());
}
@Override @Override
public default Vec3i store(IntBuffer buffer) public default Vec3i store(IntBuffer buffer) {
{
buffer.put(getX()).put(getY()).put(getZ()); buffer.put(getX()).put(getY()).put(getZ());
return this; return this;
} }
@Override @Override
public default Vec3i load(IntBuffer buffer) public default Vec3i load(IntBuffer buffer) { return set(buffer.get(), buffer.get(), buffer.get()); }
{
return set(buffer.get(), buffer.get(), buffer.get());
}
@Override @Override
public default Vec3b asByte(){return isMutable() ? Vec3b.mutable((byte)getX(), (byte)getY(), (byte)getZ()) : Vec3b.of((byte)getX(), (byte)getY(), (byte)getZ());} public default Vec3b asByte() { return isMutable() ? Vec3b.mutable((byte)getX(), (byte)getY(), (byte)getZ()) : Vec3b.of((byte)getX(), (byte)getY(), (byte)getZ()); }
@Override @Override
public default Vec3s asShort(){return isMutable() ? Vec3s.mutable((short)getX(), (short)getY(), (short)getZ()) : Vec3s.of((short)getX(), (short)getY(), (short)getZ());} public default Vec3s asShort() { return isMutable() ? Vec3s.mutable((short)getX(), (short)getY(), (short)getZ()) : Vec3s.of((short)getX(), (short)getY(), (short)getZ()); }
@Override @Override
public default Vec3l asLong(){return isMutable() ? Vec3l.mutable(getX(), getY(), getZ()) : Vec3l.of(getX(), getY(), getZ());} public default Vec3l asLong() { return isMutable() ? Vec3l.mutable(getX(), getY(), getZ()) : Vec3l.of(getX(), getY(), getZ()); }
@Override @Override
public default Vec3f asFloat() {return isMutable() ? Vec3f.mutable(getX(), getY(), getZ()) : Vec3f.of(getX(), getY(), getZ());} public default Vec3f asFloat() { return isMutable() ? Vec3f.mutable(getX(), getY(), getZ()) : Vec3f.of(getX(), getY(), getZ()); }
@Override @Override
public default Vec3d asDouble(){return isMutable() ? Vec3d.mutable(getX(), getY(), getZ()) : Vec3d.of(getX(), getY(), getZ());} public default Vec3d asDouble() { return isMutable() ? Vec3d.mutable(getX(), getY(), getZ()) : Vec3d.of(getX(), getY(), getZ()); }
@Override @Override
public default Vec3i asMutable(){return isMutable() ? this : mutable(this);} public default Vec3i asMutable() { return isMutable() ? this : mutable(this); }
@Override @Override
public default Vec3i asImmutable(){return isMutable() ? of(this) : this;} public default Vec3i asImmutable() { return isMutable() ? of(this) : this; }
@Override @Override
public default Vec3i copyAsMutable(){return mutable(this);} public default Vec3i copyAsMutable() { return mutable(this); }
@Override @Override
public default Vec3i copyAsImmutable(){return of(this);} public default Vec3i copyAsImmutable() { return of(this); }
} }

View File

@ -2,107 +2,59 @@ package speiger.src.coreengine.math.vector.ints;
import java.util.Objects; import java.util.Objects;
public class Vec3iImmutable implements Vec3i public class Vec3iImmutable implements Vec3i {
{
final int x; final int x;
final int y; final int y;
final int z; final int z;
public Vec3iImmutable() public Vec3iImmutable() {
{
x = 0; x = 0;
y = 0; y = 0;
z = 0; z = 0;
} }
public Vec3iImmutable(int value) public Vec3iImmutable(int value) {
{
x = value; x = value;
y = value; y = value;
z = value; z = value;
} }
public Vec3iImmutable(int x, int y, int z) public Vec3iImmutable(int x, int y, int z) {
{
this.x = x; this.x = x;
this.y = y; this.y = y;
this.z = z; this.z = z;
} }
@Override
public boolean isMutable()
{
return false;
}
@Override @Override
public int getX() public boolean isMutable() { return false; }
{ @Override
return x; public int getX() { return x; }
} @Override
public int getY() { return y; }
@Override
public int getZ() { return z; }
@Override
public Vec3i setX(int x) { return this.x == x ? this : Vec3i.of(x, y, z); }
@Override
public Vec3i setY(int y) { return this.y == y ? this : Vec3i.of(x, y, z); }
@Override
public Vec3i setZ(int z) { return this.z == z ? this : Vec3i.of(x, y, z); }
@Override
public Vec3i copy() { return Vec3i.of(this); }
@Override
public Vec3i set(int x, int y, int z) { return this.x == x && this.y == y && this.z == z ? this : Vec3i.of(x, y, z); }
@Override
public int hashCode() { return Objects.hash(x, y, z); }
@Override @Override
public int getY() public boolean equals(Object obj) {
{ if(obj instanceof Vec3i) {
return y;
}
@Override
public int getZ()
{
return z;
}
@Override
public Vec3i setX(int x)
{
return this.x == x ? this : Vec3i.of(x, y, z);
}
@Override
public Vec3i setY(int y)
{
return this.y == y ? this : Vec3i.of(x, y, z);
}
@Override
public Vec3i setZ(int z)
{
return this.z == z ? this : Vec3i.of(x, y, z);
}
@Override
public Vec3i copy()
{
return Vec3i.of(this);
}
@Override
public Vec3i set(int x, int y, int z)
{
return this.x == x && this.y == y && this.z == z ? this : Vec3i.of(x, y, z);
}
@Override
public int hashCode()
{
return Objects.hash(x, y, z);
}
@Override
public boolean equals(Object obj)
{
if(obj instanceof Vec3i)
{
Vec3i vec = (Vec3i)obj; Vec3i vec = (Vec3i)obj;
return vec.getX() == x && vec.getY() == y && vec.getZ() == z; return vec.getX() == x && vec.getY() == y && vec.getZ() == z;
} }
return false; return false;
} }
@Override @Override
public String toString() public String toString() { return "Vec3i[x="+x+", y="+y+", z="+z+"]"; }
{
return "Vec3i[x="+x+", y="+y+", z="+z+"]";
}
} }

View File

@ -2,84 +2,57 @@ package speiger.src.coreengine.math.vector.ints;
import java.util.Objects; import java.util.Objects;
public class Vec3iMutable implements Vec3i public class Vec3iMutable implements Vec3i {
{
int x; int x;
int y; int y;
int z; int z;
public Vec3iMutable() public Vec3iMutable() {}
{
}
public Vec3iMutable(int value) public Vec3iMutable(int value) {
{
x = value; x = value;
y = value; y = value;
z = value; z = value;
} }
public Vec3iMutable(int x, int y, int z) public Vec3iMutable(int x, int y, int z) {
{
this.x = x; this.x = x;
this.y = y; this.y = y;
this.z = z; this.z = z;
} }
@Override
public boolean isMutable()
{
return true;
}
@Override @Override
public int getX() public boolean isMutable() { return true; }
{ @Override
return x; public int getX() { return x; }
} @Override
public int getY() { return y; }
@Override
public int getZ() { return z; }
@Override @Override
public int getY() public Vec3i setX(int x) {
{
return y;
}
@Override
public int getZ()
{
return z;
}
@Override
public Vec3i setX(int x)
{
this.x = x; this.x = x;
return this; return this;
} }
@Override @Override
public Vec3i setY(int y) public Vec3i setY(int y) {
{
this.y = y; this.y = y;
return this; return this;
} }
@Override @Override
public Vec3i setZ(int z) public Vec3i setZ(int z) {
{
this.z = z; this.z = z;
return this; return this;
} }
@Override @Override
public Vec3i copy() public Vec3i copy() { return Vec3i.mutable(this); }
{
return Vec3i.mutable(this);
}
@Override @Override
public Vec3i set(int x, int y, int z) public Vec3i set(int x, int y, int z) {
{
this.x = x; this.x = x;
this.y = y; this.y = y;
this.z = z; this.z = z;
@ -87,25 +60,17 @@ public class Vec3iMutable implements Vec3i
} }
@Override @Override
public int hashCode() public int hashCode() { return Objects.hash(x, y, z); }
{
return Objects.hash(x, y, z);
}
@Override @Override
public boolean equals(Object obj) public boolean equals(Object obj) {
{ if(obj instanceof Vec3i) {
if(obj instanceof Vec3i)
{
Vec3i vec = (Vec3i)obj; Vec3i vec = (Vec3i)obj;
return vec.getX() == x && vec.getY() == y && vec.getZ() == z; return vec.getX() == x && vec.getY() == y && vec.getZ() == z;
} }
return false; return false;
} }
@Override @Override
public String toString() public String toString() { return "Vec3i[x="+x+", y="+y+", z="+z+"]"; }
{
return "Vec3i[x="+x+", y="+y+", z="+z+"]";
}
} }

View File

@ -10,21 +10,19 @@ import speiger.src.coreengine.math.vector.floats.Vec4f;
import speiger.src.coreengine.math.vector.longs.Vec4l; import speiger.src.coreengine.math.vector.longs.Vec4l;
import speiger.src.coreengine.math.vector.shorts.Vec4s; import speiger.src.coreengine.math.vector.shorts.Vec4s;
public interface Vec4i extends Veci public interface Vec4i extends Veci {
{
public static final Vec4i ZERO = of(); public static final Vec4i ZERO = of();
public static final Vec4i MINUS_ONE = of(-1); public static final Vec4i MINUS_ONE = of(-1);
public static final Vec4i ONE = of(1); public static final Vec4i ONE = of(1);
public static Vec4i mutable(){return new Vec4iMutable();} public static Vec4i mutable() { return new Vec4iMutable(); }
public static Vec4i mutable(int value){return new Vec4iMutable(value);} public static Vec4i mutable(int value) { return new Vec4iMutable(value); }
public static Vec4i mutable(int x, int y, int z, int w){return new Vec4iMutable(x, y, z, w);} public static Vec4i mutable(int x, int y, int z, int w) { return new Vec4iMutable(x, y, z, w); }
public static Vec4i mutable(Vec4i vec){return mutable(vec.getX(), vec.getY(), vec.getZ(), vec.getW());} public static Vec4i mutable(Vec4i vec) { return mutable(vec.getX(), vec.getY(), vec.getZ(), vec.getW()); }
public static Vec4i of() { return new Vec4iImmutable(); }
public static Vec4i of(){return new Vec4iImmutable();} public static Vec4i of(int value) { return new Vec4iImmutable(value); }
public static Vec4i of(int value){return new Vec4iImmutable(value);} public static Vec4i of(int x, int y, int z, int w) { return new Vec4iImmutable(x, y, z, w); }
public static Vec4i of(int x, int y, int z, int w){return new Vec4iImmutable(x, y, z, w);} public static Vec4i of(Vec4i vec) { return of(vec.getX(), vec.getY(), vec.getZ(), vec.getW()); }
public static Vec4i of(Vec4i vec){return of(vec.getX(), vec.getY(), vec.getZ(), vec.getW());}
public int getX(); public int getX();
public int getY(); public int getY();
@ -34,125 +32,104 @@ public interface Vec4i extends Veci
public Vec4i setY(int y); public Vec4i setY(int y);
public Vec4i setZ(int z); public Vec4i setZ(int z);
public Vec4i setW(int w); public Vec4i setW(int w);
@Override @Override
public default int[] asArray(){return new int[]{getX(), getY(), getZ(), getW()};} public default int[] asArray() { return new int[] {getX(), getY(), getZ(), getW()}; }
@Override @Override
public Vec4i copy(); public Vec4i copy();
@Override @Override
public default Vec4i abs(){return set(Math.abs(getX()), Math.abs(getY()), Math.abs(getZ()), Math.abs(getW()));} public default Vec4i abs() { return set(Math.abs(getX()), Math.abs(getY()), Math.abs(getZ()), Math.abs(getW())); }
@Override @Override
public default Vec4i negate(){return set(0, 0, 0, 0);} public default Vec4i negate() { return set(0, 0, 0, 0); }
@Override @Override
public default Vec4i invert(){return set(-getX(), -getY(), -getZ(), -getW());} public default Vec4i invert() { return set(-getX(), -getY(), -getZ(), -getW()); }
@Override @Override
public default Vec4i add(int value){return add(value, value, value, value);} public default Vec4i add(int value) { return add(value, value, value, value); }
public default Vec4i add(Vec4i value){return add(value.getX(), value.getY(), value.getZ(), value.getW());} public default Vec4i add(Vec4i value) { return add(value.getX(), value.getY(), value.getZ(), value.getW()); }
public default Vec4i add(int x, int y, int z, int w){return set(getX() + x, getY() + y, getZ() + z, getW() + w);} public default Vec4i add(int x, int y, int z, int w) { return set(getX() + x, getY() + y, getZ() + z, getW() + w); }
@Override @Override
public default Vec4i sub(int value){return sub(value, value, value, value);} public default Vec4i sub(int value) { return sub(value, value, value, value); }
public default Vec4i sub(Vec4i value){return sub(value.getX(), value.getY(), value.getZ(), value.getW());} public default Vec4i sub(Vec4i value) { return sub(value.getX(), value.getY(), value.getZ(), value.getW()); }
public default Vec4i sub(int x, int y, int z, int w){return set(getX() - x, getY() - y, getZ() - z, getW() - w);} public default Vec4i sub(int x, int y, int z, int w) { return set(getX() - x, getY() - y, getZ() - z, getW() - w); }
@Override @Override
public default Vec4i multiply(int value){return multiply(value, value, value, value);} public default Vec4i multiply(int value) { return multiply(value, value, value, value); }
public default Vec4i multiply(Vec4i value){return multiply(value.getX(), value.getY(), value.getZ(), value.getW());} public default Vec4i multiply(Vec4i value) { return multiply(value.getX(), value.getY(), value.getZ(), value.getW()); }
public default Vec4i multiply(int x, int y, int z, int w){return set(getX() * x, getY() * y, getZ() * z, getW() * w);} public default Vec4i multiply(int x, int y, int z, int w) { return set(getX() * x, getY() * y, getZ() * z, getW() * w); }
@Override @Override
public default Vec4i devide(int value){return devide(value, value, value, value);} public default Vec4i devide(int value) { return devide(value, value, value, value); }
public default Vec4i devide(Vec4i value){return devide(value.getX(), value.getY(), value.getZ(), value.getW());} public default Vec4i devide(Vec4i value) { return devide(value.getX(), value.getY(), value.getZ(), value.getW()); }
public default Vec4i devide(int x, int y, int z, int w){return set(getX() / x, getY() / y, getZ() / z, getW() / w);} public default Vec4i devide(int x, int y, int z, int w) { return set(getX() / x, getY() / y, getZ() / z, getW() / w); }
@Override @Override
public default Vec4i set(int value){return set(value, value, value, value);} public default Vec4i set(int value) { return set(value, value, value, value); }
public default Vec4i set(Vec4i value){return set(value.getX(), value.getY(), value.getZ(), value.getW());} public default Vec4i set(Vec4i value) { return set(value.getX(), value.getY(), value.getZ(), value.getW()); }
public Vec4i set(int x, int y, int z, int w); public Vec4i set(int x, int y, int z, int w);
public default double distanceTo(Vec4i value) { return distanceTo(value.getX(), value.getY(), value.getZ(), value.getW()); }
public default double distanceTo(Vec4i value){return distanceTo(value.getX(), value.getY(), value.getZ(), value.getW());} public default double distanceTo(int x, int y, int z, int w) { return Math.sqrt(distanceTo(x, y, z, w)); }
public default double distanceTo(int x, int y, int z, int w){return Math.sqrt(distanceTo(x, y, z, w));} public default long distanceToSquared(Vec4i value) { return distanceToSquared(value.getX(), value.getY(), value.getZ(), value.getW()); }
public default long distanceToSquared(int x, int y, int z, int w) {
public default long distanceToSquared(Vec4i value){return distanceToSquared(value.getX(), value.getY(), value.getZ(), value.getW());}
public default long distanceToSquared(int x, int y, int z, int w)
{
long xPos = getX() - x; long xPos = getX() - x;
long yPos = getY() - y; long yPos = getY() - y;
long zPos = getZ() - z; long zPos = getZ() - z;
long wPos = getW() - w; long wPos = getW() - w;
return (xPos * xPos) + (yPos * yPos) + (zPos * zPos) + (wPos * wPos); return (xPos * xPos) + (yPos * yPos) + (zPos * zPos) + (wPos * wPos);
} }
@Override
public default long lengthSquared() {return (getX() * getX()) + (getY() * getY()) + (getZ() * getZ()) + (getW() * getW());}
public default long dotProduct(Vec4i value){return dotProduct(value.getX(), value.getY(), value.getZ(), value.getW());}
public default long dotProduct(int x, int y, int z, int w){return (getX() * x) + (getY() * y) + (getZ() * z) + (getW() * w);};
public default Vec4i min(Vec4i other) {return min(other, this);}
public default Vec4i min(Vec4i other, Vec4i result){return min(other.getX(), other.getY(), other.getZ(), other.getW(), result);}
public default Vec4i min(int x, int y, int z, int w) {return min(x, y, z, w, this);}
public default Vec4i min(int x, int y, int z, int w, Vec4i result){return result.set(Math.min(getX(), x), Math.min(getY(), y), Math.min(getZ(), z), Math.min(getW(), w));}
public default Vec4i max(Vec4i other) {return max(other, this);}
public default Vec4i max(Vec4i other, Vec4i result){return max(other.getX(), other.getY(), other.getZ(), other.getW(), result);}
public default Vec4i max(int x, int y, int z, int w) {return max(x, y, z, w, this);}
public default Vec4i max(int x, int y, int z, int w, Vec4i result){return result.set(Math.max(getX(), x), Math.max(getY(), y), Math.max(getZ(), z), Math.max(getZ(), z));}
public default Vec4i difference(Vec4i other) {return difference(other, this);}
public default Vec4i difference(Vec4i other, Vec4i result){return difference(other.getX(), other.getY(), other.getZ(), other.getW(), result);}
public default Vec4i difference(int x, int y, int z, int w) {return difference(x, y, z, w, this);}
public default Vec4i difference(int x, int y, int z, int w, Vec4i result){return result.set(getX() - x, getY() - y, getZ() - z, getW() - w);}
@Override @Override
public default Vec4i clamp(int min, int max){return clamp(min, max, ALL);} public default long lengthSquared() { return (getX() * getX()) + (getY() * getY()) + (getZ() * getZ()) + (getW() * getW()); }
public default Vec4i clamp(int min, int max, Vec4i result){return clamp(min, max, result, ALL);} public default long dotProduct(Vec4i value) { return dotProduct(value.getX(), value.getY(), value.getZ(), value.getW()); }
public default long dotProduct(int x, int y, int z, int w) { return (getX() * x) + (getY() * y) + (getZ() * z) + (getW() * w); };
public default Vec4i min(Vec4i other) { return min(other, this); }
public default Vec4i min(Vec4i other, Vec4i result) { return min(other.getX(), other.getY(), other.getZ(), other.getW(), result); }
public default Vec4i min(int x, int y, int z, int w) { return min(x, y, z, w, this); }
public default Vec4i min(int x, int y, int z, int w, Vec4i result) { return result.set(Math.min(getX(), x), Math.min(getY(), y), Math.min(getZ(), z), Math.min(getW(), w)); }
public default Vec4i max(Vec4i other) { return max(other, this); }
public default Vec4i max(Vec4i other, Vec4i result) { return max(other.getX(), other.getY(), other.getZ(), other.getW(), result); }
public default Vec4i max(int x, int y, int z, int w) { return max(x, y, z, w, this); }
public default Vec4i max(int x, int y, int z, int w, Vec4i result) { return result.set(Math.max(getX(), x), Math.max(getY(), y), Math.max(getZ(), z), Math.max(getZ(), z)); }
public default Vec4i difference(Vec4i other) { return difference(other, this); }
public default Vec4i difference(Vec4i other, Vec4i result) { return difference(other.getX(), other.getY(), other.getZ(), other.getW(), result); }
public default Vec4i difference(int x, int y, int z, int w) { return difference(x, y, z, w, this); }
public default Vec4i difference(int x, int y, int z, int w, Vec4i result) { return result.set(getX() - x, getY() - y, getZ() - z, getW() - w); }
@Override @Override
public default Vec4i clamp(int min, int max, int filter){return clamp(min, max, this, filter);} public default Vec4i clamp(int min, int max) { return clamp(min, max, ALL); }
public default Vec4i clamp(int min, int max, Vec4i result, int filter){ return result.set((filter & X) == 0 ? getX() : MathUtils.clamp(min, max, getX()), (filter & Y) == 0 ? getY() : MathUtils.clamp(min, max, getY()), (filter & Z) == 0 ? getZ() : MathUtils.clamp(min, max, getZ()), (filter & W) == 0 ? getW() : MathUtils.clamp(min, max, getW()));} public default Vec4i clamp(int min, int max, Vec4i result) { return clamp(min, max, result, ALL); }
@Override
public default Vec4i clamp(int min, int max, int filter) { return clamp(min, max, this, filter); }
public default Vec4i clamp(int min, int max, Vec4i result, int filter) { return result.set((filter & X) == 0 ? getX() : MathUtils.clamp(min, max, getX()), (filter & Y) == 0 ? getY() : MathUtils.clamp(min, max, getY()), (filter & Z) == 0 ? getZ() : MathUtils.clamp(min, max, getZ()), (filter & W) == 0 ? getW() : MathUtils.clamp(min, max, getW())); }
@Override @Override
public default Vec4i store(ByteBuffer buffer) public default Vec4i store(ByteBuffer buffer) {
{
buffer.putInt(getX()).putInt(getY()).putInt(getZ()).putInt(getW()); buffer.putInt(getX()).putInt(getY()).putInt(getZ()).putInt(getW());
return this; return this;
} }
@Override @Override
public default Vec4i load(ByteBuffer buffer) public default Vec4i load(ByteBuffer buffer) { return set(buffer.getInt(), buffer.getInt(), buffer.getInt(), buffer.getInt()); }
{
return set(buffer.getInt(), buffer.getInt(), buffer.getInt(), buffer.getInt());
}
@Override @Override
public default Vec4i store(IntBuffer buffer) public default Vec4i store(IntBuffer buffer) {
{
buffer.put(getX()).put(getY()).put(getZ()).put(getW()); buffer.put(getX()).put(getY()).put(getZ()).put(getW());
return this; return this;
} }
@Override @Override
public default Vec4i load(IntBuffer buffer) public default Vec4i load(IntBuffer buffer) { return set(buffer.get(), buffer.get(), buffer.get(), buffer.get()); }
{
return set(buffer.get(), buffer.get(), buffer.get(), buffer.get());
}
@Override @Override
public default Vec4b asByte(){return isMutable() ? Vec4b.mutable((byte)getX(), (byte)getY(), (byte)getZ(), (byte)getW()) : Vec4b.of((byte)getX(), (byte)getY(), (byte)getZ(), (byte)getW());} public default Vec4b asByte() { return isMutable() ? Vec4b.mutable((byte)getX(), (byte)getY(), (byte)getZ(), (byte)getW()) : Vec4b.of((byte)getX(), (byte)getY(), (byte)getZ(), (byte)getW()); }
@Override @Override
public default Vec4s asShort(){return isMutable() ? Vec4s.mutable((short)getX(), (short)getY(), (short)getZ(), (short)getW()) : Vec4s.of((short)getX(), (short)getY(), (short)getZ(), (short)getW());} public default Vec4s asShort() { return isMutable() ? Vec4s.mutable((short)getX(), (short)getY(), (short)getZ(), (short)getW()) : Vec4s.of((short)getX(), (short)getY(), (short)getZ(), (short)getW()); }
@Override @Override
public default Vec4l asLong(){return isMutable() ? Vec4l.mutable(getX(), getY(), getZ(), getW()) : Vec4l.of(getX(), getY(), getZ(), getW());} public default Vec4l asLong() { return isMutable() ? Vec4l.mutable(getX(), getY(), getZ(), getW()) : Vec4l.of(getX(), getY(), getZ(), getW()); }
@Override @Override
public default Vec4f asFloat() {return isMutable() ? Vec4f.mutable(getX(), getY(), getZ(), getW()) : Vec4f.of(getX(), getY(), getZ(), getW());} public default Vec4f asFloat() { return isMutable() ? Vec4f.mutable(getX(), getY(), getZ(), getW()) : Vec4f.of(getX(), getY(), getZ(), getW()); }
@Override @Override
public default Vec4d asDouble(){return isMutable() ? Vec4d.mutable(getX(), getY(), getZ(), getW()) : Vec4d.of(getX(), getY(), getZ(), getW());} public default Vec4d asDouble() { return isMutable() ? Vec4d.mutable(getX(), getY(), getZ(), getW()) : Vec4d.of(getX(), getY(), getZ(), getW()); }
@Override @Override
public default Vec4i asMutable(){return isMutable() ? this : mutable(this);} public default Vec4i asMutable() { return isMutable() ? this : mutable(this); }
@Override @Override
public default Vec4i asImmutable(){return isMutable() ? of(this) : this;} public default Vec4i asImmutable() { return isMutable() ? of(this) : this; }
@Override @Override
public default Vec4i copyAsMutable(){return mutable(this);} public default Vec4i copyAsMutable() { return mutable(this); }
@Override @Override
public default Vec4i copyAsImmutable(){return of(this);} public default Vec4i copyAsImmutable() { return of(this); }
} }

View File

@ -2,114 +2,61 @@ package speiger.src.coreengine.math.vector.ints;
import java.util.Objects; import java.util.Objects;
public class Vec4iImmutable implements Vec4i public class Vec4iImmutable implements Vec4i {
{
final int x; final int x;
final int y; final int y;
final int z; final int z;
final int w; final int w;
public Vec4iImmutable() public Vec4iImmutable() {
{
x = 0; x = 0;
y = 0; y = 0;
z = 0; z = 0;
w = 0; w = 0;
} }
public Vec4iImmutable(int value) public Vec4iImmutable(int value) {
{
x = value; x = value;
y = value; y = value;
z = value; z = value;
w = value; w = value;
} }
public Vec4iImmutable(int x, int y, int z, int w) public Vec4iImmutable(int x, int y, int z, int w) {
{
this.x = x; this.x = x;
this.y = y; this.y = y;
this.z = z; this.z = z;
this.w = w; this.w = w;
} }
@Override
public boolean isMutable()
{
return false;
}
@Override @Override
public int getX() public boolean isMutable() { return false; }
{ @Override
return x; public int getX() { return x; }
} @Override
public int getY() { return y; }
@Override
public int getZ() { return z; }
@Override
public int getW() { return w; }
@Override
public Vec4i setX(int x) { return this.x == x ? this : Vec4i.of(x, y, z, w); }
@Override
public Vec4i setY(int y) { return this.y == y ? this : Vec4i.of(x, y, z, w); }
@Override
public Vec4i setZ(int z) { return this.z == z ? this : Vec4i.of(x, y, z, w); }
@Override
public Vec4i setW(int w) { return this.w == w ? this : Vec4i.of(x, y, z, w); }
@Override
public Vec4i copy() { return Vec4i.of(this); }
@Override
public Vec4i set(int x, int y, int z, int w) { return this.x == x && this.y == y && this.z == z && this.w == w ? this : Vec4i.of(x, y, z, w); }
@Override
public int hashCode() { return Objects.hash(x, y, z, w); }
@Override @Override
public int getY() public boolean equals(Object obj) {
{ if(obj instanceof Vec4i) {
return y;
}
@Override
public int getZ()
{
return z;
}
@Override
public int getW()
{
return w;
}
@Override
public Vec4i setX(int x)
{
return this.x == x ? this : Vec4i.of(x, y, z, w);
}
@Override
public Vec4i setY(int y)
{
return this.y == y ? this : Vec4i.of(x, y, z, w);
}
@Override
public Vec4i setZ(int z)
{
return this.z == z ? this : Vec4i.of(x, y, z, w);
}
@Override
public Vec4i setW(int w)
{
return this.w == w ? this : Vec4i.of(x, y, z, w);
}
@Override
public Vec4i copy()
{
return Vec4i.of(this);
}
@Override
public Vec4i set(int x, int y, int z, int w)
{
return this.x == x && this.y == y && this.z == z && this.w == w ? this : Vec4i.of(x, y, z, w);
}
@Override
public int hashCode()
{
return Objects.hash(x, y, z, w);
}
@Override
public boolean equals(Object obj)
{
if(obj instanceof Vec4i)
{
Vec4i vec = (Vec4i)obj; Vec4i vec = (Vec4i)obj;
return vec.getX() == x && vec.getY() == y && vec.getZ() == z && vec.getW() == w; return vec.getX() == x && vec.getY() == y && vec.getZ() == z && vec.getW() == w;
} }
@ -117,8 +64,5 @@ public class Vec4iImmutable implements Vec4i
} }
@Override @Override
public String toString() public String toString() { return "Vec4i[x="+x+", y="+y+", z="+z+", w="+w+"]"; }
{
return "Vec4i[x="+x+", y="+y+", z="+z+", w="+w+"]";
}
} }

View File

@ -2,100 +2,68 @@ package speiger.src.coreengine.math.vector.ints;
import java.util.Objects; import java.util.Objects;
public class Vec4iMutable implements Vec4i public class Vec4iMutable implements Vec4i {
{
int x; int x;
int y; int y;
int z; int z;
int w; int w;
public Vec4iMutable() public Vec4iMutable() {}
{
}
public Vec4iMutable(int value) public Vec4iMutable(int value) {
{
x = value; x = value;
y = value; y = value;
z = value; z = value;
w = value; w = value;
} }
public Vec4iMutable(int x, int y, int z, int w) public Vec4iMutable(int x, int y, int z, int w) {
{
this.x = x; this.x = x;
this.y = y; this.y = y;
this.z = z; this.z = z;
this.w = w; this.w = w;
} }
@Override
public boolean isMutable()
{
return true;
}
@Override @Override
public int getX() public boolean isMutable() { return true; }
{ @Override
return x; public int getX() { return x; }
} @Override
public int getY() { return y; }
@Override
public int getZ() { return z; }
@Override
public int getW() { return w; }
@Override @Override
public int getY() public Vec4i setX(int x) {
{
return y;
}
@Override
public int getZ()
{
return z;
}
@Override
public int getW()
{
return w;
}
@Override
public Vec4i setX(int x)
{
this.x = x; this.x = x;
return this; return this;
} }
@Override @Override
public Vec4i setY(int y) public Vec4i setY(int y) {
{
this.y = y; this.y = y;
return this; return this;
} }
@Override @Override
public Vec4i setZ(int z) public Vec4i setZ(int z) {
{
this.z = z; this.z = z;
return this; return this;
} }
@Override @Override
public Vec4i setW(int w) public Vec4i setW(int w) {
{
this.w = w; this.w = w;
return this; return this;
} }
@Override @Override
public Vec4i copy() public Vec4i copy() { return Vec4i.mutable(this); }
{
return Vec4i.mutable(this);
}
@Override @Override
public Vec4i set(int x, int y, int z, int w) public Vec4i set(int x, int y, int z, int w) {
{
this.x = x; this.x = x;
this.y = y; this.y = y;
this.z = z; this.z = z;
@ -104,16 +72,11 @@ public class Vec4iMutable implements Vec4i
} }
@Override @Override
public int hashCode() public int hashCode() { return Objects.hash(x, y, z, w); }
{
return Objects.hash(x, y, z, w);
}
@Override @Override
public boolean equals(Object obj) public boolean equals(Object obj) {
{ if(obj instanceof Vec4i) {
if(obj instanceof Vec4i)
{
Vec4i vec = (Vec4i)obj; Vec4i vec = (Vec4i)obj;
return vec.getX() == x && vec.getY() == y && vec.getZ() == z && vec.getW() == w; return vec.getX() == x && vec.getY() == y && vec.getZ() == z && vec.getW() == w;
} }
@ -121,8 +84,5 @@ public class Vec4iMutable implements Vec4i
} }
@Override @Override
public String toString() public String toString() { return "Vec4i[x="+x+", y="+y+", z="+z+", w="+w+"]"; }
{
return "Vec4i[x="+x+", y="+y+", z="+z+", w="+w+"]";
}
} }

View File

@ -9,8 +9,7 @@ import speiger.src.coreengine.math.vector.floats.Vecf;
import speiger.src.coreengine.math.vector.longs.Vecl; import speiger.src.coreengine.math.vector.longs.Vecl;
import speiger.src.coreengine.math.vector.shorts.Vecs; import speiger.src.coreengine.math.vector.shorts.Vecs;
public interface Veci extends Vec public interface Veci extends Vec {
{
public Veci set(int value); public Veci set(int value);
public Veci add(int value); public Veci add(int value);
public Veci sub(int value); public Veci sub(int value);
@ -18,14 +17,11 @@ public interface Veci extends Vec
public Veci devide(int value); public Veci devide(int value);
public Veci clamp(int min, int max); public Veci clamp(int min, int max);
public Veci clamp(int min, int max, int filter); public Veci clamp(int min, int max, int filter);
public long lengthSquared(); public long lengthSquared();
public default double length(){return Math.sqrt(lengthSquared());} public default double length() { return Math.sqrt(lengthSquared()); }
public Veci store(IntBuffer buffer); public Veci store(IntBuffer buffer);
public Veci load(IntBuffer buffer); public Veci load(IntBuffer buffer);
public int[] asArray(); public int[] asArray();
public Vecb asByte(); public Vecb asByte();
public Vecs asShort(); public Vecs asShort();
public Vecl asLong(); public Vecl asLong();

View File

@ -10,154 +10,129 @@ import speiger.src.coreengine.math.vector.floats.Vec2f;
import speiger.src.coreengine.math.vector.ints.Vec2i; import speiger.src.coreengine.math.vector.ints.Vec2i;
import speiger.src.coreengine.math.vector.shorts.Vec2s; import speiger.src.coreengine.math.vector.shorts.Vec2s;
public interface Vec2l extends Vecl public interface Vec2l extends Vecl {
{
public static final Vec2l ZERO = of(); public static final Vec2l ZERO = of();
public static final Vec2l MINUS_ONE = of(-1L); public static final Vec2l MINUS_ONE = of(-1L);
public static final Vec2l ONE = of(1L); public static final Vec2l ONE = of(1L);
public static Vec2l mutable(){return new Vec2lMutable();} public static Vec2l mutable() { return new Vec2lMutable(); }
public static Vec2l mutable(long value){return new Vec2lMutable(value);} public static Vec2l mutable(long value) { return new Vec2lMutable(value); }
public static Vec2l mutable(long x, long y){return new Vec2lMutable(x, y);} public static Vec2l mutable(long x, long y) { return new Vec2lMutable(x, y); }
public static Vec2l mutable(Vec2l value){return mutable(value.getX(), value.getY());} public static Vec2l mutable(Vec2l value) { return mutable(value.getX(), value.getY()); }
public static Vec2l of() { return new Vec2lImmutable(); }
public static Vec2l of(){return new Vec2lImmutable();} public static Vec2l of(long value) { return new Vec2lImmutable(value); }
public static Vec2l of(long value){return new Vec2lImmutable(value);} public static Vec2l of(long x, long y) { return new Vec2lImmutable(x, y); }
public static Vec2l of(long x, long y){return new Vec2lImmutable(x, y);} public static Vec2l of(Vec2l value) { return of(value.getX(), value.getY()); }
public static Vec2l of(Vec2l value){return of(value.getX(), value.getY());}
public long getX(); public long getX();
public long getY(); public long getY();
public Vec2l setX(long x); public Vec2l setX(long x);
public Vec2l setY(long y); public Vec2l setY(long y);
@Override @Override
public default long[] asArray(){return new long[]{getX(), getY()};} public default long[] asArray() { return new long[] {getX(), getY()}; }
@Override @Override
public Vec2l copy(); public Vec2l copy();
@Override @Override
public default Vec2l abs(){return set(Math.abs(getX()), Math.abs(getY()));} public default Vec2l abs() { return set(Math.abs(getX()), Math.abs(getY())); }
@Override @Override
public default Vec2l negate(){return set(0L, 0L);} public default Vec2l negate() { return set(0L, 0L); }
@Override @Override
public default Vec2l invert(){return set(-getX(), -getY());}; public default Vec2l invert() { return set(-getX(), -getY()); };
@Override @Override
public default Vec2l add(long value) {return add(value, value);} public default Vec2l add(long value) { return add(value, value); }
public default Vec2l add(Vec2l value) {return add(value.getX(), value.getY());} public default Vec2l add(Vec2l value) { return add(value.getX(), value.getY()); }
public default Vec2l add(long x, long y) {return set(x + getX(), y + getY());} public default Vec2l add(long x, long y) { return set(x + getX(), y + getY()); }
@Override @Override
public default Vec2l sub(long value){return sub(value, value);} public default Vec2l sub(long value) { return sub(value, value); }
public default Vec2l sub(Vec2l value){return sub(value.getX(), value.getY());} public default Vec2l sub(Vec2l value) { return sub(value.getX(), value.getY()); }
public default Vec2l sub(long x, long y) {return set(getX() - x, getY() - y);} public default Vec2l sub(long x, long y) { return set(getX() - x, getY() - y); }
@Override @Override
public default Vec2l multiply(long value){return multiply(value, value);} public default Vec2l multiply(long value) { return multiply(value, value); }
public default Vec2l multiply(Vec2l value){return multiply(value.getX(), value.getY());} public default Vec2l multiply(Vec2l value) { return multiply(value.getX(), value.getY()); }
public default Vec2l multiply(long x, long y) {return set(x * getX(), y * getY());} public default Vec2l multiply(long x, long y) { return set(x * getX(), y * getY()); }
@Override @Override
public default Vec2l devide(long value){return devide(value, value);} public default Vec2l devide(long value) { return devide(value, value); }
public default Vec2l devide(Vec2l value){return devide(value.getX(), value.getY());} public default Vec2l devide(Vec2l value) { return devide(value.getX(), value.getY()); }
public default Vec2l devide(long x, long y){return set(getX() / x, getY() / y);} public default Vec2l devide(long x, long y) { return set(getX() / x, getY() / y); }
@Override @Override
public default Vec2l set(long value){return set(value, value);}; public default Vec2l set(long value) { return set(value, value); };
public default Vec2l set(Vec2l value){return set(value.getX(), value.getY());} public default Vec2l set(Vec2l value) { return set(value.getX(), value.getY()); }
public Vec2l set(long x, long y); public Vec2l set(long x, long y);
public default double distanceTo(Vec2l value) { return distanceTo(value.getX(), value.getY()); }
public default double distanceTo(Vec2l value){return distanceTo(value.getX(), value.getY());} public default double distanceTo(long x, long y) { return Math.sqrt(distanceToSquared(x, y)); }
public default double distanceTo(long x, long y){return Math.sqrt(distanceToSquared(x, y));} public default long distanceToSquared(Vec2l value) { return distanceToSquared(value.getX(), value.getY()); }
public default long distanceToSquared(long x, long y) {
public default long distanceToSquared(Vec2l value){return distanceToSquared(value.getX(), value.getY());}
public default long distanceToSquared(long x, long y)
{
long xPos = getX() - x; long xPos = getX() - x;
long yPos = getY() - y; long yPos = getY() - y;
return (xPos * xPos) + (yPos * yPos); return (xPos * xPos) + (yPos * yPos);
} }
@Override @Override
public default long lengthSquared() {return (getX() * getX()) + (getY() * getY());} public default long lengthSquared() { return (getX() * getX()) + (getY() * getY()); }
public default long dotProduct(Vec2l value) { return dotProduct(value.getX(), value.getY()); }
public default long dotProduct(Vec2l value){return dotProduct(value.getX(), value.getY());} public default long dotProduct(long x, long y) { return (getX() * x) + (getY() * y); }
public default long dotProduct(long x, long y){return (getX() * x) + (getY() * y);} public default Vec2l rotate(long angle, Vec2l center) { return rotate(angle, center.getX(), center.getY()); }
public default Vec2l rotate(long angle, long x, long y) {
public default Vec2l rotate(long angle, Vec2l center){return rotate(angle, center.getX(), center.getY());}
public default Vec2l rotate(long angle, long x, long y)
{
long xPos = getX() - x; long xPos = getX() - x;
long yPos = getY() - y; long yPos = getY() - y;
double cos = MathUtils.cos(angle); double cos = MathUtils.cos(angle);
double sin = MathUtils.sin(angle); double sin = MathUtils.sin(angle);
return set((long)((xPos * cos) + (yPos * sin) + x), (long)(-(xPos * sin) + (yPos * cos) + y)); return set((long)((xPos * cos) + (yPos * sin) + x), (long)(-(xPos * sin) + (yPos * cos) + y));
} }
public default Vec2l min(Vec2l other) {return min(other, this);} public default Vec2l min(Vec2l other) { return min(other, this); }
public default Vec2l min(Vec2l other, Vec2l result){return min(other.getX(), other.getY(), result);} public default Vec2l min(Vec2l other, Vec2l result) { return min(other.getX(), other.getY(), result); }
public default Vec2l min(long x, long y) {return min(x, y, this);} public default Vec2l min(long x, long y) { return min(x, y, this); }
public default Vec2l min(long x, long y, Vec2l result){return result.set(Math.min(getX(), x), Math.min(getY(), y));} public default Vec2l min(long x, long y, Vec2l result) { return result.set(Math.min(getX(), x), Math.min(getY(), y)); }
public default Vec2l max(Vec2l other) { return max(other, this); }
public default Vec2l max(Vec2l other) {return max(other, this);} public default Vec2l max(Vec2l other, Vec2l result) { return max(other.getX(), other.getY(), result); }
public default Vec2l max(Vec2l other, Vec2l result){return max(other.getX(), other.getY(), result);} public default Vec2l max(long x, long y) { return max(x, y, this); }
public default Vec2l max(long x, long y) {return max(x, y, this);} public default Vec2l max(long x, long y, Vec2l result) { return result.set(Math.max(getX(), x), Math.max(getY(), y)); }
public default Vec2l max(long x, long y, Vec2l result){return result.set(Math.max(getX(), x), Math.max(getY(), y));} public default Vec2l difference(Vec2l other) { return difference(other, this); }
public default Vec2l difference(Vec2l other, Vec2l result) { return difference(other.getX(), other.getY(), result); }
public default Vec2l difference(Vec2l other) {return difference(other, this);} public default Vec2l difference(long x, long y) { return difference(x, y, this); }
public default Vec2l difference(Vec2l other, Vec2l result){return difference(other.getX(), other.getY(), result);} public default Vec2l difference(long x, long y, Vec2l result) { return result.set(getX() - x, getY() - y); }
public default Vec2l difference(long x, long y) {return difference(x, y, this);} @Override
public default Vec2l difference(long x, long y, Vec2l result){return result.set(getX() - x, getY() - y);} public default Vec2l clamp(long min, long max) { return clamp(min, max, ALL); }
public default Vec2l clamp(long min, long max, Vec2l result) { return clamp(min, max, result, ALL); }
@Override
public default Vec2l clamp(long min, long max, int filter) { return clamp(min, max, this, filter); }
public default Vec2l clamp(long min, long max, Vec2l result, int filter) { return result.set((filter & X) == 0 ? getX() : MathUtils.clamp(min, max, getX()), (filter & Y) == 0 ? getY() : MathUtils.clamp(min, max, getY())); }
@Override @Override
public default Vec2l clamp(long min, long max){return clamp(min, max, ALL);} public default Vec2l store(ByteBuffer buffer) {
public default Vec2l clamp(long min, long max, Vec2l result){return clamp(min, max, result, ALL);}
@Override
public default Vec2l clamp(long min, long max, int filter){return clamp(min, max, this, filter);}
public default Vec2l clamp(long min, long max, Vec2l result, int filter){ return result.set((filter & X) == 0 ? getX() : MathUtils.clamp(min, max, getX()), (filter & Y) == 0 ? getY() : MathUtils.clamp(min, max, getY()));}
@Override
public default Vec2l store(ByteBuffer buffer)
{
buffer.putLong(getX()).putLong(getY()); buffer.putLong(getX()).putLong(getY());
return this; return this;
} }
@Override @Override
public default Vec2l load(ByteBuffer buffer) public default Vec2l load(ByteBuffer buffer) { return set(buffer.getLong(), buffer.getLong()); }
{
return set(buffer.getLong(), buffer.getLong());
}
@Override @Override
public default Vec2l store(LongBuffer buffer) public default Vec2l store(LongBuffer buffer) {
{
buffer.put(getX()).put(getY()); buffer.put(getX()).put(getY());
return this; return this;
} }
@Override @Override
public default Vec2l load(LongBuffer buffer) public default Vec2l load(LongBuffer buffer) { return set(buffer.get(), buffer.get()); }
{
return set(buffer.get(), buffer.get());
}
@Override @Override
public default Vec2b asByte(){return isMutable() ? Vec2b.mutable((byte)getX(), (byte)getY()) : Vec2b.of((byte)getX(), (byte)getY());} public default Vec2b asByte() { return isMutable() ? Vec2b.mutable((byte)getX(), (byte)getY()) : Vec2b.of((byte)getX(), (byte)getY()); }
@Override @Override
public default Vec2s asShort(){return isMutable() ? Vec2s.mutable((short)getX(), (short)getY()) : Vec2s.of((short)getX(), (short)getY());} public default Vec2s asShort() { return isMutable() ? Vec2s.mutable((short)getX(), (short)getY()) : Vec2s.of((short)getX(), (short)getY()); }
@Override @Override
public default Vec2i asInt(){return isMutable() ? Vec2i.mutable((int)getX(), (int)getY()) : Vec2i.of((int)getX(), (int)getY());} public default Vec2i asInt() { return isMutable() ? Vec2i.mutable((int)getX(), (int)getY()) : Vec2i.of((int)getX(), (int)getY()); }
@Override @Override
public default Vec2f asFloat() {return isMutable() ? Vec2f.mutable(getX(), getY()) : Vec2f.of(getX(), getY());} public default Vec2f asFloat() { return isMutable() ? Vec2f.mutable(getX(), getY()) : Vec2f.of(getX(), getY()); }
@Override @Override
public default Vec2d asDouble(){return isMutable() ? Vec2d.mutable(getX(), getY()) : Vec2d.of(getX(), getY());} public default Vec2d asDouble() { return isMutable() ? Vec2d.mutable(getX(), getY()) : Vec2d.of(getX(), getY()); }
@Override @Override
public default Vec2l asMutable(){return isMutable() ? this : mutable(this);} public default Vec2l asMutable() { return isMutable() ? this : mutable(this); }
@Override @Override
public default Vec2l asImmutable(){return isMutable() ? of(this) : this;} public default Vec2l asImmutable() { return isMutable() ? of(this) : this; }
@Override @Override
public default Vec2l copyAsMutable(){return mutable(this);} public default Vec2l copyAsMutable() { return mutable(this); }
@Override @Override
public default Vec2l copyAsImmutable(){return of(this);} public default Vec2l copyAsImmutable() { return of(this); }
} }

View File

@ -2,91 +2,51 @@ package speiger.src.coreengine.math.vector.longs;
import java.util.Objects; import java.util.Objects;
public class Vec2lImmutable implements Vec2l public class Vec2lImmutable implements Vec2l {
{
final long x; final long x;
final long y; final long y;
public Vec2lImmutable() public Vec2lImmutable() {
{
x = 0; x = 0;
y = 0; y = 0;
} }
public Vec2lImmutable(long value) public Vec2lImmutable(long value) {
{
x = value; x = value;
y = value; y = value;
} }
public Vec2lImmutable(long x, long y) public Vec2lImmutable(long x, long y) {
{
this.x = x; this.x = x;
this.y = y; this.y = y;
} }
@Override @Override
public boolean isMutable() public boolean isMutable() { return false; }
{ @Override
return false; public long getX() { return x; }
} @Override
public long getY() { return y; }
@Override
public Vec2l setX(long x) { return this.x == x ? this : Vec2l.of(x, y); }
@Override
public Vec2l setY(long y) { return this.y == y ? this : Vec2l.of(x, y); }
@Override
public Vec2l copy() { return Vec2l.of(this); }
@Override
public Vec2l set(long x, long y) { return this.x == x && this.y == y ? this : Vec2l.of(x, y); }
@Override
public int hashCode() { return Objects.hash(x, y); }
@Override @Override
public long getX() public boolean equals(Object obj) {
{ if(obj instanceof Vec2l) {
return x;
}
@Override
public long getY()
{
return y;
}
@Override
public Vec2l setX(long x)
{
return this.x == x ? this : Vec2l.of(x, y);
}
@Override
public Vec2l setY(long y)
{
return this.y == y ? this : Vec2l.of(x, y);
}
@Override
public Vec2l copy()
{
return Vec2l.of(this);
}
@Override
public Vec2l set(long x, long y)
{
return this.x == x && this.y == y ? this : Vec2l.of(x, y);
}
@Override
public int hashCode()
{
return Objects.hash(x, y);
}
@Override
public boolean equals(Object obj)
{
if(obj instanceof Vec2l)
{
Vec2l vec = (Vec2l)obj; Vec2l vec = (Vec2l)obj;
return vec.getX() == x && vec.getY() == y; return vec.getX() == x && vec.getY() == y;
} }
return false; return false;
} }
@Override @Override
public String toString() public String toString() { return "Vec2l[x="+x+", y="+y+"]"; }
{
return "Vec2l[x="+x+", y="+y+"]";
}
} }

View File

@ -2,93 +2,63 @@ package speiger.src.coreengine.math.vector.longs;
import java.util.Objects; import java.util.Objects;
public class Vec2lMutable implements Vec2l public class Vec2lMutable implements Vec2l {
{
long x; long x;
long y; long y;
public Vec2lMutable() public Vec2lMutable() {}
{
}
public Vec2lMutable(long value) public Vec2lMutable(long value) {
{
x = value; x = value;
y = value; y = value;
} }
public Vec2lMutable(long x, long y) public Vec2lMutable(long x, long y) {
{
this.x = x; this.x = x;
this.y = y; this.y = y;
} }
@Override
public boolean isMutable()
{
return true;
}
@Override @Override
public long getX() public boolean isMutable() { return true; }
{ @Override
return x; public long getX() { return x; }
} @Override
public long getY() { return y; }
@Override @Override
public long getY() public Vec2l setX(long x) {
{
return y;
}
@Override
public Vec2l setX(long x)
{
this.x = x; this.x = x;
return this; return this;
} }
@Override @Override
public Vec2l setY(long y) public Vec2l setY(long y) {
{
this.y = y; this.y = y;
return this; return this;
} }
@Override @Override
public Vec2l copy() public Vec2l copy() { return Vec2l.mutable(this); }
{
return Vec2l.mutable(this);
}
@Override @Override
public Vec2l set(long x, long y) public Vec2l set(long x, long y) {
{
this.x = x; this.x = x;
this.y = y; this.y = y;
return this; return this;
} }
@Override @Override
public int hashCode() public int hashCode() { return Objects.hash(x, y); }
{
return Objects.hash(x, y);
}
@Override @Override
public boolean equals(Object obj) public boolean equals(Object obj) {
{ if(obj instanceof Vec2l) {
if(obj instanceof Vec2l)
{
Vec2l vec = (Vec2l)obj; Vec2l vec = (Vec2l)obj;
return vec.getX() == x && vec.getY() == y; return vec.getX() == x && vec.getY() == y;
} }
return false; return false;
} }
@Override @Override
public String toString() public String toString() { return "Vec2l[x="+x+", y="+y+"]"; }
{
return "Vec2l[x="+x+", y="+y+"]";
}
} }

View File

@ -10,22 +10,19 @@ import speiger.src.coreengine.math.vector.floats.Vec3f;
import speiger.src.coreengine.math.vector.ints.Vec3i; import speiger.src.coreengine.math.vector.ints.Vec3i;
import speiger.src.coreengine.math.vector.shorts.Vec3s; import speiger.src.coreengine.math.vector.shorts.Vec3s;
public interface Vec3l extends Vecl {
public interface Vec3l extends Vecl
{
public static final Vec3l ZERO = of(); public static final Vec3l ZERO = of();
public static final Vec3l MINUS_ONE = of(-1L); public static final Vec3l MINUS_ONE = of(-1L);
public static final Vec3l ONE = of(1L); public static final Vec3l ONE = of(1L);
public static Vec3l mutable(){return new Vec3lMutable();} public static Vec3l mutable() { return new Vec3lMutable(); }
public static Vec3l mutable(long value){return new Vec3lMutable(value);} public static Vec3l mutable(long value) { return new Vec3lMutable(value); }
public static Vec3l mutable(long x, long y, long z){return new Vec3lMutable(x, y, z);} public static Vec3l mutable(long x, long y, long z) { return new Vec3lMutable(x, y, z); }
public static Vec3l mutable(Vec3l vec){return mutable(vec.getX(), vec.getY(), vec.getZ());} public static Vec3l mutable(Vec3l vec) { return mutable(vec.getX(), vec.getY(), vec.getZ()); }
public static Vec3l of() { return new Vec3lImmutable(); }
public static Vec3l of(){return new Vec3lImmutable();} public static Vec3l of(long value) { return new Vec3lImmutable(value); }
public static Vec3l of(long value){return new Vec3lImmutable(value);} public static Vec3l of(long x, long y, long z) { return new Vec3lImmutable(x, y, z); }
public static Vec3l of(long x, long y, long z){return new Vec3lImmutable(x, y, z);} public static Vec3l of(Vec3l vec) { return of(vec.getX(), vec.getY(), vec.getZ()); }
public static Vec3l of(Vec3l vec){return of(vec.getX(), vec.getY(), vec.getZ());}
public long getX(); public long getX();
public long getY(); public long getY();
@ -33,124 +30,103 @@ public interface Vec3l extends Vecl
public Vec3l setX(long x); public Vec3l setX(long x);
public Vec3l setY(long y); public Vec3l setY(long y);
public Vec3l setZ(long z); public Vec3l setZ(long z);
@Override
public default long[] asArray(){return new long[]{getX(), getY(), getZ()};}
@Override
public default long[] asArray() { return new long[] {getX(), getY(), getZ()}; }
@Override @Override
public Vec3l copy(); public Vec3l copy();
@Override @Override
public default Vec3l abs(){return set(Math.abs(getX()), Math.abs(getY()), Math.abs(getZ()));} public default Vec3l abs() { return set(Math.abs(getX()), Math.abs(getY()), Math.abs(getZ())); }
@Override @Override
public default Vec3l negate(){return set(0L, 0L, 0L);} public default Vec3l negate() { return set(0L, 0L, 0L); }
@Override @Override
public default Vec3l invert(){return set(-getX(), -getY(), -getZ());} public default Vec3l invert() { return set(-getX(), -getY(), -getZ()); }
@Override @Override
public default Vec3l add(long value){return add(value, value, value);} public default Vec3l add(long value) { return add(value, value, value); }
public default Vec3l add(Vec3l value){return add(value.getX(), value.getY(), value.getZ());} public default Vec3l add(Vec3l value) { return add(value.getX(), value.getY(), value.getZ()); }
public default Vec3l add(long x, long y, long z){return set(getX() + x, getY() + y, getZ() + z);} public default Vec3l add(long x, long y, long z) { return set(getX() + x, getY() + y, getZ() + z); }
@Override @Override
public default Vec3l sub(long value){return sub(value, value, value);} public default Vec3l sub(long value) { return sub(value, value, value); }
public default Vec3l sub(Vec3l value){return sub(value.getX(), value.getY(), value.getZ());} public default Vec3l sub(Vec3l value) { return sub(value.getX(), value.getY(), value.getZ()); }
public default Vec3l sub(long x, long y, long z){return set(getX() - x, getY() - y, getZ() - z);} public default Vec3l sub(long x, long y, long z) { return set(getX() - x, getY() - y, getZ() - z); }
@Override @Override
public default Vec3l multiply(long value){return multiply(value, value, value);} public default Vec3l multiply(long value) { return multiply(value, value, value); }
public default Vec3l multiply(Vec3l value){return multiply(value.getX(), value.getY(), value.getZ());} public default Vec3l multiply(Vec3l value) { return multiply(value.getX(), value.getY(), value.getZ()); }
public default Vec3l multiply(long x, long y, long z){return set(getX() * x, getY() * y, getZ() * z);} public default Vec3l multiply(long x, long y, long z) { return set(getX() * x, getY() * y, getZ() * z); }
@Override @Override
public default Vec3l devide(long value){return devide(value, value, value);} public default Vec3l devide(long value) { return devide(value, value, value); }
public default Vec3l devide(Vec3l value){return devide(value.getX(), value.getY(), value.getZ());} public default Vec3l devide(Vec3l value) { return devide(value.getX(), value.getY(), value.getZ()); }
public default Vec3l devide(long x, long y, long z){return set(getX() / x, getY() / y, getZ() / z);} public default Vec3l devide(long x, long y, long z) { return set(getX() / x, getY() / y, getZ() / z); }
@Override @Override
public default Vec3l set(long value){return set(value, value, value);} public default Vec3l set(long value) { return set(value, value, value); }
public default Vec3l set(Vec3l value){return set(value.getX(), value.getY(), value.getZ());} public default Vec3l set(Vec3l value) { return set(value.getX(), value.getY(), value.getZ()); }
public Vec3l set(long x, long y, long z); public Vec3l set(long x, long y, long z);
public default double distanceTo(Vec3l value) { return distanceTo(value.getX(), value.getY(), value.getZ()); }
public default double distanceTo(Vec3l value){return distanceTo(value.getX(), value.getY(), value.getZ());} public default double distanceTo(long x, long y, long z) { return Math.sqrt(distanceToSquared(x, y, z)); }
public default double distanceTo(long x, long y, long z){return Math.sqrt(distanceToSquared(x, y, z));} public default long distanceToSquared(Vec3l value) { return distanceToSquared(value.getX(), value.getY(), value.getZ()); }
public default long distanceToSquared(long x, long y, long z) {
public default long distanceToSquared(Vec3l value){return distanceToSquared(value.getX(), value.getY(), value.getZ());}
public default long distanceToSquared(long x, long y, long z)
{
long xPos = getX() - x; long xPos = getX() - x;
long yPos = getY() - y; long yPos = getY() - y;
long zPos = getZ() - z; long zPos = getZ() - z;
return (xPos * xPos) + (yPos * yPos) + (zPos * zPos); return (xPos * xPos) + (yPos * yPos) + (zPos * zPos);
} }
@Override
public default long lengthSquared() {return (getX() * getX()) + (getY() * getY()) + (getZ() * getZ());}
public default long dotProduct(Vec3l value){return dotProduct(value.getX(), value.getY(), value.getZ());}
public default long dotProduct(long x, long y, long z){return (getX() * x) + (getY() * y) + (getZ() * z);}
public default Vec3l min(Vec3l other) {return min(other, this);}
public default Vec3l min(Vec3l other, Vec3l result){return min(other.getX(), other.getY(), other.getZ(), result);}
public default Vec3l min(long x, long y, long z) {return min(x, y, z, this);}
public default Vec3l min(long x, long y, long z, Vec3l result){return result.set(Math.min(getX(), x), Math.min(getY(), y), Math.min(getZ(), z));}
public default Vec3l max(Vec3l other) {return max(other, this);}
public default Vec3l max(Vec3l other, Vec3l result){return max(other.getX(), other.getY(), other.getZ(), result);}
public default Vec3l max(long x, long y, long z) {return max(x, y, z, this);}
public default Vec3l max(long x, long y, long z, Vec3l result){return result.set(Math.max(getX(), x), Math.max(getY(), y), Math.max(getZ(), z));}
public default Vec3l difference(Vec3l other) {return difference(other, this);}
public default Vec3l difference(Vec3l other, Vec3l result){return difference(other.getX(), other.getY(), other.getZ(), result);}
public default Vec3l difference(long x, long y, long z) {return difference(x, y, z, this);}
public default Vec3l difference(long x, long y, long z, Vec3l result){return result.set(getX() - x, getY() - y, getZ() - z);}
@Override @Override
public default Vec3l clamp(long min, long max){return clamp(min, max, ALL);} public default long lengthSquared() { return (getX() * getX()) + (getY() * getY()) + (getZ() * getZ()); }
public default Vec3l clamp(long min, long max, Vec3l result){return clamp(min, max, result, ALL);} public default long dotProduct(Vec3l value) { return dotProduct(value.getX(), value.getY(), value.getZ()); }
public default long dotProduct(long x, long y, long z) { return (getX() * x) + (getY() * y) + (getZ() * z); }
public default Vec3l min(Vec3l other) { return min(other, this); }
public default Vec3l min(Vec3l other, Vec3l result) { return min(other.getX(), other.getY(), other.getZ(), result); }
public default Vec3l min(long x, long y, long z) { return min(x, y, z, this); }
public default Vec3l min(long x, long y, long z, Vec3l result) { return result.set(Math.min(getX(), x), Math.min(getY(), y), Math.min(getZ(), z)); }
public default Vec3l max(Vec3l other) { return max(other, this); }
public default Vec3l max(Vec3l other, Vec3l result) { return max(other.getX(), other.getY(), other.getZ(), result); }
public default Vec3l max(long x, long y, long z) { return max(x, y, z, this); }
public default Vec3l max(long x, long y, long z, Vec3l result) { return result.set(Math.max(getX(), x), Math.max(getY(), y), Math.max(getZ(), z)); }
public default Vec3l difference(Vec3l other) { return difference(other, this); }
public default Vec3l difference(Vec3l other, Vec3l result) { return difference(other.getX(), other.getY(), other.getZ(), result); }
public default Vec3l difference(long x, long y, long z) { return difference(x, y, z, this); }
public default Vec3l difference(long x, long y, long z, Vec3l result) { return result.set(getX() - x, getY() - y, getZ() - z); }
@Override @Override
public default Vec3l clamp(long min, long max, int filter){return clamp(min, max, this, filter);} public default Vec3l clamp(long min, long max) { return clamp(min, max, ALL); }
public default Vec3l clamp(long min, long max, Vec3l result, int filter){ return result.set((filter & X) == 0 ? getX() : MathUtils.clamp(min, max, getX()), (filter & Y) == 0 ? getY() : MathUtils.clamp(min, max, getY()), (filter & Z) == 0 ? getZ() : MathUtils.clamp(min, max, getZ()));} public default Vec3l clamp(long min, long max, Vec3l result) { return clamp(min, max, result, ALL); }
@Override
public default Vec3l clamp(long min, long max, int filter) { return clamp(min, max, this, filter); }
public default Vec3l clamp(long min, long max, Vec3l result, int filter) { return result.set((filter & X) == 0 ? getX() : MathUtils.clamp(min, max, getX()), (filter & Y) == 0 ? getY() : MathUtils.clamp(min, max, getY()), (filter & Z) == 0 ? getZ() : MathUtils.clamp(min, max, getZ())); }
@Override @Override
public default Vec3l store(ByteBuffer buffer) public default Vec3l store(ByteBuffer buffer) {
{
buffer.putLong(getX()).putLong(getY()).putLong(getZ()); buffer.putLong(getX()).putLong(getY()).putLong(getZ());
return this; return this;
} }
@Override @Override
public default Vec3l load(ByteBuffer buffer) public default Vec3l load(ByteBuffer buffer) { return set(buffer.getLong(), buffer.getLong(), buffer.getLong()); }
{
return set(buffer.getLong(), buffer.getLong(), buffer.getLong());
}
@Override @Override
public default Vec3l store(LongBuffer buffer) public default Vec3l store(LongBuffer buffer) {
{
buffer.put(getX()).put(getY()).put(getZ()); buffer.put(getX()).put(getY()).put(getZ());
return this; return this;
} }
@Override @Override
public default Vec3l load(LongBuffer buffer) public default Vec3l load(LongBuffer buffer) { return set(buffer.get(), buffer.get(), buffer.get()); }
{
return set(buffer.get(), buffer.get(), buffer.get());
}
@Override @Override
public default Vec3b asByte(){return isMutable() ? Vec3b.mutable((byte)getX(), (byte)getY(), (byte)getZ()) : Vec3b.of((byte)getX(), (byte)getY(), (byte)getZ());} public default Vec3b asByte() { return isMutable() ? Vec3b.mutable((byte)getX(), (byte)getY(), (byte)getZ()) : Vec3b.of((byte)getX(), (byte)getY(), (byte)getZ()); }
@Override @Override
public default Vec3s asShort(){return isMutable() ? Vec3s.mutable((short)getX(), (short)getY(), (short)getZ()) : Vec3s.of((short)getX(), (short)getY(), (short)getZ());} public default Vec3s asShort() { return isMutable() ? Vec3s.mutable((short)getX(), (short)getY(), (short)getZ()) : Vec3s.of((short)getX(), (short)getY(), (short)getZ()); }
@Override @Override
public default Vec3i asInt(){return isMutable() ? Vec3i.mutable((int)getX(), (int)getY(), (int)getZ()) : Vec3i.of((int)getX(), (int)getY(), (int)getZ());} public default Vec3i asInt() { return isMutable() ? Vec3i.mutable((int)getX(), (int)getY(), (int)getZ()) : Vec3i.of((int)getX(), (int)getY(), (int)getZ()); }
@Override @Override
public default Vec3f asFloat() {return isMutable() ? Vec3f.mutable(getX(), getY(), getZ()) : Vec3f.of(getX(), getY(), getZ());} public default Vec3f asFloat() { return isMutable() ? Vec3f.mutable(getX(), getY(), getZ()) : Vec3f.of(getX(), getY(), getZ()); }
@Override @Override
public default Vec3d asDouble(){return isMutable() ? Vec3d.mutable(getX(), getY(), getZ()) : Vec3d.of(getX(), getY(), getZ());} public default Vec3d asDouble() { return isMutable() ? Vec3d.mutable(getX(), getY(), getZ()) : Vec3d.of(getX(), getY(), getZ()); }
@Override @Override
public default Vec3l asMutable(){return isMutable() ? this : mutable(this);} public default Vec3l asMutable() { return isMutable() ? this : mutable(this); }
@Override @Override
public default Vec3l asImmutable(){return isMutable() ? of(this) : this;} public default Vec3l asImmutable() { return isMutable() ? of(this) : this; }
@Override @Override
public default Vec3l copyAsMutable(){return mutable(this);} public default Vec3l copyAsMutable() { return mutable(this); }
@Override @Override
public default Vec3l copyAsImmutable(){return of(this);} public default Vec3l copyAsImmutable() { return of(this); }
} }

View File

@ -2,107 +2,59 @@ package speiger.src.coreengine.math.vector.longs;
import java.util.Objects; import java.util.Objects;
public class Vec3lImmutable implements Vec3l public class Vec3lImmutable implements Vec3l {
{
final long x; final long x;
final long y; final long y;
final long z; final long z;
public Vec3lImmutable() public Vec3lImmutable() {
{
x = 0; x = 0;
y = 0; y = 0;
z = 0; z = 0;
} }
public Vec3lImmutable(long value) public Vec3lImmutable(long value) {
{
x = value; x = value;
y = value; y = value;
z = value; z = value;
} }
public Vec3lImmutable(long x, long y, long z) public Vec3lImmutable(long x, long y, long z) {
{
this.x = x; this.x = x;
this.y = y; this.y = y;
this.z = z; this.z = z;
} }
@Override
public boolean isMutable()
{
return false;
}
@Override @Override
public long getX() public boolean isMutable() { return false; }
{ @Override
return x; public long getX() { return x; }
} @Override
public long getY() { return y; }
@Override
public long getZ() { return z; }
@Override
public Vec3l setX(long x) { return this.x == x ? this : Vec3l.of(x, y, z); }
@Override
public Vec3l setY(long y) { return this.y == y ? this : Vec3l.of(x, y, z); }
@Override
public Vec3l setZ(long z) { return this.z == z ? this : Vec3l.of(x, y, z); }
@Override
public Vec3l copy() { return Vec3l.of(this); }
@Override
public Vec3l set(long x, long y, long z) { return this.x == x && this.y == y && this.z == z ? this : Vec3l.of(x, y, z); }
@Override
public int hashCode() { return Objects.hash(x, y, z); }
@Override @Override
public long getY() public boolean equals(Object obj) {
{ if(obj instanceof Vec3l) {
return y;
}
@Override
public long getZ()
{
return z;
}
@Override
public Vec3l setX(long x)
{
return this.x == x ? this : Vec3l.of(x, y, z);
}
@Override
public Vec3l setY(long y)
{
return this.y == y ? this : Vec3l.of(x, y, z);
}
@Override
public Vec3l setZ(long z)
{
return this.z == z ? this : Vec3l.of(x, y, z);
}
@Override
public Vec3l copy()
{
return Vec3l.of(this);
}
@Override
public Vec3l set(long x, long y, long z)
{
return this.x == x && this.y == y && this.z == z ? this : Vec3l.of(x, y, z);
}
@Override
public int hashCode()
{
return Objects.hash(x, y, z);
}
@Override
public boolean equals(Object obj)
{
if(obj instanceof Vec3l)
{
Vec3l vec = (Vec3l)obj; Vec3l vec = (Vec3l)obj;
return vec.getX() == x && vec.getY() == y && vec.getZ() == z; return vec.getX() == x && vec.getY() == y && vec.getZ() == z;
} }
return false; return false;
} }
@Override @Override
public String toString() public String toString() { return "Vec3l[x="+x+", y="+y+", z="+z+"]"; }
{
return "Vec3l[x="+x+", y="+y+", z="+z+"]";
}
} }

View File

@ -2,84 +2,57 @@ package speiger.src.coreengine.math.vector.longs;
import java.util.Objects; import java.util.Objects;
public class Vec3lMutable implements Vec3l public class Vec3lMutable implements Vec3l {
{
long x; long x;
long y; long y;
long z; long z;
public Vec3lMutable() public Vec3lMutable() {}
{
}
public Vec3lMutable(long value) public Vec3lMutable(long value) {
{
x = value; x = value;
y = value; y = value;
z = value; z = value;
} }
public Vec3lMutable(long x, long y, long z) public Vec3lMutable(long x, long y, long z) {
{
this.x = x; this.x = x;
this.y = y; this.y = y;
this.z = z; this.z = z;
} }
@Override
public boolean isMutable()
{
return true;
}
@Override @Override
public long getX() public boolean isMutable() { return true; }
{ @Override
return x; public long getX() { return x; }
} @Override
public long getY() { return y; }
@Override
public long getZ() { return z; }
@Override @Override
public long getY() public Vec3l setX(long x) {
{
return y;
}
@Override
public long getZ()
{
return z;
}
@Override
public Vec3l setX(long x)
{
this.x = x; this.x = x;
return this; return this;
} }
@Override @Override
public Vec3l setY(long y) public Vec3l setY(long y) {
{
this.y = y; this.y = y;
return this; return this;
} }
@Override @Override
public Vec3l setZ(long z) public Vec3l setZ(long z) {
{
this.z = z; this.z = z;
return this; return this;
} }
@Override @Override
public Vec3l copy() public Vec3l copy() { return Vec3l.mutable(this); }
{
return Vec3l.mutable(this);
}
@Override @Override
public Vec3l set(long x, long y, long z) public Vec3l set(long x, long y, long z) {
{
this.x = x; this.x = x;
this.y = y; this.y = y;
this.z = z; this.z = z;
@ -87,25 +60,17 @@ public class Vec3lMutable implements Vec3l
} }
@Override @Override
public int hashCode() public int hashCode() { return Objects.hash(x, y, z); }
{
return Objects.hash(x, y, z);
}
@Override @Override
public boolean equals(Object obj) public boolean equals(Object obj) {
{ if(obj instanceof Vec3l) {
if(obj instanceof Vec3l)
{
Vec3l vec = (Vec3l)obj; Vec3l vec = (Vec3l)obj;
return vec.getX() == x && vec.getY() == y && vec.getZ() == z; return vec.getX() == x && vec.getY() == y && vec.getZ() == z;
} }
return false; return false;
} }
@Override @Override
public String toString() public String toString() { return "Vec3l[x="+x+", y="+y+", z="+z+"]"; }
{
return "Vec3l[x="+x+", y="+y+", z="+z+"]";
}
} }

View File

@ -10,21 +10,19 @@ import speiger.src.coreengine.math.vector.floats.Vec4f;
import speiger.src.coreengine.math.vector.ints.Vec4i; import speiger.src.coreengine.math.vector.ints.Vec4i;
import speiger.src.coreengine.math.vector.shorts.Vec4s; import speiger.src.coreengine.math.vector.shorts.Vec4s;
public interface Vec4l extends Vecl public interface Vec4l extends Vecl {
{
public static final Vec4l ZERO = of(); public static final Vec4l ZERO = of();
public static final Vec4l MINUS_ONE = of(-1L); public static final Vec4l MINUS_ONE = of(-1L);
public static final Vec4l ONE = of(1L); public static final Vec4l ONE = of(1L);
public static Vec4l mutable(){return new Vec4lMutable();} public static Vec4l mutable() { return new Vec4lMutable(); }
public static Vec4l mutable(long value){return new Vec4lMutable(value);} public static Vec4l mutable(long value) { return new Vec4lMutable(value); }
public static Vec4l mutable(long x, long y, long z, long w){return new Vec4lMutable(x, y, z, w);} public static Vec4l mutable(long x, long y, long z, long w) { return new Vec4lMutable(x, y, z, w); }
public static Vec4l mutable(Vec4l vec){return mutable(vec.getX(), vec.getY(), vec.getZ(), vec.getW());} public static Vec4l mutable(Vec4l vec) { return mutable(vec.getX(), vec.getY(), vec.getZ(), vec.getW()); }
public static Vec4l of() { return new Vec4lImmutable(); }
public static Vec4l of(){return new Vec4lImmutable();} public static Vec4l of(long value) { return new Vec4lImmutable(value); }
public static Vec4l of(long value){return new Vec4lImmutable(value);} public static Vec4l of(long x, long y, long z, long w) { return new Vec4lImmutable(x, y, z, w); }
public static Vec4l of(long x, long y, long z, long w){return new Vec4lImmutable(x, y, z, w);} public static Vec4l of(Vec4l vec) { return of(vec.getX(), vec.getY(), vec.getZ(), vec.getW()); }
public static Vec4l of(Vec4l vec){return of(vec.getX(), vec.getY(), vec.getZ(), vec.getW());}
public long getX(); public long getX();
public long getY(); public long getY();
@ -34,125 +32,104 @@ public interface Vec4l extends Vecl
public Vec4l setY(long y); public Vec4l setY(long y);
public Vec4l setZ(long z); public Vec4l setZ(long z);
public Vec4l setW(long w); public Vec4l setW(long w);
@Override @Override
public default long[] asArray(){return new long[]{getX(), getY(), getZ(), getW()};} public default long[] asArray() { return new long[] {getX(), getY(), getZ(), getW()}; }
@Override @Override
public Vec4l copy(); public Vec4l copy();
@Override @Override
public default Vec4l abs(){return set(Math.abs(getX()), Math.abs(getY()), Math.abs(getZ()), Math.abs(getW()));} public default Vec4l abs() { return set(Math.abs(getX()), Math.abs(getY()), Math.abs(getZ()), Math.abs(getW())); }
@Override @Override
public default Vec4l negate(){return set(0L, 0L, 0L, 0L);} public default Vec4l negate() { return set(0L, 0L, 0L, 0L); }
@Override @Override
public default Vec4l invert(){return set(-getX(), -getY(), -getZ(), -getW());} public default Vec4l invert() { return set(-getX(), -getY(), -getZ(), -getW()); }
@Override @Override
public default Vec4l add(long value){return add(value, value, value, value);} public default Vec4l add(long value) { return add(value, value, value, value); }
public default Vec4l add(Vec4l value){return add(value.getX(), value.getY(), value.getZ(), value.getW());} public default Vec4l add(Vec4l value) { return add(value.getX(), value.getY(), value.getZ(), value.getW()); }
public default Vec4l add(long x, long y, long z, long w){return set(getX() + x, getY() + y, getZ() + z, getW() + w);} public default Vec4l add(long x, long y, long z, long w) { return set(getX() + x, getY() + y, getZ() + z, getW() + w); }
@Override @Override
public default Vec4l sub(long value){return sub(value, value, value, value);} public default Vec4l sub(long value) { return sub(value, value, value, value); }
public default Vec4l sub(Vec4l value){return sub(value.getX(), value.getY(), value.getZ(), value.getW());} public default Vec4l sub(Vec4l value) { return sub(value.getX(), value.getY(), value.getZ(), value.getW()); }
public default Vec4l sub(long x, long y, long z, long w){return set(getX() - x, getY() - y, getZ() - z, getW() - w);} public default Vec4l sub(long x, long y, long z, long w) { return set(getX() - x, getY() - y, getZ() - z, getW() - w); }
@Override @Override
public default Vec4l multiply(long value){return multiply(value, value, value, value);} public default Vec4l multiply(long value) { return multiply(value, value, value, value); }
public default Vec4l multiply(Vec4l value){return multiply(value.getX(), value.getY(), value.getZ(), value.getW());} public default Vec4l multiply(Vec4l value) { return multiply(value.getX(), value.getY(), value.getZ(), value.getW()); }
public default Vec4l multiply(long x, long y, long z, long w){return set(getX() * x, getY() * y, getZ() * z, getW() * w);} public default Vec4l multiply(long x, long y, long z, long w) { return set(getX() * x, getY() * y, getZ() * z, getW() * w); }
@Override @Override
public default Vec4l devide(long value){return devide(value, value, value, value);} public default Vec4l devide(long value) { return devide(value, value, value, value); }
public default Vec4l devide(Vec4l value){return devide(value.getX(), value.getY(), value.getZ(), value.getW());} public default Vec4l devide(Vec4l value) { return devide(value.getX(), value.getY(), value.getZ(), value.getW()); }
public default Vec4l devide(long x, long y, long z, long w){return set(getX() / x, getY() / y, getZ() / z, getW() / w);} public default Vec4l devide(long x, long y, long z, long w) { return set(getX() / x, getY() / y, getZ() / z, getW() / w); }
@Override @Override
public default Vec4l set(long value){return set(value, value, value, value);} public default Vec4l set(long value) { return set(value, value, value, value); }
public default Vec4l set(Vec4l value){return set(value.getX(), value.getY(), value.getZ(), value.getW());} public default Vec4l set(Vec4l value) { return set(value.getX(), value.getY(), value.getZ(), value.getW()); }
public Vec4l set(long x, long y, long z, long w); public Vec4l set(long x, long y, long z, long w);
public default double distanceTo(Vec4l value) { return distanceTo(value.getX(), value.getY(), value.getZ(), value.getW()); }
public default double distanceTo(Vec4l value){return distanceTo(value.getX(), value.getY(), value.getZ(), value.getW());} public default double distanceTo(long x, long y, long z, long w) { return Math.sqrt(distanceTo(x, y, z, w)); }
public default double distanceTo(long x, long y, long z, long w){return Math.sqrt(distanceTo(x, y, z, w));} public default long distanceToSquared(Vec4l value) { return distanceToSquared(value.getX(), value.getY(), value.getZ(), value.getW()); }
public default long distanceToSquared(long x, long y, long z, long w) {
public default long distanceToSquared(Vec4l value){return distanceToSquared(value.getX(), value.getY(), value.getZ(), value.getW());}
public default long distanceToSquared(long x, long y, long z, long w)
{
long xPos = getX() - x; long xPos = getX() - x;
long yPos = getY() - y; long yPos = getY() - y;
long zPos = getZ() - z; long zPos = getZ() - z;
long wPos = getW() - w; long wPos = getW() - w;
return (xPos * xPos) + (yPos * yPos) + (zPos * zPos) + (wPos * wPos); return (xPos * xPos) + (yPos * yPos) + (zPos * zPos) + (wPos * wPos);
} }
@Override
public default long lengthSquared() {return (getX() * getX()) + (getY() * getY()) + (getZ() * getZ()) + (getW() * getW());}
public default long dotProduct(Vec4l value){return dotProduct(value.getX(), value.getY(), value.getZ(), value.getW());}
public default long dotProduct(long x, long y, long z, long w){return (getX() * x) + (getY() * y) + (getZ() * z) + (getW() * w);};
public default Vec4l min(Vec4l other) {return min(other, this);}
public default Vec4l min(Vec4l other, Vec4l result){return min(other.getX(), other.getY(), other.getZ(), other.getW(), result);}
public default Vec4l min(long x, long y, long z, long w) {return min(x, y, z, w, this);}
public default Vec4l min(long x, long y, long z, long w, Vec4l result){return result.set(Math.min(getX(), x), Math.min(getY(), y), Math.min(getZ(), z), Math.min(getW(), w));}
public default Vec4l max(Vec4l other) {return max(other, this);}
public default Vec4l max(Vec4l other, Vec4l result){return max(other.getX(), other.getY(), other.getZ(), other.getW(), result);}
public default Vec4l max(long x, long y, long z, long w) {return max(x, y, z, w, this);}
public default Vec4l max(long x, long y, long z, long w, Vec4l result){return result.set(Math.max(getX(), x), Math.max(getY(), y), Math.max(getZ(), z), Math.max(getZ(), z));}
public default Vec4l difference(Vec4l other) {return difference(other, this);}
public default Vec4l difference(Vec4l other, Vec4l result){return difference(other.getX(), other.getY(), other.getZ(), other.getW(), result);}
public default Vec4l difference(long x, long y, long z, long w) {return difference(x, y, z, w, this);}
public default Vec4l difference(long x, long y, long z, long w, Vec4l result){return result.set(getX() - x, getY() - y, getZ() - z, getW() - w);}
@Override @Override
public default Vec4l clamp(long min, long max){return clamp(min, max, ALL);} public default long lengthSquared() { return (getX() * getX()) + (getY() * getY()) + (getZ() * getZ()) + (getW() * getW()); }
public default Vec4l clamp(long min, long max, Vec4l result){return clamp(min, max, result, ALL);} public default long dotProduct(Vec4l value) { return dotProduct(value.getX(), value.getY(), value.getZ(), value.getW()); }
public default long dotProduct(long x, long y, long z, long w) { return (getX() * x) + (getY() * y) + (getZ() * z) + (getW() * w); };
public default Vec4l min(Vec4l other) { return min(other, this); }
public default Vec4l min(Vec4l other, Vec4l result) { return min(other.getX(), other.getY(), other.getZ(), other.getW(), result); }
public default Vec4l min(long x, long y, long z, long w) { return min(x, y, z, w, this); }
public default Vec4l min(long x, long y, long z, long w, Vec4l result) { return result.set(Math.min(getX(), x), Math.min(getY(), y), Math.min(getZ(), z), Math.min(getW(), w)); }
public default Vec4l max(Vec4l other) { return max(other, this); }
public default Vec4l max(Vec4l other, Vec4l result) { return max(other.getX(), other.getY(), other.getZ(), other.getW(), result); }
public default Vec4l max(long x, long y, long z, long w) { return max(x, y, z, w, this); }
public default Vec4l max(long x, long y, long z, long w, Vec4l result) { return result.set(Math.max(getX(), x), Math.max(getY(), y), Math.max(getZ(), z), Math.max(getZ(), z)); }
public default Vec4l difference(Vec4l other) { return difference(other, this); }
public default Vec4l difference(Vec4l other, Vec4l result) { return difference(other.getX(), other.getY(), other.getZ(), other.getW(), result); }
public default Vec4l difference(long x, long y, long z, long w) { return difference(x, y, z, w, this); }
public default Vec4l difference(long x, long y, long z, long w, Vec4l result) { return result.set(getX() - x, getY() - y, getZ() - z, getW() - w); }
@Override @Override
public default Vec4l clamp(long min, long max, int filter){return clamp(min, max, this, filter);} public default Vec4l clamp(long min, long max) { return clamp(min, max, ALL); }
public default Vec4l clamp(long min, long max, Vec4l result, int filter){ return result.set((filter & X) == 0 ? getX() : MathUtils.clamp(min, max, getX()), (filter & Y) == 0 ? getY() : MathUtils.clamp(min, max, getY()), (filter & Z) == 0 ? getZ() : MathUtils.clamp(min, max, getZ()), (filter & W) == 0 ? getW() : MathUtils.clamp(min, max, getW()));} public default Vec4l clamp(long min, long max, Vec4l result) { return clamp(min, max, result, ALL); }
@Override
public default Vec4l clamp(long min, long max, int filter) { return clamp(min, max, this, filter); }
public default Vec4l clamp(long min, long max, Vec4l result, int filter) { return result.set((filter & X) == 0 ? getX() : MathUtils.clamp(min, max, getX()), (filter & Y) == 0 ? getY() : MathUtils.clamp(min, max, getY()), (filter & Z) == 0 ? getZ() : MathUtils.clamp(min, max, getZ()), (filter & W) == 0 ? getW() : MathUtils.clamp(min, max, getW())); }
@Override @Override
public default Vec4l store(ByteBuffer buffer) public default Vec4l store(ByteBuffer buffer) {
{
buffer.putLong(getX()).putLong(getY()).putLong(getZ()).putLong(getW()); buffer.putLong(getX()).putLong(getY()).putLong(getZ()).putLong(getW());
return this; return this;
} }
@Override @Override
public default Vec4l load(ByteBuffer buffer) public default Vec4l load(ByteBuffer buffer) { return set(buffer.getLong(), buffer.getLong(), buffer.getLong(), buffer.getLong()); }
{
return set(buffer.getLong(), buffer.getLong(), buffer.getLong(), buffer.getLong());
}
@Override @Override
public default Vec4l store(LongBuffer buffer) public default Vec4l store(LongBuffer buffer) {
{
buffer.put(getX()).put(getY()).put(getZ()).put(getW()); buffer.put(getX()).put(getY()).put(getZ()).put(getW());
return this; return this;
} }
@Override @Override
public default Vec4l load(LongBuffer buffer) public default Vec4l load(LongBuffer buffer) { return set(buffer.get(), buffer.get(), buffer.get(), buffer.get()); }
{
return set(buffer.get(), buffer.get(), buffer.get(), buffer.get());
}
@Override @Override
public default Vec4b asByte(){return isMutable() ? Vec4b.mutable((byte)getX(), (byte)getY(), (byte)getZ(), (byte)getW()) : Vec4b.of((byte)getX(), (byte)getY(), (byte)getZ(), (byte)getW());} public default Vec4b asByte() { return isMutable() ? Vec4b.mutable((byte)getX(), (byte)getY(), (byte)getZ(), (byte)getW()) : Vec4b.of((byte)getX(), (byte)getY(), (byte)getZ(), (byte)getW()); }
@Override @Override
public default Vec4s asShort(){return isMutable() ? Vec4s.mutable((short)getX(), (short)getY(), (short)getZ(), (short)getW()) : Vec4s.of((short)getX(), (short)getY(), (short)getZ(), (short)getW());} public default Vec4s asShort() { return isMutable() ? Vec4s.mutable((short)getX(), (short)getY(), (short)getZ(), (short)getW()) : Vec4s.of((short)getX(), (short)getY(), (short)getZ(), (short)getW()); }
@Override @Override
public default Vec4i asInt(){return isMutable() ? Vec4i.mutable((int)getX(), (int)getY(), (int)getZ(), (int)getW()) : Vec4i.of((int)getX(), (int)getY(), (int)getZ(), (int)getW());} public default Vec4i asInt() { return isMutable() ? Vec4i.mutable((int)getX(), (int)getY(), (int)getZ(), (int)getW()) : Vec4i.of((int)getX(), (int)getY(), (int)getZ(), (int)getW()); }
@Override @Override
public default Vec4f asFloat() {return isMutable() ? Vec4f.mutable(getX(), getY(), getZ(), getW()) : Vec4f.of(getX(), getY(), getZ(), getW());} public default Vec4f asFloat() { return isMutable() ? Vec4f.mutable(getX(), getY(), getZ(), getW()) : Vec4f.of(getX(), getY(), getZ(), getW()); }
@Override @Override
public default Vec4d asDouble(){return isMutable() ? Vec4d.mutable(getX(), getY(), getZ(), getW()) : Vec4d.of(getX(), getY(), getZ(), getW());} public default Vec4d asDouble() { return isMutable() ? Vec4d.mutable(getX(), getY(), getZ(), getW()) : Vec4d.of(getX(), getY(), getZ(), getW()); }
@Override @Override
public default Vec4l asMutable(){return isMutable() ? this : mutable(this);} public default Vec4l asMutable() { return isMutable() ? this : mutable(this); }
@Override @Override
public default Vec4l asImmutable(){return isMutable() ? of(this) : this;} public default Vec4l asImmutable() { return isMutable() ? of(this) : this; }
@Override @Override
public default Vec4l copyAsMutable(){return mutable(this);} public default Vec4l copyAsMutable() { return mutable(this); }
@Override @Override
public default Vec4l copyAsImmutable(){return of(this);} public default Vec4l copyAsImmutable() { return of(this); }
} }

View File

@ -2,114 +2,61 @@ package speiger.src.coreengine.math.vector.longs;
import java.util.Objects; import java.util.Objects;
public class Vec4lImmutable implements Vec4l public class Vec4lImmutable implements Vec4l {
{
final long x; final long x;
final long y; final long y;
final long z; final long z;
final long w; final long w;
public Vec4lImmutable() public Vec4lImmutable() {
{
x = 0; x = 0;
y = 0; y = 0;
z = 0; z = 0;
w = 0; w = 0;
} }
public Vec4lImmutable(long value) public Vec4lImmutable(long value) {
{
x = value; x = value;
y = value; y = value;
z = value; z = value;
w = value; w = value;
} }
public Vec4lImmutable(long x, long y, long z, long w) public Vec4lImmutable(long x, long y, long z, long w) {
{
this.x = x; this.x = x;
this.y = y; this.y = y;
this.z = z; this.z = z;
this.w = w; this.w = w;
} }
@Override
public boolean isMutable()
{
return false;
}
@Override @Override
public long getX() public boolean isMutable() { return false; }
{ @Override
return x; public long getX() { return x; }
} @Override
public long getY() { return y; }
@Override
public long getZ() { return z; }
@Override
public long getW() { return w; }
@Override
public Vec4l setX(long x) { return this.x == x ? this : Vec4l.of(x, y, z, w); }
@Override
public Vec4l setY(long y) { return this.y == y ? this : Vec4l.of(x, y, z, w); }
@Override
public Vec4l setZ(long z) { return this.z == z ? this : Vec4l.of(x, y, z, w); }
@Override
public Vec4l setW(long w) { return this.w == w ? this : Vec4l.of(x, y, z, w); }
@Override
public Vec4l copy() { return Vec4l.of(this); }
@Override
public Vec4l set(long x, long y, long z, long w) { return this.x == x && this.y == y && this.z == z && this.w == w ? this : Vec4l.of(x, y, z, w); }
@Override
public int hashCode() { return Objects.hash(x, y, z, w); }
@Override @Override
public long getY() public boolean equals(Object obj) {
{ if(obj instanceof Vec4l) {
return y;
}
@Override
public long getZ()
{
return z;
}
@Override
public long getW()
{
return w;
}
@Override
public Vec4l setX(long x)
{
return this.x == x ? this : Vec4l.of(x, y, z, w);
}
@Override
public Vec4l setY(long y)
{
return this.y == y ? this : Vec4l.of(x, y, z, w);
}
@Override
public Vec4l setZ(long z)
{
return this.z == z ? this : Vec4l.of(x, y, z, w);
}
@Override
public Vec4l setW(long w)
{
return this.w == w ? this : Vec4l.of(x, y, z, w);
}
@Override
public Vec4l copy()
{
return Vec4l.of(this);
}
@Override
public Vec4l set(long x, long y, long z, long w)
{
return this.x == x && this.y == y && this.z == z && this.w == w ? this : Vec4l.of(x, y, z, w);
}
@Override
public int hashCode()
{
return Objects.hash(x, y, z, w);
}
@Override
public boolean equals(Object obj)
{
if(obj instanceof Vec4l)
{
Vec4l vec = (Vec4l)obj; Vec4l vec = (Vec4l)obj;
return vec.getX() == x && vec.getY() == y && vec.getZ() == z && vec.getW() == w; return vec.getX() == x && vec.getY() == y && vec.getZ() == z && vec.getW() == w;
} }
@ -117,8 +64,5 @@ public class Vec4lImmutable implements Vec4l
} }
@Override @Override
public String toString() public String toString() { return "Vec4l[x="+x+", y="+y+", z="+z+", w="+w+"]"; }
{
return "Vec4l[x="+x+", y="+y+", z="+z+", w="+w+"]";
}
} }

View File

@ -2,100 +2,68 @@ package speiger.src.coreengine.math.vector.longs;
import java.util.Objects; import java.util.Objects;
public class Vec4lMutable implements Vec4l public class Vec4lMutable implements Vec4l {
{
long x; long x;
long y; long y;
long z; long z;
long w; long w;
public Vec4lMutable() public Vec4lMutable() {}
{
}
public Vec4lMutable(long value) public Vec4lMutable(long value) {
{
x = value; x = value;
y = value; y = value;
z = value; z = value;
w = value; w = value;
} }
public Vec4lMutable(long x, long y, long z, long w) public Vec4lMutable(long x, long y, long z, long w) {
{
this.x = x; this.x = x;
this.y = y; this.y = y;
this.z = z; this.z = z;
this.w = w; this.w = w;
} }
@Override
public boolean isMutable()
{
return true;
}
@Override @Override
public long getX() public boolean isMutable() { return true; }
{ @Override
return x; public long getX() { return x; }
} @Override
public long getY() { return y; }
@Override
public long getZ() { return z; }
@Override
public long getW() { return w; }
@Override @Override
public long getY() public Vec4l setX(long x) {
{
return y;
}
@Override
public long getZ()
{
return z;
}
@Override
public long getW()
{
return w;
}
@Override
public Vec4l setX(long x)
{
this.x = x; this.x = x;
return this; return this;
} }
@Override @Override
public Vec4l setY(long y) public Vec4l setY(long y) {
{
this.y = y; this.y = y;
return this; return this;
} }
@Override @Override
public Vec4l setZ(long z) public Vec4l setZ(long z) {
{
this.z = z; this.z = z;
return this; return this;
} }
@Override @Override
public Vec4l setW(long w) public Vec4l setW(long w) {
{
this.w = w; this.w = w;
return this; return this;
} }
@Override @Override
public Vec4l copy() public Vec4l copy() { return Vec4l.mutable(this); }
{
return Vec4l.mutable(this);
}
@Override @Override
public Vec4l set(long x, long y, long z, long w) public Vec4l set(long x, long y, long z, long w) {
{
this.x = x; this.x = x;
this.y = y; this.y = y;
this.z = z; this.z = z;
@ -104,16 +72,11 @@ public class Vec4lMutable implements Vec4l
} }
@Override @Override
public int hashCode() public int hashCode() { return Objects.hash(x, y, z, w); }
{
return Objects.hash(x, y, z, w);
}
@Override @Override
public boolean equals(Object obj) public boolean equals(Object obj) {
{ if(obj instanceof Vec4l) {
if(obj instanceof Vec4l)
{
Vec4l vec = (Vec4l)obj; Vec4l vec = (Vec4l)obj;
return vec.getX() == x && vec.getY() == y && vec.getZ() == z && vec.getW() == w; return vec.getX() == x && vec.getY() == y && vec.getZ() == z && vec.getW() == w;
} }
@ -121,8 +84,5 @@ public class Vec4lMutable implements Vec4l
} }
@Override @Override
public String toString() public String toString() { return "Vec4l[x="+x+", y="+y+", z="+z+", w="+w+"]"; }
{
return "Vec4l[x="+x+", y="+y+", z="+z+", w="+w+"]";
}
} }

View File

@ -9,8 +9,7 @@ import speiger.src.coreengine.math.vector.floats.Vecf;
import speiger.src.coreengine.math.vector.ints.Veci; import speiger.src.coreengine.math.vector.ints.Veci;
import speiger.src.coreengine.math.vector.shorts.Vecs; import speiger.src.coreengine.math.vector.shorts.Vecs;
public interface Vecl extends Vec public interface Vecl extends Vec {
{
public Vecl set(long value); public Vecl set(long value);
public Vecl add(long value); public Vecl add(long value);
public Vecl sub(long value); public Vecl sub(long value);
@ -18,14 +17,11 @@ public interface Vecl extends Vec
public Vecl devide(long value); public Vecl devide(long value);
public Vecl clamp(long min, long max); public Vecl clamp(long min, long max);
public Vecl clamp(long min, long max, int filter); public Vecl clamp(long min, long max, int filter);
public long lengthSquared(); public long lengthSquared();
public default double length(){return Math.sqrt(lengthSquared());} public default double length() { return Math.sqrt(lengthSquared()); }
public Vecl store(LongBuffer buffer); public Vecl store(LongBuffer buffer);
public Vecl load(LongBuffer buffer); public Vecl load(LongBuffer buffer);
public long[] asArray(); public long[] asArray();
public Vecb asByte(); public Vecb asByte();
public Vecs asShort(); public Vecs asShort();
public Veci asInt(); public Veci asInt();

View File

@ -5,80 +5,55 @@ import java.nio.FloatBuffer;
import java.util.Arrays; import java.util.Arrays;
import speiger.src.coreengine.math.MathUtils; import speiger.src.coreengine.math.MathUtils;
import speiger.src.coreengine.math.vector.VectorUtil;
import speiger.src.coreengine.math.vector.floats.Vec2f; import speiger.src.coreengine.math.vector.floats.Vec2f;
import speiger.src.coreengine.math.vector.floats.Vec3f; import speiger.src.coreengine.math.vector.floats.Vec3f;
import speiger.src.coreengine.math.vector.floats.Vec4f; import speiger.src.coreengine.math.vector.floats.Vec4f;
import speiger.src.coreengine.math.vector.quaternion.Quaternion; import speiger.src.coreengine.math.vector.quaternion.Quaternion;
public class Matrix4f public class Matrix4f {
{
static final Vec3f X_ROTATION = Vec3f.of(1F, 0F, 0F); static final Vec3f X_ROTATION = Vec3f.of(1F, 0F, 0F);
static final Vec3f Y_ROTATION = Vec3f.of(0F, 1F, 0F); static final Vec3f Y_ROTATION = Vec3f.of(0F, 1F, 0F);
static final Vec3f Z_ROTATION = Vec3f.of(0F, 0F, 1F); static final Vec3f Z_ROTATION = Vec3f.of(0F, 0F, 1F);
float[] data = new float[16]; float[] data = new float[16];
public Matrix4f() public Matrix4f() { setIdentity(); }
{
setIdentity();
}
public Matrix4f(float[] data) public Matrix4f(float[] data) { System.arraycopy(data, 0, this.data, 0, 16); }
{
System.arraycopy(data, 0, this.data, 0, 16);
}
public Matrix4f(Matrix4f other) public Matrix4f(Matrix4f other) { this(other.data); }
{
this(other.data);
}
public Matrix4f store(FloatBuffer buffer) public Matrix4f store(FloatBuffer buffer) {
{
buffer.put(data); buffer.put(data);
return this; return this;
} }
public Matrix4f store(ByteBuffer buffer) public Matrix4f store(ByteBuffer buffer) {
{ for(int i = 0;i < 16;i++) { buffer.putFloat(data[i]); }
for(int i = 0;i < 16;i++)
{
buffer.putFloat(data[i]);
}
return this; return this;
} }
public Matrix4f store(Matrix4f other) public Matrix4f store(Matrix4f other) {
{
System.arraycopy(data, 0, other.data, 0, 16); System.arraycopy(data, 0, other.data, 0, 16);
return this; return this;
} }
public Matrix4f load(FloatBuffer buffer) public Matrix4f load(FloatBuffer buffer) {
{
buffer.get(data); buffer.get(data);
return this; return this;
} }
public Matrix4f load(ByteBuffer buffer) public Matrix4f load(ByteBuffer buffer) {
{ for(int i = 0;i < 16;i++) { data[i] = buffer.getFloat(); }
for(int i = 0;i < 16;i++)
{
data[i] = buffer.getFloat();
}
return this; return this;
} }
public Matrix4f load(Matrix4f other) public Matrix4f load(Matrix4f other) {
{
System.arraycopy(other.data, 0, data, 0, 16); System.arraycopy(other.data, 0, data, 0, 16);
return this; return this;
} }
@Override @Override
public String toString() public String toString() {
{
StringBuilder buf = new StringBuilder().append("\n"); StringBuilder buf = new StringBuilder().append("\n");
buf.append("x0=").append(data[0]).append(' ').append("y0=").append(data[4]).append(' ').append("z0=").append(data[8]).append(' ').append("w0=").append(data[12]).append('\n'); buf.append("x0=").append(data[0]).append(' ').append("y0=").append(data[4]).append(' ').append("z0=").append(data[8]).append(' ').append("w0=").append(data[12]).append('\n');
buf.append("x1=").append(data[1]).append(' ').append("y1=").append(data[5]).append(' ').append("z1=").append(data[9]).append(' ').append("w1=").append(data[13]).append('\n'); buf.append("x1=").append(data[1]).append(' ').append("y1=").append(data[5]).append(' ').append("z1=").append(data[9]).append(' ').append("w1=").append(data[13]).append('\n');
@ -88,44 +63,28 @@ public class Matrix4f
} }
@Override @Override
public boolean equals(Object obj) public boolean equals(Object obj) {
{ if(obj instanceof Matrix4f) { return Arrays.equals(data, ((Matrix4f)obj).data); }
if(obj instanceof Matrix4f)
{
return Arrays.equals(data, ((Matrix4f)obj).data);
}
return false; return false;
} }
public float[] getData() public float[] getData() { return data; }
{
return data;
}
public float get(int index) public float get(int index) { return data[index]; }
{
return data[index];
}
public float get(int column, int row) public float get(int column, int row) { return data[(column * 4) + row]; }
{
return data[(column * 4) + row];
}
public Matrix4f set(int column, int row, float value) public Matrix4f set(int column, int row, float value) {
{
data[(column * 4) + row] = value; data[(column * 4) + row] = value;
return this; return this;
} }
public Matrix4f set(int index, float value) public Matrix4f set(int index, float value) {
{
data[index] = value; data[index] = value;
return this; return this;
} }
public Matrix4f setIdentity() public Matrix4f setIdentity() {
{
Arrays.fill(data, 0F); Arrays.fill(data, 0F);
data[0] = 1F; data[0] = 1F;
data[5] = 1F; data[5] = 1F;
@ -134,11 +93,9 @@ public class Matrix4f
return this; return this;
} }
public Matrix4f invert() public Matrix4f invert() {
{
float determinant = determinant(); float determinant = determinant();
if(determinant != 0F) if(determinant != 0F) {
{
float determinant_inv = 1F / determinant; float determinant_inv = 1F / determinant;
float t00 = determinant3x3(data[5], data[6], data[7], data[9], data[10], data[11], data[13], data[14], data[15]); float t00 = determinant3x3(data[5], data[6], data[7], data[9], data[10], data[11], data[13], data[14], data[15]);
float t01 = -determinant3x3(data[4], data[6], data[7], data[8], data[10], data[11], data[12], data[14], data[15]); float t01 = -determinant3x3(data[4], data[6], data[7], data[8], data[10], data[11], data[12], data[14], data[15]);
@ -177,8 +134,7 @@ public class Matrix4f
return this; return this;
} }
public Matrix4f flip() public Matrix4f flip() {
{
data[0] = -data[0]; data[0] = -data[0];
data[1] = -data[1]; data[1] = -data[1];
data[2] = -data[2]; data[2] = -data[2];
@ -198,14 +154,12 @@ public class Matrix4f
return this; return this;
} }
public Matrix4f negate() public Matrix4f negate() {
{
Arrays.fill(data, 0F); Arrays.fill(data, 0F);
return this; return this;
} }
public Matrix4f add(Matrix4f other) public Matrix4f add(Matrix4f other) {
{
data[0] += other.data[0]; data[0] += other.data[0];
data[1] += other.data[1]; data[1] += other.data[1];
data[2] += other.data[2]; data[2] += other.data[2];
@ -225,8 +179,7 @@ public class Matrix4f
return this; return this;
} }
public Matrix4f sub(Matrix4f other) public Matrix4f sub(Matrix4f other) {
{
data[0] -= other.data[0]; data[0] -= other.data[0];
data[1] -= other.data[1]; data[1] -= other.data[1];
data[2] -= other.data[2]; data[2] -= other.data[2];
@ -246,8 +199,7 @@ public class Matrix4f
return this; return this;
} }
public Matrix4f multiply(Matrix4f other) public Matrix4f multiply(Matrix4f other) {
{
float data0 = data[0] * other.data[0] + data[4] * other.data[1] + data[8] * other.data[2] + data[12] * other.data[3]; float data0 = data[0] * other.data[0] + data[4] * other.data[1] + data[8] * other.data[2] + data[12] * other.data[3];
float data1 = data[1] * other.data[0] + data[5] * other.data[1] + data[9] * other.data[2] + data[13] * other.data[3]; float data1 = data[1] * other.data[0] + data[5] * other.data[1] + data[9] * other.data[2] + data[13] * other.data[3];
float data2 = data[2] * other.data[0] + data[6] * other.data[1] + data[10] * other.data[2] + data[14] * other.data[3]; float data2 = data[2] * other.data[0] + data[6] * other.data[1] + data[10] * other.data[2] + data[14] * other.data[3];
@ -283,8 +235,7 @@ public class Matrix4f
return this; return this;
} }
public Matrix4f transpose() public Matrix4f transpose() {
{
float data0 = data[0]; float data0 = data[0];
float data1 = data[4]; float data1 = data[4];
float data2 = data[8]; float data2 = data[8];
@ -321,8 +272,7 @@ public class Matrix4f
return this; return this;
} }
public Matrix4f transpose3x3() public Matrix4f transpose3x3() {
{
float nm00 = data[0]; float nm00 = data[0];
float nm01 = data[4]; float nm01 = data[4];
float nm02 = data[8]; float nm02 = data[8];
@ -344,29 +294,23 @@ public class Matrix4f
return this; return this;
} }
public Matrix4f decompose(Vec3f position, Quaternion rotation, Vec3f scale) public Matrix4f decompose(Vec3f position, Quaternion rotation, Vec3f scale) {
{
position.set(get(3, 0), get(3, 1), get(3, 2)); position.set(get(3, 0), get(3, 1), get(3, 2));
rotation.set(this); rotation.set(this);
scale.set(get(0, 0), get(1, 1), get(2, 2)); scale.set(get(0, 0), get(1, 1), get(2, 2));
return this; return this;
} }
public Matrix4f setTranslation(Vec3f vec) public Matrix4f setTranslation(Vec3f vec) {
{
data[12] = vec.getX(); data[12] = vec.getX();
data[13] = vec.getY(); data[13] = vec.getY();
data[14] = vec.getZ(); data[14] = vec.getZ();
return this; return this;
} }
public Matrix4f translate(Vec2f vec) public Matrix4f translate(Vec2f vec) { return translate(vec.getX(), vec.getY()); }
{
return translate(vec.getX(), vec.getY());
}
public Matrix4f translate(float x, float y) public Matrix4f translate(float x, float y) {
{
data[12] += data[0] * x + data[4] * y; data[12] += data[0] * x + data[4] * y;
data[13] += data[1] * x + data[5] * y; data[13] += data[1] * x + data[5] * y;
data[14] += data[2] * x + data[6] * y; data[14] += data[2] * x + data[6] * y;
@ -374,8 +318,7 @@ public class Matrix4f
return this; return this;
} }
public Matrix4f translate(Vec3f vec) public Matrix4f translate(Vec3f vec) {
{
data[12] += data[0] * vec.getX() + data[4] * vec.getY() + data[8] * vec.getZ(); data[12] += data[0] * vec.getX() + data[4] * vec.getY() + data[8] * vec.getZ();
data[13] += data[1] * vec.getX() + data[5] * vec.getY() + data[9] * vec.getZ(); data[13] += data[1] * vec.getX() + data[5] * vec.getY() + data[9] * vec.getZ();
data[14] += data[2] * vec.getX() + data[6] * vec.getY() + data[10] * vec.getZ(); data[14] += data[2] * vec.getX() + data[6] * vec.getY() + data[10] * vec.getZ();
@ -383,8 +326,7 @@ public class Matrix4f
return this; return this;
} }
public Matrix4f translate(float x, float y, float z) public Matrix4f translate(float x, float y, float z) {
{
data[12] += data[0] * x + data[4] * y + data[8] * z; data[12] += data[0] * x + data[4] * y + data[8] * z;
data[13] += data[1] * x + data[5] * y + data[9] * z; data[13] += data[1] * x + data[5] * y + data[9] * z;
data[14] += data[2] * x + data[6] * y + data[10] * z; data[14] += data[2] * x + data[6] * y + data[10] * z;
@ -392,38 +334,19 @@ public class Matrix4f
return this; return this;
} }
public Matrix4f rotateX(float angle) public Matrix4f rotateX(float angle) { return rotate((float)Math.toRadians(angle), X_ROTATION); }
{
return rotate((float)Math.toRadians(angle), X_ROTATION);
}
public Matrix4f rotateY(float angle) public Matrix4f rotateY(float angle) { return rotate((float)Math.toRadians(angle), Y_ROTATION); }
{
return rotate((float)Math.toRadians(angle), Y_ROTATION);
}
public Matrix4f rotateZ(float angle) public Matrix4f rotateZ(float angle) { return rotate((float)Math.toRadians(angle), Z_ROTATION); }
{
return rotate((float)Math.toRadians(angle), Z_ROTATION);
}
public Matrix4f rotateRadX(float angle) public Matrix4f rotateRadX(float angle) { return rotate(angle, X_ROTATION); }
{
return rotate(angle, X_ROTATION);
}
public Matrix4f rotateRadY(float angle) public Matrix4f rotateRadY(float angle) { return rotate(angle, Y_ROTATION); }
{
return rotate(angle, Y_ROTATION);
}
public Matrix4f rotateRadZ(float angle) public Matrix4f rotateRadZ(float angle) { return rotate(angle, Z_ROTATION); }
{
return rotate(angle, Z_ROTATION);
}
public Matrix4f rotate(float angle, Vec3f axis) public Matrix4f rotate(float angle, Vec3f axis) {
{
float c = MathUtils.cos(angle); float c = MathUtils.cos(angle);
float s = MathUtils.sin(angle); float s = MathUtils.sin(angle);
float oneminusc = 1.0f - c; float oneminusc = 1.0f - c;
@ -469,8 +392,7 @@ public class Matrix4f
return this; return this;
} }
public Matrix4f rotate(Quaternion rotation) public Matrix4f rotate(Quaternion rotation) {
{
float w2 = rotation.getW() * rotation.getW(); float w2 = rotation.getW() * rotation.getW();
float x2 = rotation.getX() * rotation.getX(); float x2 = rotation.getX() * rotation.getX();
float y2 = rotation.getY() * rotation.getY(); float y2 = rotation.getY() * rotation.getY();
@ -519,8 +441,7 @@ public class Matrix4f
return this; return this;
} }
public Matrix4f setRotation(Matrix4f source) public Matrix4f setRotation(Matrix4f source) {
{
data[0] = source.data[0]; data[0] = source.data[0];
data[1] = source.data[1]; data[1] = source.data[1];
data[2] = source.data[2]; data[2] = source.data[2];
@ -533,8 +454,7 @@ public class Matrix4f
return this; return this;
} }
public Matrix4f setBillboard(Matrix4f source) public Matrix4f setBillboard(Matrix4f source) {
{
data[0] = source.data[0]; data[0] = source.data[0];
data[1] = source.data[4]; data[1] = source.data[4];
data[2] = source.data[8]; data[2] = source.data[8];
@ -547,18 +467,11 @@ public class Matrix4f
return this; return this;
} }
public Matrix4f scale(Vec3f vec) public Matrix4f scale(Vec3f vec) { return scale(vec.getX(), vec.getY(), vec.getZ()); }
{
return scale(vec.getX(), vec.getY(), vec.getZ());
}
public Matrix4f scale(float value) public Matrix4f scale(float value) { return scale(value, value, value); }
{
return scale(value, value, value);
}
public Matrix4f scale(float x, float y, float z) public Matrix4f scale(float x, float y, float z) {
{
data[0] *= x; data[0] *= x;
data[1] *= x; data[1] *= x;
data[2] *= x; data[2] *= x;
@ -574,18 +487,11 @@ public class Matrix4f
return this; return this;
} }
public Matrix4f unscale(Vec3f vec) public Matrix4f unscale(Vec3f vec) { return unscale(vec.getX(), vec.getY(), vec.getZ()); }
{
return unscale(vec.getX(), vec.getY(), vec.getZ());
}
public Matrix4f unscale(float scale) public Matrix4f unscale(float scale) { return unscale(scale, scale, scale); }
{
return unscale(scale, scale, scale);
}
public Matrix4f unscale(float x, float y, float z) public Matrix4f unscale(float x, float y, float z) {
{
data[0] /= x; data[0] /= x;
data[1] /= x; data[1] /= x;
data[2] /= x; data[2] /= x;
@ -601,50 +507,40 @@ public class Matrix4f
return this; return this;
} }
public Matrix4f setPerspective(float fovy, float aspect, float zNear, float zFar) public Matrix4f setPerspective(float fovy, float aspect, float zNear, float zFar) {
{
float h = (float)Math.tan(fovy * 0.5f); float h = (float)Math.tan(fovy * 0.5f);
set(0, 0, 1F / (h * aspect)).set(1, 1, 1F / h); set(0, 0, 1F / (h * aspect)).set(1, 1, 1F / h);
boolean farInf = zFar > 0 && Float.isInfinite(zFar); boolean farInf = zFar > 0 && Float.isInfinite(zFar);
boolean nearInf = zNear > 0 && Float.isInfinite(zNear); boolean nearInf = zNear > 0 && Float.isInfinite(zNear);
if(farInf) if(farInf) {
{
float e = 1E-6f; float e = 1E-6f;
set(2, 2, e - 1F).set(3, 2, (e - 2F) * zNear); set(2, 2, e - 1F).set(3, 2, (e - 2F) * zNear);
} }
else if(nearInf) else if(nearInf) {
{
float e = 1E-6f; float e = 1E-6f;
set(2, 2, 1F - e).set(3, 2, (2F - e) * zFar); set(2, 2, 1F - e).set(3, 2, (2F - e) * zFar);
} }
else else {
{
set(2, 2, (zFar + zNear) / (zNear - zFar)).set(3, 2, (zFar + zFar) * zNear / (zNear - zFar)); set(2, 2, (zFar + zNear) / (zNear - zFar)).set(3, 2, (zFar + zFar) * zNear / (zNear - zFar));
} }
return set(2, 3, -1.0f); return set(2, 3, -1.0f);
} }
public Matrix4f getTranslation(Vec3f vec) public Matrix4f getTranslation(Vec3f vec) {
{
vec.set(data[12], data[13], data[14]); vec.set(data[12], data[13], data[14]);
return this; return this;
} }
public Matrix4f getScale(Vec3f vec) public Matrix4f getScale(Vec3f vec) {
{
vec.setX((float)Math.sqrt(data[0] * data[0] + data[1] * data[1] + data[2] * data[2])); vec.setX((float)Math.sqrt(data[0] * data[0] + data[1] * data[1] + data[2] * data[2]));
vec.setY((float)Math.sqrt(data[4] * data[4] + data[5] * data[5] + data[6] * data[6])); vec.setY((float)Math.sqrt(data[4] * data[4] + data[5] * data[5] + data[6] * data[6]));
vec.setZ((float)Math.sqrt(data[8] * data[8] + data[9] * data[9] + data[10] * data[10])); vec.setZ((float)Math.sqrt(data[8] * data[8] + data[9] * data[9] + data[10] * data[10]));
return this; return this;
} }
public Vec4f transform(Vec4f input) public Vec4f transform(Vec4f input) { return transform(input, input); }
{
return transform(input, input);
}
public Vec4f transform(Vec4f input, Vec4f output) public Vec4f transform(Vec4f input, Vec4f output) {
{
float x = data[0] * input.getX() + data[4] * input.getY() + data[8] * input.getZ() + data[12] * input.getW(); float x = data[0] * input.getX() + data[4] * input.getY() + data[8] * input.getZ() + data[12] * input.getW();
float y = data[1] * input.getX() + data[5] * input.getY() + data[9] * input.getZ() + data[13] * input.getW(); float y = data[1] * input.getX() + data[5] * input.getY() + data[9] * input.getZ() + data[13] * input.getW();
float z = data[2] * input.getX() + data[6] * input.getY() + data[10] * input.getZ() + data[14] * input.getW(); float z = data[2] * input.getX() + data[6] * input.getY() + data[10] * input.getZ() + data[14] * input.getW();
@ -652,35 +548,28 @@ public class Matrix4f
return output.set(x, y, z, w); return output.set(x, y, z, w);
} }
public void transform(Vec4f input, FloatBuffer buffer) public void transform(Vec4f input, FloatBuffer buffer) {
{
buffer.put(data[0] * input.getX() + data[4] * input.getY() + data[8] * input.getZ() + data[12] * input.getW()); buffer.put(data[0] * input.getX() + data[4] * input.getY() + data[8] * input.getZ() + data[12] * input.getW());
buffer.put(data[1] * input.getX() + data[5] * input.getY() + data[9] * input.getZ() + data[13] * input.getW()); buffer.put(data[1] * input.getX() + data[5] * input.getY() + data[9] * input.getZ() + data[13] * input.getW());
buffer.put(data[2] * input.getX() + data[6] * input.getY() + data[10] * input.getZ() + data[14] * input.getW()); buffer.put(data[2] * input.getX() + data[6] * input.getY() + data[10] * input.getZ() + data[14] * input.getW());
buffer.put(data[3] * input.getX() + data[7] * input.getY() + data[11] * input.getZ() + data[15] * input.getW()); buffer.put(data[3] * input.getX() + data[7] * input.getY() + data[11] * input.getZ() + data[15] * input.getW());
} }
public Vec3f transform(Vec3f input, boolean position) public Vec3f transform(Vec3f input, boolean position) { return transform(input, input, position); }
{
return transform(input, input, position);
}
public Vec3f transform(Vec3f input, Vec3f output, boolean position) public Vec3f transform(Vec3f input, Vec3f output, boolean position) {
{
float pos = position ? 1F : 0F; float pos = position ? 1F : 0F;
return output.set(data[0] * input.getX() + data[4] * input.getY() + data[8] * input.getZ() + data[12] * pos, data[1] * input.getX() + data[5] * input.getY() + data[9] * input.getZ() + data[13] * pos, data[2] * input.getX() + data[6] * input.getY() + data[10] * input.getZ() + data[14] * pos); return output.set(data[0] * input.getX() + data[4] * input.getY() + data[8] * input.getZ() + data[12] * pos, data[1] * input.getX() + data[5] * input.getY() + data[9] * input.getZ() + data[13] * pos, data[2] * input.getX() + data[6] * input.getY() + data[10] * input.getZ() + data[14] * pos);
} }
public void transform(Vec3f input, FloatBuffer buffer, boolean position) public void transform(Vec3f input, FloatBuffer buffer, boolean position) {
{
float pos = position ? 1F : 0F; float pos = position ? 1F : 0F;
buffer.put(data[0] * input.getX() + data[4] * input.getY() + data[8] * input.getZ() + data[12] * pos); buffer.put(data[0] * input.getX() + data[4] * input.getY() + data[8] * input.getZ() + data[12] * pos);
buffer.put(data[1] * input.getX() + data[5] * input.getY() + data[9] * input.getZ() + data[13] * pos); buffer.put(data[1] * input.getX() + data[5] * input.getY() + data[9] * input.getZ() + data[13] * pos);
buffer.put(data[2] * input.getX() + data[6] * input.getY() + data[10] * input.getZ() + data[14] * pos); buffer.put(data[2] * input.getX() + data[6] * input.getY() + data[10] * input.getZ() + data[14] * pos);
} }
public float determinant() public float determinant() {
{
float f = data[0] * ((data[5] * data[10] * data[15] + data[6] * data[11] * data[13] + data[7] * data[9] * data[14]) - data[7] * data[10] * data[13] - data[5] * data[11] * data[14] - data[6] * data[9] * data[15]); float f = data[0] * ((data[5] * data[10] * data[15] + data[6] * data[11] * data[13] + data[7] * data[9] * data[14]) - data[7] * data[10] * data[13] - data[5] * data[11] * data[14] - data[6] * data[9] * data[15]);
f -= data[1] * ((data[4] * data[10] * data[15] + data[6] * data[11] * data[12] + data[7] * data[8] * data[14]) - data[7] * data[10] * data[12] - data[4] * data[11] * data[14] - data[6] * data[8] * data[15]); f -= data[1] * ((data[4] * data[10] * data[15] + data[6] * data[11] * data[12] + data[7] * data[8] * data[14]) - data[7] * data[10] * data[12] - data[4] * data[11] * data[14] - data[6] * data[8] * data[15]);
f += data[2] * ((data[4] * data[9] * data[15] + data[5] * data[11] * data[12] + data[7] * data[8] * data[13]) - data[7] * data[9] * data[12] - data[4] * data[11] * data[13] - data[5] * data[8] * data[15]); f += data[2] * ((data[4] * data[9] * data[15] + data[5] * data[11] * data[12] + data[7] * data[8] * data[13]) - data[7] * data[9] * data[12] - data[4] * data[11] * data[13] - data[5] * data[8] * data[15]);
@ -688,13 +577,9 @@ public class Matrix4f
return f; return f;
} }
public float determinant3x3(float t00, float t01, float t02, float t10, float t11, float t12, float t20, float t21, float t22) public 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); }
{
return t00 * (t11 * t22 - t12 * t21) + t01 * (t12 * t20 - t10 * t22) + t02 * (t10 * t21 - t11 * t20);
}
public Matrix4f setTransform(Vec3f position, Vec3f rotation, float scale) public Matrix4f setTransform(Vec3f position, Vec3f rotation, float scale) {
{
setIdentity(); setIdentity();
translate(position); translate(position);
rotate((float)Math.toRadians(rotation.getX()), X_ROTATION); rotate((float)Math.toRadians(rotation.getX()), X_ROTATION);
@ -704,8 +589,7 @@ public class Matrix4f
return this; return this;
} }
public Matrix4f setTransform(Vec3f position, Vec3f rotation, Vec3f scale) public Matrix4f setTransform(Vec3f position, Vec3f rotation, Vec3f scale) {
{
setIdentity(); setIdentity();
translate(position); translate(position);
rotate((float)Math.toRadians(rotation.getX()), X_ROTATION); rotate((float)Math.toRadians(rotation.getX()), X_ROTATION);
@ -715,8 +599,7 @@ public class Matrix4f
return this; return this;
} }
public Matrix4f setTransform(Vec3f position, Vec3f offset, Vec3f rotation, float scale) public Matrix4f setTransform(Vec3f position, Vec3f offset, Vec3f rotation, float scale) {
{
setIdentity(); setIdentity();
translate(position); translate(position);
translate(offset); translate(offset);
@ -727,8 +610,7 @@ public class Matrix4f
return this; return this;
} }
public Matrix4f setTransform(Vec3f position, Vec3f offset, Vec3f rotation, Vec3f scale) public Matrix4f setTransform(Vec3f position, Vec3f offset, Vec3f rotation, Vec3f scale) {
{
setIdentity(); setIdentity();
translate(position); translate(position);
translate(offset); translate(offset);
@ -739,8 +621,7 @@ public class Matrix4f
return this; return this;
} }
public Matrix4f setTransform(Vec3f position, Quaternion rotation, float scale) public Matrix4f setTransform(Vec3f position, Quaternion rotation, float scale) {
{
setIdentity(); setIdentity();
translate(position); translate(position);
rotate(rotation); rotate(rotation);
@ -748,8 +629,7 @@ public class Matrix4f
return this; return this;
} }
public Matrix4f setTransform(Vec3f position, Quaternion rotation, Vec3f scale) public Matrix4f setTransform(Vec3f position, Quaternion rotation, Vec3f scale) {
{
setIdentity(); setIdentity();
translate(position); translate(position);
rotate(rotation); rotate(rotation);
@ -757,8 +637,7 @@ public class Matrix4f
return this; return this;
} }
public Matrix4f setTransform(Vec3f position, Vec3f offset, Quaternion rotation, float scale) public Matrix4f setTransform(Vec3f position, Vec3f offset, Quaternion rotation, float scale) {
{
setIdentity(); setIdentity();
translate(position); translate(position);
translate(offset); translate(offset);
@ -767,8 +646,7 @@ public class Matrix4f
return this; return this;
} }
public Matrix4f setTransform(Vec3f position, Vec3f offset, Quaternion rotation, Vec3f scale) public Matrix4f setTransform(Vec3f position, Vec3f offset, Quaternion rotation, Vec3f scale) {
{
setIdentity(); setIdentity();
translate(position); translate(position);
translate(offset); translate(offset);
@ -777,8 +655,7 @@ public class Matrix4f
return this; return this;
} }
public Matrix4f setTransform(Vec3f position, Matrix4f billRotation, float scale) public Matrix4f setTransform(Vec3f position, Matrix4f billRotation, float scale) {
{
setIdentity(); setIdentity();
translate(position); translate(position);
setBillboard(billRotation); setBillboard(billRotation);
@ -786,8 +663,7 @@ public class Matrix4f
return this; return this;
} }
public Matrix4f setTransform(Vec3f position, Matrix4f billRotation, Vec3f scale) public Matrix4f setTransform(Vec3f position, Matrix4f billRotation, Vec3f scale) {
{
setIdentity(); setIdentity();
translate(position); translate(position);
setBillboard(billRotation); setBillboard(billRotation);
@ -796,60 +672,55 @@ public class Matrix4f
return this; return this;
} }
public Vec3f project(float x, float y, float z, int[] viewport, Vec3f winCoordsDest) public Vec3f project(float x, float y, float z, int[] viewport, Vec3f winCoordsDest) {
{ float invW = 1F / Math.fma(data[3], x, Math.fma(data[7], y, Math.fma(data[11], z, data[15])));
float invW = 1F / VectorUtil.fma(data[3], x, VectorUtil.fma(data[7], y, VectorUtil.fma(data[11], z, data[15]))); float nx = Math.fma(data[0], x, Math.fma(data[4], y, Math.fma(data[8], z, data[12]))) * invW;
float nx = VectorUtil.fma(data[0], x, VectorUtil.fma(data[4], y, VectorUtil.fma(data[8], z, data[12]))) * invW; float ny = Math.fma(data[1], x, Math.fma(data[5], y, Math.fma(data[9], z, data[13]))) * invW;
float ny = VectorUtil.fma(data[1], x, VectorUtil.fma(data[5], y, VectorUtil.fma(data[9], z, data[13]))) * invW; float nz = Math.fma(data[2], x, Math.fma(data[6], y, Math.fma(data[10], z, data[14]))) * invW;
float nz = VectorUtil.fma(data[2], x, VectorUtil.fma(data[6], y, VectorUtil.fma(data[10], z, data[14]))) * invW; return winCoordsDest.set( Math.fma(Math.fma(nx, 0.5F, 0.5F), viewport[2], viewport[0]), Math.fma( Math.fma(ny, 0.5F, 0.5F), viewport[3], viewport[1]), Math.fma(0.5F, nz, 0.5F));
return winCoordsDest.set(VectorUtil.fma(VectorUtil.fma(nx, 0.5F, 0.5F), viewport[2], viewport[0]), VectorUtil.fma(VectorUtil.fma(ny, 0.5F, 0.5F), viewport[3], viewport[1]), VectorUtil.fma(0.5F, nz, 0.5F));
} }
public Vec3f unproject(float winX, float winY, float winZ, int[] viewport, Vec3f dest) { public Vec3f unproject(float winX, float winY, float winZ, int[] viewport, Vec3f dest) {
float a = data[0] * data[5] - data[1] * data[4]; float a = data[0] * data[5] - data[1] * data[4];
float b = data[0] * data[6] - data[2] * data[4]; float b = data[0] * data[6] - data[2] * data[4];
float c = data[0] * data[7] - data[3] * data[4]; float c = data[0] * data[7] - data[3] * data[4];
float d = data[1] * data[6] - data[2] * data[5]; float d = data[1] * data[6] - data[2] * data[5];
float e = data[1] * data[7] - data[3] * data[5]; float e = data[1] * data[7] - data[3] * data[5];
float f = data[2] * data[7] - data[3] * data[6]; float f = data[2] * data[7] - data[3] * data[6];
float g = data[8] * data[13] - data[9] * data[12]; float g = data[8] * data[13] - data[9] * data[12];
float h = data[8] * data[14] - data[10] * data[12]; float h = data[8] * data[14] - data[10] * data[12];
float i = data[8] * data[15] - data[11] * data[12]; float i = data[8] * data[15] - data[11] * data[12];
float j = data[9] * data[14] - data[10] * data[13]; float j = data[9] * data[14] - data[10] * data[13];
float k = data[9] * data[15] - data[11] * data[13]; float k = data[9] * data[15] - data[11] * data[13];
float l = data[10] * data[15] - data[11] * data[14]; float l = data[10] * data[15] - data[11] * data[14];
float det = a * l - b * k + c * j + d * i - e * h + f * g; float det = a * l - b * k + c * j + d * i - e * h + f * g;
det = 1.0f / det; det = 1.0f / det;
float im00 = ( data[5] * l - data[6] * k + data[7] * j) * det; float im00 = (data[5] * l - data[6] * k + data[7] * j) * det;
float im01 = (-data[1] * l + data[2] * k - data[3] * j) * det; float im01 = (-data[1] * l + data[2] * k - data[3] * j) * det;
float im02 = ( data[13] * f - data[14] * e + data[15] * d) * det; float im02 = (data[13] * f - data[14] * e + data[15] * d) * det;
float im03 = (-data[9] * f + data[10] * e - data[11] * d) * det; float im03 = (-data[9] * f + data[10] * e - data[11] * d) * det;
float im10 = (-data[4] * l + data[6] * i - data[7] * h) * det; float im10 = (-data[4] * l + data[6] * i - data[7] * h) * det;
float im11 = ( data[0] * l - data[2] * i + data[3] * h) * det; float im11 = (data[0] * l - data[2] * i + data[3] * h) * det;
float im12 = (-data[12] * f + data[14] * c - data[15] * b) * det; float im12 = (-data[12] * f + data[14] * c - data[15] * b) * det;
float im13 = ( data[8] * f - data[10] * c + data[11] * b) * det; float im13 = (data[8] * f - data[10] * c + data[11] * b) * det;
float im20 = ( data[4] * k - data[5] * i + data[7] * g) * det; float im20 = (data[4] * k - data[5] * i + data[7] * g) * det;
float im21 = (-data[0] * k + data[1] * i - data[3] * g) * det; float im21 = (-data[0] * k + data[1] * i - data[3] * g) * det;
float im22 = ( data[12] * e - data[13] * c + data[15] * a) * det; float im22 = (data[12] * e - data[13] * c + data[15] * a) * det;
float im23 = (-data[8] * e + data[9] * c - data[11] * a) * det; float im23 = (-data[8] * e + data[9] * c - data[11] * a) * det;
float im30 = (-data[4] * j + data[5] * h - data[6] * g) * det; float im30 = (-data[4] * j + data[5] * h - data[6] * g) * det;
float im31 = ( data[0] * j - data[1] * h + data[2] * g) * det; float im31 = (data[0] * j - data[1] * h + data[2] * g) * det;
float im32 = (-data[12] * d + data[13] * b - data[14] * a) * det; float im32 = (-data[12] * d + data[13] * b - data[14] * a) * det;
float im33 = ( data[8] * d - data[9] * b + data[10] * a) * det; float im33 = (data[8] * d - data[9] * b + data[10] * a) * det;
float ndcX = (winX-viewport[0])/viewport[2]*2.0f-1.0f; float ndcX = (winX - viewport[0]) / viewport[2] * 2.0f - 1.0f;
float ndcY = (winY-viewport[1])/viewport[3]*2.0f-1.0f; float ndcY = (winY - viewport[1]) / viewport[3] * 2.0f - 1.0f;
float ndcZ = winZ+winZ-1.0f; float ndcZ = winZ + winZ - 1.0f;
float invW = 1.0f / (im03 * ndcX + im13 * ndcY + im23 * ndcZ + im33); float invW = 1.0f / (im03 * ndcX + im13 * ndcY + im23 * ndcZ + im33);
return dest.set((im00 * ndcX + im10 * ndcY + im20 * ndcZ + im30) * invW, (im01 * ndcX + im11 * ndcY + im21 * ndcZ + im31) * invW, (im02 * ndcX + im12 * ndcY + im22 * ndcZ + im32) * invW); return dest.set((im00 * ndcX + im10 * ndcY + im20 * ndcZ + im30) * invW, (im01 * ndcX + im11 * ndcY + im21 * ndcZ + im31) * invW, (im02 * ndcX + im12 * ndcY + im22 * ndcZ + im32) * invW);
} }
public Matrix4f ortho(float x, float y, float width, float height, float zNear, float zFar)
{
return ortho(x, x+width, y+height, y, zNear, zFar, false);
}
public Matrix4f ortho(float left, float right, float bottom, float top, float zNear, float zFar, boolean zZeroToOne) public Matrix4f ortho(float x, float y, float width, float height, float zNear, float zFar) { return ortho(x, x + width, y + height, y, zNear, zFar, false); }
{
public Matrix4f ortho(float left, float right, float bottom, float top, float zNear, float zFar, boolean zZeroToOne) {
float rm00 = 2F / (right - left); float rm00 = 2F / (right - left);
float rm11 = 2F / (top - bottom); float rm11 = 2F / (top - bottom);
float rm22 = (zZeroToOne ? 1F : 2F) / (zFar - zNear); float rm22 = (zZeroToOne ? 1F : 2F) / (zFar - zNear);
@ -876,10 +747,8 @@ public class Matrix4f
return this; return this;
} }
public Vec4f storeFrustrumPlane(int plane, Vec4f toStore) public Vec4f storeFrustrumPlane(int plane, Vec4f toStore) {
{ switch(plane) {
switch(plane)
{
case 0: case 0:
return toStore.set(data[3] + data[0], data[7] + data[4], data[11] + data[8], data[15] + data[12]).normalize3D(); return toStore.set(data[3] + data[0], data[7] + data[4], data[11] + data[8], data[15] + data[12]).normalize3D();
case 1: case 1:

View File

@ -7,24 +7,21 @@ import speiger.src.coreengine.math.MathUtils;
import speiger.src.coreengine.math.vector.floats.Vec4f; import speiger.src.coreengine.math.vector.floats.Vec4f;
import speiger.src.coreengine.math.vector.matrix.Matrix4f; import speiger.src.coreengine.math.vector.matrix.Matrix4f;
public interface Quaternion public interface Quaternion {
{
public static final Quaternion ZERO = of(0F, 0F, 0F, 0F); public static final Quaternion ZERO = of(0F, 0F, 0F, 0F);
public static final Quaternion IDENTITY = of(); public static final Quaternion IDENTITY = of();
public static Quaternion mutable(){return new QuaternionMutable();} public static Quaternion mutable() { return new QuaternionMutable(); }
public static Quaternion mutable(Quaternion source){return mutable(source.getX(), source.getY(), source.getZ(), source.getW());} public static Quaternion mutable(Quaternion source) { return mutable(source.getX(), source.getY(), source.getZ(), source.getW()); }
public static Quaternion mutable(float x, float y, float z, float w){return new QuaternionMutable(x, y, z, w);} public static Quaternion mutable(float x, float y, float z, float w) { return new QuaternionMutable(x, y, z, w); }
public static Quaternion mutableRad(float x, float y, float z, float angle){return mutable().setAxisRad(x, y, z, angle);} public static Quaternion mutableRad(float x, float y, float z, float angle) { return mutable().setAxisRad(x, y, z, angle); }
public static Quaternion mutableDeg(float x, float y, float z, float angle){return mutable().setAxisDeg(x, y, z, angle);} public static Quaternion mutableDeg(float x, float y, float z, float angle) { return mutable().setAxisDeg(x, y, z, angle); }
public static Quaternion of() { return new QuaternionImmutable(); }
public static Quaternion of(){return new QuaternionImmutable();} public static Quaternion of(Quaternion source) { return of(source.getX(), source.getY(), source.getZ(), source.getW()); }
public static Quaternion of(Quaternion source){return of(source.getX(), source.getY(), source.getZ(), source.getW());} public static Quaternion of(float x, float y, float z, float w) { return new QuaternionImmutable(x, y, z, w); }
public static Quaternion of(float x, float y, float z, float w){return new QuaternionImmutable(x, y, z, w);} public static Quaternion ofRad(float x, float y, float z, float angle) { return ZERO.setAxisRad(x, y, z, angle); }
public static Quaternion ofRad(float x, float y, float z, float angle){return ZERO.setAxisRad(x, y, z, angle);} public static Quaternion ofDeg(float x, float y, float z, float angle) { return ZERO.setAxisDeg(x, y, z, angle); }
public static Quaternion ofDeg(float x, float y, float z, float angle){return ZERO.setAxisDeg(x, y, z, angle);} public static double acos(double v) { return v < -1D ? 3.141592653589793D : (v > 1D ? 0D : Math.acos(v)); }
public static double acos(double v){return v < -1D ? 3.141592653589793D : (v > 1D ? 0D : Math.acos(v));}
public Quaternion setX(float x); public Quaternion setX(float x);
public Quaternion setY(float y); public Quaternion setY(float y);
@ -34,46 +31,42 @@ public interface Quaternion
public float getY(); public float getY();
public float getZ(); public float getZ();
public float getW(); public float getW();
public default float[] asArray(){return new float[]{getX(), getY(), getZ(), getW()};}
public default Quaternion negate(){return set(0F, 0F, 0F, 0F);} public default float[] asArray() { return new float[] {getX(), getY(), getZ(), getW()}; }
public default Quaternion invert(){return set(-getX(), -getY(), -getZ(), -getW());} public default Quaternion negate() { return set(0F, 0F, 0F, 0F); }
public default Quaternion normalize(){return scale(1.0F / length());} public default Quaternion invert() { return set(-getX(), -getY(), -getZ(), -getW()); }
public default Quaternion conjugate(){return set(-getX(), -getY(), -getZ(), getW());} public default Quaternion normalize() { return scale(1.0F / length()); }
public default Quaternion setIdentity(){return set(0F, 0F, 0F, 1F);} public default Quaternion conjugate() { return set(-getX(), -getY(), -getZ(), getW()); }
public default Quaternion setIdentity() { return set(0F, 0F, 0F, 1F); }
public default Quaternion multiply(Quaternion other){return set(getX() * other.getW() + getW() * other.getX() + getY() * other.getZ() - getZ() * other.getY(), getY() * other.getW() + getW() * other.getY() + getZ() * other.getX() - getX() * other.getZ(), getZ() * other.getW() + getW() * other.getZ() + getX() * other.getY() - getY() * other.getX(), getW() * other.getW() - getX() * other.getX() - getY() * other.getY() - getZ() * other.getZ());} public default Quaternion multiply(Quaternion other) { return set(getX() * other.getW() + getW() * other.getX() + getY() * other.getZ() - getZ() * other.getY(), getY() * other.getW() + getW() * other.getY() + getZ() * other.getX() - getX() * other.getZ(), getZ() * other.getW() + getW() * other.getZ() + getX() * other.getY() - getY() * other.getX(), getW() * other.getW() - getX() * other.getX() - getY() * other.getY() - getZ() * other.getZ()); }
public default Quaternion scale(float scale){return set(getX() * scale, getY() * scale, getZ() * scale, getW() * scale);} public default Quaternion scale(float scale) { return set(getX() * scale, getY() * scale, getZ() * scale, getW() * scale); }
public default Quaternion rotateX(float angle) public default Quaternion rotateX(float angle) {
{
angle = (float)Math.toRadians(angle); angle = (float)Math.toRadians(angle);
float sin = MathUtils.sin(angle * 0.5D); float sin = MathUtils.sin(angle * 0.5D);
float cos = MathUtils.cos(angle * 0.5D); float cos = MathUtils.cos(angle * 0.5D);
return set(getW() * sin + getX() * cos, getY() * cos + getZ() * sin, getZ() * cos - getY() * sin, getW() * cos - getX() * sin); return set(getW() * sin + getX() * cos, getY() * cos + getZ() * sin, getZ() * cos - getY() * sin, getW() * cos - getX() * sin);
} }
public default Quaternion rotateY(float angle)
{ public default Quaternion rotateY(float angle) {
angle = (float)Math.toRadians(angle); angle = (float)Math.toRadians(angle);
float sin = MathUtils.sin(angle * 0.5D); float sin = MathUtils.sin(angle * 0.5D);
float cos = MathUtils.cos(angle * 0.5D); float cos = MathUtils.cos(angle * 0.5D);
return set(getX() * cos - getZ() * sin, getW() * sin + getY() * cos, getX() * sin + getZ() * cos, getW() * cos - getY() * sin); return set(getX() * cos - getZ() * sin, getW() * sin + getY() * cos, getX() * sin + getZ() * cos, getW() * cos - getY() * sin);
} }
public default Quaternion rotateZ(float angle)
{ public default Quaternion rotateZ(float angle) {
angle = (float)Math.toRadians(angle); angle = (float)Math.toRadians(angle);
float sin = MathUtils.sin(angle * 0.5D); float sin = MathUtils.sin(angle * 0.5D);
float cos = MathUtils.cos(angle * 0.5D); float cos = MathUtils.cos(angle * 0.5D);
return set(getX() * cos + getY() * sin, getY() * cos - getX() * sin, getW() * sin + getZ() * cos, getW() * cos - getZ() * sin); return set(getX() * cos + getY() * sin, getY() * cos - getX() * sin, getW() * sin + getZ() * cos, getW() * cos - getZ() * sin);
} }
public default Quaternion set(Vec4f value){return set(value.getX(), value.getY(), value.getZ(), value.getW());} public default Quaternion set(Vec4f value) { return set(value.getX(), value.getY(), value.getZ(), value.getW()); }
public default Quaternion set(Quaternion value){return set(value.getX(), value.getY(), value.getZ(), value.getW());} public default Quaternion set(Quaternion value) { return set(value.getX(), value.getY(), value.getZ(), value.getW()); }
public default Quaternion set(Matrix4f matrix) public default Quaternion set(Matrix4f matrix) {
{
float tr = matrix.get(0, 0) + matrix.get(1, 1) + matrix.get(2, 2); float tr = matrix.get(0, 0) + matrix.get(1, 1) + matrix.get(2, 2);
if(tr >= 0.0D) if(tr >= 0.0D) {
{
float s = (float)Math.sqrt(tr + 1.0D); float s = (float)Math.sqrt(tr + 1.0D);
float w = s * 0.5F; float w = s * 0.5F;
s = 0.5F / s; s = 0.5F / s;
@ -82,11 +75,9 @@ public interface Quaternion
float z = (matrix.get(1, 0) - matrix.get(0, 1)) * s; float z = (matrix.get(1, 0) - matrix.get(0, 1)) * s;
return set(x, y, z, w); return set(x, y, z, w);
} }
else else {
{
float max = Math.max(Math.max(matrix.get(0, 0), matrix.get(1, 1)), matrix.get(2, 2)); float max = Math.max(Math.max(matrix.get(0, 0), matrix.get(1, 1)), matrix.get(2, 2));
if(max == matrix.get(0, 0)) if(max == matrix.get(0, 0)) {
{
float s = (float)Math.sqrt(matrix.get(0, 0) - (matrix.get(1, 1) + matrix.get(2, 2)) + 1.0D); float s = (float)Math.sqrt(matrix.get(0, 0) - (matrix.get(1, 1) + matrix.get(2, 2)) + 1.0D);
float x = s * 0.5F; float x = s * 0.5F;
s = 0.5F / s; s = 0.5F / s;
@ -95,8 +86,7 @@ public interface Quaternion
float w = (matrix.get(2, 1) - matrix.get(1, 2)) * s; float w = (matrix.get(2, 1) - matrix.get(1, 2)) * s;
return set(x, y, z, w); return set(x, y, z, w);
} }
else if(max == matrix.get(1, 1)) else if(max == matrix.get(1, 1)) {
{
float s = (float)Math.sqrt(matrix.get(1, 1) - (matrix.get(2, 2) + matrix.get(0, 0)) + 1.0D); float s = (float)Math.sqrt(matrix.get(1, 1) - (matrix.get(2, 2) + matrix.get(0, 0)) + 1.0D);
float y = s * 0.5F; float y = s * 0.5F;
s = 0.5F / s; s = 0.5F / s;
@ -105,8 +95,7 @@ public interface Quaternion
float w = (matrix.get(0, 2) - matrix.get(2, 0)) * s; float w = (matrix.get(0, 2) - matrix.get(2, 0)) * s;
return set(x, y, z, w); return set(x, y, z, w);
} }
else else {
{
float s = (float)Math.sqrt(matrix.get(2, 2) - (matrix.get(0, 0) + matrix.get(1, 1)) + 1.0D); float s = (float)Math.sqrt(matrix.get(2, 2) - (matrix.get(0, 0) + matrix.get(1, 1)) + 1.0D);
float z = s * 0.5F; float z = s * 0.5F;
s = 0.5F / s; s = 0.5F / s;
@ -118,49 +107,45 @@ public interface Quaternion
} }
} }
public default Quaternion setAxisRad(float x, float y, float z, float angle) public default Quaternion setAxisRad(float x, float y, float z, float angle) {
{
float sin = MathUtils.sin(angle * 0.5D); float sin = MathUtils.sin(angle * 0.5D);
float cos = MathUtils.cos(angle * 0.5D); float cos = MathUtils.cos(angle * 0.5D);
return set(x * sin, y * sin, z * sin, cos); return set(x * sin, y * sin, z * sin, cos);
} }
public default Quaternion setAxisDeg(float x, float y, float z, float angle)
{ public default Quaternion setAxisDeg(float x, float y, float z, float angle) {
angle = (float)Math.toRadians(angle); angle = (float)Math.toRadians(angle);
float sin = MathUtils.sin(angle * 0.5D); float sin = MathUtils.sin(angle * 0.5D);
float cos = MathUtils.cos(angle * 0.5D); float cos = MathUtils.cos(angle * 0.5D);
return set(x * sin, y * sin, z * sin, cos); return set(x * sin, y * sin, z * sin, cos);
} }
public Quaternion set(float x, float y, float z, float w);
public default float dot(Quaternion other){return getX() * other.getX() + getY() * other.getY() + getZ() * other.getZ() + getW() * other.getW();} public Quaternion set(float x, float y, float z, float w);
public default Quaternion difference(Quaternion other){return difference(other, this);} public default float dot(Quaternion other) { return getX() * other.getX() + getY() * other.getY() + getZ() * other.getZ() + getW() * other.getW(); }
public default Quaternion difference(Quaternion other, Quaternion result) public default Quaternion difference(Quaternion other) { return difference(other, this); }
{ public default Quaternion difference(Quaternion other, Quaternion result) {
float invNorm = 1.0F / (getX() * getX() + getY() * getY() + getZ() * getZ() + getW() * getW()); float invNorm = 1.0F / (getX() * getX() + getY() * getY() + getZ() * getZ() + getW() * getW());
float x = -getX() * invNorm; float x = -getX() * invNorm;
float y = -getY() * invNorm; float y = -getY() * invNorm;
float z = -getZ() * invNorm; float z = -getZ() * invNorm;
float w = getW() * invNorm; float w = getW() * invNorm;
return set(w * other.getX() + x * other.getW() + y * other.getZ() - z * other.getY(), w * other.getY() - x * other.getZ() + y * other.getW() + z * other.getX(), w * other.getZ() + x * other.getY() - y * other.getX() + z * other.getW(), w * other.getW() - x * other.getX() - y * other.getY() - z * other.getZ()); return set(w * other.getX() + x * other.getW() + y * other.getZ() - z * other.getY(), w * other.getY() - x * other.getZ() + y * other.getW() + z * other.getX(), w * other.getZ() + x * other.getY() - y * other.getX() + z * other.getW(), w * other.getW() - x * other.getX() - y * other.getY() - z * other.getZ());
} }
public default Quaternion lerp(Quaternion other, float progress){return lerp(other, progress, this);}
public default Quaternion lerp(Quaternion other, float progress, Quaternion result) public default Quaternion lerp(Quaternion other, float progress) { return lerp(other, progress, this); }
{ public default Quaternion lerp(Quaternion other, float progress, Quaternion result) {
float cosom = getX() * other.getX() + getY() * other.getY() + getZ() * other.getZ() + getW() * other.getW(); float cosom = getX() * other.getX() + getY() * other.getY() + getZ() * other.getZ() + getW() * other.getW();
float absCosom = Math.abs(cosom); float absCosom = Math.abs(cosom);
float scale1; float scale1;
float scale0; float scale0;
if(1.0F - absCosom > 1.0E-006F) if(1.0F - absCosom > 1.0E-006F) {
{
float sinSqr = 1.0F - absCosom * absCosom; float sinSqr = 1.0F - absCosom * absCosom;
float sinom = (float)(1.0D / Math.sqrt(sinSqr)); float sinom = (float)(1.0D / Math.sqrt(sinSqr));
float omega = (float)Math.atan2(sinSqr * sinom, absCosom); float omega = (float)Math.atan2(sinSqr * sinom, absCosom);
scale0 = MathUtils.sin((1.0D - progress) * omega) * sinom; scale0 = MathUtils.sin((1.0D - progress) * omega) * sinom;
scale1 = MathUtils.sin(progress * omega) * sinom; scale1 = MathUtils.sin(progress * omega) * sinom;
} }
else else {
{
scale0 = 1.0F - progress; scale0 = 1.0F - progress;
scale1 = progress; scale1 = progress;
} }
@ -168,49 +153,39 @@ public interface Quaternion
return result.set(scale0 * getX() + scale1 * other.getX(), scale0 * getY() + scale1 * other.getY(), scale0 * getZ() + scale1 * other.getZ(), scale0 * getW() + scale1 * other.getW()); return result.set(scale0 * getX() + scale1 * other.getX(), scale0 * getY() + scale1 * other.getY(), scale0 * getZ() + scale1 * other.getZ(), scale0 * getW() + scale1 * other.getW());
} }
public default float length(){return (float)Math.sqrt(lengthSquared());} public default float length() { return (float)Math.sqrt(lengthSquared()); }
public default double lengthSquared(){return (getX() * getX()) + (getY() * getY()) + (getZ() * getZ()) + (getW() * getW());} public default double lengthSquared() { return (getX() * getX()) + (getY() * getY()) + (getZ() * getZ()) + (getW() * getW()); }
public default Matrix4f asRotationMatrix() { return new Matrix4f().rotate(this); }
public default Matrix4f asRotationMatrix(){return new Matrix4f().rotate(this);} public default Vec4f toAxisDegreeRotation() { return toAxisDegreeRotation(Vec4f.mutable()); }
public default Vec4f toAxisDegreeRotation() {return toAxisDegreeRotation(Vec4f.mutable());} public default Vec4f toAxisDegreeRotation(Vec4f input) {
public default Vec4f toAxisDegreeRotation(Vec4f input) double invSqrt = 1.0D / Math.sqrt(1.0D - getW() * getW());
{ return input.set((float)(getX() * invSqrt), (float)(getY() * invSqrt), (float)(getZ() * invSqrt), (float)Math.toDegrees(acos(getW()) * 2F));
double invSqrt = 1.0D / Math.sqrt(1.0D - getW() * getW());
return input.set((float)(getX() * invSqrt), (float)(getY() * invSqrt), (float)(getZ() * invSqrt), (float)Math.toDegrees(acos(getW()) * 2F));
} }
public default Vec4f toAxisRotation() {return toAxisRotation(Vec4f.mutable());}
public default Vec4f toAxisRotation(Vec4f input) public default Vec4f toAxisRotation() { return toAxisRotation(Vec4f.mutable()); }
{ public default Vec4f toAxisRotation(Vec4f input) {
double invSqrt = 1.0D / Math.sqrt(1.0D - getW() * getW()); double invSqrt = 1.0D / Math.sqrt(1.0D - getW() * getW());
return input.set((float)(getX() * invSqrt), (float)(getY() * invSqrt), (float)(getZ() * invSqrt), (float)acos(getW()) * 2F); return input.set((float)(getX() * invSqrt), (float)(getY() * invSqrt), (float)(getZ() * invSqrt), (float)acos(getW()) * 2F);
} }
public default Quaternion store(ByteBuffer buffer) public default Quaternion store(ByteBuffer buffer) {
{
buffer.putFloat(getX()).putFloat(getY()).putFloat(getZ()).putFloat(getW()); buffer.putFloat(getX()).putFloat(getY()).putFloat(getZ()).putFloat(getW());
return this; return this;
} }
public default Quaternion load(ByteBuffer buffer) public default Quaternion load(ByteBuffer buffer) { return set(buffer.getFloat(), buffer.getFloat(), buffer.getFloat(), buffer.getFloat()); }
{
return set(buffer.getFloat(), buffer.getFloat(), buffer.getFloat(), buffer.getFloat());
}
public default Quaternion store(FloatBuffer buffer) public default Quaternion store(FloatBuffer buffer) {
{
buffer.put(getX()).put(getY()).put(getZ()).put(getW()); buffer.put(getX()).put(getY()).put(getZ()).put(getW());
return this; return this;
} }
public default Quaternion load(FloatBuffer buffer) public default Quaternion load(FloatBuffer buffer) { return set(buffer.get(), buffer.get(), buffer.get(), buffer.get()); }
{
return set(buffer.get(), buffer.get(), buffer.get(), buffer.get());
}
public Quaternion copy(); public Quaternion copy();
public boolean isMutable(); public boolean isMutable();
public default Quaternion asMutable(){return isMutable() ? this : of(this);} public default Quaternion asMutable() { return isMutable() ? this : of(this); }
public default Quaternion asImmutable(){return isMutable() ? mutable(this) : this;} public default Quaternion asImmutable() { return isMutable() ? mutable(this) : this; }
public default Quaternion copyAsMutable(){return mutable(this);} public default Quaternion copyAsMutable() { return mutable(this); }
public default Quaternion copyAsImmutable(){return of(this);} public default Quaternion copyAsImmutable() { return of(this); }
} }

View File

@ -2,106 +2,54 @@ package speiger.src.coreengine.math.vector.quaternion;
import java.util.Arrays; import java.util.Arrays;
public class QuaternionImmutable implements Quaternion public class QuaternionImmutable implements Quaternion {
{
final float x; final float x;
final float y; final float y;
final float z; final float z;
final float w; final float w;
public QuaternionImmutable() public QuaternionImmutable() {
{
x = 0F; x = 0F;
y = 0F; y = 0F;
z = 0F; z = 0F;
w = 1F; w = 1F;
} }
public QuaternionImmutable(float x, float y, float z, float w) public QuaternionImmutable(float x, float y, float z, float w) {
{
this.x = x; this.x = x;
this.y = y; this.y = y;
this.z = z; this.z = z;
this.w = w; this.w = w;
} }
@Override
public Quaternion setX(float x)
{
return this.x == x ? this : set(x, y, z, w);
}
@Override @Override
public Quaternion setY(float y) public Quaternion setX(float x) { return this.x == x ? this : set(x, y, z, w); }
{ @Override
return this.y == y ? this : set(x, y, z, w); public Quaternion setY(float y) { return this.y == y ? this : set(x, y, z, w); }
} @Override
public Quaternion setZ(float z) { return this.z == z ? this : set(x, y, z, w); }
@Override
public Quaternion setW(float w) { return this.w == w ? this : set(x, y, z, w); }
@Override
public float getX() { return x; }
@Override
public float getY() { return y; }
@Override
public float getZ() { return z; }
@Override
public float getW() { return w; }
@Override
public Quaternion set(float x, float y, float z, float w) { return this.x == x && this.y == y && this.z == z && this.w == w ? this : Quaternion.of(x, y, z, w); }
@Override
public Quaternion copy() { return Quaternion.of(this); }
@Override
public boolean isMutable() { return false; }
@Override
public int hashCode() { return Arrays.hashCode(new float[] {x, y, z, w}); }
@Override @Override
public Quaternion setZ(float z) public boolean equals(Object obj) {
{ if(obj instanceof Quaternion) {
return this.z == z ? this : set(x, y, z, w);
}
@Override
public Quaternion setW(float w)
{
return this.w == w ? this : set(x, y, z, w);
}
@Override
public float getX()
{
return x;
}
@Override
public float getY()
{
return y;
}
@Override
public float getZ()
{
return z;
}
@Override
public float getW()
{
return w;
}
@Override
public Quaternion set(float x, float y, float z, float w)
{
return this.x == x && this.y == y && this.z == z && this.w == w ? this : Quaternion.of(x, y, z, w);
}
@Override
public Quaternion copy()
{
return Quaternion.of(this);
}
@Override
public boolean isMutable()
{
return false;
}
@Override
public int hashCode()
{
return Arrays.hashCode(new float[]{x,y,z,w});
}
@Override
public boolean equals(Object obj)
{
if(obj instanceof Quaternion)
{
Quaternion other = (Quaternion)obj; Quaternion other = (Quaternion)obj;
return other.getX() == x && other.getY() == y && other.getZ() == z && other.getW() == w; return other.getX() == x && other.getY() == y && other.getZ() == z && other.getW() == w;
} }
@ -109,8 +57,5 @@ public class QuaternionImmutable implements Quaternion
} }
@Override @Override
public String toString() public String toString() { return "Quaternion[x="+x+", y="+y+", z="+z+", w="+w+"]"; }
{
return "Quaternion[x="+x+", y="+y+", z="+z+", w="+w+"]";
}
} }

View File

@ -2,23 +2,20 @@ package speiger.src.coreengine.math.vector.quaternion;
import java.util.Arrays; import java.util.Arrays;
public class QuaternionMutable implements Quaternion public class QuaternionMutable implements Quaternion {
{
float x; float x;
float y; float y;
float z; float z;
float w; float w;
public QuaternionMutable() public QuaternionMutable() {
{
x = 0F; x = 0F;
y = 0F; y = 0F;
z = 0F; z = 0F;
w = 1F; w = 1F;
} }
public QuaternionMutable(float x, float y, float z, float w) public QuaternionMutable(float x, float y, float z, float w) {
{
this.x = x; this.x = x;
this.y = y; this.y = y;
this.z = z; this.z = z;
@ -26,60 +23,40 @@ public class QuaternionMutable implements Quaternion
} }
@Override @Override
public Quaternion setX(float x) public Quaternion setX(float x) {
{
this.x = x; this.x = x;
return this; return this;
} }
@Override @Override
public Quaternion setY(float y) public Quaternion setY(float y) {
{
this.y = y; this.y = y;
return this; return this;
} }
@Override @Override
public Quaternion setZ(float z) public Quaternion setZ(float z) {
{
this.z = z; this.z = z;
return this; return this;
} }
@Override @Override
public Quaternion setW(float w) public Quaternion setW(float w) {
{
this.w = w; this.w = w;
return this; return this;
} }
@Override @Override
public float getX() public float getX() { return x; }
{ @Override
return x; public float getY() { return y; }
} @Override
public float getZ() { return z; }
@Override
public float getW() { return w; }
@Override @Override
public float getY() public Quaternion set(float x, float y, float z, float w) {
{
return y;
}
@Override
public float getZ()
{
return z;
}
@Override
public float getW()
{
return w;
}
@Override
public Quaternion set(float x, float y, float z, float w)
{
this.x = x; this.x = x;
this.y = y; this.y = y;
this.z = z; this.z = z;
@ -88,28 +65,15 @@ public class QuaternionMutable implements Quaternion
} }
@Override @Override
public Quaternion copy() public Quaternion copy() { return Quaternion.mutable(this); }
{ @Override
return Quaternion.mutable(this); public boolean isMutable() { return true; }
} @Override
public int hashCode() { return Arrays.hashCode(new float[] {x, y, z, w}); }
@Override @Override
public boolean isMutable() public boolean equals(Object obj) {
{ if(obj instanceof Quaternion) {
return true;
}
@Override
public int hashCode()
{
return Arrays.hashCode(new float[]{x,y,z,w});
}
@Override
public boolean equals(Object obj)
{
if(obj instanceof Quaternion)
{
Quaternion other = (Quaternion)obj; Quaternion other = (Quaternion)obj;
return other.getX() == x && other.getY() == y && other.getZ() == z && other.getW() == w; return other.getX() == x && other.getY() == y && other.getZ() == z && other.getW() == w;
} }
@ -117,8 +81,5 @@ public class QuaternionMutable implements Quaternion
} }
@Override @Override
public String toString() public String toString() { return "Quaternion[x="+x+", y="+y+", z="+z+", w="+w+"]"; }
{
return "Quaternion[x="+x+", y="+y+", z="+z+", w="+w+"]";
}
} }

View File

@ -10,153 +10,128 @@ import speiger.src.coreengine.math.vector.floats.Vec2f;
import speiger.src.coreengine.math.vector.ints.Vec2i; import speiger.src.coreengine.math.vector.ints.Vec2i;
import speiger.src.coreengine.math.vector.longs.Vec2l; import speiger.src.coreengine.math.vector.longs.Vec2l;
public interface Vec2s extends Vecs public interface Vec2s extends Vecs {
{
public static final Vec2s ZERO = of(); public static final Vec2s ZERO = of();
public static final Vec2s MINUS_ONE = of((short)-1); public static final Vec2s MINUS_ONE = of((short)-1);
public static final Vec2s ONE = of((short)1); public static final Vec2s ONE = of((short)1);
public static Vec2s mutable(){return new Vec2sMutable();} public static Vec2s mutable() { return new Vec2sMutable(); }
public static Vec2s mutable(short value){return new Vec2sMutable(value);} public static Vec2s mutable(short value) { return new Vec2sMutable(value); }
public static Vec2s mutable(short x, short y){return new Vec2sMutable(x, y);} public static Vec2s mutable(short x, short y) { return new Vec2sMutable(x, y); }
public static Vec2s mutable(Vec2s value){return mutable(value.getX(), value.getY());} public static Vec2s mutable(Vec2s value) { return mutable(value.getX(), value.getY()); }
public static Vec2s of() { return new Vec2sImmutable(); }
public static Vec2s of(){return new Vec2sImmutable();} public static Vec2s of(short value) { return new Vec2sImmutable(value); }
public static Vec2s of(short value){return new Vec2sImmutable(value);} public static Vec2s of(short x, short y) { return new Vec2sImmutable(x, y); }
public static Vec2s of(short x, short y){return new Vec2sImmutable(x, y);} public static Vec2s of(Vec2s value) { return of(value.getX(), value.getY()); }
public static Vec2s of(Vec2s value){return of(value.getX(), value.getY());}
public short getX(); public short getX();
public short getY(); public short getY();
public Vec2s setX(short x); public Vec2s setX(short x);
public Vec2s setY(short y); public Vec2s setY(short y);
@Override @Override
public default short[] asArray(){return new short[]{getX(), getY()};} public default short[] asArray() { return new short[] {getX(), getY()}; }
@Override @Override
public Vec2s copy(); public Vec2s copy();
@Override @Override
public default Vec2s abs(){return set((short)Math.abs(getX()), (short)Math.abs(getY()));} public default Vec2s abs() { return set((short)Math.abs(getX()), (short)Math.abs(getY())); }
@Override @Override
public default Vec2s negate(){return set((short)0, (short)0);} public default Vec2s negate() { return set((short)0, (short)0); }
@Override @Override
public default Vec2s invert(){return set((short)(-getX()), (short)(-getY()));}; public default Vec2s invert() { return set((short)(-getX()), (short)(-getY())); };
@Override @Override
public default Vec2s add(short value) {return add(value, value);} public default Vec2s add(short value) { return add(value, value); }
public default Vec2s add(Vec2s value) {return add(value.getX(), value.getY());} public default Vec2s add(Vec2s value) { return add(value.getX(), value.getY()); }
public default Vec2s add(short x, short y) {return set((short)(x + getX()), (short)(y + getY()));} public default Vec2s add(short x, short y) { return set((short)(x + getX()), (short)(y + getY())); }
@Override @Override
public default Vec2s sub(short value){return sub(value, value);} public default Vec2s sub(short value) { return sub(value, value); }
public default Vec2s sub(Vec2s value){return sub(value.getX(), value.getY());} public default Vec2s sub(Vec2s value) { return sub(value.getX(), value.getY()); }
public default Vec2s sub(short x, short y) {return set((short)(getX() - x), (short)(getY() - y));} public default Vec2s sub(short x, short y) { return set((short)(getX() - x), (short)(getY() - y)); }
@Override @Override
public default Vec2s multiply(short value){return multiply(value, value);} public default Vec2s multiply(short value) { return multiply(value, value); }
public default Vec2s multiply(Vec2s value){return multiply(value.getX(), value.getY());} public default Vec2s multiply(Vec2s value) { return multiply(value.getX(), value.getY()); }
public default Vec2s multiply(short x, short y) {return set((short)(x * getX()), (short)(y * getY()));} public default Vec2s multiply(short x, short y) { return set((short)(x * getX()), (short)(y * getY())); }
@Override @Override
public default Vec2s devide(short value){return devide(value, value);} public default Vec2s devide(short value) { return devide(value, value); }
public default Vec2s devide(Vec2s value){return devide(value.getX(), value.getY());} public default Vec2s devide(Vec2s value) { return devide(value.getX(), value.getY()); }
public default Vec2s devide(short x, short y){return set((short)(getX() / x), (short)(getY() / y));} public default Vec2s devide(short x, short y) { return set((short)(getX() / x), (short)(getY() / y)); }
@Override @Override
public default Vec2s set(short value){return set(value, value);}; public default Vec2s set(short value) { return set(value, value); };
public default Vec2s set(Vec2s value){return set(value.getX(), value.getY());} public default Vec2s set(Vec2s value) { return set(value.getX(), value.getY()); }
public Vec2s set(short x, short y); public Vec2s set(short x, short y);
public default double distanceTo(Vec2s value) { return distanceTo(value.getX(), value.getY()); }
public default double distanceTo(Vec2s value){return distanceTo(value.getX(), value.getY());} public default double distanceTo(short x, short y) { return Math.sqrt(distanceToSquared(x, y)); }
public default double distanceTo(short x, short y){return Math.sqrt(distanceToSquared(x, y));} public default long distanceToSquared(Vec2s value) { return distanceToSquared(value.getX(), value.getY()); }
public default long distanceToSquared(short x, short y) {
public default long distanceToSquared(Vec2s value){return distanceToSquared(value.getX(), value.getY());}
public default long distanceToSquared(short x, short y)
{
long xPos = getX() - x; long xPos = getX() - x;
long yPos = getY() - y; long yPos = getY() - y;
return (xPos * xPos) + (yPos * yPos); return (xPos * xPos) + (yPos * yPos);
} }
@Override @Override
public default long lengthSquared() {return (getX() * getX()) + (getY() * getY());} public default long lengthSquared() { return (getX() * getX()) + (getY() * getY()); }
public default long dotProduct(Vec2s value) { return dotProduct(value.getX(), value.getY()); }
public default long dotProduct(Vec2s value){return dotProduct(value.getX(), value.getY());} public default long dotProduct(short x, short y) { return (getX() * x) + (getY() * y); }
public default long dotProduct(short x, short y){return (getX() * x) + (getY() * y);} public default Vec2s rotate(short angle, Vec2s center) { return rotate(angle, center.getX(), center.getY()); }
public default Vec2s rotate(short angle, short x, short y) {
public default Vec2s rotate(short angle, Vec2s center){return rotate(angle, center.getX(), center.getY());}
public default Vec2s rotate(short angle, short x, short y)
{
short xPos = (short)(getX() - x); short xPos = (short)(getX() - x);
short yPos = (short)(getY() - y); short yPos = (short)(getY() - y);
double cos = MathUtils.cos(angle); double cos = MathUtils.cos(angle);
double sin = MathUtils.sin(angle); double sin = MathUtils.sin(angle);
return set((short)((xPos * cos) + (yPos * sin) + x), (short)(-(xPos * sin) + (yPos * cos) + y)); return set((short)((xPos * cos) + (yPos * sin) + x), (short)(-(xPos * sin) + (yPos * cos) + y));
} }
public default Vec2s min(Vec2s other) {return min(other, this);} public default Vec2s min(Vec2s other) { return min(other, this); }
public default Vec2s min(Vec2s other, Vec2s result){return min(other.getX(), other.getY(), result);} public default Vec2s min(Vec2s other, Vec2s result) { return min(other.getX(), other.getY(), result); }
public default Vec2s min(short x, short y) {return min(x, y, this);} public default Vec2s min(short x, short y) { return min(x, y, this); }
public default Vec2s min(short x, short y, Vec2s result){return result.set((short)Math.min(getX(), x), (short)Math.min(getY(), y));} public default Vec2s min(short x, short y, Vec2s result) { return result.set((short)Math.min(getX(), x), (short)Math.min(getY(), y)); }
public default Vec2s max(Vec2s other) { return max(other, this); }
public default Vec2s max(Vec2s other) {return max(other, this);} public default Vec2s max(Vec2s other, Vec2s result) { return max(other.getX(), other.getY(), result); }
public default Vec2s max(Vec2s other, Vec2s result){return max(other.getX(), other.getY(), result);} public default Vec2s max(short x, short y) { return max(x, y, this); }
public default Vec2s max(short x, short y) {return max(x, y, this);} public default Vec2s max(short x, short y, Vec2s result) { return result.set((short)Math.max(getX(), x), (short)Math.max(getY(), y)); }
public default Vec2s max(short x, short y, Vec2s result){return result.set((short)Math.max(getX(), x), (short)Math.max(getY(), y));} public default Vec2s difference(Vec2s other) { return difference(other, this); }
public default Vec2s difference(Vec2s other, Vec2s result) { return difference(other.getX(), other.getY(), result); }
public default Vec2s difference(Vec2s other) {return difference(other, this);} public default Vec2s difference(short x, short y) { return difference(x, y, this); }
public default Vec2s difference(Vec2s other, Vec2s result){return difference(other.getX(), other.getY(), result);} public default Vec2s difference(short x, short y, Vec2s result) { return result.set((short)(getX() - x), (short)(getY() - y)); }
public default Vec2s difference(short x, short y) {return difference(x, y, this);}
public default Vec2s difference(short x, short y, Vec2s result){return result.set((short)(getX() - x), (short)(getY() - y));}
@Override @Override
public default Vec2s clamp(short min, short max){return clamp(min, max, ALL);} public default Vec2s clamp(short min, short max) { return clamp(min, max, ALL); }
public default Vec2s clamp(short min, short max, Vec2s result){return clamp(min, max, result, ALL);} public default Vec2s clamp(short min, short max, Vec2s result) { return clamp(min, max, result, ALL); }
@Override @Override
public default Vec2s clamp(short min, short max, int filter){return clamp(min, max, this, filter);} public default Vec2s clamp(short min, short max, int filter) { return clamp(min, max, this, filter); }
public default Vec2s clamp(short min, short max, Vec2s result, int filter){ return result.set((filter & X) == 0 ? getX() : MathUtils.clamp(min, max, getX()), (filter & Y) == 0 ? getY() : MathUtils.clamp(min, max, getY()));} public default Vec2s clamp(short min, short max, Vec2s result, int filter) { return result.set((filter & X) == 0 ? getX() : MathUtils.clamp(min, max, getX()), (filter & Y) == 0 ? getY() : MathUtils.clamp(min, max, getY())); }
@Override @Override
public default Vec2s store(ByteBuffer buffer) public default Vec2s store(ByteBuffer buffer) {
{
buffer.putShort(getX()).putShort(getY()); buffer.putShort(getX()).putShort(getY());
return this; return this;
} }
@Override @Override
public default Vec2s load(ByteBuffer buffer) public default Vec2s load(ByteBuffer buffer) { return set(buffer.getShort(), buffer.getShort()); }
{
return set(buffer.getShort(), buffer.getShort());
}
@Override @Override
public default Vec2s store(ShortBuffer buffer) public default Vec2s store(ShortBuffer buffer) {
{
buffer.put(getX()).put(getY()); buffer.put(getX()).put(getY());
return this; return this;
} }
@Override @Override
public default Vec2s load(ShortBuffer buffer) public default Vec2s load(ShortBuffer buffer) { return set(buffer.get(), buffer.get()); }
{
return set(buffer.get(), buffer.get());
}
@Override @Override
public default Vec2b asByte(){return isMutable() ? Vec2b.mutable((byte)getX(), (byte)getY()) : Vec2b.of((byte)getX(), (byte)getY());} public default Vec2b asByte() { return isMutable() ? Vec2b.mutable((byte)getX(), (byte)getY()) : Vec2b.of((byte)getX(), (byte)getY()); }
@Override @Override
public default Vec2i asInt(){return isMutable() ? Vec2i.mutable(getX(), getY()) : Vec2i.of(getX(), getY());} public default Vec2i asInt() { return isMutable() ? Vec2i.mutable(getX(), getY()) : Vec2i.of(getX(), getY()); }
@Override @Override
public default Vec2l asLong(){return isMutable() ? Vec2l.mutable(getX(), getY()) : Vec2l.of(getX(), getY());} public default Vec2l asLong() { return isMutable() ? Vec2l.mutable(getX(), getY()) : Vec2l.of(getX(), getY()); }
@Override @Override
public default Vec2f asFloat() {return isMutable() ? Vec2f.mutable(getX(), getY()) : Vec2f.of(getX(), getY());} public default Vec2f asFloat() { return isMutable() ? Vec2f.mutable(getX(), getY()) : Vec2f.of(getX(), getY()); }
@Override @Override
public default Vec2d asDouble(){return isMutable() ? Vec2d.mutable(getX(), getY()) : Vec2d.of(getX(), getY());} public default Vec2d asDouble() { return isMutable() ? Vec2d.mutable(getX(), getY()) : Vec2d.of(getX(), getY()); }
@Override @Override
public default Vec2s asMutable(){return isMutable() ? this : of(this);} public default Vec2s asMutable() { return isMutable() ? this : of(this); }
@Override @Override
public default Vec2s asImmutable(){return isMutable() ? mutable(this) : this;} public default Vec2s asImmutable() { return isMutable() ? mutable(this) : this; }
@Override @Override
public default Vec2s copyAsMutable(){return mutable(this);} public default Vec2s copyAsMutable() { return mutable(this); }
@Override @Override
public default Vec2s copyAsImmutable(){return of(this);} public default Vec2s copyAsImmutable() { return of(this); }
} }

View File

@ -2,91 +2,51 @@ package speiger.src.coreengine.math.vector.shorts;
import java.util.Objects; import java.util.Objects;
public class Vec2sImmutable implements Vec2s public class Vec2sImmutable implements Vec2s {
{
final short x; final short x;
final short y; final short y;
public Vec2sImmutable() public Vec2sImmutable() {
{
x = 0; x = 0;
y = 0; y = 0;
} }
public Vec2sImmutable(short value) public Vec2sImmutable(short value) {
{
x = value; x = value;
y = value; y = value;
} }
public Vec2sImmutable(short x, short y) public Vec2sImmutable(short x, short y) {
{
this.x = x; this.x = x;
this.y = y; this.y = y;
} }
@Override
public boolean isMutable()
{
return false;
}
@Override @Override
public short getX() public boolean isMutable() { return false; }
{ @Override
return x; public short getX() { return x; }
} @Override
public short getY() { return y; }
@Override
public Vec2s setX(short x) { return this.x == x ? this : Vec2s.of(x, y); }
@Override
public Vec2s setY(short y) { return this.y == y ? this : Vec2s.of(x, y); }
@Override
public Vec2s copy() { return Vec2s.of(this); }
@Override
public Vec2s set(short x, short y) { return this.x == x && this.y == y ? this : Vec2s.of(x, y); }
@Override
public int hashCode() { return Objects.hash(x, y); }
@Override @Override
public short getY() public boolean equals(Object obj) {
{ if(obj instanceof Vec2s) {
return y;
}
@Override
public Vec2s setX(short x)
{
return this.x == x ? this : Vec2s.of(x, y);
}
@Override
public Vec2s setY(short y)
{
return this.y == y ? this : Vec2s.of(x, y);
}
@Override
public Vec2s copy()
{
return Vec2s.of(this);
}
@Override
public Vec2s set(short x, short y)
{
return this.x == x && this.y == y ? this : Vec2s.of(x, y);
}
@Override
public int hashCode()
{
return Objects.hash(x, y);
}
@Override
public boolean equals(Object obj)
{
if(obj instanceof Vec2s)
{
Vec2s vec = (Vec2s)obj; Vec2s vec = (Vec2s)obj;
return vec.getX() == x && vec.getY() == y; return vec.getX() == x && vec.getY() == y;
} }
return false; return false;
} }
@Override @Override
public String toString() public String toString() { return "Vec2s[x="+x+", y="+y+"]"; }
{
return "Vec2s[x="+x+", y="+y+"]";
}
} }

View File

@ -2,93 +2,63 @@ package speiger.src.coreengine.math.vector.shorts;
import java.util.Objects; import java.util.Objects;
public class Vec2sMutable implements Vec2s public class Vec2sMutable implements Vec2s {
{
short x; short x;
short y; short y;
public Vec2sMutable() public Vec2sMutable() {}
{
}
public Vec2sMutable(short value) public Vec2sMutable(short value) {
{
x = value; x = value;
y = value; y = value;
} }
public Vec2sMutable(short x, short y) public Vec2sMutable(short x, short y) {
{
this.x = x; this.x = x;
this.y = y; this.y = y;
} }
@Override
public boolean isMutable()
{
return true;
}
@Override @Override
public short getX() public boolean isMutable() { return true; }
{ @Override
return x; public short getX() { return x; }
} @Override
public short getY() { return y; }
@Override @Override
public short getY() public Vec2s setX(short x) {
{
return y;
}
@Override
public Vec2s setX(short x)
{
this.x = x; this.x = x;
return this; return this;
} }
@Override @Override
public Vec2s setY(short y) public Vec2s setY(short y) {
{
this.y = y; this.y = y;
return this; return this;
} }
@Override @Override
public Vec2s copy() public Vec2s copy() { return Vec2s.mutable(this); }
{
return Vec2s.mutable(this);
}
@Override @Override
public Vec2s set(short x, short y) public Vec2s set(short x, short y) {
{
this.x = x; this.x = x;
this.y = y; this.y = y;
return this; return this;
} }
@Override @Override
public int hashCode() public int hashCode() { return Objects.hash(x, y); }
{
return Objects.hash(x, y);
}
@Override @Override
public boolean equals(Object obj) public boolean equals(Object obj) {
{ if(obj instanceof Vec2s) {
if(obj instanceof Vec2s)
{
Vec2s vec = (Vec2s)obj; Vec2s vec = (Vec2s)obj;
return vec.getX() == x && vec.getY() == y; return vec.getX() == x && vec.getY() == y;
} }
return false; return false;
} }
@Override @Override
public String toString() public String toString() { return "Vec2s[x="+x+", y="+y+"]"; }
{
return "Vec2s[x="+x+", y="+y+"]";
}
} }

View File

@ -10,21 +10,19 @@ import speiger.src.coreengine.math.vector.floats.Vec3f;
import speiger.src.coreengine.math.vector.ints.Vec3i; import speiger.src.coreengine.math.vector.ints.Vec3i;
import speiger.src.coreengine.math.vector.longs.Vec3l; import speiger.src.coreengine.math.vector.longs.Vec3l;
public interface Vec3s extends Vecs public interface Vec3s extends Vecs {
{
public static final Vec3s ZERO = of(); public static final Vec3s ZERO = of();
public static final Vec3s MINUS_ONE = of((short)-1); public static final Vec3s MINUS_ONE = of((short)-1);
public static final Vec3s ONE = of((short)1); public static final Vec3s ONE = of((short)1);
public static Vec3s mutable(){return new Vec3sMutable();} public static Vec3s mutable() { return new Vec3sMutable(); }
public static Vec3s mutable(short value){return new Vec3sMutable(value);} public static Vec3s mutable(short value) { return new Vec3sMutable(value); }
public static Vec3s mutable(short x, short y, short z){return new Vec3sMutable(x, y, z);} public static Vec3s mutable(short x, short y, short z) { return new Vec3sMutable(x, y, z); }
public static Vec3s mutable(Vec3s vec){return mutable(vec.getX(), vec.getY(), vec.getZ());} public static Vec3s mutable(Vec3s vec) { return mutable(vec.getX(), vec.getY(), vec.getZ()); }
public static Vec3s of() { return new Vec3sImmutable(); }
public static Vec3s of(){return new Vec3sImmutable();} public static Vec3s of(short value) { return new Vec3sImmutable(value); }
public static Vec3s of(short value){return new Vec3sImmutable(value);} public static Vec3s of(short x, short y, short z) { return new Vec3sImmutable(x, y, z); }
public static Vec3s of(short x, short y, short z){return new Vec3sImmutable(x, y, z);} public static Vec3s of(Vec3s vec) { return of(vec.getX(), vec.getY(), vec.getZ()); }
public static Vec3s of(Vec3s vec){return of(vec.getX(), vec.getY(), vec.getZ());}
public short getX(); public short getX();
public short getY(); public short getY();
@ -32,125 +30,103 @@ public interface Vec3s extends Vecs
public Vec3s setX(short x); public Vec3s setX(short x);
public Vec3s setY(short y); public Vec3s setY(short y);
public Vec3s setZ(short z); public Vec3s setZ(short z);
@Override
public default short[] asArray(){return new short[]{getX(), getY(), getZ()};}
@Override
public default short[] asArray() { return new short[] {getX(), getY(), getZ()}; }
@Override @Override
public Vec3s copy(); public Vec3s copy();
@Override @Override
public default Vec3s abs(){return set((short)Math.abs(getX()), (short)Math.abs(getY()), (short)Math.abs(getZ()));} public default Vec3s abs() { return set((short)Math.abs(getX()), (short)Math.abs(getY()), (short)Math.abs(getZ())); }
@Override @Override
public default Vec3s negate(){return set((short)0, (short)0, (short)0);} public default Vec3s negate() { return set((short)0, (short)0, (short)0); }
@Override @Override
public default Vec3s invert(){return set((short)-getX(), (short)-getY(), (short)-getZ());} public default Vec3s invert() { return set((short)-getX(), (short)-getY(), (short)-getZ()); }
@Override @Override
public default Vec3s add(short value){return add(value, value, value);} public default Vec3s add(short value) { return add(value, value, value); }
public default Vec3s add(Vec3s value){return add(value.getX(), value.getY(), value.getZ());} public default Vec3s add(Vec3s value) { return add(value.getX(), value.getY(), value.getZ()); }
public default Vec3s add(short x, short y, short z){return set((short)(getX() + x), (short)(getY() + y), (short)(getZ() + z));} public default Vec3s add(short x, short y, short z) { return set((short)(getX() + x), (short)(getY() + y), (short)(getZ() + z)); }
@Override @Override
public default Vec3s sub(short value){return sub(value, value, value);} public default Vec3s sub(short value) { return sub(value, value, value); }
public default Vec3s sub(Vec3s value){return sub(value.getX(), value.getY(), value.getZ());} public default Vec3s sub(Vec3s value) { return sub(value.getX(), value.getY(), value.getZ()); }
public default Vec3s sub(short x, short y, short z){return set((short)(getX() - x), (short)(getY() - y), (short)(getZ() - z));} public default Vec3s sub(short x, short y, short z) { return set((short)(getX() - x), (short)(getY() - y), (short)(getZ() - z)); }
@Override @Override
public default Vec3s multiply(short value){return multiply(value, value, value);} public default Vec3s multiply(short value) { return multiply(value, value, value); }
public default Vec3s multiply(Vec3s value){return multiply(value.getX(), value.getY(), value.getZ());} public default Vec3s multiply(Vec3s value) { return multiply(value.getX(), value.getY(), value.getZ()); }
public default Vec3s multiply(short x, short y, short z){return set((short)(getX() * x), (short)(getY() * y), (short)(getZ() * z));} public default Vec3s multiply(short x, short y, short z) { return set((short)(getX() * x), (short)(getY() * y), (short)(getZ() * z)); }
@Override @Override
public default Vec3s devide(short value){return devide(value, value, value);} public default Vec3s devide(short value) { return devide(value, value, value); }
public default Vec3s devide(Vec3s value){return devide(value.getX(), value.getY(), value.getZ());} public default Vec3s devide(Vec3s value) { return devide(value.getX(), value.getY(), value.getZ()); }
public default Vec3s devide(short x, short y, short z){return set((short)(getX() / x), (short)(getY() / y), (short)(getZ() / z));} public default Vec3s devide(short x, short y, short z) { return set((short)(getX() / x), (short)(getY() / y), (short)(getZ() / z)); }
@Override @Override
public default Vec3s set(short value){return set(value, value, value);} public default Vec3s set(short value) { return set(value, value, value); }
public default Vec3s set(Vec3s value){return set(value.getX(), value.getY(), value.getZ());} public default Vec3s set(Vec3s value) { return set(value.getX(), value.getY(), value.getZ()); }
public Vec3s set(short x, short y, short z); public Vec3s set(short x, short y, short z);
public default double distanceTo(Vec3s value) { return distanceTo(value.getX(), value.getY(), value.getZ()); }
public default double distanceTo(Vec3s value){return distanceTo(value.getX(), value.getY(), value.getZ());} public default double distanceTo(short x, short y, short z) { return Math.sqrt(distanceToSquared(x, y, z)); }
public default double distanceTo(short x, short y, short z){return Math.sqrt(distanceToSquared(x, y, z));} public default long distanceToSquared(Vec3s value) { return distanceToSquared(value.getX(), value.getY(), value.getZ()); }
public default long distanceToSquared(short x, short y, short z) {
public default long distanceToSquared(Vec3s value){return distanceToSquared(value.getX(), value.getY(), value.getZ());}
public default long distanceToSquared(short x, short y, short z)
{
long xPos = getX() - x; long xPos = getX() - x;
long yPos = getY() - y; long yPos = getY() - y;
long zPos = getZ() - z; long zPos = getZ() - z;
return (xPos * xPos) + (yPos * yPos) + (zPos * zPos); return (xPos * xPos) + (yPos * yPos) + (zPos * zPos);
} }
@Override
public default long lengthSquared() {return (getX() * getX()) + (getY() * getY()) + (getZ() * getZ());}
public default long dotProduct(Vec3s value){return dotProduct(value.getX(), value.getY(), value.getZ());}
public default long dotProduct(short x, short y, short z){return (getX() * x) + (getY() * y) + (getZ() * z);}
public default Vec3s min(Vec3s other) {return min(other, this);}
public default Vec3s min(Vec3s other, Vec3s result){return min(other.getX(), other.getY(), other.getZ(), result);}
public default Vec3s min(short x, short y, short z) {return min(x, y, z, this);}
public default Vec3s min(short x, short y, short z, Vec3s result){return result.set((short)Math.min(getX(), x), (short)Math.min(getY(), y), (short)Math.min(getZ(), z));}
public default Vec3s max(Vec3s other) {return max(other, this);}
public default Vec3s max(Vec3s other, Vec3s result){return max(other.getX(), other.getY(), other.getZ(), result);}
public default Vec3s max(short x, short y, short z) {return max(x, y, z, this);}
public default Vec3s max(short x, short y, short z, Vec3s result){return result.set((short)Math.max(getX(), x), (short)Math.max(getY(), y), (short)Math.max(getZ(), z));}
public default Vec3s difference(Vec3s other) {return difference(other, this);}
public default Vec3s difference(Vec3s other, Vec3s result){return difference(other.getX(), other.getY(), other.getZ(), result);}
public default Vec3s difference(short x, short y, short z) {return difference(x, y, z, this);}
public default Vec3s difference(short x, short y, short z, Vec3s result){return result.set((short)(getX() - x), (short)(getY() - y), (short)(getZ() - z));}
@Override @Override
public default Vec3s clamp(short min, short max){return clamp(min, max, ALL);} public default long lengthSquared() { return (getX() * getX()) + (getY() * getY()) + (getZ() * getZ()); }
public default Vec3s clamp(short min, short max, Vec3s result){return clamp(min, max, result, ALL);} public default long dotProduct(Vec3s value) { return dotProduct(value.getX(), value.getY(), value.getZ()); }
public default long dotProduct(short x, short y, short z) { return (getX() * x) + (getY() * y) + (getZ() * z); }
public default Vec3s min(Vec3s other) { return min(other, this); }
public default Vec3s min(Vec3s other, Vec3s result) { return min(other.getX(), other.getY(), other.getZ(), result); }
public default Vec3s min(short x, short y, short z) { return min(x, y, z, this); }
public default Vec3s min(short x, short y, short z, Vec3s result) { return result.set((short)Math.min(getX(), x), (short)Math.min(getY(), y), (short)Math.min(getZ(), z)); }
public default Vec3s max(Vec3s other) { return max(other, this); }
public default Vec3s max(Vec3s other, Vec3s result) { return max(other.getX(), other.getY(), other.getZ(), result); }
public default Vec3s max(short x, short y, short z) { return max(x, y, z, this); }
public default Vec3s max(short x, short y, short z, Vec3s result) { return result.set((short)Math.max(getX(), x), (short)Math.max(getY(), y), (short)Math.max(getZ(), z)); }
public default Vec3s difference(Vec3s other) { return difference(other, this); }
public default Vec3s difference(Vec3s other, Vec3s result) { return difference(other.getX(), other.getY(), other.getZ(), result); }
public default Vec3s difference(short x, short y, short z) { return difference(x, y, z, this); }
public default Vec3s difference(short x, short y, short z, Vec3s result) { return result.set((short)(getX() - x), (short)(getY() - y), (short)(getZ() - z)); }
@Override @Override
public default Vec3s clamp(short min, short max, int filter){return clamp(min, max, this, filter);} public default Vec3s clamp(short min, short max) { return clamp(min, max, ALL); }
public default Vec3s clamp(short min, short max, Vec3s result, int filter){ return result.set((filter & X) == 0 ? getX() : MathUtils.clamp(min, max, getX()), (filter & Y) == 0 ? getY() : MathUtils.clamp(min, max, getY()), (filter & Z) == 0 ? getZ() : MathUtils.clamp(min, max, getZ()));} public default Vec3s clamp(short min, short max, Vec3s result) { return clamp(min, max, result, ALL); }
@Override
public default Vec3s clamp(short min, short max, int filter) { return clamp(min, max, this, filter); }
public default Vec3s clamp(short min, short max, Vec3s result, int filter) { return result.set((filter & X) == 0 ? getX() : MathUtils.clamp(min, max, getX()), (filter & Y) == 0 ? getY() : MathUtils.clamp(min, max, getY()), (filter & Z) == 0 ? getZ() : MathUtils.clamp(min, max, getZ())); }
@Override @Override
public default Vec3s store(ByteBuffer buffer) public default Vec3s store(ByteBuffer buffer) {
{
buffer.putShort(getX()).putShort(getY()).putShort(getZ()); buffer.putShort(getX()).putShort(getY()).putShort(getZ());
return this; return this;
} }
@Override @Override
public default Vec3s load(ByteBuffer buffer) public default Vec3s load(ByteBuffer buffer) { return set(buffer.getShort(), buffer.getShort(), buffer.getShort()); }
{
return set(buffer.getShort(), buffer.getShort(), buffer.getShort());
}
@Override @Override
public default Vec3s store(ShortBuffer buffer) public default Vec3s store(ShortBuffer buffer) {
{
buffer.put(getX()).put(getY()).put(getZ()); buffer.put(getX()).put(getY()).put(getZ());
return this; return this;
} }
@Override @Override
public default Vec3s load(ShortBuffer buffer) public default Vec3s load(ShortBuffer buffer) { return set(buffer.get(), buffer.get(), buffer.get()); }
{
return set(buffer.get(), buffer.get(), buffer.get());
}
@Override @Override
public default Vec3b asByte(){return isMutable() ? Vec3b.mutable((byte)getX(), (byte)getY(), (byte)getZ()) : Vec3b.of((byte)getX(), (byte)getY(), (byte)getZ());} public default Vec3b asByte() { return isMutable() ? Vec3b.mutable((byte)getX(), (byte)getY(), (byte)getZ()) : Vec3b.of((byte)getX(), (byte)getY(), (byte)getZ()); }
@Override @Override
public default Vec3i asInt(){return isMutable() ? Vec3i.mutable(getX(), getY(), getZ()) : Vec3i.of(getX(), getY(), getZ());} public default Vec3i asInt() { return isMutable() ? Vec3i.mutable(getX(), getY(), getZ()) : Vec3i.of(getX(), getY(), getZ()); }
@Override @Override
public default Vec3l asLong(){return isMutable() ? Vec3l.mutable(getX(), getY(), getZ()) : Vec3l.of(getX(), getY(), getZ());} public default Vec3l asLong() { return isMutable() ? Vec3l.mutable(getX(), getY(), getZ()) : Vec3l.of(getX(), getY(), getZ()); }
@Override @Override
public default Vec3f asFloat() {return isMutable() ? Vec3f.mutable(getX(), getY(), getZ()) : Vec3f.of(getX(), getY(), getZ());} public default Vec3f asFloat() { return isMutable() ? Vec3f.mutable(getX(), getY(), getZ()) : Vec3f.of(getX(), getY(), getZ()); }
@Override @Override
public default Vec3d asDouble(){return isMutable() ? Vec3d.mutable(getX(), getY(), getZ()) : Vec3d.of(getX(), getY(), getZ());} public default Vec3d asDouble() { return isMutable() ? Vec3d.mutable(getX(), getY(), getZ()) : Vec3d.of(getX(), getY(), getZ()); }
@Override @Override
public default Vec3s asMutable(){return isMutable() ? this : of(this);} public default Vec3s asMutable() { return isMutable() ? this : of(this); }
@Override @Override
public default Vec3s asImmutable(){return isMutable() ? mutable(this) : this;} public default Vec3s asImmutable() { return isMutable() ? mutable(this) : this; }
@Override @Override
public default Vec3s copyAsMutable(){return mutable(this);} public default Vec3s copyAsMutable() { return mutable(this); }
@Override @Override
public default Vec3s copyAsImmutable(){return of(this);} public default Vec3s copyAsImmutable() { return of(this); }
} }

View File

@ -2,107 +2,59 @@ package speiger.src.coreengine.math.vector.shorts;
import java.util.Objects; import java.util.Objects;
public class Vec3sImmutable implements Vec3s public class Vec3sImmutable implements Vec3s {
{
final short x; final short x;
final short y; final short y;
final short z; final short z;
public Vec3sImmutable() public Vec3sImmutable() {
{
x = 0; x = 0;
y = 0; y = 0;
z = 0; z = 0;
} }
public Vec3sImmutable(short value) public Vec3sImmutable(short value) {
{
x = value; x = value;
y = value; y = value;
z = value; z = value;
} }
public Vec3sImmutable(short x, short y, short z) public Vec3sImmutable(short x, short y, short z) {
{
this.x = x; this.x = x;
this.y = y; this.y = y;
this.z = z; this.z = z;
} }
@Override
public boolean isMutable()
{
return false;
}
@Override @Override
public short getX() public boolean isMutable() { return false; }
{ @Override
return x; public short getX() { return x; }
} @Override
public short getY() { return y; }
@Override
public short getZ() { return z; }
@Override
public Vec3s setX(short x) { return this.x == x ? this : Vec3s.of(x, y, z); }
@Override
public Vec3s setY(short y) { return this.y == y ? this : Vec3s.of(x, y, z); }
@Override
public Vec3s setZ(short z) { return this.z == z ? this : Vec3s.of(x, y, z); }
@Override
public Vec3s copy() { return Vec3s.of(this); }
@Override
public Vec3s set(short x, short y, short z) { return this.x == x && this.y == y && this.z == z ? this : Vec3s.of(x, y, z); }
@Override
public int hashCode() { return Objects.hash(x, y, z); }
@Override @Override
public short getY() public boolean equals(Object obj) {
{ if(obj instanceof Vec3s) {
return y;
}
@Override
public short getZ()
{
return z;
}
@Override
public Vec3s setX(short x)
{
return this.x == x ? this : Vec3s.of(x, y, z);
}
@Override
public Vec3s setY(short y)
{
return this.y == y ? this : Vec3s.of(x, y, z);
}
@Override
public Vec3s setZ(short z)
{
return this.z == z ? this : Vec3s.of(x, y, z);
}
@Override
public Vec3s copy()
{
return Vec3s.of(this);
}
@Override
public Vec3s set(short x, short y, short z)
{
return this.x == x && this.y == y && this.z == z ? this : Vec3s.of(x, y, z);
}
@Override
public int hashCode()
{
return Objects.hash(x, y, z);
}
@Override
public boolean equals(Object obj)
{
if(obj instanceof Vec3s)
{
Vec3s vec = (Vec3s)obj; Vec3s vec = (Vec3s)obj;
return vec.getX() == x && vec.getY() == y && vec.getZ() == z; return vec.getX() == x && vec.getY() == y && vec.getZ() == z;
} }
return false; return false;
} }
@Override @Override
public String toString() public String toString() { return "Vec3s[x="+x+", y="+y+", z="+z+"]"; }
{
return "Vec3s[x="+x+", y="+y+", z="+z+"]";
}
} }

View File

@ -2,84 +2,57 @@ package speiger.src.coreengine.math.vector.shorts;
import java.util.Objects; import java.util.Objects;
public class Vec3sMutable implements Vec3s public class Vec3sMutable implements Vec3s {
{
short x; short x;
short y; short y;
short z; short z;
public Vec3sMutable() public Vec3sMutable() {}
{
}
public Vec3sMutable(short value) public Vec3sMutable(short value) {
{
x = value; x = value;
y = value; y = value;
z = value; z = value;
} }
public Vec3sMutable(short x, short y, short z) public Vec3sMutable(short x, short y, short z) {
{
this.x = x; this.x = x;
this.y = y; this.y = y;
this.z = z; this.z = z;
} }
@Override
public boolean isMutable()
{
return true;
}
@Override @Override
public short getX() public boolean isMutable() { return true; }
{ @Override
return x; public short getX() { return x; }
} @Override
public short getY() { return y; }
@Override
public short getZ() { return z; }
@Override @Override
public short getY() public Vec3s setX(short x) {
{
return y;
}
@Override
public short getZ()
{
return z;
}
@Override
public Vec3s setX(short x)
{
this.x = x; this.x = x;
return this; return this;
} }
@Override @Override
public Vec3s setY(short y) public Vec3s setY(short y) {
{
this.y = y; this.y = y;
return this; return this;
} }
@Override @Override
public Vec3s setZ(short z) public Vec3s setZ(short z) {
{
this.z = z; this.z = z;
return this; return this;
} }
@Override @Override
public Vec3s copy() public Vec3s copy() { return Vec3s.mutable(this); }
{
return Vec3s.mutable(this);
}
@Override @Override
public Vec3s set(short x, short y, short z) public Vec3s set(short x, short y, short z) {
{
this.x = x; this.x = x;
this.y = y; this.y = y;
this.z = z; this.z = z;
@ -87,25 +60,17 @@ public class Vec3sMutable implements Vec3s
} }
@Override @Override
public int hashCode() public int hashCode() { return Objects.hash(x, y, z); }
{
return Objects.hash(x, y, z);
}
@Override @Override
public boolean equals(Object obj) public boolean equals(Object obj) {
{ if(obj instanceof Vec3s) {
if(obj instanceof Vec3s)
{
Vec3s vec = (Vec3s)obj; Vec3s vec = (Vec3s)obj;
return vec.getX() == x && vec.getY() == y && vec.getZ() == z; return vec.getX() == x && vec.getY() == y && vec.getZ() == z;
} }
return false; return false;
} }
@Override @Override
public String toString() public String toString() { return "Vec3s[x="+x+", y="+y+", z="+z+"]"; }
{
return "Vec3s[x="+x+", y="+y+", z="+z+"]";
}
} }

View File

@ -10,21 +10,19 @@ import speiger.src.coreengine.math.vector.floats.Vec4f;
import speiger.src.coreengine.math.vector.ints.Vec4i; import speiger.src.coreengine.math.vector.ints.Vec4i;
import speiger.src.coreengine.math.vector.longs.Vec4l; import speiger.src.coreengine.math.vector.longs.Vec4l;
public interface Vec4s extends Vecs public interface Vec4s extends Vecs {
{
public static final Vec4s ZERO = of(); public static final Vec4s ZERO = of();
public static final Vec4s MINUS_ONE = of((short)-1); public static final Vec4s MINUS_ONE = of((short)-1);
public static final Vec4s ONE = of((short)1); public static final Vec4s ONE = of((short)1);
public static Vec4s mutable(){return new Vec4sMutable();} public static Vec4s mutable() { return new Vec4sMutable(); }
public static Vec4s mutable(short value){return new Vec4sMutable(value);} public static Vec4s mutable(short value) { return new Vec4sMutable(value); }
public static Vec4s mutable(short x, short y, short z, short w){return new Vec4sMutable(x, y, z, w);} public static Vec4s mutable(short x, short y, short z, short w) { return new Vec4sMutable(x, y, z, w); }
public static Vec4s mutable(Vec4s vec){return mutable(vec.getX(), vec.getY(), vec.getZ(), vec.getW());} public static Vec4s mutable(Vec4s vec) { return mutable(vec.getX(), vec.getY(), vec.getZ(), vec.getW()); }
public static Vec4s of() { return new Vec4sImmutable(); }
public static Vec4s of(){return new Vec4sImmutable();} public static Vec4s of(short value) { return new Vec4sImmutable(value); }
public static Vec4s of(short value){return new Vec4sImmutable(value);} public static Vec4s of(short x, short y, short z, short w) { return new Vec4sImmutable(x, y, z, w); }
public static Vec4s of(short x, short y, short z, short w){return new Vec4sImmutable(x, y, z, w);} public static Vec4s of(Vec4s vec) { return of(vec.getX(), vec.getY(), vec.getZ(), vec.getW()); }
public static Vec4s of(Vec4s vec){return of(vec.getX(), vec.getY(), vec.getZ(), vec.getW());}
public short getX(); public short getX();
public short getY(); public short getY();
@ -34,126 +32,104 @@ public interface Vec4s extends Vecs
public Vec4s setY(short y); public Vec4s setY(short y);
public Vec4s setZ(short z); public Vec4s setZ(short z);
public Vec4s setW(short w); public Vec4s setW(short w);
@Override @Override
public default short[] asArray(){return new short[]{getX(), getY(), getZ(), getW()};} public default short[] asArray() { return new short[] {getX(), getY(), getZ(), getW()}; }
@Override @Override
public Vec4s copy(); public Vec4s copy();
@Override @Override
public default Vec4s abs(){return set((short)Math.abs(getX()), (short)Math.abs(getY()), (short)Math.abs(getZ()), (short)Math.abs(getW()));} public default Vec4s abs() { return set((short)Math.abs(getX()), (short)Math.abs(getY()), (short)Math.abs(getZ()), (short)Math.abs(getW())); }
@Override @Override
public default Vec4s negate(){return set((short)0, (short)0, (short)0, (short)0);} public default Vec4s negate() { return set((short)0, (short)0, (short)0, (short)0); }
@Override @Override
public default Vec4s invert(){return set((short)-getX(), (short)-getY(), (short)-getZ(), (short)-getW());} public default Vec4s invert() { return set((short)-getX(), (short)-getY(), (short)-getZ(), (short)-getW()); }
@Override @Override
public default Vec4s add(short value){return add(value, value, value, value);} public default Vec4s add(short value) { return add(value, value, value, value); }
public default Vec4s add(Vec4s value){return add(value.getX(), value.getY(), value.getZ(), value.getW());} public default Vec4s add(Vec4s value) { return add(value.getX(), value.getY(), value.getZ(), value.getW()); }
public default Vec4s add(short x, short y, short z, short w){return set((short)(getX() + x), (short)(getY() + y), (short)(getZ() + z), (short)(getW() + w));} public default Vec4s add(short x, short y, short z, short w) { return set((short)(getX() + x), (short)(getY() + y), (short)(getZ() + z), (short)(getW() + w)); }
@Override @Override
public default Vec4s sub(short value){return sub(value, value, value, value);} public default Vec4s sub(short value) { return sub(value, value, value, value); }
public default Vec4s sub(Vec4s value){return sub(value.getX(), value.getY(), value.getZ(), value.getW());} public default Vec4s sub(Vec4s value) { return sub(value.getX(), value.getY(), value.getZ(), value.getW()); }
public default Vec4s sub(short x, short y, short z, short w){return set((short)(getX() - x), (short)(getY() - y), (short)(getZ() - z), (short)(getW() - w));} public default Vec4s sub(short x, short y, short z, short w) { return set((short)(getX() - x), (short)(getY() - y), (short)(getZ() - z), (short)(getW() - w)); }
@Override @Override
public default Vec4s multiply(short value){return multiply(value, value, value, value);} public default Vec4s multiply(short value) { return multiply(value, value, value, value); }
public default Vec4s multiply(Vec4s value){return multiply(value.getX(), value.getY(), value.getZ(), value.getW());} public default Vec4s multiply(Vec4s value) { return multiply(value.getX(), value.getY(), value.getZ(), value.getW()); }
public default Vec4s multiply(short x, short y, short z, short w){return set((short)(getX() * x), (short)(getY() * y), (short)(getZ() * z), (short)(getW() * w));} public default Vec4s multiply(short x, short y, short z, short w) { return set((short)(getX() * x), (short)(getY() * y), (short)(getZ() * z), (short)(getW() * w)); }
@Override @Override
public default Vec4s devide(short value){return devide(value, value, value, value);} public default Vec4s devide(short value) { return devide(value, value, value, value); }
public default Vec4s devide(Vec4s value){return devide(value.getX(), value.getY(), value.getZ(), value.getW());} public default Vec4s devide(Vec4s value) { return devide(value.getX(), value.getY(), value.getZ(), value.getW()); }
public default Vec4s devide(short x, short y, short z, short w){return set((short)(getX() / x), (short)(getY() / y), (short)(getZ() / z), (short)(getW() / w));} public default Vec4s devide(short x, short y, short z, short w) { return set((short)(getX() / x), (short)(getY() / y), (short)(getZ() / z), (short)(getW() / w)); }
@Override @Override
public default Vec4s set(short value){return set(value, value, value, value);} public default Vec4s set(short value) { return set(value, value, value, value); }
public default Vec4s set(Vec4s value){return set(value.getX(), value.getY(), value.getZ(), value.getW());} public default Vec4s set(Vec4s value) { return set(value.getX(), value.getY(), value.getZ(), value.getW()); }
public Vec4s set(short x, short y, short z, short w); public Vec4s set(short x, short y, short z, short w);
public default double distanceTo(Vec4s value) { return distanceTo(value.getX(), value.getY(), value.getZ(), value.getW()); }
public default double distanceTo(Vec4s value){return distanceTo(value.getX(), value.getY(), value.getZ(), value.getW());} public default double distanceTo(short x, short y, short z, short w) { return Math.sqrt(distanceTo(x, y, z, w)); }
public default double distanceTo(short x, short y, short z, short w){return Math.sqrt(distanceTo(x, y, z, w));} public default long distanceToSquared(Vec4s value) { return distanceToSquared(value.getX(), value.getY(), value.getZ(), value.getW()); }
public default long distanceToSquared(short x, short y, short z, short w) {
public default long distanceToSquared(Vec4s value){return distanceToSquared(value.getX(), value.getY(), value.getZ(), value.getW());}
public default long distanceToSquared(short x, short y, short z, short w)
{
long xPos = getX() - x; long xPos = getX() - x;
long yPos = getY() - y; long yPos = getY() - y;
long zPos = getZ() - z; long zPos = getZ() - z;
long wPos = getW() - w; long wPos = getW() - w;
return (xPos * xPos) + (yPos * yPos) + (zPos * zPos) + (wPos * wPos); return (xPos * xPos) + (yPos * yPos) + (zPos * zPos) + (wPos * wPos);
} }
@Override
public default long lengthSquared() {return (getX() * getX()) + (getY() * getY()) + (getZ() * getZ()) + (getW() * getW());}
public default long dotProduct(Vec4s value){return dotProduct(value.getX(), value.getY(), value.getZ(), value.getW());}
public default long dotProduct(short x, short y, short z, short w){return (getX() * x) + (getY() * y) + (getZ() * z) + (getW() * w);};
public default Vec4s min(Vec4s other) {return min(other, this);}
public default Vec4s min(Vec4s other, Vec4s result){return min(other.getX(), other.getY(), other.getZ(), other.getW(), result);}
public default Vec4s min(short x, short y, short z, short w) {return min(x, y, z, w, this);}
public default Vec4s min(short x, short y, short z, short w, Vec4s result){return result.set((short)Math.min(getX(), x), (short)Math.min(getY(), y), (short)Math.min(getZ(), z), (short)Math.min(getW(), w));}
public default Vec4s max(Vec4s other) {return max(other, this);}
public default Vec4s max(Vec4s other, Vec4s result){return max(other.getX(), other.getY(), other.getZ(), other.getW(), result);}
public default Vec4s max(short x, short y, short z, short w) {return max(x, y, z, w, this);}
public default Vec4s max(short x, short y, short z, short w, Vec4s result){return result.set((short)Math.max(getX(), x), (short)Math.max(getY(), y), (short)Math.max(getZ(), z), (short)Math.max(getZ(), z));}
public default Vec4s difference(Vec4s other) {return difference(other, this);}
public default Vec4s difference(Vec4s other, Vec4s result){return difference(other.getX(), other.getY(), other.getZ(), other.getW(), result);}
public default Vec4s difference(short x, short y, short z, short w) {return difference(x, y, z, w, this);}
public default Vec4s difference(short x, short y, short z, short w, Vec4s result){return result.set((short)(getX() - x), (short)(getY() - y), (short)(getZ() - z), (short)(getW() - w));}
@Override @Override
public default Vec4s clamp(short min, short max){return clamp(min, max, ALL);} public default long lengthSquared() { return (getX() * getX()) + (getY() * getY()) + (getZ() * getZ()) + (getW() * getW()); }
public default Vec4s clamp(short min, short max, Vec4s result){return clamp(min, max, result, ALL);} public default long dotProduct(Vec4s value) { return dotProduct(value.getX(), value.getY(), value.getZ(), value.getW()); }
public default long dotProduct(short x, short y, short z, short w) { return (getX() * x) + (getY() * y) + (getZ() * z) + (getW() * w); };
public default Vec4s min(Vec4s other) { return min(other, this); }
public default Vec4s min(Vec4s other, Vec4s result) { return min(other.getX(), other.getY(), other.getZ(), other.getW(), result); }
public default Vec4s min(short x, short y, short z, short w) { return min(x, y, z, w, this); }
public default Vec4s min(short x, short y, short z, short w, Vec4s result) { return result.set((short)Math.min(getX(), x), (short)Math.min(getY(), y), (short)Math.min(getZ(), z), (short)Math.min(getW(), w)); }
public default Vec4s max(Vec4s other) { return max(other, this); }
public default Vec4s max(Vec4s other, Vec4s result) { return max(other.getX(), other.getY(), other.getZ(), other.getW(), result); }
public default Vec4s max(short x, short y, short z, short w) { return max(x, y, z, w, this); }
public default Vec4s max(short x, short y, short z, short w, Vec4s result) { return result.set((short)Math.max(getX(), x), (short)Math.max(getY(), y), (short)Math.max(getZ(), z), (short)Math.max(getZ(), z)); }
public default Vec4s difference(Vec4s other) { return difference(other, this); }
public default Vec4s difference(Vec4s other, Vec4s result) { return difference(other.getX(), other.getY(), other.getZ(), other.getW(), result); }
public default Vec4s difference(short x, short y, short z, short w) { return difference(x, y, z, w, this); }
public default Vec4s difference(short x, short y, short z, short w, Vec4s result) { return result.set((short)(getX() - x), (short)(getY() - y), (short)(getZ() - z), (short)(getW() - w)); }
@Override @Override
public default Vec4s clamp(short min, short max, int filter){return clamp(min, max, this, filter);} public default Vec4s clamp(short min, short max) { return clamp(min, max, ALL); }
public default Vec4s clamp(short min, short max, Vec4s result, int filter){ return result.set((filter & X) == 0 ? getX() : MathUtils.clamp(min, max, getX()), (filter & Y) == 0 ? getY() : MathUtils.clamp(min, max, getY()), (filter & Z) == 0 ? getZ() : MathUtils.clamp(min, max, getZ()), (filter & W) == 0 ? getW() : MathUtils.clamp(min, max, getW()));} public default Vec4s clamp(short min, short max, Vec4s result) { return clamp(min, max, result, ALL); }
@Override
public default Vec4s clamp(short min, short max, int filter) { return clamp(min, max, this, filter); }
public default Vec4s clamp(short min, short max, Vec4s result, int filter) { return result.set((filter & X) == 0 ? getX() : MathUtils.clamp(min, max, getX()), (filter & Y) == 0 ? getY() : MathUtils.clamp(min, max, getY()), (filter & Z) == 0 ? getZ() : MathUtils.clamp(min, max, getZ()), (filter & W) == 0 ? getW() : MathUtils.clamp(min, max, getW())); }
@Override @Override
public default Vec4s store(ByteBuffer buffer) public default Vec4s store(ByteBuffer buffer) {
{
buffer.putShort(getX()).putShort(getY()).putShort(getZ()).putShort(getW()); buffer.putShort(getX()).putShort(getY()).putShort(getZ()).putShort(getW());
return this; return this;
} }
@Override @Override
public default Vec4s load(ByteBuffer buffer) public default Vec4s load(ByteBuffer buffer) { return set(buffer.getShort(), buffer.getShort(), buffer.getShort(), buffer.getShort()); }
{
return set(buffer.getShort(), buffer.getShort(), buffer.getShort(), buffer.getShort());
}
@Override @Override
public default Vec4s store(ShortBuffer buffer) public default Vec4s store(ShortBuffer buffer) {
{
buffer.put(getX()).put(getY()).put(getZ()).put(getW()); buffer.put(getX()).put(getY()).put(getZ()).put(getW());
return this; return this;
} }
@Override @Override
public default Vec4s load(ShortBuffer buffer) public default Vec4s load(ShortBuffer buffer) { return set(buffer.get(), buffer.get(), buffer.get(), buffer.get()); }
{
return set(buffer.get(), buffer.get(), buffer.get(), buffer.get());
}
@Override @Override
public default Vec4b asByte(){return isMutable() ? Vec4b.mutable((byte)getX(), (byte)getY(), (byte)getZ(), (byte)getW()) : Vec4b.of((byte)getX(), (byte)getY(), (byte)getZ(), (byte)getW());} public default Vec4b asByte() { return isMutable() ? Vec4b.mutable((byte)getX(), (byte)getY(), (byte)getZ(), (byte)getW()) : Vec4b.of((byte)getX(), (byte)getY(), (byte)getZ(), (byte)getW()); }
@Override @Override
public default Vec4i asInt(){return isMutable() ? Vec4i.mutable(getX(), getY(), getZ(), getW()) : Vec4i.of(getX(), getY(), getZ(), getW());} public default Vec4i asInt() { return isMutable() ? Vec4i.mutable(getX(), getY(), getZ(), getW()) : Vec4i.of(getX(), getY(), getZ(), getW()); }
@Override @Override
public default Vec4l asLong(){return isMutable() ? Vec4l.mutable(getX(), getY(), getZ(), getW()) : Vec4l.of(getX(), getY(), getZ(), getW());} public default Vec4l asLong() { return isMutable() ? Vec4l.mutable(getX(), getY(), getZ(), getW()) : Vec4l.of(getX(), getY(), getZ(), getW()); }
@Override @Override
public default Vec4f asFloat() {return isMutable() ? Vec4f.mutable(getX(), getY(), getZ(), getW()) : Vec4f.of(getX(), getY(), getZ(), getW());} public default Vec4f asFloat() { return isMutable() ? Vec4f.mutable(getX(), getY(), getZ(), getW()) : Vec4f.of(getX(), getY(), getZ(), getW()); }
@Override @Override
public default Vec4d asDouble(){return isMutable() ? Vec4d.mutable(getX(), getY(), getZ(), getW()) : Vec4d.of(getX(), getY(), getZ(), getW());} public default Vec4d asDouble() { return isMutable() ? Vec4d.mutable(getX(), getY(), getZ(), getW()) : Vec4d.of(getX(), getY(), getZ(), getW()); }
@Override @Override
public default Vec4s asMutable(){return isMutable() ? this : of(this);} public default Vec4s asMutable() { return isMutable() ? this : of(this); }
@Override @Override
public default Vec4s asImmutable(){return isMutable() ? mutable(this) : this;} public default Vec4s asImmutable() { return isMutable() ? mutable(this) : this; }
@Override @Override
public default Vec4s copyAsMutable(){return mutable(this);} public default Vec4s copyAsMutable() { return mutable(this); }
@Override @Override
public default Vec4s copyAsImmutable(){return of(this);} public default Vec4s copyAsImmutable() { return of(this); }
} }

View File

@ -2,114 +2,61 @@ package speiger.src.coreengine.math.vector.shorts;
import java.util.Objects; import java.util.Objects;
public class Vec4sImmutable implements Vec4s public class Vec4sImmutable implements Vec4s {
{
final short x; final short x;
final short y; final short y;
final short z; final short z;
final short w; final short w;
public Vec4sImmutable() public Vec4sImmutable() {
{
x = 0; x = 0;
y = 0; y = 0;
z = 0; z = 0;
w = 0; w = 0;
} }
public Vec4sImmutable(short value) public Vec4sImmutable(short value) {
{
x = value; x = value;
y = value; y = value;
z = value; z = value;
w = value; w = value;
} }
public Vec4sImmutable(short x, short y, short z, short w) public Vec4sImmutable(short x, short y, short z, short w) {
{
this.x = x; this.x = x;
this.y = y; this.y = y;
this.z = z; this.z = z;
this.w = w; this.w = w;
} }
@Override
public boolean isMutable()
{
return false;
}
@Override @Override
public short getX() public boolean isMutable() { return false; }
{ @Override
return x; public short getX() { return x; }
} @Override
public short getY() { return y; }
@Override
public short getZ() { return z; }
@Override
public short getW() { return w; }
@Override
public Vec4s setX(short x) { return this.x == x ? this : Vec4s.of(x, y, z, w); }
@Override
public Vec4s setY(short y) { return this.y == y ? this : Vec4s.of(x, y, z, w); }
@Override
public Vec4s setZ(short z) { return this.z == z ? this : Vec4s.of(x, y, z, w); }
@Override
public Vec4s setW(short w) { return this.w == w ? this : Vec4s.of(x, y, z, w); }
@Override
public Vec4s copy() { return Vec4s.of(this); }
@Override
public Vec4s set(short x, short y, short z, short w) { return this.x == x && this.y == y && this.z == z && this.w == w ? this : Vec4s.of(x, y, z, w); }
@Override
public int hashCode() { return Objects.hash(x, y, z, w); }
@Override @Override
public short getY() public boolean equals(Object obj) {
{ if(obj instanceof Vec4s) {
return y;
}
@Override
public short getZ()
{
return z;
}
@Override
public short getW()
{
return w;
}
@Override
public Vec4s setX(short x)
{
return this.x == x ? this : Vec4s.of(x, y, z, w);
}
@Override
public Vec4s setY(short y)
{
return this.y == y ? this : Vec4s.of(x, y, z, w);
}
@Override
public Vec4s setZ(short z)
{
return this.z == z ? this : Vec4s.of(x, y, z, w);
}
@Override
public Vec4s setW(short w)
{
return this.w == w ? this : Vec4s.of(x, y, z, w);
}
@Override
public Vec4s copy()
{
return Vec4s.of(this);
}
@Override
public Vec4s set(short x, short y, short z, short w)
{
return this.x == x && this.y == y && this.z == z && this.w == w ? this : Vec4s.of(x, y, z, w);
}
@Override
public int hashCode()
{
return Objects.hash(x, y, z, w);
}
@Override
public boolean equals(Object obj)
{
if(obj instanceof Vec4s)
{
Vec4s vec = (Vec4s)obj; Vec4s vec = (Vec4s)obj;
return vec.getX() == x && vec.getY() == y && vec.getZ() == z && vec.getW() == w; return vec.getX() == x && vec.getY() == y && vec.getZ() == z && vec.getW() == w;
} }
@ -117,8 +64,5 @@ public class Vec4sImmutable implements Vec4s
} }
@Override @Override
public String toString() public String toString() { return "Vec4s[x="+x+", y="+y+", z="+z+", w="+w+"]"; }
{
return "Vec4s[x="+x+", y="+y+", z="+z+", w="+w+"]";
}
} }

View File

@ -2,100 +2,68 @@ package speiger.src.coreengine.math.vector.shorts;
import java.util.Objects; import java.util.Objects;
public class Vec4sMutable implements Vec4s public class Vec4sMutable implements Vec4s {
{
short x; short x;
short y; short y;
short z; short z;
short w; short w;
public Vec4sMutable() public Vec4sMutable() {}
{
}
public Vec4sMutable(short value) public Vec4sMutable(short value) {
{
x = value; x = value;
y = value; y = value;
z = value; z = value;
w = value; w = value;
} }
public Vec4sMutable(short x, short y, short z, short w) public Vec4sMutable(short x, short y, short z, short w) {
{
this.x = x; this.x = x;
this.y = y; this.y = y;
this.z = z; this.z = z;
this.w = w; this.w = w;
} }
@Override
public boolean isMutable()
{
return true;
}
@Override @Override
public short getX() public boolean isMutable() { return true; }
{ @Override
return x; public short getX() { return x; }
} @Override
public short getY() { return y; }
@Override
public short getZ() { return z; }
@Override
public short getW() { return w; }
@Override @Override
public short getY() public Vec4s setX(short x) {
{
return y;
}
@Override
public short getZ()
{
return z;
}
@Override
public short getW()
{
return w;
}
@Override
public Vec4s setX(short x)
{
this.x = x; this.x = x;
return this; return this;
} }
@Override @Override
public Vec4s setY(short y) public Vec4s setY(short y) {
{
this.y = y; this.y = y;
return this; return this;
} }
@Override @Override
public Vec4s setZ(short z) public Vec4s setZ(short z) {
{
this.z = z; this.z = z;
return this; return this;
} }
@Override @Override
public Vec4s setW(short w) public Vec4s setW(short w) {
{
this.w = w; this.w = w;
return this; return this;
} }
@Override @Override
public Vec4s copy() public Vec4s copy() { return Vec4s.mutable(this); }
{
return Vec4s.mutable(this);
}
@Override @Override
public Vec4s set(short x, short y, short z, short w) public Vec4s set(short x, short y, short z, short w) {
{
this.x = x; this.x = x;
this.y = y; this.y = y;
this.z = z; this.z = z;
@ -104,16 +72,11 @@ public class Vec4sMutable implements Vec4s
} }
@Override @Override
public int hashCode() public int hashCode() { return Objects.hash(x, y, z, w); }
{
return Objects.hash(x, y, z, w);
}
@Override @Override
public boolean equals(Object obj) public boolean equals(Object obj) {
{ if(obj instanceof Vec4s) {
if(obj instanceof Vec4s)
{
Vec4s vec = (Vec4s)obj; Vec4s vec = (Vec4s)obj;
return vec.getX() == x && vec.getY() == y && vec.getZ() == z && vec.getW() == w; return vec.getX() == x && vec.getY() == y && vec.getZ() == z && vec.getW() == w;
} }
@ -121,8 +84,5 @@ public class Vec4sMutable implements Vec4s
} }
@Override @Override
public String toString() public String toString() { return "Vec4s[x="+x+", y="+y+", z="+z+", w="+w+"]"; }
{
return "Vec4s[x="+x+", y="+y+", z="+z+", w="+w+"]";
}
} }

View File

@ -9,8 +9,7 @@ import speiger.src.coreengine.math.vector.floats.Vecf;
import speiger.src.coreengine.math.vector.ints.Veci; import speiger.src.coreengine.math.vector.ints.Veci;
import speiger.src.coreengine.math.vector.longs.Vecl; import speiger.src.coreengine.math.vector.longs.Vecl;
public interface Vecs extends Vec public interface Vecs extends Vec {
{
public Vecs set(short value); public Vecs set(short value);
public Vecs add(short value); public Vecs add(short value);
public Vecs sub(short value); public Vecs sub(short value);
@ -18,14 +17,11 @@ public interface Vecs extends Vec
public Vecs devide(short value); public Vecs devide(short value);
public Vecs clamp(short min, short max); public Vecs clamp(short min, short max);
public Vecs clamp(short min, short max, int filter); public Vecs clamp(short min, short max, int filter);
public long lengthSquared(); public long lengthSquared();
public default double length(){return Math.sqrt(lengthSquared());} public default double length() { return Math.sqrt(lengthSquared()); }
public Vecs store(ShortBuffer buffer); public Vecs store(ShortBuffer buffer);
public Vecs load(ShortBuffer buffer); public Vecs load(ShortBuffer buffer);
public short[] asArray(); public short[] asArray();
public Vecb asByte(); public Vecb asByte();
public Veci asInt(); public Veci asInt();
public Vecl asLong(); public Vecl asLong();

View File

@ -167,40 +167,27 @@ public abstract class GuiBase
public final void onMouseEvent(MouseEvent evt) public final void onMouseEvent(MouseEvent evt)
{ {
if(evt instanceof MouseClickEvent) if(evt instanceof MouseClickEvent click)
{ {
MouseClickEvent click = (MouseClickEvent)evt; if(click.isPress()) {
if(click.press) pressedButtons.add(click.getButton());
{ if(onMousePressed(click.getButton(), evt.getX(), evt.getY()))
pressedButtons.add(click.button);
if(onMousePressed(click.button, evt.mouseX, evt.mouseY))
{
evt.cancel(); evt.cancel();
}
} }
else else
{ {
pressedButtons.remove(click.button); pressedButtons.remove(click.getButton());
if(onMouseReleased(click.button, evt.mouseX, evt.mouseY)) if(onMouseReleased(click.getButton(), evt.getX(), evt.getY()))
{
evt.cancel(); evt.cancel();
}
} }
} }
else if(evt instanceof MouseMoveEvent && pressedButtons.size() > 0) else if(evt instanceof MouseMoveEvent && pressedButtons.size() > 0) {
{ if(onMouseDragged(pressedButtons.getButtons(), evt.getX(), evt.getY(), pressedButtons))
if(onMouseDragged(pressedButtons.getButtons(), evt.mouseX, evt.mouseY, pressedButtons))
{
evt.cancel(); evt.cancel();
}
} }
else if(evt instanceof MouseScrollEvent) else if(evt instanceof MouseScrollEvent scroll) {
{ if(onMouseScroll(evt.getX(), evt.getY(), scroll.getScrollY()))
MouseScrollEvent scroll = (MouseScrollEvent)evt;
if(onMouseScroll(evt.mouseX, evt.mouseY, scroll.scrollY))
{
evt.cancel(); evt.cancel();
}
} }
} }

View File

@ -40,8 +40,8 @@ public abstract class GuiManager implements IWindowListener
this.window = window; this.window = window;
font = manager.loadFont(AssetLocation.of("font/roboto.json"), 18.5F); font = manager.loadFont(AssetLocation.of("font/roboto.json"), 18.5F);
bus.register(MouseEvent.class, this::onMouseEvent); bus.register(MouseEvent.class, this::onMouseEvent);
bus.register(KeyPressEvent.class, (T) -> T.setCanceled(onKeyPressed(T.key))); bus.register(KeyPressEvent.class, T -> T.setCanceled(onKeyPressed(T.key)));
bus.register(CharTypeEvent.class, (T) -> T.setCanceled(onCharTyped(T.character, T.codePoint))); bus.register(CharTypeEvent.class, T -> T.setCanceled(onCharTyped(T.character, T.codePoint)));
window.addListener(this, false); window.addListener(this, false);
debug = createOverlay(); debug = createOverlay();
activeGuis[1] = debug; activeGuis[1] = debug;

View File

@ -86,6 +86,7 @@ public class CheckBoxGroup<T extends GuiComponent & ICheckBox<T>> implements Con
} }
@Override @Override
@SuppressWarnings("unchecked")
public void accept(GuiComponent t) public void accept(GuiComponent t)
{ {
ICheckBox<T> box = t.tryCast(ICheckBox.class); ICheckBox<T> box = t.tryCast(ICheckBox.class);

View File

@ -6,7 +6,7 @@ import speiger.src.collections.objects.lists.ObjectArrayList;
public class GuiBox implements IGuiBox public class GuiBox implements IGuiBox
{ {
List<IGuiBox> children = new ObjectArrayList<IGuiBox>(); List<IGuiBox> children = new ObjectArrayList<>();
IGuiBox parent; IGuiBox parent;
float minX; float minX;
@ -25,54 +25,41 @@ public class GuiBox implements IGuiBox
float baseScale = 1F; float baseScale = 1F;
protected GuiBox() protected GuiBox() {}
{
}
public GuiBox(float x, float y, float width, float height) public GuiBox(float x, float y, float width, float height) {
{
set(x, y, width, height); set(x, y, width, height);
onChanged(); onChanged();
} }
public static IGuiBox createSimpleBox(float x, float y, float width, float height) public static IGuiBox createSimpleBox(float x, float y, float width, float height) {
{
return new GuiBox(x, y, width, height); return new GuiBox(x, y, width, height);
} }
public static IGuiBox createParentBox(IGuiBox box) public static IGuiBox createParentBox(IGuiBox box) {
{
return new GuiBox(box.getMinX(), box.getMinY(), box.getWidth(), box.getHeight()); return new GuiBox(box.getMinX(), box.getMinY(), box.getWidth(), box.getHeight());
} }
public static IGuiBox createParentBox(IGuiBox box, float padding) public static IGuiBox createParentBox(IGuiBox box, float padding) {
{ return new GuiBox(box.getMinX() + padding, box.getMinY() + padding, box.getWidth() - padding * 2F, box.getHeight() - padding * 2F);
return new GuiBox(box.getMinX() + padding, box.getMinY() + padding, box.getWidth() - (padding * 2F), box.getHeight() - (padding * 2F));
} }
@Override @Override
public IGuiBox addChild(IGuiBox box) public IGuiBox addChild(IGuiBox box) {
{
children.add(box); children.add(box);
box.setParent(this); box.setParent(this);
return this; return this;
} }
@Override @Override
public IGuiBox removeChild(IGuiBox box) public IGuiBox removeChild(IGuiBox box) {
{ if(children.remove(box)) box.setParent(null);
if(children.remove(box))
{
box.setParent(null);
}
return this; return this;
} }
@Override @Override
public IGuiBox clearChildren() public IGuiBox clearChildren() {
{ for(int i = 0,m=children.size();i<m;i++) {
for(int i = 0,m=children.size();i<m;i++)
{
children.get(i).setParent(null); children.get(i).setParent(null);
} }
children.clear(); children.clear();
@ -80,192 +67,96 @@ public class GuiBox implements IGuiBox
} }
@Override @Override
public IGuiBox onChanged() public IGuiBox onChanged() {
{ minX = parent == null ? baseX : parent.getMinX(baseX);
minX = (parent == null ? baseX : parent.getMinX(baseX)); minY = parent == null ? baseY : parent.getMinY(baseY);
minY = (parent == null ? baseY : parent.getMinY(baseY)); maxX = parent == null ? baseX + width : parent.getMinX(baseX + width);
maxX = (parent == null ? baseX + width : parent.getMinX(baseX + width)); maxY = parent == null ? baseY + height : parent.getMinY(baseY + height);
maxY = (parent == null ? baseY + height : parent.getMinY(baseY + height)); scale = parent == null ? baseScale : parent.getScale() * baseScale;
scale = (parent == null ? baseScale : parent.getScale() * baseScale); for(int i = 0,m=children.size();i<m;i++) {
for(int i = 0,m=children.size();i<m;i++)
{
children.get(i).onChanged(); children.get(i).onChanged();
} }
return this; return this;
} }
@Override @Override
public IGuiBox setParent(IGuiBox box) public IGuiBox setParent(IGuiBox box) {
{
parent = box; parent = box;
return this; return this;
} }
@Override @Override
public IGuiBox getParent() public IGuiBox getParent() { return parent; }
{
return parent;
}
@Override @Override
public float getScale() public float getScale() { return scale; }
{
return scale;
}
@Override @Override
public float getBaseX() public float getBaseX() { return baseX; }
{
return baseX;
}
@Override @Override
public float getBaseY() public float getBaseY() { return baseY; }
{
return baseY;
}
@Override @Override
public float getRelativeX() public float getRelativeX() { return parent != null ? baseX : 0F; }
{
return parent != null ? baseX : 0F;
}
@Override @Override
public float getRelativeY() public float getRelativeY() { return parent != null ? baseY : 0F; }
{
return parent != null ? baseY : 0F;
}
@Override @Override
public float getWidth() public float getWidth() { return baseWidth * scale; }
{
return baseWidth * scale;
}
@Override @Override
public float getWidth(float extra) public float getWidth(float extra) { return baseWidth * scale + extra * baseScale; }
{
return (baseWidth * scale) + (extra * baseScale);
}
@Override @Override
public float getHeight() public float getHeight() { return baseHeight * scale; }
{
return baseHeight * scale;
}
@Override @Override
public float getHeight(float extra) public float getHeight(float extra) { return baseHeight * scale + extra * baseScale; }
{
return (baseHeight * scale) + (extra * baseScale);
}
@Override @Override
public float getMinX() public float getMinX() { return minX; }
{
return minX;
}
@Override @Override
public float getMinX(float extra) public float getMinX(float extra) { return minX + extra * scale; }
{
return minX + (extra * scale);
}
@Override @Override
public float getMinY() public float getMinY() { return minY; }
{
return minY;
}
@Override @Override
public float getMinY(float extra) public float getMinY(float extra) { return minY + extra * scale; }
{
return minY + (extra * scale);
}
@Override @Override
public float getMaxX() public float getMaxX() { return maxX; }
{
return maxX;
}
@Override @Override
public float getMaxX(float extra) public float getMaxX(float extra) { return maxX + extra * scale; }
{
return maxX + (extra * scale);
}
@Override @Override
public float getMaxY() public float getMaxY() { return maxY; }
{
return maxY;
}
@Override @Override
public float getMaxY(float extra) public float getMaxY(float extra) { return maxY + extra * scale; }
{
return maxY + (extra * scale);
}
@Override @Override
public float getCenterX() public float getCenterX() { return minX + (maxX - minX) * 0.5F; }
{
return minX + ((maxX - minX) * 0.5F);
}
@Override @Override
public float getCenterX(float extra) public float getCenterX(float extra) { return minX + (maxX - minX) * 0.5F + extra * scale; }
{
return minX + ((maxX - minX) * 0.5F) + (extra * scale);
}
@Override @Override
public float getCenterY() public float getCenterY() { return minY + (maxY - minY) * 0.5F; }
{
return minY + ((maxY - minY) * 0.5F);
}
@Override @Override
public float getCenterY(float extra) public float getCenterY(float extra) { return minY + (maxY - minY) * 0.5F + extra * scale; }
{
return minY + ((maxY - minY) * 0.5F) + (extra * scale);
}
@Override @Override
public IGuiBox setX(float x) public IGuiBox setX(float x) {
{
baseX = x; baseX = x;
return this; return this;
} }
@Override @Override
public IGuiBox setY(float y) public IGuiBox setY(float y) {
{
baseY = y; baseY = y;
return this; return this;
} }
@Override @Override
public IGuiBox setWidth(float width) public IGuiBox setWidth(float width) {
{
baseWidth = width; baseWidth = width;
this.width = baseWidth * baseScale; this.width = baseWidth * baseScale;
return this; return this;
} }
@Override @Override
public IGuiBox setHeight(float height) public IGuiBox setHeight(float height) {
{
baseHeight = height; baseHeight = height;
this.height = baseHeight * baseScale; this.height = baseHeight * baseScale;
return this; return this;
} }
@Override @Override
public IGuiBox setScale(float scale) public IGuiBox setScale(float scale) {
{
baseScale = scale; baseScale = scale;
width = baseWidth * baseScale; width = baseWidth * baseScale;
height = baseHeight * baseScale; height = baseHeight * baseScale;
@ -273,44 +164,17 @@ public class GuiBox implements IGuiBox
} }
@Override @Override
public IGuiBox move(float xOffset, float yOffset) public IGuiBox move(float xOffset, float yOffset) { return setXY(baseX + xOffset, baseY + yOffset); }
{
return setXY(baseX + xOffset, baseY + yOffset);
}
@Override @Override
public IGuiBox grow(float xGrowth, float yGrowth) public IGuiBox grow(float xGrowth, float yGrowth) { return setBounds(baseWidth + xGrowth, baseHeight + yGrowth); }
{
return setBounds(baseWidth + xGrowth, baseHeight + yGrowth);
}
@Override @Override
public IGuiBox scale(float scale) public IGuiBox scale(float scale) { return setScale(scale * baseScale); }
{
return setScale(scale * baseScale);
}
@Override @Override
public float getBaseScale() public float getBaseScale() { return baseScale; }
{
return baseScale;
}
@Override @Override
public float getBaseWidth() public float getBaseWidth() { return baseWidth; }
{
return baseWidth;
}
@Override @Override
public float getBaseHeight() public float getBaseHeight() { return baseHeight; }
{
return baseHeight;
}
@Override @Override
public String toString() public String toString() { return "GuiBox[minX="+minX+", minY="+minY+", maxX="+maxX+", maxY="+maxY+", width="+width+", height="+height+"]"; }
{
return "GuiBox[minX="+minX+", minY="+minY+", maxX="+maxX+", maxY="+maxY+", width="+width+", height="+height+"]";
}
} }

View File

@ -26,13 +26,11 @@ public interface IGuiBox extends IScreenBox
public float getWidth(float extra); public float getWidth(float extra);
public float getHeight(); public float getHeight();
public float getHeight(float extra); public float getHeight(float extra);
public default float getSquaredWidth() public default float getSquaredWidth() {
{
float value = getWidth(); float value = getWidth();
return value * value; return value * value;
} }
public default float getSquaredHeight() public default float getSquaredHeight() {
{
float value = getHeight(); float value = getHeight();
return value * value; return value * value;
} }
@ -60,22 +58,18 @@ public interface IGuiBox extends IScreenBox
public IGuiBox grow(float xGrowth, float yGrowth); public IGuiBox grow(float xGrowth, float yGrowth);
public IGuiBox scale(float scale); public IGuiBox scale(float scale);
public default IGuiBox setXY(float x, float y){return setX(x).setY(y);} public default IGuiBox setXY(float x, float y) { return setX(x).setY(y); }
public default IGuiBox setXY(Vec2f pos){return setX(pos.getX()).setY(pos.getY());} public default IGuiBox setXY(Vec2f pos) { return setX(pos.getX()).setY(pos.getY()); }
public default IGuiBox setBounds(float width, float height){return setWidth(width).setHeight(height);} public default IGuiBox setBounds(float width, float height) { return setWidth(width).setHeight(height); }
public default IGuiBox setBounds(Vec2f bounds){return setWidth(bounds.getX()).setHeight(bounds.getY());} public default IGuiBox setBounds(Vec2f bounds) {return setWidth(bounds.getX()).setHeight(bounds.getY()); }
public default IGuiBox set(float x, float y, float width, float height){return setX(x).setY(y).setWidth(width).setHeight(height);} public default IGuiBox set(float x, float y, float width, float height) { return setX(x).setY(y).setWidth(width).setHeight(height); }
public default IGuiBox set(Vec4f vec){return setX(vec.getX()).setY(vec.getY()).setWidth(vec.getZ()).setHeight(vec.getW());} public default IGuiBox set(Vec4f vec) { return setX(vec.getX()).setY(vec.getY()).setWidth(vec.getZ()).setHeight(vec.getW()); }
public default boolean isColiding(float x, float y) public default boolean isColiding(float x, float y) { return getMinX() <= x && getMaxX() >= x && getMinY() <= y && getMaxY() >= y; }
{
return getMinX() <= x && getMaxX() >= x && getMinY() <= y && getMaxY() >= y;
}
public default FacingList getColidingBorder(float x, float y, float margin) public default FacingList getColidingBorder(float x, float y, float margin) {
{
margin *= getScale(); margin *= getScale();
float minX = getMinX(); float minX = getMinX();
float maxX = getMaxX(); float maxX = getMaxX();
@ -89,13 +83,12 @@ public interface IGuiBox extends IScreenBox
return list; return list;
} }
public default boolean isIntersecting(IGuiBox box){return isIntersecting(box.getMinX(), box.getMaxX(), box.getMinY(), box.getMaxY());} public default boolean isIntersecting(IGuiBox box) { return isIntersecting(box.getMinX(), box.getMaxX(), box.getMinY(), box.getMaxY()); }
public default boolean isIntersecting(float minX, float maxX, float minY, float maxY) public default boolean isIntersecting(float minX, float maxX, float minY, float maxY) {
{
float xMin = getMinX(); float xMin = getMinX();
float yMin = getMinY(); float yMin = getMinY();
float xMax = getMaxX(); float xMax = getMaxX();
float yMax = getMaxY(); float yMax = getMaxY();
return ((minX >= xMin && minX <= xMax) || (maxX >= xMin && maxX <= xMax)) && ((minY >= yMin && minY <= yMax) || (maxY >= yMin && maxY <= yMax)); return ((minX >= xMin && minX <= xMax) || (maxX >= xMin && maxX <= xMax)) && ((minY >= yMin && minY <= yMax) || (maxY >= yMin && maxY <= yMax));
} }
} }

View File

@ -3,19 +3,15 @@ package speiger.src.coreengine.rendering.gui.helper.box;
public interface IScreenBox public interface IScreenBox
{ {
public float getBaseScale(); public float getBaseScale();
public float getBaseWidth(); public float getBaseWidth();
public float getBaseHeight();
public default float getSquaredBaseWidth() public default float getSquaredBaseWidth() {
{
float value = getBaseWidth(); float value = getBaseWidth();
return value * value; return value * value;
} }
public float getBaseHeight(); public default float getSquaredBaseHeight() {
public default float getSquaredBaseHeight()
{
float value = getBaseWidth(); float value = getBaseWidth();
return value * value; return value * value;
} }

View File

@ -6,7 +6,7 @@ import speiger.src.collections.objects.lists.ObjectArrayList;
public class ParentBox implements IGuiBox public class ParentBox implements IGuiBox
{ {
List<IGuiBox> children = new ObjectArrayList<IGuiBox>(); List<IGuiBox> children = new ObjectArrayList<>();
IGuiBox parent; IGuiBox parent;
float minX; float minX;
@ -14,16 +14,14 @@ public class ParentBox implements IGuiBox
float maxX; float maxX;
float maxY; float maxY;
public ParentBox(float value) public ParentBox(float value) {
{
minX = value; minX = value;
minY = value; minY = value;
maxX = -value; maxX = -value;
maxY = -value; maxY = -value;
} }
public ParentBox(float paddingTop, float paddingLeft, float paddingBottom, float paddingRight) public ParentBox(float paddingTop, float paddingLeft, float paddingBottom, float paddingRight) {
{
minX = paddingLeft; minX = paddingLeft;
minY = paddingTop; minY = paddingTop;
maxX = paddingRight; maxX = paddingRight;
@ -31,28 +29,21 @@ public class ParentBox implements IGuiBox
} }
@Override @Override
public IGuiBox addChild(IGuiBox box) public IGuiBox addChild(IGuiBox box) {
{
children.add(box); children.add(box);
box.setParent(this); box.setParent(this);
return this; return this;
} }
@Override @Override
public IGuiBox removeChild(IGuiBox box) public IGuiBox removeChild(IGuiBox box) {
{ if(children.remove(box)) box.setParent(null);
if(children.remove(box))
{
box.setParent(null);
}
return this; return this;
} }
@Override @Override
public IGuiBox clearChildren() public IGuiBox clearChildren() {
{ for(int i = 0,m=children.size();i<m;i++) {
for(int i = 0,m=children.size();i<m;i++)
{
children.get(i).setParent(null); children.get(i).setParent(null);
} }
children.clear(); children.clear();
@ -60,217 +51,83 @@ public class ParentBox implements IGuiBox
} }
@Override @Override
public IGuiBox onChanged() public IGuiBox onChanged() {
{ for(int i = 0,m=children.size();i<m;i++) {
for(int i = 0,m=children.size();i<m;i++)
{
children.get(i).onChanged(); children.get(i).onChanged();
} }
return this; return this;
} }
@Override @Override
public IGuiBox setParent(IGuiBox box) public IGuiBox setParent(IGuiBox box) {
{
parent = box; parent = box;
return this; return this;
} }
@Override @Override
public IGuiBox getParent() public IGuiBox getParent() { return parent; }
{
return parent;
}
@Override @Override
public float getScale() public float getScale() { return parent.getScale(); }
{
return parent.getScale();
}
@Override @Override
public float getBaseX() public float getBaseX() { return minX + parent.getBaseX(); }
{
return minX + parent.getBaseX();
}
@Override @Override
public float getBaseY() public float getBaseY() { return minY + parent.getBaseY(); }
{
return minY + parent.getBaseY();
}
@Override @Override
public float getRelativeX() public float getRelativeX() { return minX + parent.getRelativeX(); }
{
return minX + parent.getRelativeX();
}
@Override @Override
public float getRelativeY() public float getRelativeY() { return minY + parent.getRelativeY(); }
{
return minY + parent.getRelativeY();
}
@Override @Override
public float getWidth() public float getWidth() { return parent.getWidth(maxX - minX); }
{
return parent.getWidth(maxX - minX);
}
@Override @Override
public float getWidth(float extra) public float getWidth(float extra) { return parent.getWidth((maxX - minX) + extra); }
{
return parent.getWidth((maxX - minX) + extra);
}
@Override @Override
public float getHeight() public float getHeight() { return parent.getHeight(maxY - minY); }
{
return parent.getHeight(maxY - minY);
}
@Override @Override
public float getHeight(float extra) public float getHeight(float extra) { return parent.getHeight((maxY - minY) + extra); }
{
return parent.getHeight((maxY - minY) + extra);
}
@Override @Override
public float getMinX() public float getMinX() { return parent.getMinX(minX); }
{
return parent.getMinX(minX);
}
@Override @Override
public float getMinX(float extra) public float getMinX(float extra) { return parent.getMinX(minX + extra); }
{
return parent.getMinX(minX + extra);
}
@Override @Override
public float getMinY() public float getMinY() { return parent.getMinY(minY); }
{
return parent.getMinY(minY);
}
@Override @Override
public float getMinY(float extra) public float getMinY(float extra) { return parent.getMinY(minY + extra); }
{
return parent.getMinY(minY + extra);
}
@Override @Override
public float getMaxX() public float getMaxX() { return parent.getMaxX(maxX); }
{
return parent.getMaxX(maxX);
}
@Override @Override
public float getMaxX(float extra) public float getMaxX(float extra) { return parent.getMaxX(maxX + extra); }
{
return parent.getMaxX(maxX + extra);
}
@Override @Override
public float getMaxY() public float getMaxY() { return parent.getMaxY(maxY); }
{
return parent.getMaxY(maxY);
}
@Override @Override
public float getMaxY(float extra) public float getMaxY(float extra) { return parent.getMaxY(maxY + extra); }
{
return parent.getMaxY(maxY + extra);
}
@Override @Override
public float getCenterX() public float getCenterX() { return parent.getCenterX((maxX - minX) * 0.5F); }
{
return parent.getCenterX((maxX - minX) * 0.5F);
}
@Override @Override
public float getCenterX(float extra) public float getCenterX(float extra) { return parent.getCenterX((maxX - minX) * 0.5F + extra); }
{
return parent.getCenterX(((maxX - minX) * 0.5F) + extra);
}
@Override @Override
public float getCenterY() public float getCenterY() { return parent.getCenterY((maxY - minY) * 0.5F); }
{
return parent.getCenterY((maxY - minY) * 0.5F);
}
@Override @Override
public float getCenterY(float extra) public float getCenterY(float extra) { return parent.getCenterY((maxY - minY) * 0.5F + extra); }
{
return parent.getCenterY(((maxY - minY) * 0.5F) + extra);
}
@Override @Override
public IGuiBox setX(float x) public IGuiBox setX(float x) { throw new UnsupportedOperationException(); }
{
throw new UnsupportedOperationException();
}
@Override @Override
public IGuiBox setY(float y) public IGuiBox setY(float y) { throw new UnsupportedOperationException(); }
{
throw new UnsupportedOperationException();
}
@Override @Override
public IGuiBox setWidth(float width) public IGuiBox setWidth(float width) { throw new UnsupportedOperationException(); }
{
throw new UnsupportedOperationException();
}
@Override @Override
public IGuiBox setHeight(float height) public IGuiBox setHeight(float height) { throw new UnsupportedOperationException(); }
{
throw new UnsupportedOperationException();
}
@Override @Override
public IGuiBox setScale(float scale) public IGuiBox setScale(float scale) { throw new UnsupportedOperationException(); }
{
throw new UnsupportedOperationException();
}
@Override @Override
public IGuiBox move(float xOffset, float yOffset) public IGuiBox move(float xOffset, float yOffset) { throw new UnsupportedOperationException(); }
{
throw new UnsupportedOperationException();
}
@Override @Override
public IGuiBox grow(float xGrowth, float yGrowth) public IGuiBox grow(float xGrowth, float yGrowth) { throw new UnsupportedOperationException(); }
{
throw new UnsupportedOperationException();
}
@Override @Override
public IGuiBox scale(float scale) public IGuiBox scale(float scale) { throw new UnsupportedOperationException(); }
{
throw new UnsupportedOperationException();
}
@Override @Override
public float getBaseScale() public float getBaseScale() { return 1F; }
{
return 1F;
}
@Override @Override
public float getBaseWidth() public float getBaseWidth() { return parent.getBaseWidth() + (maxX - minX); }
{
return parent.getBaseWidth() + (maxX - minX);
}
@Override @Override
public float getBaseHeight() public float getBaseHeight() { return parent.getBaseHeight() + (maxY - minY); }
{
return parent.getBaseHeight() + (maxY - minY);
}
} }

View File

@ -93,7 +93,7 @@ public class BitmapFontProvider implements IFontProvider
{ {
FontInfo info = new FontInfo(object.getAsJsonObject("info")); FontInfo info = new FontInfo(object.getAsJsonObject("info"));
float multiplier = info.setDesiredHeight(desiredSize); float multiplier = info.setDesiredHeight(desiredSize);
Int2ObjectMap<CharInstance>[] maps = new Int2ObjectMap[]{new Int2ObjectOpenHashMap<CharInstance>(), new Int2ObjectOpenHashMap<CharInstance>()}; Int2ObjectMap<CharInstance>[] maps = new Int2ObjectMap[]{new Int2ObjectOpenHashMap<>(), new Int2ObjectOpenHashMap<>()};
JsonUtil.iterate(object.get("chars"), T -> { JsonUtil.iterate(object.get("chars"), T -> {
CharInstance instance = info.create(T); CharInstance instance = info.create(T);
instance.scale(multiplier); instance.scale(multiplier);

View File

@ -1,6 +1,8 @@
package speiger.src.coreengine.rendering.input; package speiger.src.coreengine.rendering.input;
import java.io.File; import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.lwjgl.glfw.GLFW; import org.lwjgl.glfw.GLFW;
import org.lwjgl.glfw.GLFWDropCallback; import org.lwjgl.glfw.GLFWDropCallback;
@ -15,24 +17,19 @@ public class DropListener
EventBus bus; EventBus bus;
ScaledResolution resolution; ScaledResolution resolution;
public DropListener(Window window, EventBus bus) public DropListener(Window window, EventBus bus) {
{
window.addCallback(T -> GLFW.glfwSetDropCallback(T, this::onFileDropped)); window.addCallback(T -> GLFW.glfwSetDropCallback(T, this::onFileDropped));
resolution = window.getUIFrame(); resolution = window.getUIFrame();
this.bus = bus; this.bus = bus;
} }
public void onFileDropped(long windowId, int count, long names) public void onFileDropped(long windowId, int count, long names) {
{
int x = Mouse.getX(); int x = Mouse.getX();
int y = Mouse.getY(); int y = Mouse.getY();
for(int i = 0;i<count;i++) for(int i = 0;i<count;i++) {
{ Path file = Paths.get(GLFWDropCallback.getName(names, i));
File file = new File(GLFWDropCallback.getName(names, i)); if(Files.notExists(file)) continue;
if(file.exists()) bus.post(new FileDropEvent(file, windowId, x, y, resolution));
{
bus.post(new FileDropEvent(file, x, y, resolution));
}
} }
} }
} }

View File

@ -19,99 +19,76 @@ public class Keyboard
EventBus bus; EventBus bus;
BiPredicate<Integer, Keyboard> filter; BiPredicate<Integer, Keyboard> filter;
public void init(EventBus bus, Window window) public void init(EventBus bus, Window window) {
{
this.bus = bus; this.bus = bus;
window.addCallback(T -> GLFW.glfwSetKeyCallback(T, this::onKeyTyped)); window.addCallback(T -> GLFW.glfwSetKeyCallback(T, this::onKeyTyped));
window.addCallback(T -> GLFW.glfwSetCharCallback(T, this::onCharTyped)); window.addCallback(T -> GLFW.glfwSetCharCallback(T, this::onCharTyped));
} }
public static void setFilter(BiPredicate<Integer, Keyboard> filter) public static void setFilter(BiPredicate<Integer, Keyboard> filter) {
{
INSTANCE.filter = filter; INSTANCE.filter = filter;
} }
public static void clearFilter() public static void clearFilter() {
{
setFilter(null); setFilter(null);
} }
protected void onKeyTyped(long window, int key, int scancode, int action, int mods) protected void onKeyTyped(long window, int key, int scancode, int action, int mods) {
{ if(key > 350 || key < 0) return;
if(key > 350 || key < 0) if(action >= 1) {
{
return;
}
if(action >= 1)
{
pressedKeys[key] = true; pressedKeys[key] = true;
onKeyPressed(key); onKeyPressed(key);
} }
else else {
{
pressedKeys[key] = false; pressedKeys[key] = false;
nonConsumedKeys[key] = false; nonConsumedKeys[key] = false;
InputBinding.BINDINGS.updatePressing(BindingType.KEYBOARD, key, false); InputBinding.BINDINGS.updatePressing(BindingType.KEYBOARD, key, false);
} }
} }
public void onKeyPressed(int key) public void onKeyPressed(int key) {
{ if(filter == null || filter.test(key, this)) {
if(filter == null || filter.test(key, this))
{
KeyPressEvent event = new KeyPressEvent(key); KeyPressEvent event = new KeyPressEvent(key);
bus.post(event); bus.post(event);
if(event.isCanceled()) if(event.isCanceled()) return;
{
return;
}
nonConsumedKeys[key] = true; nonConsumedKeys[key] = true;
InputBinding.BINDINGS.updatePressing(BindingType.KEYBOARD, key, true); InputBinding.BINDINGS.updatePressing(BindingType.KEYBOARD, key, true);
} }
} }
public void onCharTyped(long windowId, int codepoint) public void onCharTyped(long windowId, int codepoint) {
{
bus.post(new CharTypeEvent((char)codepoint, codepoint)); bus.post(new CharTypeEvent((char)codepoint, codepoint));
} }
public static boolean isCtrlDown() public static boolean isCtrlDown() {
{
return isKeyPressed(GLFW.GLFW_KEY_LEFT_CONTROL) || isKeyPressed(GLFW.GLFW_KEY_RIGHT_CONTROL); return isKeyPressed(GLFW.GLFW_KEY_LEFT_CONTROL) || isKeyPressed(GLFW.GLFW_KEY_RIGHT_CONTROL);
} }
public static boolean isShiftDown() public static boolean isShiftDown() {
{
return isKeyPressed(GLFW.GLFW_KEY_LEFT_SHIFT) || isKeyPressed(GLFW.GLFW_KEY_RIGHT_SHIFT); return isKeyPressed(GLFW.GLFW_KEY_LEFT_SHIFT) || isKeyPressed(GLFW.GLFW_KEY_RIGHT_SHIFT);
} }
public static boolean isAltDown() public static boolean isAltDown() {
{
return isKeyPressed(GLFW.GLFW_KEY_LEFT_ALT) || isKeyPressed(GLFW.GLFW_KEY_RIGHT_ALT); return isKeyPressed(GLFW.GLFW_KEY_LEFT_ALT) || isKeyPressed(GLFW.GLFW_KEY_RIGHT_ALT);
} }
public static boolean isPrintableKey(int key) public static boolean isPrintableKey(int key) {
{
return key <= 162; return key <= 162;
} }
public static boolean isKeyFullyPressed(int key) public static boolean isKeyFullyPressed(int key) {
{
return INSTANCE.isPressed(key) && !INSTANCE.isConsumed(key); return INSTANCE.isPressed(key) && !INSTANCE.isConsumed(key);
} }
public static boolean isKeyPressed(int key) public static boolean isKeyPressed(int key) {
{
return INSTANCE.isPressed(key); return INSTANCE.isPressed(key);
} }
public boolean isPressed(int key) public boolean isPressed(int key) {
{
return pressedKeys[key]; return pressedKeys[key];
} }
public boolean isConsumed(int key) public boolean isConsumed(int key) {
{
return !nonConsumedKeys[key]; return !nonConsumedKeys[key];
} }
} }

View File

@ -31,30 +31,33 @@ public class Mouse
{ {
this.bus = bus; this.bus = bus;
ray = new MouseRay(cam, window); ray = new MouseRay(cam, window);
initSubWindow(window);
}
public void initSubWindow(Window window) {
window.addCallback(T -> GLFW.glfwSetCursorPosCallback(T, Mouse.this::onDrag)); window.addCallback(T -> GLFW.glfwSetCursorPosCallback(T, Mouse.this::onDrag));
window.addCallback(T -> GLFW.glfwSetMouseButtonCallback(T, Mouse.this::onClick)); window.addCallback(T -> GLFW.glfwSetMouseButtonCallback(T, Mouse.this::onClick));
window.addCallback(T -> GLFW.glfwSetScrollCallback(T, Mouse.this::onScroll)); window.addCallback(T -> GLFW.glfwSetScrollCallback(T, Mouse.this::onScroll));
window.addCallback(T -> GLFW.glfwSetCursorEnterCallback(T, (K, V) -> active = V)); window.addCallback(T -> GLFW.glfwSetCursorEnterCallback(T, (K, V) -> active = V));
} }
protected void onDrag(long window, double xpos, double ypos) protected void onDrag(long window, double xpos, double ypos) {
{
int xChange = (int)xpos - position.getX(); int xChange = (int)xpos - position.getX();
int yChange = (int)ypos - position.getY(); int yChange = (int)ypos - position.getY();
position.set((int)xpos, (int)ypos); position.set((int)xpos, (int)ypos);
pushEvent(new MouseMoveEvent(position.getX(), position.getY(), xChange, yChange)); pushEvent(new MouseMoveEvent(window, position.getX(), position.getY(), xChange, yChange));
} }
protected void onScroll(long window, double xScroll, double yScroll) protected void onScroll(long window, double xScroll, double yScroll)
{ {
pushEvent(new MouseScrollEvent(position.getX(), position.getY(), (int)xScroll, (int)yScroll)); pushEvent(new MouseScrollEvent(window, position.getX(), position.getY(), (int)xScroll, (int)yScroll));
} }
protected void onClick(long window, int button, int action, int mods) protected void onClick(long window, int button, int action, int mods)
{ {
if(action == 1) pressedButton.add(button); if(action == 1) pressedButton.add(button);
else pressedButton.remove(button); else pressedButton.remove(button);
pushEvent(new MouseClickEvent(position.getX(), position.getY(), button, action == 1)); pushEvent(new MouseClickEvent(window, position.getX(), position.getY(), button, action == 1));
} }
public static void update() public static void update()
@ -109,17 +112,17 @@ public class Mouse
if(event instanceof MouseMoveEvent) if(event instanceof MouseMoveEvent)
{ {
MouseMoveEvent move = (MouseMoveEvent)event; MouseMoveEvent move = (MouseMoveEvent)event;
movement.add(move.xMove, move.yMove); movement.add(move.getXMove(), move.getYMove());
} }
else if(event instanceof MouseClickEvent) else if(event instanceof MouseClickEvent)
{ {
MouseClickEvent click = (MouseClickEvent)event; MouseClickEvent click = (MouseClickEvent)event;
InputBinding.BINDINGS.updatePressing(BindingType.MOUSE, click.button, click.press); InputBinding.BINDINGS.updatePressing(BindingType.MOUSE, click.getButton(), click.isPress());
} }
else if(event instanceof MouseScrollEvent) else if(event instanceof MouseScrollEvent)
{ {
MouseScrollEvent scroll = (MouseScrollEvent)event; MouseScrollEvent scroll = (MouseScrollEvent)event;
this.scroll.add(scroll.scrollX, scroll.scrollY); this.scroll.add(scroll.getScrollX(), scroll.getScrollY());
} }
} }
} }

View File

@ -1,16 +1,16 @@
package speiger.src.coreengine.rendering.input.bindings; package speiger.src.coreengine.rendering.input.bindings;
import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
import org.lwjgl.glfw.GLFW; import org.lwjgl.glfw.GLFW;
import speiger.src.collections.objects.maps.interfaces.Object2ObjectMap;
import speiger.src.coreengine.rendering.input.Mouse; import speiger.src.coreengine.rendering.input.Mouse;
import speiger.src.coreengine.rendering.input.bindings.utils.BindingType; import speiger.src.coreengine.rendering.input.bindings.utils.BindingType;
public class Axis public class Axis
{ {
static final Map<String, Axis> AXIS_MAP = new LinkedHashMap<String, Axis>(); static final Map<String, Axis> AXIS_MAP = Object2ObjectMap.builder().linkedMap();
public static final IAxisSource MAIN_SCROLL_WEEL = new ScrollAxis(false); public static final IAxisSource MAIN_SCROLL_WEEL = new ScrollAxis(false);
public static final IAxisSource SECOND_SCROLL_WEEL = new ScrollAxis(true); public static final IAxisSource SECOND_SCROLL_WEEL = new ScrollAxis(true);
public static final Axis XMOVEMENT = new Axis("XMovement", BindingType.KEYBOARD, GLFW.GLFW_KEY_S, GLFW.GLFW_KEY_W); public static final Axis XMOVEMENT = new Axis("XMovement", BindingType.KEYBOARD, GLFW.GLFW_KEY_S, GLFW.GLFW_KEY_W);
@ -19,71 +19,52 @@ public class Axis
public static final Axis PITCH = new Axis("Pitch", BindingType.KEYBOARD, GLFW.GLFW_KEY_X, GLFW.GLFW_KEY_C); public static final Axis PITCH = new Axis("Pitch", BindingType.KEYBOARD, GLFW.GLFW_KEY_X, GLFW.GLFW_KEY_C);
public static final Axis ZOOM = new Axis("Zoom", MAIN_SCROLL_WEEL); public static final Axis ZOOM = new Axis("Zoom", MAIN_SCROLL_WEEL);
String name; String name;
IAxisSource source; IAxisSource source;
public Axis(String name) public Axis(String name) {
{
this(name, null); this(name, null);
} }
public Axis(String name, BindingType type, int pos, int neg) public Axis(String name, BindingType type, int pos, int neg) {
{
this(name, new KeySource(type, neg, pos)); this(name, new KeySource(type, neg, pos));
} }
public Axis(String id, IAxisSource provider) public Axis(String id, IAxisSource provider) {
{
name = id; name = id;
source = provider; source = provider;
AXIS_MAP.put(id, this); AXIS_MAP.put(id, this);
} }
public void setSource(BindingType type, int pos, int neg) public void setSource(BindingType type, int pos, int neg) {
{
setSource(new KeySource(type, neg, pos)); setSource(new KeySource(type, neg, pos));
} }
public void setSource(IAxisSource provider) public void setSource(IAxisSource provider) {
{
source = provider; source = provider;
} }
public static Axis getAxis(String name) public static Axis getAxis(String name) {
{
return AXIS_MAP.get(name); return AXIS_MAP.get(name);
} }
public IAxisSource getSource() public IAxisSource getSource() {
{
return source; return source;
} }
public float getValue() public float getValue() {
{ return source != null ? source.getValue() : 0F;
if(source != null)
{
return source.getValue();
}
return 0F;
} }
public String getName() public String getName() {
{
return name; return name;
} }
public static interface IAxisSource public static interface IAxisSource {
{
public float getValue(); public float getValue();
public boolean isButton(); public boolean isButton();
public String getButtonName(boolean first); public String getButtonName(boolean first);
public String getAxisName(); public String getAxisName();
public boolean isAlive(); public boolean isAlive();
} }
@ -91,83 +72,42 @@ public class Axis
{ {
boolean first; boolean first;
public ScrollAxis(boolean data) public ScrollAxis(boolean data) {
{
first = data; first = data;
} }
@Override @Override
public float getValue() public float getValue() { return first ? Mouse.INSTANCE.getScroll().getX() : Mouse.INSTANCE.getScroll().getY(); }
{
return first ? Mouse.INSTANCE.getScroll().getX() : Mouse.INSTANCE.getScroll().getY();
}
@Override @Override
public boolean isAlive() public boolean isAlive() { return true; }
{
return true;
}
@Override @Override
public boolean isButton() public boolean isButton() { return false; }
{
return false;
}
@Override @Override
public String getButtonName(boolean first) public String getButtonName(boolean first) { return "Not Present"; }
{
return "Not Present";
}
@Override @Override
public String getAxisName() public String getAxisName() { return "ScrollWeel "+(first ? 0 : 1); }
{
return "ScrollWeel "+(first ? 0 : 1);
}
} }
public static class KeySource implements IAxisSource public static class KeySource implements IAxisSource {
{
BindingType type; BindingType type;
int neg; int neg;
int pos; int pos;
public KeySource(BindingType type, int neg, int pos) public KeySource(BindingType type, int neg, int pos) {
{
this.type = type; this.type = type;
this.neg = neg; this.neg = neg;
this.pos = pos; this.pos = pos;
} }
@Override @Override
public float getValue() public float getValue() { return (type.isPressed(pos) ? 1F : 0F) - (type.isPressed(neg) ? 1F : 0F); }
{
return (type.isPressed(pos) ? 1F : 0F) - (type.isPressed(neg) ? 1F : 0F);
}
@Override @Override
public boolean isButton() public boolean isButton() { return true; }
{
return true;
}
@Override @Override
public boolean isAlive() public boolean isAlive() { return true; }
{
return true;
}
@Override @Override
public String getButtonName(boolean first) public String getButtonName(boolean first) { return type.getName(first ? pos : neg); }
{
return type.getName(first ? pos : neg);
}
@Override @Override
public String getAxisName() public String getAxisName() { return "Not Present"; }
{
return "Not Present";
}
} }
} }

View File

@ -1,10 +1,10 @@
package speiger.src.coreengine.rendering.input.bindings; package speiger.src.coreengine.rendering.input.bindings;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.function.Consumer; import java.util.function.Consumer;
import speiger.src.collections.objects.lists.ObjectArrayList;
import speiger.src.coreengine.rendering.input.bindings.utils.BindingRegistry; import speiger.src.coreengine.rendering.input.bindings.utils.BindingRegistry;
import speiger.src.coreengine.rendering.input.bindings.utils.BindingType; import speiger.src.coreengine.rendering.input.bindings.utils.BindingType;
import speiger.src.coreengine.rendering.input.bindings.utils.ModType; import speiger.src.coreengine.rendering.input.bindings.utils.ModType;
@ -37,7 +37,7 @@ public class InputBinding
boolean pressed; boolean pressed;
int timePressed; int timePressed;
List<Consumer<InputBinding>> listeners = new ArrayList<Consumer<InputBinding>>(); List<Consumer<InputBinding>> listeners = new ObjectArrayList<>();
public InputBinding(String category, String name, int key) public InputBinding(String category, String name, int key)
{ {

View File

@ -1,64 +1,37 @@
package speiger.src.coreengine.rendering.input.bindings.utils; package speiger.src.coreengine.rendering.input.bindings.utils;
import java.util.Collections; import java.util.Collections;
import java.util.EnumMap;
import java.util.Map;
import java.util.Set; import java.util.Set;
import speiger.src.collections.ints.maps.impl.hash.Int2ObjectLinkedOpenHashMap; import speiger.src.collections.ints.maps.impl.hash.Int2ObjectLinkedOpenHashMap;
import speiger.src.collections.ints.maps.interfaces.Int2ObjectMap; import speiger.src.collections.ints.maps.interfaces.Int2ObjectMap;
import speiger.src.collections.objects.maps.impl.misc.Enum2ObjectMap;
import speiger.src.collections.objects.maps.interfaces.Object2ObjectMap;
import speiger.src.collections.objects.sets.ObjectLinkedOpenHashSet; import speiger.src.collections.objects.sets.ObjectLinkedOpenHashSet;
import speiger.src.coreengine.rendering.input.bindings.InputBinding; import speiger.src.coreengine.rendering.input.bindings.InputBinding;
public class BindingRegistry public class BindingRegistry
{ {
Map<BindingType, Int2ObjectMap<Set<InputBinding>>> handlers = new EnumMap<>(BindingType.class); Object2ObjectMap<BindingType, Int2ObjectMap<Set<InputBinding>>> handlers = new Enum2ObjectMap<>(BindingType.class);
public void registerBinding(InputBinding binding) public void registerBinding(InputBinding binding) {
{ handlers.supplyIfAbsent(binding.getInputType(), Int2ObjectLinkedOpenHashMap::new).supplyIfAbsent(binding.getKey(), ObjectLinkedOpenHashSet::new).add(binding);
Int2ObjectMap<Set<InputBinding>> bindings = handlers.get(binding.getInputType());
if(bindings == null)
{
bindings = new Int2ObjectLinkedOpenHashMap<Set<InputBinding>>();
handlers.put(binding.getInputType(), bindings);
}
Set<InputBinding> entries = bindings.get(binding.getKey());
if(entries == null)
{
entries = new ObjectLinkedOpenHashSet<InputBinding>();
bindings.put(binding.getKey(), entries);
}
entries.add(binding);
} }
public void removeBinding(InputBinding binding) public void removeBinding(InputBinding binding) {
{
Int2ObjectMap<Set<InputBinding>> bindings = handlers.get(binding.getInputType()); Int2ObjectMap<Set<InputBinding>> bindings = handlers.get(binding.getInputType());
if(bindings == null) if(bindings == null) return;
{
return;
}
Set<InputBinding> entries = bindings.get(binding.getKey()); Set<InputBinding> entries = bindings.get(binding.getKey());
if(entries.remove(binding) && entries.isEmpty()) if(entries.remove(binding) && entries.isEmpty()) {
{
bindings.remove(binding.getKey()); bindings.remove(binding.getKey());
if(bindings.isEmpty()) if(bindings.isEmpty()) handlers.remove(binding.getInputType());
{
handlers.remove(binding.getInputType());
}
} }
} }
public void updatePressing(BindingType type, int key, boolean pressed) public void updatePressing(BindingType type, int key, boolean pressed) {
{
Int2ObjectMap<Set<InputBinding>> bindings = handlers.get(type); Int2ObjectMap<Set<InputBinding>> bindings = handlers.get(type);
if(bindings == null) if(bindings == null) return;
{
return;
}
for(InputBinding binding : bindings.getOrDefault(key, Collections.emptySet())) for(InputBinding binding : bindings.getOrDefault(key, Collections.emptySet()))
{
binding.setPressed(pressed); binding.setPressed(pressed);
}
} }
} }

View File

@ -7,11 +7,9 @@ import speiger.src.coreengine.rendering.input.Mouse;
public enum BindingType public enum BindingType
{ {
KEYBOARD KEYBOARD {
{
@Override @Override
public String getName(int key) public String getName(int key) {
{
if(key >= GLFW.GLFW_KEY_F1 && key <= GLFW.GLFW_KEY_F25) return "F"+(key - GLFW.GLFW_KEY_F1+1); if(key >= GLFW.GLFW_KEY_F1 && key <= GLFW.GLFW_KEY_F25) return "F"+(key - GLFW.GLFW_KEY_F1+1);
else if(key == GLFW.GLFW_KEY_DELETE) return "Delete"; else if(key == GLFW.GLFW_KEY_DELETE) return "Delete";
String s = GLFW.glfwGetKeyName(key, GLFW.glfwGetKeyScancode(key)); String s = GLFW.glfwGetKeyName(key, GLFW.glfwGetKeyScancode(key));
@ -19,41 +17,20 @@ public enum BindingType
} }
@Override @Override
public boolean isPressed(int key) public boolean isPressed(int key) { return Keyboard.isKeyFullyPressed(key); }
{
return Keyboard.isKeyFullyPressed(key);
}
}, },
MOUSE MOUSE {
{
@Override @Override
public String getName(int key) public String getName(int key) { return "Button: "+key; }
{
return "Button: "+key;
}
@Override @Override
public boolean isPressed(int key) public boolean isPressed(int key) { return Mouse.isButtonPressed(key); }
{
return Mouse.isButtonPressed(key);
}
}, },
NONE NONE {
{
@Override @Override
public String getName(int key) public String getName(int key) { return "None"; }
{
return "None";
}
@Override @Override
public boolean isPressed(int key) public boolean isPressed(int key) { return false; }
{
return false;
}
}; };
public abstract String getName(int key); public abstract String getName(int key);
public abstract boolean isPressed(int key); public abstract boolean isPressed(int key);
} }

View File

@ -12,14 +12,12 @@ public final class ModType
public static final int ALT = 4; public static final int ALT = 4;
public static final int IGNORE = 8; public static final int IGNORE = 8;
public static boolean isActive(int flags) public static boolean isActive(int flags) {
{
boolean ignore = (flags & IGNORE) != 0; boolean ignore = (flags & IGNORE) != 0;
return valid(Keyboard.isCtrlDown(), (flags & CTRL) != 0, ignore) && valid(Keyboard.isShiftDown(), (flags & SHIFT) != 0, ignore) && valid(Keyboard.isAltDown(), (flags & ALT) != 0, ignore); return valid(Keyboard.isCtrlDown(), (flags & CTRL) != 0, ignore) && valid(Keyboard.isShiftDown(), (flags & SHIFT) != 0, ignore) && valid(Keyboard.isAltDown(), (flags & ALT) != 0, ignore);
} }
public static String getMods(int flags) public static String getMods(int flags) {
{
flags &= ~IGNORE; flags &= ~IGNORE;
if(flags == 0) return ""; if(flags == 0) return "";
StringJoiner builder = new StringJoiner(" + ", "", " + "); StringJoiner builder = new StringJoiner(" + ", "", " + ");
@ -29,8 +27,7 @@ public final class ModType
return builder.toString(); return builder.toString();
} }
static boolean valid(boolean binding, boolean flags, boolean ignore) static boolean valid(boolean binding, boolean flags, boolean ignore) {
{
return (flags == binding) || (!flags && ignore); return (flags == binding) || (!flags && ignore);
} }
} }

View File

@ -1,42 +1,35 @@
package speiger.src.coreengine.rendering.input.events; package speiger.src.coreengine.rendering.input.events;
import java.io.File; import java.nio.file.Path;
import speiger.src.coreengine.rendering.input.window.ScaledResolution; import speiger.src.coreengine.rendering.input.window.ScaledResolution;
public class FileDropEvent extends MouseEvent public class FileDropEvent extends MouseEvent
{ {
final File file; final Path file;
final String fileName; final String fileName;
final String fileExtension; final String fileExtension;
public FileDropEvent(File file, int x, int y, ScaledResolution res) public FileDropEvent(Path file, long windowId, int x, int y, ScaledResolution res) {
{ super(windowId, x, y);
super(x, y);
this.file = file; this.file = file;
fileName = file.getName(); fileName = file.getFileName().toString();
fileExtension = fileName.substring(fileName.lastIndexOf(".")+1); fileExtension = fileName.substring(fileName.lastIndexOf(".")+1);
convertToScreenCoords(res); convertToScreenCoords(res);
} }
public String getFileExtension() public String getFileExtension() {
{
return fileExtension; return fileExtension;
} }
public String getFileName() public String getFileName() {
{
return fileName; return fileName;
} }
public File getFile() public Path getFile() {
{
return file; return file;
} }
@Override @Override
public boolean isCancelable() public boolean isCancelable(){ return true; }
{
return true;
}
} }

View File

@ -5,28 +5,23 @@ import speiger.src.coreengine.utils.eventbus.Event;
public abstract class KeyEvent extends Event public abstract class KeyEvent extends Event
{ {
@Override @Override
public boolean isCancelable() public boolean isCancelable() {
{
return true; return true;
} }
public static class KeyPressEvent extends KeyEvent public static class KeyPressEvent extends KeyEvent {
{
public final int key; public final int key;
public KeyPressEvent(int key) public KeyPressEvent(int key) {
{
this.key = key; this.key = key;
} }
} }
public static class CharTypeEvent extends KeyEvent public static class CharTypeEvent extends KeyEvent {
{
public final char character; public final char character;
public final int codePoint; public final int codePoint;
public CharTypeEvent(char character, int codePoint) public CharTypeEvent(char character, int codePoint) {
{
this.character = character; this.character = character;
this.codePoint = codePoint; this.codePoint = codePoint;
} }

View File

@ -3,86 +3,85 @@ package speiger.src.coreengine.rendering.input.events;
import speiger.src.coreengine.rendering.input.window.ScaledResolution; import speiger.src.coreengine.rendering.input.window.ScaledResolution;
import speiger.src.coreengine.utils.eventbus.Event; import speiger.src.coreengine.utils.eventbus.Event;
public class MouseEvent extends Event public abstract class MouseEvent extends Event
{ {
public int mouseX; final long windowId;
public int mouseY; int mouseX;
public final int originX; int mouseY;
public final int originY; final int originX;
final int originY;
public MouseEvent(int x, int y) public MouseEvent(long windowId, int x, int y) {
{ this.windowId = windowId;
mouseX = x; mouseX = x;
mouseY = y; mouseY = y;
originX = x; originX = x;
originY = y; originY = y;
} }
public void convertToOrigin() public long getWindowId() { return windowId; }
{ public int getX() { return mouseX; }
public int getY() { return mouseY; }
public void setX(int x) { mouseX = x; }
public void setY(int y) { mouseY = y; }
public int getOriginX() { return originX; }
public int getOriginY() { return originY; }
public void convertToOrigin() {
mouseX = originX; mouseX = originX;
mouseY = originY; mouseY = originY;
} }
public void convertToScreenCoords(ScaledResolution res) public void convertToScreenCoords(ScaledResolution res) {
{
res.getScaledMouseEvent(this); res.getScaledMouseEvent(this);
} }
@Override @Override
public boolean isCancelable() public boolean isCancelable() { return true; }
{ public boolean isForced() { return false; }
return true;
}
public boolean isForced() public static class MouseClickEvent extends MouseEvent {
{ final int button;
return false; final boolean press;
}
public static class MouseClickEvent extends MouseEvent
{
public final int button;
public final boolean press;
public MouseClickEvent(int x, int y, int button, boolean press) public MouseClickEvent(long windowId, int x, int y, int button, boolean press) {
{ super(windowId, x, y);
super(x, y);
this.button = button; this.button = button;
this.press = press; this.press = press;
} }
//Forced so Buttons are always released. Maybe gets disabled. Not sure yet //Forced so Buttons are always released. Maybe gets disabled. Not sure yet
@Override @Override
public boolean isForced() public boolean isForced() { return !press; }
{ public int getButton() { return button; }
return !press; public boolean isPress() { return press; }
}
} }
public static class MouseMoveEvent extends MouseEvent public static class MouseMoveEvent extends MouseEvent {
{ final int xMove;
public final int xMove; final int yMove;
public final int yMove;
public MouseMoveEvent(int x, int y, int xMove, int yMove) public MouseMoveEvent(long windowId, int x, int y, int xMove, int yMove) {
{ super(windowId, x, y);
super(x, y);
this.xMove = xMove; this.xMove = xMove;
this.yMove = yMove; this.yMove = yMove;
} }
public int getXMove() { return xMove; }
public int getYMove() { return yMove; }
} }
public static class MouseScrollEvent extends MouseEvent public static class MouseScrollEvent extends MouseEvent {
{ final int scrollX;
public final int scrollX; final int scrollY;
public final int scrollY;
public MouseScrollEvent(int x, int y, int scrollX, int scrollY) public MouseScrollEvent(long windowId, int x, int y, int scrollX, int scrollY) {
{ super(windowId, x, y);
super(x, y);
this.scrollX = scrollX; this.scrollX = scrollX;
this.scrollY = scrollY; this.scrollY = scrollY;
} }
public int getScrollX() { return scrollX; }
public int getScrollY() { return scrollY; }
} }
} }

View File

@ -2,34 +2,13 @@ package speiger.src.coreengine.rendering.input.raycast;
import speiger.src.coreengine.math.vector.floats.Vec3f; import speiger.src.coreengine.math.vector.floats.Vec3f;
public class Ray public record Ray(Vec3f start, Vec3f end)
{ {
protected Vec3f start; public Vec3f interpolate(float progress) {
protected Vec3f end;
public Ray(Vec3f start, Vec3f end)
{
this.start = start.asImmutable();
this.end = end.asImmutable();
}
public Vec3f getStart()
{
return start;
}
public Vec3f getEnd()
{
return end;
}
public Vec3f interpolate(float progress)
{
return start.lerp(end, progress, Vec3f.ZERO); return start.lerp(end, progress, Vec3f.ZERO);
} }
public Vec3f distance() public Vec3f distance() {
{
return end.asMutable().sub(start); return end.asMutable().sub(start);
} }
} }

View File

@ -38,7 +38,7 @@ public class RayCollisions
Vec3f distance = ray.distance(); Vec3f distance = ray.distance();
double hitDot = distance.dotProduct(cross); double hitDot = distance.dotProduct(cross);
if(Math.abs(hitDot) < 0.0000000001D) return null; if(Math.abs(hitDot) < 0.0000000001D) return null;
double step = first.sub(ray.getStart()).dotProduct(cross) / hitDot; double step = first.sub(ray.start()).dotProduct(cross) / hitDot;
return new RayResult(ray, ray.interpolate((float)step), step); return new RayResult(ray, ray.interpolate((float)step), step);
} }
} }

View File

@ -1,7 +1,5 @@
package speiger.src.coreengine.rendering.input.window; package speiger.src.coreengine.rendering.input.window;
public interface IWindowListener {
public interface IWindowListener
{
public void onWindowChanged(Window window); public void onWindowChanged(Window window);
} }

View File

@ -6,30 +6,25 @@ import org.lwjgl.PointerBuffer;
import org.lwjgl.glfw.GLFW; import org.lwjgl.glfw.GLFW;
import org.lwjgl.glfw.GLFWVidMode; import org.lwjgl.glfw.GLFWVidMode;
import speiger.src.collections.longs.maps.impl.hash.Long2ObjectOpenHashMap; import speiger.src.collections.longs.maps.impl.hash.Long2ObjectLinkedOpenHashMap;
import speiger.src.collections.longs.maps.interfaces.Long2ObjectMap; import speiger.src.collections.longs.maps.interfaces.Long2ObjectMap;
import speiger.src.collections.objects.lists.ObjectArrayList; import speiger.src.collections.objects.lists.ObjectArrayList;
public class Monitor public class Monitor
{ {
final long monitor; final long monitor;
List<VideoMode> modes = new ObjectArrayList<VideoMode>(); List<VideoMode> modes = new ObjectArrayList<>();
VideoMode defaultMode; VideoMode defaultMode;
int xOffset; int xOffset;
int yOffset; int yOffset;
public Monitor(long monitor) public Monitor(long monitor) {
{
this.monitor = monitor; this.monitor = monitor;
GLFWVidMode.Buffer buffer = GLFW.glfwGetVideoModes(monitor); GLFWVidMode.Buffer buffer = GLFW.glfwGetVideoModes(monitor);
for(int i = buffer.limit() - 1;i >= 0;--i) for(int i = buffer.limit() - 1;i >= 0;--i) {
{ VideoMode videomode = new VideoMode(this, buffer.position(i));
buffer.position(i); if(videomode.redBits() >= 8 && videomode.greenBits() >= 8 && videomode.blueBits() >= 8)
VideoMode videomode = new VideoMode(this, buffer);
if(videomode.getRedBits() >= 8 && videomode.getGreenBits() >= 8 && videomode.getBlueBits() >= 8)
{
modes.add(videomode); modes.add(videomode);
}
} }
defaultMode = new VideoMode(this, GLFW.glfwGetVideoMode(monitor)); defaultMode = new VideoMode(this, GLFW.glfwGetVideoMode(monitor));
int[] xPos = new int[1]; int[] xPos = new int[1];
@ -39,69 +34,56 @@ public class Monitor
yOffset = yPos[0]; yOffset = yPos[0];
} }
public String getMonitorName() public String getMonitorName() {
{
return GLFW.glfwGetMonitorName(monitor); return GLFW.glfwGetMonitorName(monitor);
} }
public long getMonitorId() public long getMonitorId() {
{
return monitor; return monitor;
} }
public int size() public int size() {
{
return modes.size(); return modes.size();
} }
public VideoMode getMode(int index) public VideoMode getMode(int index) {
{
return modes.get(index); return modes.get(index);
} }
public boolean contains(VideoMode mode) public boolean contains(VideoMode mode) {
{
return modes.indexOf(mode) != -1; return modes.indexOf(mode) != -1;
} }
public List<VideoMode> getVideoMods() public List<VideoMode> getVideoMods() {
{ return new ObjectArrayList<>(modes);
return new ObjectArrayList<VideoMode>(modes);
} }
public VideoMode getDefaultMode() public VideoMode getDefaultMode() {
{
return defaultMode; return defaultMode;
} }
public int getXOffset() public int getXOffset() {
{
return xOffset; return xOffset;
} }
public int getYOffset() public int getYOffset() {
{
return yOffset; return yOffset;
} }
public long getInBounds(Window window) public long getInBounds(Window window) {
{ if(xOffset <= window.getXPos() + window.getActualWidth() && xOffset + defaultMode.width() >= window.getXPos() && yOffset <= window.getYPos() + window.getActualHeight() && yOffset + defaultMode.height() >= window.getYPos()) {
if(xOffset <= window.getXPos() + window.getActualWidth() && xOffset + defaultMode.getWidth() >= window.getXPos() && yOffset <= window.getYPos() + window.getActualHeight() && yOffset + defaultMode.getHeight() >= window.getYPos()) int xArea = Math.abs(window.getActualWidth() * defaultMode.width());
{ int yArea = Math.abs(window.getActualHeight() * defaultMode.height());
int xArea = Math.abs(window.getActualWidth() * defaultMode.getWidth()); int areaI = (Math.min(window.getXPos() + window.getActualWidth(), xOffset + defaultMode.width()) - Math.max(window.getXPos(), xOffset)) * (Math.min(window.getYPos() + window.getActualHeight(), yOffset + defaultMode.height()) - Math.max(window.getYPos(), yOffset));
int yArea = Math.abs(window.getActualHeight() * defaultMode.getHeight());
int areaI = (Math.min(window.getXPos() + window.getActualWidth(), xOffset + defaultMode.getWidth()) - Math.max(window.getXPos(), xOffset)) * (Math.min(window.getYPos() + window.getActualHeight(), yOffset + defaultMode.getHeight()) - Math.max(window.getYPos(), yOffset));
return (xArea + yArea) - areaI; return (xArea + yArea) - areaI;
} }
return 0L; return 0L;
} }
public static Long2ObjectMap<Monitor> createMonitors() public static Long2ObjectMap<Monitor> createMonitors() {
{ Long2ObjectMap<Monitor> monitors = new Long2ObjectLinkedOpenHashMap<>();
Long2ObjectMap<Monitor> monitors = new Long2ObjectOpenHashMap<Monitor>();
PointerBuffer buffer = GLFW.glfwGetMonitors(); PointerBuffer buffer = GLFW.glfwGetMonitors();
for(int i = 0,m=buffer.limit();i<m;i++) for(int i = 0,m=buffer.limit();i<m;i++) {
{
long id = buffer.get(); long id = buffer.get();
monitors.put(id, new Monitor(id)); monitors.put(id, new Monitor(id));
} }

View File

@ -12,71 +12,40 @@ public class ScaledResolution
int scaledHeight; int scaledHeight;
int scale; int scale;
public ScaledResolution(Window wind) public ScaledResolution(Window wind) {
{
window = wind; window = wind;
updateScale(); updateScale();
} }
void updateScale() void updateScale() {
{
scale = (Math.min(1 + calculateScreenScale(), window.uiScale == 0 ? 99 : window.uiScale)); scale = (Math.min(1 + calculateScreenScale(), window.uiScale == 0 ? 99 : window.uiScale));
scaledWidth = window.getWidth() / scale; scaledWidth = window.getWidth() / scale;
scaledHeight = window.getHeight() / scale; scaledHeight = window.getHeight() / scale;
} }
public int calculateScreenScale() public int calculateScreenScale() { return calculateMaxScales(window.getWidth(), window.getHeight()); }
{ public int calculateMaxScales(int width, int height) { return Math.max(0, Math.min((int)(width / 320F), (int)(height / 240F)) - 1); }
return calculateMaxScales(window.getWidth(), window.getHeight()); public int getScaledWidth() { return scaledWidth; }
public int getScaledHeight() { return scaledHeight; }
public double getCurrentScale() { return scale; }
public Vec2i getScaledMouse() {
return !Mouse.isActive() || scaledWidth == 0 || scaledHeight == 0 ? Vec2i.MINUS_ONE : Vec2i.of(Mouse.getX() * scaledWidth / window.getWidth(), Mouse.getY() * scaledHeight / window.getHeight());
} }
public int calculateMaxScales(int width, int height) public MouseEvent getScaledMouseEvent(MouseEvent evt) {
{ if(window.getWidth() != 0 && window.getHeight() != 0) {
return Math.max(0, Math.min((int)(width / 320F), (int)(height / 240F)) - 1); evt.setX(evt.getOriginX() * scaledWidth / window.getWidth());
} evt.setY(evt.getOriginY() * scaledHeight / window.getHeight());
public int getScaledWidth()
{
return scaledWidth;
}
public int getScaledHeight()
{
return scaledHeight;
}
public double getCurrentScale()
{
return scale;
}
public Vec2i getScaledMouse()
{
if(!Mouse.isActive() || scaledWidth == 0 || scaledHeight == 0)
{
return Vec2i.MINUS_ONE;
} }
return Vec2i.of(Mouse.getX() * scaledWidth / window.getWidth(), Mouse.getY() * scaledHeight / window.getHeight());
}
public MouseEvent getScaledMouseEvent(MouseEvent evt)
{
if(window.getWidth() == 0 || window.getHeight() == 0)
{
return evt;
}
evt.mouseX = evt.originX * scaledWidth / window.getWidth();
evt.mouseY = evt.originY * scaledHeight / window.getHeight();
return evt; return evt;
} }
public Vec2i getReverseScale(int xPos, int yPos) public Vec2i getReverseScale(int xPos, int yPos) {
{
return Vec2i.of(xPos * window.getWidth() / scaledWidth, yPos * window.getHeight() / scaledHeight); return Vec2i.of(xPos * window.getWidth() / scaledWidth, yPos * window.getHeight() / scaledHeight);
} }
public Vec2d getScaleVec() public Vec2d getScaleVec() {
{
return Vec2d.of((double)window.getWidth() / scaledWidth, (double)window.getHeight() / scaledHeight); return Vec2d.of((double)window.getWidth() / scaledWidth, (double)window.getHeight() / scaledHeight);
} }
} }

View File

@ -2,87 +2,13 @@ package speiger.src.coreengine.rendering.input.window;
import org.lwjgl.glfw.GLFWVidMode; import org.lwjgl.glfw.GLFWVidMode;
public class VideoMode public record VideoMode(Monitor monitor, int width, int height, int redBits, int greenBits, int blueBits, int refreshrate) {
{
final Monitor monitor; public VideoMode(Monitor monitor, GLFWVidMode buffer) {
final int width; this(monitor, buffer.width(), buffer.height(), buffer.redBits(), buffer.greenBits(), buffer.blueBits(), buffer.refreshRate());
final int height;
final int redBits;
final int greenBits;
final int blueBits;
final int refreshrate;
public VideoMode(Monitor monitor, GLFWVidMode buffer)
{
this.monitor = monitor;
width = buffer.width();
height = buffer.height();
redBits = buffer.redBits();
greenBits = buffer.greenBits();
blueBits = buffer.blueBits();
refreshrate = buffer.refreshRate();
} }
public VideoMode(Monitor monitor, GLFWVidMode.Buffer buffer) public VideoMode(Monitor monitor, GLFWVidMode.Buffer buffer) {
{ this(monitor, buffer.width(), buffer.height(), buffer.redBits(), buffer.greenBits(), buffer.blueBits(), buffer.refreshRate());
this.monitor = monitor;
width = buffer.width();
height = buffer.height();
redBits = buffer.redBits();
greenBits = buffer.greenBits();
blueBits = buffer.blueBits();
refreshrate = buffer.refreshRate();
}
public VideoMode(Monitor monitor, int width, int height, int redBits, int greenBits, int blueBits, int refreshrate)
{
this.monitor = monitor;
this.width = width;
this.height = height;
this.redBits = redBits;
this.greenBits = greenBits;
this.blueBits = blueBits;
this.refreshrate = refreshrate;
}
public Monitor getMonitor()
{
return monitor;
}
public int getWidth()
{
return width;
}
public int getHeight()
{
return height;
}
public int getRedBits()
{
return redBits;
}
public int getGreenBits()
{
return greenBits;
}
public int getBlueBits()
{
return blueBits;
}
public int getRefreshRate()
{
return refreshrate;
}
@Override
public String toString()
{
return "Video Mode[Width="+width+", Height="+height+", Rate="+refreshrate+", Monitor="+monitor+"]";
} }
} }

View File

@ -53,8 +53,7 @@ public class Window
List<IWindowListener> listeners = new ObjectArrayList<>(); List<IWindowListener> listeners = new ObjectArrayList<>();
GLCapabilities capabilities; GLCapabilities capabilities;
public Window() public Window() {
{
GLFW.glfwDefaultWindowHints(); GLFW.glfwDefaultWindowHints();
GLFW.glfwWindowHint(GLFW.GLFW_VISIBLE, 0); // 0 = False, 1 = true GLFW.glfwWindowHint(GLFW.GLFW_VISIBLE, 0); // 0 = False, 1 = true
GLFW.glfwWindowHint(GLFW.GLFW_RESIZABLE, 1); GLFW.glfwWindowHint(GLFW.GLFW_RESIZABLE, 1);
@ -64,16 +63,14 @@ public class Window
GLFW.glfwWindowHint(GLFW.GLFW_OPENGL_FORWARD_COMPAT, 1); GLFW.glfwWindowHint(GLFW.GLFW_OPENGL_FORWARD_COMPAT, 1);
} }
protected void initWindowListeners() protected void initWindowListeners() {
{
addCallback(T -> GLFW.glfwSetFramebufferSizeCallback(T, this::onResize)); addCallback(T -> GLFW.glfwSetFramebufferSizeCallback(T, this::onResize));
addCallback(T -> GLFW.glfwSetWindowMaximizeCallback(T, (K, V) -> flags.setFlag(FLAG_WINDOW_CHANGE))); addCallback(T -> GLFW.glfwSetWindowMaximizeCallback(T, (K, V) -> flags.setFlag(FLAG_WINDOW_CHANGE)));
addCallback(T -> GLFW.glfwSetWindowPosCallback(T, (W, X, Y) -> setPosition(X, Y))); addCallback(T -> GLFW.glfwSetWindowPosCallback(T, (W, X, Y) -> setPosition(X, Y)));
addCallback(T -> GLFW.glfwSetWindowFocusCallback(T, (K, V) -> flags.setFlag(FLAG_FOCUS, V))); addCallback(T -> GLFW.glfwSetWindowFocusCallback(T, (K, V) -> flags.setFlag(FLAG_FOCUS, V)));
} }
Window createWindow(WindowStats stat) Window createWindow(WindowStats stat) {
{
owner = stat.provider; owner = stat.provider;
title = stat.name; title = stat.name;
width = stat.width; width = stat.width;
@ -88,32 +85,21 @@ public class Window
GLFW.glfwWindowHint(GLFW.GLFW_SAMPLES, aaLevel); GLFW.glfwWindowHint(GLFW.GLFW_SAMPLES, aaLevel);
GLFW.glfwWindowHint(GLFW.GLFW_DECORATED, flags.isFlagNotSet(FLAG_FULL_SCREEN) && flags.isFlagSet(FLAG_BORDERLESS) ? 0 : 1); GLFW.glfwWindowHint(GLFW.GLFW_DECORATED, flags.isFlagNotSet(FLAG_FULL_SCREEN) && flags.isFlagSet(FLAG_BORDERLESS) ? 0 : 1);
GLFW.glfwWindowHint(GLFW.GLFW_FLOATING, flags.isFlagNotSet(FLAG_FULL_SCREEN) && flags.isFlagSet(FLAG_FLOATING) ? 1 : 0); GLFW.glfwWindowHint(GLFW.GLFW_FLOATING, flags.isFlagNotSet(FLAG_FULL_SCREEN) && flags.isFlagSet(FLAG_FLOATING) ? 1 : 0);
if(videoMode == null || videoMode.getMonitor() == null) if(videoMode == null || videoMode.monitor() == null) throw new IllegalStateException("Monitor or Video Mode is missing: "+videoMode);
{ Monitor monitor = videoMode.monitor();
throw new IllegalStateException("Monitor or Video Mode is missing: "+videoMode); windowId = GLFW.glfwCreateWindow(flags.isFlagSet(FLAG_FULL_SCREEN) ? videoMode.width() : width, flags.isFlagSet(FLAG_FULL_SCREEN) ? videoMode.height() : height, title, flags.isFlagSet(FLAG_FULL_SCREEN) ? monitor.getMonitorId() : 0L, stat.parent == null ? 0 : stat.parent.windowId);
} if(windowId == 0) throw new IllegalStateException("Window Couldn't be Created");
Monitor monitor = videoMode.getMonitor();
windowId = GLFW.glfwCreateWindow(flags.isFlagSet(FLAG_FULL_SCREEN) ? videoMode.getWidth() : width, flags.isFlagSet(FLAG_FULL_SCREEN) ? videoMode.getHeight() : height, title, flags.isFlagSet(FLAG_FULL_SCREEN) ? monitor.getMonitorId() : 0L, stat.parent == null ? 0 : stat.parent.windowId);
if(windowId == 0)
{
throw new IllegalStateException("Window Couldn't be Created");
}
initWindowListeners(); initWindowListeners();
GLFW.glfwMakeContextCurrent(windowId); GLFW.glfwMakeContextCurrent(windowId);
if(capabilities == null) if(capabilities == null) capabilities = GL.createCapabilities();
{ if(flags.isFlagNotSet(FLAG_FULL_SCREEN)) {
capabilities = GL.createCapabilities(); xPos = stat.center ? (monitor.getXOffset() + (videoMode.width() / 2) - (width / 2)) : monitor.getXOffset() + xPos;
} yPos = stat.center ? (monitor.getYOffset() + (videoMode.height() / 2) - (width / 2)) : monitor.getYOffset() + yPos;
if(flags.isFlagNotSet(FLAG_FULL_SCREEN))
{
xPos = stat.center ? (monitor.getXOffset() + (videoMode.getWidth() / 2) - (width / 2)) : monitor.getXOffset() + xPos;
yPos = stat.center ? (monitor.getYOffset() + (videoMode.getHeight() / 2) - (width / 2)) : monitor.getYOffset() + yPos;
GLFW.glfwSetWindowPos(windowId, xPos, yPos); GLFW.glfwSetWindowPos(windowId, xPos, yPos);
} }
else else {
{ xPos = monitor.getXOffset() + (videoMode.width() / 2) - (width / 2);
xPos = monitor.getXOffset() + (videoMode.getWidth() / 2) - (width / 2); yPos = monitor.getYOffset() + (videoMode.height() / 2) - (width / 2);
yPos = monitor.getYOffset() + (videoMode.getHeight() / 2) - (width / 2);
tempWidth = width; tempWidth = width;
tempHeight = height; tempHeight = height;
} }
@ -123,52 +109,39 @@ public class Window
return this; return this;
} }
protected void onResize(long window, int newWidth, int newHeight) protected void onResize(long window, int newWidth, int newHeight) {
{ if(flags.isFlagNotSet(FLAG_FULL_SCREEN | FLAG_MAXIMIZED) && window == windowId && (width != newWidth || height != newHeight)) {
if(flags.isFlagNotSet(FLAG_FULL_SCREEN | FLAG_MAXIMIZED) && window == windowId && (width != newWidth || height != newHeight))
{
width = newWidth; width = newWidth;
height = newHeight; height = newHeight;
flags.setFlag(FLAG_WINDOW_CHANGE); flags.setFlag(FLAG_WINDOW_CHANGE);
} }
} }
protected void updateCallbacks() protected void updateCallbacks() {
{ for(int i = 0,m=callbacks.size();i<m;i++) {
for(int i = 0,m=callbacks.size();i<m;i++) callbacks.get(i).reload(windowId);
{
WindowCallback callback = callbacks.get(i);
callback.destroy();
callback.reload(windowId);
} }
GLUtils.reapplyState(); GLUtils.reapplyState();
} }
protected void updateViewPort() protected void updateViewPort() {
{
flags.clearFlag(FLAG_WINDOW_CHANGE); flags.clearFlag(FLAG_WINDOW_CHANGE);
GLUtils.VIEW_PORT.setDefault(0, 0, width, height); GLUtils.VIEW_PORT.setDefault(0, 0, width, height);
createProjectionMatrix(); createProjectionMatrix();
ui_frame.updateScale(); ui_frame.updateScale();
for(int i = 0,m=listeners.size();i<m;i++) for(int i = 0,m=listeners.size();i<m;i++) {
{
listeners.get(i).onWindowChanged(this); listeners.get(i).onWindowChanged(this);
} }
} }
public void setVideoMode(VideoMode mode) public void setVideoMode(VideoMode mode) {
{ if(videoMode != mode && mode.monitor() == getMonitor()) {
if(videoMode != mode && mode.getMonitor() == getMonitor())
{
videoMode = mode; videoMode = mode;
if(flags.isAnyFlagSet(FLAG_FULL_SCREEN | FLAG_MAXIMIZED)) if(flags.isAnyFlagSet(FLAG_FULL_SCREEN | FLAG_MAXIMIZED)) {
{ if(flags.isFlagSet(FLAG_FULL_SCREEN)) {
if(flags.isFlagSet(FLAG_FULL_SCREEN)) GLFW.glfwSetWindowMonitor(windowId, videoMode.monitor().getMonitorId(), 0, 0, videoMode.width(), videoMode.height(), videoMode.refreshrate());
{
GLFW.glfwSetWindowMonitor(windowId, videoMode.getMonitor().getMonitorId(), 0, 0, videoMode.getWidth(), videoMode.getHeight(), videoMode.getRefreshRate());
} }
else if(flags.isFlagSet(FLAG_MAXIMIZED)) else if(flags.isFlagSet(FLAG_MAXIMIZED)) {
{
GLFW.glfwRestoreWindow(windowId); GLFW.glfwRestoreWindow(windowId);
GLFW.glfwMaximizeWindow(windowId); GLFW.glfwMaximizeWindow(windowId);
} }
@ -178,10 +151,8 @@ public class Window
} }
} }
public boolean setTitle(String title) public boolean setTitle(String title) {
{ if(title != null && !this.title.equals(title)) {
if(title != null && !this.title.equals(title))
{
this.title = title; this.title = title;
GLFW.glfwSetWindowTitle(windowId, title); GLFW.glfwSetWindowTitle(windowId, title);
return true; return true;
@ -189,62 +160,47 @@ public class Window
return false; return false;
} }
public boolean setVsync(boolean value) public boolean setVsync(boolean value) {
{ if(flags.setFlag(FLAG_VSYNC, value)) {
if(flags.setFlag(FLAG_VSYNC, value))
{
GLFW.glfwSwapInterval(value ? 1 : 0); GLFW.glfwSwapInterval(value ? 1 : 0);
return true; return true;
} }
return false; return false;
} }
public boolean setFPSLimit(boolean value) public boolean setFPSLimit(boolean value) {
{
return flags.setFlag(FLAG_CPU_FPS_CAP, value); return flags.setFlag(FLAG_CPU_FPS_CAP, value);
} }
public boolean setFullscreen(boolean value) public boolean setFullscreen(boolean value) {
{ if(flags.setFlag(FLAG_FULL_SCREEN, value)) {
if(flags.setFlag(FLAG_FULL_SCREEN, value)) if(value) {
{ if(flags.isFlagNotSet(FLAG_MAXIMIZED)) {
if(value)
{
if(flags.isFlagNotSet(FLAG_MAXIMIZED))
{
tempWidth = width; tempWidth = width;
tempHeight = height; tempHeight = height;
} }
Monitor monitor = getMonitor(); Monitor monitor = getMonitor();
if(!monitor.contains(videoMode)) if(!monitor.contains(videoMode)) videoMode = monitor.getDefaultMode();
{ GLFW.glfwSetWindowMonitor(windowId, monitor.getMonitorId(), 0, 0, videoMode.width(), videoMode.height(), videoMode.refreshrate());
videoMode = monitor.getDefaultMode();
}
GLFW.glfwSetWindowMonitor(windowId, monitor.getMonitorId(), 0, 0, videoMode.getWidth(), videoMode.getHeight(), videoMode.getRefreshRate());
fetchWindowBounds(); fetchWindowBounds();
} }
else else {
{ if(flags.isFlagNotSet(FLAG_MAXIMIZED)) {
if(flags.isFlagNotSet(FLAG_MAXIMIZED))
{
width = tempWidth; width = tempWidth;
height = tempHeight; height = tempHeight;
GLFW.glfwSetWindowMonitor(windowId, 0, xPos, yPos, width, height, videoMode.getRefreshRate()); GLFW.glfwSetWindowMonitor(windowId, 0, xPos, yPos, width, height, videoMode.refreshrate());
} }
else else {
{ GLFW.glfwSetWindowMonitor(windowId, 0, 0, 0, width, height, videoMode.refreshrate());
GLFW.glfwSetWindowMonitor(windowId, 0, 0, 0, width, height, videoMode.getRefreshRate());
GLFW.glfwMaximizeWindow(windowId); GLFW.glfwMaximizeWindow(windowId);
fetchWindowBounds(); fetchWindowBounds();
} }
if(flags.isFlagSet(FLAG_BORDERLESS)) if(flags.isFlagSet(FLAG_BORDERLESS)) {
{
GLFW.glfwSetWindowAttrib(windowId, GLFW.GLFW_DECORATED, 0); GLFW.glfwSetWindowAttrib(windowId, GLFW.GLFW_DECORATED, 0);
GLFW.glfwRestoreWindow(windowId); GLFW.glfwRestoreWindow(windowId);
GLFW.glfwMaximizeWindow(windowId); GLFW.glfwMaximizeWindow(windowId);
} }
else else {
{
GLFW.glfwSetWindowAttrib(windowId, GLFW.GLFW_DECORATED, 1); GLFW.glfwSetWindowAttrib(windowId, GLFW.GLFW_DECORATED, 1);
} }
} }
@ -255,13 +211,10 @@ public class Window
return false; return false;
} }
public boolean setBorderless(boolean value) public boolean setBorderless(boolean value) {
{ if(flags.isFlagNotSet(FLAG_FULL_SCREEN) && flags.setFlag(FLAG_BORDERLESS, value)) {
if(flags.isFlagNotSet(FLAG_FULL_SCREEN) && flags.setFlag(FLAG_BORDERLESS, value))
{
GLFW.glfwSetWindowAttrib(windowId, GLFW.GLFW_DECORATED, value ? 0 : 1); GLFW.glfwSetWindowAttrib(windowId, GLFW.GLFW_DECORATED, value ? 0 : 1);
if(flags.isFlagSet(FLAG_MAXIMIZED)) if(flags.isFlagSet(FLAG_MAXIMIZED)) {
{
GLFW.glfwRestoreWindow(windowId); GLFW.glfwRestoreWindow(windowId);
GLFW.glfwMaximizeWindow(windowId); GLFW.glfwMaximizeWindow(windowId);
fetchWindowBounds(); fetchWindowBounds();
@ -271,29 +224,23 @@ public class Window
return false; return false;
} }
public boolean setFloating(boolean value) public boolean setFloating(boolean value) {
{ if(flags.isFlagNotSet(FLAG_FULL_SCREEN) && flags.setFlag(FLAG_FLOATING, value)) {
if(flags.isFlagNotSet(FLAG_FULL_SCREEN) && flags.setFlag(FLAG_FLOATING, value))
{
GLFW.glfwSetWindowAttrib(windowId, GLFW.GLFW_FLOATING, value ? 1 : 0); GLFW.glfwSetWindowAttrib(windowId, GLFW.GLFW_FLOATING, value ? 1 : 0);
return true; return true;
} }
return false; return false;
} }
public boolean setMaximized(boolean value) public boolean setMaximized(boolean value) {
{ if(flags.isFlagNotSet(FLAG_FULL_SCREEN) && flags.setFlag(FLAG_MAXIMIZED, value)) {
if(flags.isFlagNotSet(FLAG_FULL_SCREEN) && flags.setFlag(FLAG_MAXIMIZED, value)) if(value) {
{
if(value)
{
tempWidth = width; tempWidth = width;
tempHeight = height; tempHeight = height;
GLFW.glfwMaximizeWindow(windowId); GLFW.glfwMaximizeWindow(windowId);
fetchWindowBounds(); fetchWindowBounds();
} }
else else {
{
width = tempWidth; width = tempWidth;
height = tempHeight; height = tempHeight;
GLFW.glfwRestoreWindow(windowId); GLFW.glfwRestoreWindow(windowId);
@ -303,10 +250,8 @@ public class Window
return false; return false;
} }
public boolean setAntiAliasing(int level) public boolean setAntiAliasing(int level) {
{ if(aaLevel != level) {
if(aaLevel != level)
{
aaLevel = level; aaLevel = level;
long last = windowId; long last = windowId;
GLFW.glfwDefaultWindowHints(); GLFW.glfwDefaultWindowHints();
@ -315,15 +260,9 @@ public class Window
GLFW.glfwWindowHint(GLFW.GLFW_SAMPLES, aaLevel); GLFW.glfwWindowHint(GLFW.GLFW_SAMPLES, aaLevel);
GLFW.glfwWindowHint(GLFW.GLFW_DECORATED, flags.isFlagNotSet(FLAG_FULL_SCREEN) && flags.isFlagSet(FLAG_BORDERLESS) ? 0 : 1); GLFW.glfwWindowHint(GLFW.GLFW_DECORATED, flags.isFlagNotSet(FLAG_FULL_SCREEN) && flags.isFlagSet(FLAG_BORDERLESS) ? 0 : 1);
Monitor monitor = getMonitor(); Monitor monitor = getMonitor();
if(!monitor.contains(videoMode)) if(!monitor.contains(videoMode)) videoMode = monitor.getDefaultMode();
{ windowId = GLFW.glfwCreateWindow(flags.isFlagSet(FLAG_FULL_SCREEN) ? videoMode.width() : width, flags.isFlagSet(FLAG_FULL_SCREEN) ? videoMode.height() : height, title, flags.isFlagSet(FLAG_FULL_SCREEN) ? monitor.getMonitorId() : 0L, windowId);
videoMode = monitor.getDefaultMode(); if(windowId == 0) throw new IllegalStateException("Window Couldn't be Created");
}
windowId = GLFW.glfwCreateWindow(flags.isFlagSet(FLAG_FULL_SCREEN) ? videoMode.getWidth() : width, flags.isFlagSet(FLAG_FULL_SCREEN) ? videoMode.getHeight() : height, title, flags.isFlagSet(FLAG_FULL_SCREEN) ? monitor.getMonitorId() : 0L, windowId);
if(windowId == 0)
{
throw new IllegalStateException("Window Couldn't be Created");
}
GLFW.glfwMakeContextCurrent(windowId); GLFW.glfwMakeContextCurrent(windowId);
GLFW.glfwDestroyWindow(last); GLFW.glfwDestroyWindow(last);
GLFW.glfwSwapInterval(flags.isFlagSet(FLAG_VSYNC) ? 1 : 0); GLFW.glfwSwapInterval(flags.isFlagSet(FLAG_VSYNC) ? 1 : 0);
@ -335,10 +274,8 @@ public class Window
return false; return false;
} }
public boolean setWindowSize(int newWidth, int newHeight) public boolean setWindowSize(int newWidth, int newHeight) {
{ if(flags.isFlagNotSet(FLAG_MAXIMIZED | FLAG_FULL_SCREEN) && (width != newWidth || height != newWidth)) {
if(flags.isFlagNotSet(FLAG_MAXIMIZED | FLAG_FULL_SCREEN) && (width != newWidth || height != newWidth))
{
width = newWidth; width = newWidth;
height = newHeight; height = newHeight;
flags.setFlag(FLAG_WINDOW_CHANGE); flags.setFlag(FLAG_WINDOW_CHANGE);
@ -347,10 +284,8 @@ public class Window
return false; return false;
} }
public boolean setPosition(int xNewPos, int yNewPos) public boolean setPosition(int xNewPos, int yNewPos) {
{ if(flags.isFlagNotSet(FLAG_MAXIMIZED | FLAG_FULL_SCREEN) && (xPos != xNewPos || yPos != yNewPos)) {
if(flags.isFlagNotSet(FLAG_MAXIMIZED | FLAG_FULL_SCREEN) && (xPos != xNewPos || yPos != yNewPos))
{
xPos = xNewPos; xPos = xNewPos;
yPos = yNewPos; yPos = yNewPos;
return true; return true;
@ -358,243 +293,118 @@ public class Window
return false; return false;
} }
public boolean setVisible(boolean value) public boolean setVisible(boolean value) {
{ if(flags.setFlag(FLAG_VISIBLE, value)) {
if(flags.setFlag(FLAG_VISIBLE, value)) if(value) GLFW.glfwShowWindow(windowId);
{ else GLFW.glfwHideWindow(windowId);
if(value)
{
GLFW.glfwShowWindow(windowId);
}
else
{
GLFW.glfwHideWindow(windowId);
}
return true; return true;
} }
return false; return false;
} }
public void setUIScale(int newScale) public void setUIScale(int newScale) {
{
int lastScale = uiScale; int lastScale = uiScale;
uiScale = MathUtils.clamp(0, 100, newScale); uiScale = MathUtils.clamp(0, 100, newScale);
if(lastScale != uiScale) if(lastScale != uiScale) flags.setFlag(FLAG_WINDOW_CHANGE);
{
flags.setFlag(FLAG_WINDOW_CHANGE);
}
} }
public void editScale(int change) public void editScale(int change) {
{ if(change != 0) {
if(change != 0)
{
uiScale = MathUtils.clamp(0, 100, uiScale + change); uiScale = MathUtils.clamp(0, 100, uiScale + change);
flags.setFlag(FLAG_WINDOW_CHANGE); flags.setFlag(FLAG_WINDOW_CHANGE);
} }
} }
public void setClipboardString(String text) public boolean isChanged() { return flags.isFlagSet(FLAG_WINDOW_CHANGE); }
{ public boolean isFullscreen() { return flags.isFlagSet(FLAG_FULL_SCREEN); }
GLFW.glfwSetClipboardString(windowId, text); public boolean isMaximized() { return flags.isFlagSet(FLAG_MAXIMIZED); }
} public boolean isBorderless() { return flags.isFlagSet(FLAG_BORDERLESS); }
public boolean isCPULimited() { return flags.isFlagSet(FLAG_CPU_FPS_CAP); }
public int getAntiAliasingLevel() { return aaLevel; }
public long getId() { return windowId; }
public int getWidth() { return width; }
public int getHeight() { return height; }
int getActualWidth() { return flags.isAnyFlagSet(FLAG_FULL_SCREEN | FLAG_MAXIMIZED) ? tempWidth : width; }
int getActualHeight() { return flags.isAnyFlagSet(FLAG_FULL_SCREEN | FLAG_MAXIMIZED) ? tempHeight : height; }
int getXPos() { return xPos; }
int getYPos() { return yPos; }
public void requestClose() public Monitor getMonitor() { return owner.getMonitorFromWindow(this); }
{ public String getClipboardString() { return GLFW.glfwGetClipboardString(windowId); }
flags.setFlag(FLAG_CLOSE); public void setClipboardString(String text) { GLFW.glfwSetClipboardString(windowId, text); }
}
public void requestClose() { flags.setFlag(FLAG_CLOSE); }
public boolean shouldRun() { return flags.isFlagNotSet(FLAG_CLOSE) && !GLFW.glfwWindowShouldClose(windowId); }
public boolean isChanged() public void finishWindow() {
{
return flags.isFlagSet(FLAG_WINDOW_CHANGE);
}
public boolean isFullscreen()
{
return flags.isFlagSet(FLAG_FULL_SCREEN);
}
public boolean isMaximized()
{
return flags.isFlagSet(FLAG_MAXIMIZED);
}
public boolean isBorderless()
{
return flags.isFlagSet(FLAG_BORDERLESS);
}
public boolean isCPULimited()
{
return flags.isFlagSet(FLAG_CPU_FPS_CAP);
}
public int getAntiAliasingLevel()
{
return aaLevel;
}
public boolean shouldRun()
{
return flags.isFlagNotSet(FLAG_CLOSE) && !GLFW.glfwWindowShouldClose(windowId);
}
public void finishWindow()
{
setVisible(true); setVisible(true);
GLFW.glfwShowWindow(windowId); GLFW.glfwShowWindow(windowId);
updateViewPort(); updateViewPort();
} }
public void update() public void update() {
{ if(flags.isFlagSet(FLAG_WINDOW_CHANGE)) updateViewPort();
if(flags.isFlagSet(FLAG_WINDOW_CHANGE))
{
updateViewPort();
}
} }
public void finishFrame() public void finishFrame() {
{
GLFW.glfwSwapBuffers(windowId); GLFW.glfwSwapBuffers(windowId);
} }
public void gatherInputs() public void gatherInputs() {
{
GLFW.glfwPollEvents(); GLFW.glfwPollEvents();
} }
public void destroy() public void destroy() {
{
GLFW.glfwDestroyWindow(windowId); GLFW.glfwDestroyWindow(windowId);
for(WindowCallback back : callbacks) callbacks.forEach(WindowCallback::destroy);
{
back.destroy();
}
callbacks.clear(); callbacks.clear();
} }
public long getId() public Matrix4f getProjectionMatrix() {
{
return windowId;
}
public int getWidth()
{
return width;
}
public int getHeight()
{
return height;
}
int getActualWidth()
{
return flags.isAnyFlagSet(FLAG_FULL_SCREEN | FLAG_MAXIMIZED) ? tempWidth : width;
}
int getActualHeight()
{
return flags.isAnyFlagSet(FLAG_FULL_SCREEN | FLAG_MAXIMIZED) ? tempHeight : height;
}
int getXPos()
{
return xPos;
}
int getYPos()
{
return yPos;
}
public Monitor getMonitor()
{
return owner.getMonitorFromWindow(this);
}
public String getClipboardString()
{
return GLFW.glfwGetClipboardString(windowId);
}
public Matrix4f getProjectionMatrix()
{
return projection; return projection;
} }
public Matrix4f getInvertedProjectionMatrix() public Matrix4f getInvertedProjectionMatrix() {
{
return invertedProjection; return invertedProjection;
} }
public ScaledResolution getUIFrame() public ScaledResolution getUIFrame() {
{
return ui_frame; return ui_frame;
} }
public void addListener(IWindowListener listener, boolean notify) public void addListener(IWindowListener listener, boolean notify) {
{ if(listener != null) {
if(listener != null)
{
listeners.add(listener); listeners.add(listener);
if(notify) if(notify) listener.onWindowChanged(this);
{
listener.onWindowChanged(this);
}
} }
} }
public void removeListener(IWindowListener listener) public void removeListener(IWindowListener listener) {
{
listeners.remove(listener); listeners.remove(listener);
} }
public WindowCallback addCallback(LongFunction<Callback> provider) public WindowCallback addCallback(LongFunction<Callback> provider) {
{ if(provider == null) return null;
if(provider == null)
{
return null;
}
WindowCallback callback = new WindowCallback(provider); WindowCallback callback = new WindowCallback(provider);
callbacks.add(callback); callbacks.add(callback);
if(windowId != 0) if(windowId != 0) {
{ callback.load(windowId);
callback.reload(windowId);
} }
return callback; return callback;
} }
public void removeCallback(WindowCallback call) public void removeCallback(WindowCallback call) {
{ if(callbacks.remove(call)) {
if(callbacks.remove(call))
{
call.destroy(); call.destroy();
} }
} }
private void createProjectionMatrix() private void createProjectionMatrix() {
{
// float aspectRatio = (float)width / (float)height;
// float y_scale = (float)((1f / Math.tan(Math.toRadians(fieldOfView / 2f))) * aspectRatio);
// float x_scale = y_scale / aspectRatio;
// float frustum_length = far_plane - near_plane;
// projection.setIdentity();
// projection.set(0, x_scale);
// projection.set(5, y_scale);
// projection.set(10, -((far_plane + near_plane) / frustum_length));
// projection.set(11, -1);
// projection.set(14, -((2 * near_plane * far_plane) / frustum_length));
// projection.set(15, 0);
// invertedProjection.load(projection).invert();
//
projection.setIdentity().setPerspective((float)Math.toRadians(fieldOfView), (float)width / (float)height, near_plane, far_plane); projection.setIdentity().setPerspective((float)Math.toRadians(fieldOfView), (float)width / (float)height, near_plane, far_plane);
invertedProjection.load(projection).invert(); invertedProjection.load(projection).invert();
} }
protected void fetchWindowBounds() protected void fetchWindowBounds() {
{
int[] width = new int[1]; int[] width = new int[1];
int[] height = new int[1]; int[] height = new int[1];
GLFW.glfwGetWindowSize(windowId, width, height); GLFW.glfwGetWindowSize(windowId, width, height);

View File

@ -9,22 +9,22 @@ public class WindowCallback
Callback callback; Callback callback;
LongFunction<Callback> provider; LongFunction<Callback> provider;
public WindowCallback(LongFunction<Callback> provider) public WindowCallback(LongFunction<Callback> provider) {
{
this.provider = provider; this.provider = provider;
} }
public void reload(long windowID) public void reload(long windowId) {
{ destroy();
callback = provider.apply(windowID); load(windowId);
} }
public void destroy() public void load(long windowId) {
{ callback = provider.apply(windowId);
if(callback != null) }
{
callback.free(); public void destroy() {
callback = null; if(callback == null) return;
} callback.free();
callback = null;
} }
} }

View File

@ -1,6 +1,7 @@
package speiger.src.coreengine.rendering.input.window; package speiger.src.coreengine.rendering.input.window;
import java.util.List; import java.util.List;
import java.util.Objects;
import org.lwjgl.glfw.GLFW; import org.lwjgl.glfw.GLFW;
import org.lwjgl.system.Callback; import org.lwjgl.system.Callback;
@ -14,16 +15,13 @@ public class WindowProvider
List<Callback> callbacks = new ObjectArrayList<>(); List<Callback> callbacks = new ObjectArrayList<>();
List<Window> activeWindows = new ObjectArrayList<>(); List<Window> activeWindows = new ObjectArrayList<>();
public void init() public void init() {
{
monitors = Monitor.createMonitors(); monitors = Monitor.createMonitors();
callbacks.add(GLFW.glfwSetMonitorCallback(this::onMonitorChange)); callbacks.add(GLFW.glfwSetMonitorCallback(this::onMonitorChange));
} }
protected void onMonitorChange(long id, int state) protected void onMonitorChange(long id, int state) {
{ switch(state) {
switch(state)
{
case GLFW.GLFW_CONNECTED: case GLFW.GLFW_CONNECTED:
monitors.put(id, new Monitor(id)); monitors.put(id, new Monitor(id));
break; break;
@ -33,30 +31,31 @@ public class WindowProvider
} }
} }
public WindowStats createBuilder() public WindowStats createBuilder() {
{
return new WindowStats(this); return new WindowStats(this);
} }
public Monitor getMonitors(long id) public Monitor getMonitors(long id) {
{
return monitors.get(id); return monitors.get(id);
} }
public List<Window> getActiveWindows() public Window getWindowFromId(long id) {
{ for(Window window : activeWindows) {
if(window.getId() == id) return window;
}
return null;
}
public List<Window> getActiveWindows() {
return activeWindows; return activeWindows;
} }
public Monitor getMonitorFromWindow(Window window) public Monitor getMonitorFromWindow(Window window) {
{
Monitor monitor = null; Monitor monitor = null;
long overlap = Long.MIN_VALUE; long overlap = Long.MIN_VALUE;
for(Monitor entry : monitors.values()) for(Monitor entry : monitors.values()) {
{
long thisOverlap = entry.getInBounds(window); long thisOverlap = entry.getInBounds(window);
if(thisOverlap > overlap) if(thisOverlap > overlap) {
{
monitor = entry; monitor = entry;
overlap = thisOverlap; overlap = thisOverlap;
} }
@ -64,40 +63,26 @@ public class WindowProvider
return monitor == null ? monitors.get(GLFW.glfwGetPrimaryMonitor()) : monitor; return monitor == null ? monitors.get(GLFW.glfwGetPrimaryMonitor()) : monitor;
} }
public List<Monitor> getMonitors() public List<Monitor> getMonitors() {
{ return new ObjectArrayList<>(monitors.values());
return new ObjectArrayList<Monitor>(monitors.values());
} }
public void destroy() public void destroy() {
{ callbacks.forEach(Callback::free);
for(int i = 0,m=callbacks.size();i<m;i++)
{
callbacks.get(i).free();
}
callbacks.clear(); callbacks.clear();
GLFW.glfwTerminate(); GLFW.glfwTerminate();
GLFW.glfwSetErrorCallback(null).free(); GLFW.glfwSetErrorCallback(null).free();
} }
public void updateWindows() public void updateWindows() {
{ activeWindows.forEach(Window::update);
for(Window window : activeWindows)
{
window.update();
}
} }
public void finishFrame() public void finishFrame() {
{ activeWindows.forEach(Window::finishFrame);
for(Window window : activeWindows)
{
window.finishFrame();
}
} }
public static class WindowStats public static class WindowStats {
{
WindowProvider provider; WindowProvider provider;
String name = ""; String name = "";
int width; int width;
@ -112,114 +97,78 @@ public class WindowProvider
Window parent; Window parent;
VideoMode videoMode; VideoMode videoMode;
WindowStats(WindowProvider provider) WindowStats(WindowProvider provider) {
{
this.provider = provider; this.provider = provider;
videoMode = provider.monitors.get(GLFW.glfwGetPrimaryMonitor()).getDefaultMode(); videoMode = provider.monitors.get(GLFW.glfwGetPrimaryMonitor()).getDefaultMode();
} }
public WindowStats setName(String name) public WindowStats setName(String name) {
{ this.name = Objects.requireNonNull(name);
if(name != null)
{
this.name = name;
}
return this; return this;
} }
public WindowStats setWidth(int width) public WindowStats setWidth(int width) {
{ this.width = Math.max(1, width);
if(width > 0)
{
this.width = width;
}
return this; return this;
} }
public WindowStats setHeight(int height) public WindowStats setHeight(int height) {
{ this.height = Math.max(1, height);
if(height > 0)
{
this.height = height;
}
return this; return this;
} }
public WindowStats setAntiAlis(int antiAlis) public WindowStats setAntiAlis(int antiAlis) {
{ this.antiAlis = Math.max(1, antiAlis);
if(antiAlis >= 0)
{
this.antiAlis = antiAlis;
}
return this; return this;
} }
public WindowStats setSubWindow(Window parent) public WindowStats setSubWindow(Window parent) {
{
this.parent = parent; this.parent = parent;
return this; return this;
} }
public WindowStats setFullScreen(boolean fullScreen) public WindowStats setFullScreen(boolean fullScreen) {
{
this.fullScreen = fullScreen; this.fullScreen = fullScreen;
if(fullScreen) borderless &= !fullScreen;
{ floating &= !fullScreen;
borderless = false;
floating = false;
}
return this; return this;
} }
public WindowStats setBorderless(boolean borderless) public WindowStats setBorderless(boolean borderless) {
{
this.borderless = borderless; this.borderless = borderless;
if(borderless) fullScreen &= !borderless;
{
fullScreen = false;
}
return this; return this;
} }
public WindowStats setFloating(boolean floating) public WindowStats setFloating(boolean floating) {
{
this.floating = floating; this.floating = floating;
if(floating) fullScreen &= !floating;
{
fullScreen = false;
}
return this; return this;
} }
public WindowStats setCentered(boolean center) public WindowStats setCentered(boolean center) {
{
this.center = center; this.center = center;
return this; return this;
} }
public WindowStats setMonitor(VideoMode videoMode) public WindowStats setMonitor(VideoMode videoMode) {
{ if(videoMode != null && videoMode.monitor() != null) {
if(videoMode != null && videoMode.getMonitor() != null)
{
this.videoMode = videoMode; this.videoMode = videoMode;
} }
return this; return this;
} }
public WindowStats setVsync(boolean value) public WindowStats setVsync(boolean value) {
{
vsync = value; vsync = value;
return this; return this;
} }
public WindowStats setFPSCap(boolean cap) public WindowStats setFPSCap(boolean cap) {
{
fpsCap = cap; fpsCap = cap;
return this; return this;
} }
public Window build() public Window build() {
{
Window window = new Window().createWindow(this); Window window = new Window().createWindow(this);
provider.activeWindows.add(window); provider.activeWindows.add(window);
return window; return window;

View File

@ -0,0 +1,175 @@
package speiger.src.coreengine.rendering.newGui.components.base;
import java.util.List;
import java.util.function.Consumer;
import speiger.src.collections.ints.sets.IntOpenHashSet;
import speiger.src.collections.ints.sets.IntSet;
import speiger.src.collections.objects.lists.ObjectArrayList;
import speiger.src.coreengine.rendering.gui.helper.box.IGuiBox;
import speiger.src.coreengine.utils.collections.CollectionUtils;
import speiger.src.coreengine.utils.collections.FlagObject;
public non-sealed class GuiComponent extends FlagObject implements IInteractableContainer, ICastable, ILayoutComponent, IListableComponent {
private static final int FLAG_FOCUSED = 1<<0;
private static final int FLAG_ENABLED = 1<<1;
private static final int FLAG_VISIBLE = 1<<2;
private static final int FLAG_MANUAL_MANAGED = 1<<3;
private static final int FLAG_SCISSORED = 1<<4;
IGuiBox box;
GuiComponent parent;
List<GuiComponent> children = new ObjectArrayList<>();
List<IInteractable> interactions = new ObjectArrayList<>();
List<Consumer<GuiComponent>>[] listeners = CollectionUtils.createList(IListableComponent.MAX_LISTENER_TYPES);
IInteractable focused;
IntSet activeButtons = new IntOpenHashSet();
@Override
public List<? extends IInteractable> getChildren() {
return interactions;
}
@Override
public void setFocusedChild(IInteractable child) {
if(focused != null) focused.setFocused(false);
this.focused = child;
if(focused != null) focused.setFocused(true);
}
@Override
public IInteractable getFocusedChild() {
return focused;
}
@Override
public IntSet getActiveButtons() {
return activeButtons;
}
@Override
public void calculateBounds(ILayoutScanner output) {
output.accept(getBox());
for(GuiComponent child : children) {
if(child.isVisible() || output.acceptsInvisble()) {
child.calculateBounds(output);
}
}
}
@Override
public GuiComponent addListener(Consumer<GuiComponent> listener, int index) {
listeners[index].add(listener);
return this;
}
@Override
public GuiComponent removeListener(Consumer<GuiComponent> listener, int index) {
listeners[index].remove(listener);
return this;
}
@Override
public void notifyListeners(int index) {
if(listeners[index].isEmpty()) return;
for(Consumer<GuiComponent> comp : listeners[index]) {
comp.accept(this);
}
}
@Override
public IGuiBox getBox() {
return box;
}
@Override
public boolean isMouseColliding(int mouseX, int mouseY) {
return isVisible() && box.isColiding(mouseX, mouseY);
}
@Override
public GuiComponent set(float x, float y) {
if(box.getBaseX() != x || box.getBaseY() != y) {
box.setXY(x, y);
//TODO implement onChanged
}
return this;
}
@Override
public GuiComponent bounds(float width, float height) {
if(box.getBaseWidth() != width || box.getBaseHeight() != height) {
box.setBounds(width, height);
//TODO implement onChanged
}
return this;
}
@Override
public GuiComponent resize(float width, float height) {
if(width != 0F || height != 0F) {
box.grow(width, height);
//TODO implement onChanged
}
return this;
}
@Override
public GuiComponent move(float moveX, float moveY) {
if(moveX != 0F || moveY != 0F) {
box.move(moveX, moveY);
//TODO implement onChanged
}
return this;
}
@Override
public final boolean isFocused() {
return isFlagSet(FLAG_FOCUSED);
}
public final boolean isEnabled() {
return isFlagSet(FLAG_ENABLED);
}
public final boolean isVisible() {
return isFlagSet(FLAG_VISIBLE);
}
public final boolean isManualManaged() {
return isFlagSet(FLAG_MANUAL_MANAGED);
}
public final boolean isScissored() {
return isFlagSet(FLAG_SCISSORED);
}
@Override
public final void setFocused(boolean value) {
setFlag(FLAG_FOCUSED, value);
if(!value) setFocusedChild(null);
}
public final GuiComponent setEnabled(boolean value) {
setFlag(FLAG_ENABLED, value);
return this;
}
public final GuiComponent setVisible(boolean value) {
setFlag(FLAG_VISIBLE, value);
return this;
}
public final GuiComponent setManualManaged(boolean value) {
setFlag(FLAG_MANUAL_MANAGED, value);
return this;
}
public final GuiComponent setScissored(boolean value) {
setFlag(FLAG_SCISSORED, value);
return this;
}
}

View File

@ -0,0 +1,19 @@
package speiger.src.coreengine.rendering.newGui.components.base;
public interface ICastable
{
@SuppressWarnings("unchecked")
public default <T> T cast() {
return (T)this;
}
@SuppressWarnings("unchecked")
public default <T> T cast(Class<T> clz) {
return (T)this;
}
@SuppressWarnings("unchecked")
public default <T> T tryCast(Class<T> clz) {
return clz.isInstance(this) ? (T)this : null;
}
}

View File

@ -0,0 +1,19 @@
package speiger.src.coreengine.rendering.newGui.components.base;
public interface IInteractable
{
public boolean isMouseColliding(int mouseX, int mouseY);
public default boolean onMouseClick(int button, int mouseX, int mouseY) { return false; }
public default boolean onMouseDragged(int mouseX, int mouseY, int diffX, int diffY) { return false; }
public default boolean onMouseReleased(int button, int mouseX, int mouseY) { return false; }
public default boolean onMouseScroll(int scroll, int mouseX, int mouseY) { return false; }
public default boolean isPriorityKeyTarget() { return false; }
public default boolean onKeyPressed(int key, int mouseX, int mouseY) { return false; }
public default boolean onKeyReleased(int key, int mouseX, int mouseY) { return false; }
public default boolean onKeyTyped(char letter, int codepoint) { return false; }
public boolean isFocused();
public void setFocused(boolean value);
}

View File

@ -0,0 +1,92 @@
package speiger.src.coreengine.rendering.newGui.components.base;
import java.util.List;
import speiger.src.collections.ints.sets.IntSet;
public interface IInteractableContainer extends IInteractable
{
public List<? extends IInteractable> getChildren();
public void setFocusedChild(IInteractable child);
public IInteractable getFocusedChild();
public IntSet getActiveButtons();
public default IInteractable getChildAt(int mouseX, int mouseY) {
List<? extends IInteractable> children = getChildren();
for(int i = 0,m=children.size();i<m;i++) {
IInteractable interact = children.get(i);
if(interact.isMouseColliding(mouseX, mouseY)) return interact;
}
return null;
}
@Override
default boolean onMouseClick(int button, int mouseX, int mouseY) {
IntSet active = getActiveButtons();
if(active.size() > 0 && getFocusedChild() != null) {
IInteractable focus = getFocusedChild();
if(focus.isMouseColliding(mouseX, mouseY) && focus.onMouseClick(button, mouseX, mouseY)) {
active.add(button);
return true;
}
return false;
}
List<? extends IInteractable> children = getChildren();
for(int i = 0,m=children.size();i<m;i++) {
IInteractable interact = children.get(i);
if(interact.isMouseColliding(mouseX, mouseY) && interact.onMouseClick(button, mouseX, mouseY)) {
setFocusedChild(interact);
active.add(button);
return true;
}
}
if(active.isEmpty() && getFocusedChild() != null) setFocusedChild(null);
return false;
}
@Override
default boolean onMouseDragged(int mouseX, int mouseY, int diffX, int diffY) {
return getFocusedChild() != null && getActiveButtons().contains(0) && getFocusedChild().onMouseDragged(mouseX, mouseY, diffX, diffY);
}
@Override
default boolean onMouseReleased(int button, int mouseX, int mouseY) {
getActiveButtons().remove(button);
IInteractable interact = getChildAt(mouseX, mouseY);
return interact != null && interact == getFocusedChild() && interact.onMouseReleased(button, mouseX, mouseY);
}
@Override
default boolean onMouseScroll(int scroll, int mouseX, int mouseY) {
IInteractable interact = getChildAt(mouseX, mouseY);
return interact != null && interact.onMouseScroll(scroll, mouseX, mouseY);
}
@Override
default boolean onKeyPressed(int key, int mouseX, int mouseY) {
IInteractable interact = getFocusedChild();
if(interact != null && (interact.onKeyPressed(key, mouseX, mouseY) || interact.isPriorityKeyTarget())) return true;
List<? extends IInteractable> children = getChildren();
for(int i = 0,m=children.size();i<m;i++) {
if(children.get(i).onKeyPressed(key, mouseX, mouseY)) return true;
}
return false;
}
@Override
default boolean onKeyReleased(int key, int mouseX, int mouseY) {
IInteractable interact = getFocusedChild();
if(interact != null && (interact.onKeyReleased(key, mouseX, mouseY) || interact.isPriorityKeyTarget())) return true;
List<? extends IInteractable> children = getChildren();
for(int i = 0,m=children.size();i<m;i++) {
if(children.get(i).onKeyReleased(key, mouseX, mouseY)) return true;
}
return false;
}
@Override
default boolean onKeyTyped(char letter, int codepoint) {
return getFocusedChild() != null && getFocusedChild().onKeyTyped(letter, codepoint);
}
}

View File

@ -0,0 +1,64 @@
package speiger.src.coreengine.rendering.newGui.components.base;
import speiger.src.coreengine.rendering.gui.helper.box.IGuiBox;
public interface ILayoutComponent {
public void calculateBounds(ILayoutScanner output);
public IGuiBox getBox();
public default float getX() {
return getBox().getMinX();
}
public default float getY() {
return getBox().getMinY();
}
public default float getWidth() {
return getBox().getWidth();
}
public default float getHeight() {
return getBox().getHeight();
}
public ILayoutComponent set(float x, float y);
public ILayoutComponent bounds(float width, float height);
public ILayoutComponent resize(float width, float height);
public ILayoutComponent move(float moveX, float moveY);
public static interface ILayoutScanner {
public default void accept(IGuiBox box) { accept(box.getMinX(), box.getMinY(), box.getMaxX(), box.getMaxY()); }
public void accept(float minX, float minY, float maxX, float maxY);
public boolean acceptsInvisble();
public static ArrayFetcher of() { return new ArrayFetcher(false); }
public static ArrayFetcher includeInvisible() { return new ArrayFetcher(true); }
}
public static class ArrayFetcher implements ILayoutScanner {
float[] result = new float[] {Float.MAX_VALUE, Float.MAX_VALUE, -Float.MAX_VALUE, -Float.MAX_VALUE};
boolean includeInvisible = false;
public ArrayFetcher(boolean includeInvisible) {
this.includeInvisible = includeInvisible;
}
@Override
public boolean acceptsInvisble() {
return includeInvisible;
}
@Override
public void accept(float minX, float minY, float maxX, float maxY) {
result[0] = Math.min(minX, result[0]);
result[1] = Math.min(minX, result[1]);
result[2] = Math.max(minX, result[2]);
result[3] = Math.max(minX, result[3]);
}
public float[] getResult() {
return result;
}
}
}

Some files were not shown because too many files have changed in this diff Show More