resourceLocation is null, isn't separated by a colon, or has multiple colons.
- */
- IDhApiRenderableBoxGroup createForSingleBox(String resourceLocation, DhApiRenderableBox cube) throws IllegalArgumentException;
-
- /**
- * Creates a {@link IDhApiRenderableBoxGroup} from the given list of {@link DhApiRenderableBox} where each
- * one is positioned relative to given originBlockPos, which in turn is relative to the level's origin.
- *
- * @param resourceLocation A colon separated Resource Location string, similar to vanilla Minecraft, for example: "DistantHorizons:Clouds"
- * @param originBlockPos The starting position for this {@link IDhApiRenderableBoxGroup}, can be changed during runtime.
- *
- *
- * @see DhApiRenderableBox
- * @see IDhApiRenderableBoxGroup#getResourceLocationNamespace()
- * @see IDhApiRenderableBoxGroup#getResourceLocationPath()
- *
- * @throws IllegalArgumentException if resourceLocation is null, isn't separated by a colon, or has multiple colons.
- */
- IDhApiRenderableBoxGroup createRelativePositionedGroup(String resourceLocation, DhApiVec3d originBlockPos, ListresourceLocation is null, isn't separated by a colon, or has multiple colons.
- */
- IDhApiRenderableBoxGroup createAbsolutePositionedGroup(String resourceLocation, List
- * m00, m10, m20, m30,
- * m01, m11, m21, m31,
- * m02, m12, m22, m32,
- * m03, m13, m23, m33
- *
- *
* @author James Seibel
- * @version 2024-6-30
+ * @version 11-11-2021
*/
-public class DhApiMat4f implements IDhApiCopyable
+public class Mat4f
{
- public float m00;
- public float m01;
- public float m02;
- public float m03;
-
- public float m10;
- public float m11;
- public float m12;
- public float m13;
-
- public float m20;
- public float m21;
- public float m22;
- public float m23;
-
- public float m30;
- public float m31;
- public float m32;
- public float m33;
+ private float m00;
+ private float m01;
+ private float m02;
+ private float m03;
+ private float m10;
+ private float m11;
+ private float m12;
+ private float m13;
+ private float m20;
+ private float m21;
+ private float m22;
+ private float m23;
+ private float m30;
+ private float m31;
+ private float m32;
+ private float m33;
+ public Mat4f()
+ {
+
+ }
- //==============//
- // constructors //
- //==============//
-
- public DhApiMat4f() { /* all values are 0 */ }
-
- public DhApiMat4f(DhApiMat4f sourceMatrix)
+ public Mat4f(Mat4f sourceMatrix)
{
this.m00 = sourceMatrix.m00;
this.m01 = sourceMatrix.m01;
@@ -85,36 +76,163 @@ public class DhApiMat4f implements IDhApiCopyable
this.m33 = sourceMatrix.m33;
}
- /** Expects the values of the input array to be in row major order (AKA rows then columns) */
- public DhApiMat4f(float[] values)
+ public Mat4f(Matrix4fc sourceMatrix) { this(convertJomlMatrixToArray(sourceMatrix)); }
+ private static float[] convertJomlMatrixToArray(Matrix4fc sourceMatrix)
{
- m00 = values[0];
- m01 = values[1];
- m02 = values[2];
- m03 = values[3];
+ FloatBuffer buffer = FloatBuffer.allocate(16);
- m10 = values[4];
- m11 = values[5];
- m12 = values[6];
- m13 = values[7];
+ buffer.put(bufferIndex(0, 0), sourceMatrix.m00());
+ buffer.put(bufferIndex(0, 1), sourceMatrix.m01());
+ buffer.put(bufferIndex(0, 2), sourceMatrix.m02());
+ buffer.put(bufferIndex(0, 3), sourceMatrix.m03());
+ buffer.put(bufferIndex(1, 0), sourceMatrix.m10());
+ buffer.put(bufferIndex(1, 1), sourceMatrix.m11());
+ buffer.put(bufferIndex(1, 2), sourceMatrix.m12());
+ buffer.put(bufferIndex(1, 3), sourceMatrix.m13());
+ buffer.put(bufferIndex(2, 0), sourceMatrix.m20());
+ buffer.put(bufferIndex(2, 1), sourceMatrix.m21());
+ buffer.put(bufferIndex(2, 2), sourceMatrix.m22());
+ buffer.put(bufferIndex(2, 3), sourceMatrix.m23());
+ buffer.put(bufferIndex(3, 0), sourceMatrix.m30());
+ buffer.put(bufferIndex(3, 1), sourceMatrix.m31());
+ buffer.put(bufferIndex(3, 2), sourceMatrix.m32());
+ buffer.put(bufferIndex(3, 3), sourceMatrix.m33());
- m20 = values[8];
- m21 = values[9];
- m22 = values[10];
- m23 = values[11];
-
- m30 = values[12];
- m31 = values[13];
- m32 = values[14];
- m33 = values[15];
+ return buffer.array();
+ }
+
+ /* Quaternions are not currently needed/implemented
+ public Matrix4float(Quaternion p_i48104_1_)
+ {
+ float f = p_i48104_1_.i();
+ float f1 = p_i48104_1_.j();
+ float f2 = p_i48104_1_.k();
+ float f3 = p_i48104_1_.r();
+ float f4 = 2.0F * f * f;
+ float f5 = 2.0F * f1 * f1;
+ float f6 = 2.0F * f2 * f2;
+ this.m00 = 1.0F - f5 - f6;
+ this.m11 = 1.0F - f6 - f4;
+ this.m22 = 1.0F - f4 - f5;
+ this.m33 = 1.0F;
+ float f7 = f * f1;
+ float f8 = f1 * f2;
+ float f9 = f2 * f;
+ float f10 = f * f3;
+ float f11 = f1 * f3;
+ float f12 = f2 * f3;
+ this.m10 = 2.0F * (f7 + f12);
+ this.m01 = 2.0F * (f7 - f12);
+ this.m20 = 2.0F * (f9 - f11);
+ this.m02 = 2.0F * (f9 + f11);
+ this.m21 = 2.0F * (f8 + f10);
+ this.m12 = 2.0F * (f8 - f10);
+ }
+ */
+
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
+ {
+ return true;
+ }
+ else if (obj != null && this.getClass() == obj.getClass())
+ {
+ Mat4f otherMatrix = (Mat4f) obj;
+ return Float.compare(otherMatrix.m00, this.m00) == 0
+ && Float.compare(otherMatrix.m01, this.m01) == 0
+ && Float.compare(otherMatrix.m02, this.m02) == 0
+ && Float.compare(otherMatrix.m03, this.m03) == 0
+ && Float.compare(otherMatrix.m10, this.m10) == 0
+ && Float.compare(otherMatrix.m11, this.m11) == 0
+ && Float.compare(otherMatrix.m12, this.m12) == 0
+ && Float.compare(otherMatrix.m13, this.m13) == 0
+ && Float.compare(otherMatrix.m20, this.m20) == 0
+ && Float.compare(otherMatrix.m21, this.m21) == 0
+ && Float.compare(otherMatrix.m22, this.m22) == 0
+ && Float.compare(otherMatrix.m23, this.m23) == 0
+ && Float.compare(otherMatrix.m30, this.m30) == 0
+ && Float.compare(otherMatrix.m31, this.m31) == 0
+ && Float.compare(otherMatrix.m32, this.m32) == 0
+ && Float.compare(otherMatrix.m33, this.m33) == 0;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ @Override
+ public int hashCode()
+ {
+ int i = this.m00 != 0.0F ? Float.floatToIntBits(this.m00) : 0;
+ i = 31 * i + (this.m01 != 0.0F ? Float.floatToIntBits(this.m01) : 0);
+ i = 31 * i + (this.m02 != 0.0F ? Float.floatToIntBits(this.m02) : 0);
+ i = 31 * i + (this.m03 != 0.0F ? Float.floatToIntBits(this.m03) : 0);
+ i = 31 * i + (this.m10 != 0.0F ? Float.floatToIntBits(this.m10) : 0);
+ i = 31 * i + (this.m11 != 0.0F ? Float.floatToIntBits(this.m11) : 0);
+ i = 31 * i + (this.m12 != 0.0F ? Float.floatToIntBits(this.m12) : 0);
+ i = 31 * i + (this.m13 != 0.0F ? Float.floatToIntBits(this.m13) : 0);
+ i = 31 * i + (this.m20 != 0.0F ? Float.floatToIntBits(this.m20) : 0);
+ i = 31 * i + (this.m21 != 0.0F ? Float.floatToIntBits(this.m21) : 0);
+ i = 31 * i + (this.m22 != 0.0F ? Float.floatToIntBits(this.m22) : 0);
+ i = 31 * i + (this.m23 != 0.0F ? Float.floatToIntBits(this.m23) : 0);
+ i = 31 * i + (this.m30 != 0.0F ? Float.floatToIntBits(this.m30) : 0);
+ i = 31 * i + (this.m31 != 0.0F ? Float.floatToIntBits(this.m31) : 0);
+ i = 31 * i + (this.m32 != 0.0F ? Float.floatToIntBits(this.m32) : 0);
+ return 31 * i + (this.m33 != 0.0F ? Float.floatToIntBits(this.m33) : 0);
}
+ @Override
+ public String toString()
+ {
+ return "Matrix4f:\n" +
+ this.m00 + " " + this.m01 + " " + this.m02 + " " + this.m03 + "\n" +
+ this.m10 + " " + this.m11 + " " + this.m12 + " " + this.m13 + "\n" +
+ this.m20 + " " + this.m21 + " " + this.m22 + " " + this.m23 + "\n" +
+ this.m30 + " " + this.m31 + " " + this.m32 + " " + this.m33 + "\n";
+ }
- //=========//
- // methods //
- //=========//
+ public void store(FloatBuffer floatBuffer)
+ {
+ floatBuffer.put(bufferIndex(0, 0), this.m00);
+ floatBuffer.put(bufferIndex(0, 1), this.m01);
+ floatBuffer.put(bufferIndex(0, 2), this.m02);
+ floatBuffer.put(bufferIndex(0, 3), this.m03);
+ floatBuffer.put(bufferIndex(1, 0), this.m10);
+ floatBuffer.put(bufferIndex(1, 1), this.m11);
+ floatBuffer.put(bufferIndex(1, 2), this.m12);
+ floatBuffer.put(bufferIndex(1, 3), this.m13);
+ floatBuffer.put(bufferIndex(2, 0), this.m20);
+ floatBuffer.put(bufferIndex(2, 1), this.m21);
+ floatBuffer.put(bufferIndex(2, 2), this.m22);
+ floatBuffer.put(bufferIndex(2, 3), this.m23);
+ floatBuffer.put(bufferIndex(3, 0), this.m30);
+ floatBuffer.put(bufferIndex(3, 1), this.m31);
+ floatBuffer.put(bufferIndex(3, 2), this.m32);
+ floatBuffer.put(bufferIndex(3, 3), this.m33);
+ }
+
+ public Matrix4f createJomlMatrix()
+ {
+ return new Matrix4f(
+ this.m00, this.m10, this.m20, this.m30,
+ this.m01, this.m11, this.m21, this.m31,
+ this.m02, this.m12, this.m22, this.m32,
+ this.m03, this.m13, this.m23, this.m33
+ );
+ }
+
+
+ private static int bufferIndex(int xIndex, int zIndex)
+ {
+ return (zIndex * 4) + xIndex;
+ }
+
public void setIdentity()
{
@@ -223,7 +341,7 @@ public class DhApiMat4f implements IDhApiCopyable
}
}
- public void multiply(DhApiMat4f multMatrix)
+ public void multiply(Mat4f multMatrix)
{
float f = this.m00 * multMatrix.m00 + this.m01 * multMatrix.m10 + this.m02 * multMatrix.m20 + this.m03 * multMatrix.m30;
float f1 = this.m00 * multMatrix.m01 + this.m01 * multMatrix.m11 + this.m02 * multMatrix.m21 + this.m03 * multMatrix.m31;
@@ -259,6 +377,13 @@ public class DhApiMat4f implements IDhApiCopyable
this.m33 = f15;
}
+ /* Quaternions aren't currently needed/implemented
+ public void multiply(Quaternion p_226596_1_)
+ {
+ this.multiply(new Matrix4f(p_226596_1_));
+ }
+ */
+
public void multiply(float scalar)
{
this.m00 *= scalar;
@@ -279,6 +404,81 @@ public class DhApiMat4f implements IDhApiCopyable
this.m33 *= scalar;
}
+ public static Mat4f perspective(double fov, float widthHeightRatio, float nearClipPlane, float farClipPlane)
+ {
+ float f = (float) (1.0D / Math.tan(fov * ((float) Math.PI / 180F) / 2.0D));
+ Mat4f matrix = new Mat4f();
+ matrix.m00 = f / widthHeightRatio;
+ matrix.m11 = f;
+ matrix.m22 = (farClipPlane + nearClipPlane) / (nearClipPlane - farClipPlane);
+ matrix.m32 = -1.0F;
+ matrix.m23 = 2.0F * farClipPlane * nearClipPlane / (nearClipPlane - farClipPlane);
+ return matrix;
+ }
+
+
+ /* not currently needed/implemented
+ * Also the parameter names should be double checked as they may be incorrect
+ public static Matrix4Float orthographic(float left, float right, float top, float bottom)
+ {
+ Matrix4Float matrix4f = new Matrix4Float();
+ matrix4f.m00 = 2.0F / left;
+ matrix4f.m11 = 2.0F / right;
+ float f = bottom - top;
+ matrix4f.m22 = -2.0F / f;
+ matrix4f.m33 = 1.0F;
+ matrix4f.m03 = -1.0F;
+ matrix4f.m13 = -1.0F;
+ matrix4f.m23 = -(bottom + top) / f;
+ return matrix4f;
+ }
+ */
+
+ /**
+ * TODO: what kind of translation is this?
+ * and how is this different from "multiplyTranslationMatrix"?
+ * Answer: This is faster and direct (but only if this is pure translation matrix without rotate)
+ */
+ public void translate(Vec3f vec)
+ {
+ this.m03 += vec.x;
+ this.m13 += vec.y;
+ this.m23 += vec.z;
+ }
+
+ /** originally "translate" from Minecraft's MatrixStack */
+ public void multiplyTranslationMatrix(double x, double y, double z)
+ {
+ multiply(createTranslateMatrix((float) x, (float) y, (float) z));
+ }
+
+ public Mat4f copy()
+ {
+ return new Mat4f(this);
+ }
+
+ public static Mat4f createScaleMatrix(float x, float y, float z)
+ {
+ Mat4f matrix = new Mat4f();
+ matrix.m00 = x;
+ matrix.m11 = y;
+ matrix.m22 = z;
+ matrix.m33 = 1.0F;
+ return matrix;
+ }
+
+ public static Mat4f createTranslateMatrix(float x, float y, float z)
+ {
+ Mat4f matrix = new Mat4f();
+ matrix.m00 = 1.0F;
+ matrix.m11 = 1.0F;
+ matrix.m22 = 1.0F;
+ matrix.m33 = 1.0F;
+ matrix.m03 = x;
+ matrix.m13 = y;
+ matrix.m23 = z;
+ return matrix;
+ }
@@ -287,8 +487,6 @@ public class DhApiMat4f implements IDhApiCopyable
// methods //
//==================//
- private static int getArrayIndex(int xIndex, int zIndex) { return (zIndex * 4) + xIndex; }
-
/** Returns the values of this matrix in row major order (AKA rows then columns) */
public float[] getValuesAsArray()
{
@@ -315,77 +513,113 @@ public class DhApiMat4f implements IDhApiCopyable
};
}
-
-
- //================//
- // base overrides //
- //================//
-
- @Override
- public boolean equals(Object obj)
+ public Vec3f asNonNormalizedLookForwardVector()
{
- if (this == obj)
- {
- return true;
- }
- else if (obj != null && this.getClass() == obj.getClass())
- {
- DhApiMat4f otherMatrix = (DhApiMat4f) obj;
- return Float.compare(otherMatrix.m00, this.m00) == 0
- && Float.compare(otherMatrix.m01, this.m01) == 0
- && Float.compare(otherMatrix.m02, this.m02) == 0
- && Float.compare(otherMatrix.m03, this.m03) == 0
- && Float.compare(otherMatrix.m10, this.m10) == 0
- && Float.compare(otherMatrix.m11, this.m11) == 0
- && Float.compare(otherMatrix.m12, this.m12) == 0
- && Float.compare(otherMatrix.m13, this.m13) == 0
- && Float.compare(otherMatrix.m20, this.m20) == 0
- && Float.compare(otherMatrix.m21, this.m21) == 0
- && Float.compare(otherMatrix.m22, this.m22) == 0
- && Float.compare(otherMatrix.m23, this.m23) == 0
- && Float.compare(otherMatrix.m30, this.m30) == 0
- && Float.compare(otherMatrix.m31, this.m31) == 0
- && Float.compare(otherMatrix.m32, this.m32) == 0
- && Float.compare(otherMatrix.m33, this.m33) == 0;
- }
- else
- {
- return false;
- }
+ return new Vec3f(this.m02, this.m12, this.m22);
}
- @Override
- public int hashCode()
+ //===============//
+ // Forge methods //
+ //===============//
+
+ public Mat4f(float[] values)
{
- int i = this.m00 != 0.0F ? Float.floatToIntBits(this.m00) : 0;
- i = 31 * i + (this.m01 != 0.0F ? Float.floatToIntBits(this.m01) : 0);
- i = 31 * i + (this.m02 != 0.0F ? Float.floatToIntBits(this.m02) : 0);
- i = 31 * i + (this.m03 != 0.0F ? Float.floatToIntBits(this.m03) : 0);
- i = 31 * i + (this.m10 != 0.0F ? Float.floatToIntBits(this.m10) : 0);
- i = 31 * i + (this.m11 != 0.0F ? Float.floatToIntBits(this.m11) : 0);
- i = 31 * i + (this.m12 != 0.0F ? Float.floatToIntBits(this.m12) : 0);
- i = 31 * i + (this.m13 != 0.0F ? Float.floatToIntBits(this.m13) : 0);
- i = 31 * i + (this.m20 != 0.0F ? Float.floatToIntBits(this.m20) : 0);
- i = 31 * i + (this.m21 != 0.0F ? Float.floatToIntBits(this.m21) : 0);
- i = 31 * i + (this.m22 != 0.0F ? Float.floatToIntBits(this.m22) : 0);
- i = 31 * i + (this.m23 != 0.0F ? Float.floatToIntBits(this.m23) : 0);
- i = 31 * i + (this.m30 != 0.0F ? Float.floatToIntBits(this.m30) : 0);
- i = 31 * i + (this.m31 != 0.0F ? Float.floatToIntBits(this.m31) : 0);
- i = 31 * i + (this.m32 != 0.0F ? Float.floatToIntBits(this.m32) : 0);
- return 31 * i + (this.m33 != 0.0F ? Float.floatToIntBits(this.m33) : 0);
+ m00 = values[0];
+ m01 = values[1];
+ m02 = values[2];
+ m03 = values[3];
+ m10 = values[4];
+ m11 = values[5];
+ m12 = values[6];
+ m13 = values[7];
+ m20 = values[8];
+ m21 = values[9];
+ m22 = values[10];
+ m23 = values[11];
+ m30 = values[12];
+ m31 = values[13];
+ m32 = values[14];
+ m33 = values[15];
}
- @Override
- public String toString()
+ public Mat4f(FloatBuffer buffer)
{
- return "Matrix4f:\n" +
- this.m00 + " " + this.m01 + " " + this.m02 + " " + this.m03 + "\n" +
- this.m10 + " " + this.m11 + " " + this.m12 + " " + this.m13 + "\n" +
- this.m20 + " " + this.m21 + " " + this.m22 + " " + this.m23 + "\n" +
- this.m30 + " " + this.m31 + " " + this.m32 + " " + this.m33 + "\n";
+ this(buffer.array());
}
- @Override
- public DhApiMat4f copy() { return new DhApiMat4f(this); }
+ public void set(Mat4f mat)
+ {
+ this.m00 = mat.m00;
+ this.m01 = mat.m01;
+ this.m02 = mat.m02;
+ this.m03 = mat.m03;
+ this.m10 = mat.m10;
+ this.m11 = mat.m11;
+ this.m12 = mat.m12;
+ this.m13 = mat.m13;
+ this.m20 = mat.m20;
+ this.m21 = mat.m21;
+ this.m22 = mat.m22;
+ this.m23 = mat.m23;
+ this.m30 = mat.m30;
+ this.m31 = mat.m31;
+ this.m32 = mat.m32;
+ this.m33 = mat.m33;
+ }
+
+ public void add(Mat4f other)
+ {
+ m00 += other.m00;
+ m01 += other.m01;
+ m02 += other.m02;
+ m03 += other.m03;
+ m10 += other.m10;
+ m11 += other.m11;
+ m12 += other.m12;
+ m13 += other.m13;
+ m20 += other.m20;
+ m21 += other.m21;
+ m22 += other.m22;
+ m23 += other.m23;
+ m30 += other.m30;
+ m31 += other.m31;
+ m32 += other.m32;
+ m33 += other.m33;
+ }
+
+ public void multiplyBackward(Mat4f other)
+ {
+ Mat4f copy = other.copy();
+ copy.multiply(this);
+ this.set(copy);
+ }
+
+ public void setTranslation(float x, float y, float z)
+ {
+ this.m00 = 1.0F;
+ this.m11 = 1.0F;
+ this.m22 = 1.0F;
+ this.m33 = 1.0F;
+ this.m03 = x;
+ this.m13 = y;
+ this.m23 = z;
+ }
+
+ /**
+ * Changes the values that store the clipping planes.
+ * Formula for calculating matrix values is the same that OpenGL uses when making matrices.
+ *
+ * @param nearClip New near clipping plane value.
+ * @param farClip New far clipping plane value.
+ */
+ public void setClipPlanes(float nearClip, float farClip)
+ {
+ //convert to matrix values, formula copied from a textbook / openGL specification.
+ float matNearClip = -((farClip + nearClip) / (farClip - nearClip));
+ float matFarClip = -((2 * farClip * nearClip) / (farClip - nearClip));
+ //set new values for the clip planes.
+ this.m22 = matNearClip;
+ this.m23 = matFarClip;
+ }
}
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/util/math/Vec3d.java b/api/src/main/java/com/seibel/distanthorizons/coreapi/util/math/Vec3d.java
similarity index 50%
rename from core/src/main/java/com/seibel/distanthorizons/core/util/math/Vec3d.java
rename to api/src/main/java/com/seibel/distanthorizons/coreapi/util/math/Vec3d.java
index 57911612f..a1374d8de 100644
--- a/core/src/main/java/com/seibel/distanthorizons/core/util/math/Vec3d.java
+++ b/api/src/main/java/com/seibel/distanthorizons/coreapi/util/math/Vec3d.java
@@ -17,9 +17,8 @@
* along with this program. If not, see