[FEAT] continue maven integration

This commit is contained in:
Edouard DUPIN 2024-06-09 09:57:21 +02:00
parent b60809bc81
commit 5a5e7de99d
13 changed files with 491 additions and 521 deletions

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<fileset-config file-format-version="1.2.0" simple-config="true" sync-formatter="false"> <fileset-config file-format-version="1.2.0" simple-config="true" sync-formatter="false">
<fileset name="all" enabled="true" check-config-name="Ewol" local="false"> <fileset name="all" enabled="true" check-config-name="Google Checks" local="false">
<file-match-pattern match-pattern="." include-pattern="true"/> <file-match-pattern match-pattern="." include-pattern="true"/>
</fileset> </fileset>
</fileset-config> </fileset-config>

View File

@ -1,28 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry including="**/*.java" kind="src" output="out/maven/classes" path="src">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="out/maven/test-classes" path="test/src">
<attributes>
<attribute name="test" value="true"/>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-21">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="out/maven/classes"/>
</classpath>

View File

@ -1,46 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>atriasoft-etk</name>
<comment></comment>
<projects>
<project>atriasoft-etk</project>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.ui.externaltools.ExternalToolBuilder</name>
<triggers>full,incremental,</triggers>
<arguments>
<dictionary>
<key>LaunchConfigHandle</key>
<value>&lt;project&gt;/.externalToolBuilders/net.sf.eclipsecs.core.CheckstyleBuilder.launch</value>
</dictionary>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>net.sf.eclipsecs.core.CheckstyleNature</nature>
</natures>
<filteredResources>
<filter>
<id>1664626602847</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>1.0-name-matches-false-true-node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>

View File

@ -32,17 +32,17 @@
<dependency> <dependency>
<groupId>org.slf4j</groupId> <groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId> <artifactId>slf4j-api</artifactId>
<version>2.0.7</version> <version>2.1.0-alpha1</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.github.spotbugs</groupId> <groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-annotations</artifactId> <artifactId>spotbugs-annotations</artifactId>
<version>4.7.3</version> <version>4.8.5</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.junit.jupiter</groupId> <groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId> <artifactId>junit-jupiter-api</artifactId>
<version>5.9.3</version> <version>5.11.0-M2</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
</dependencies> </dependencies>
@ -50,7 +50,6 @@
<build> <build>
<sourceDirectory>src</sourceDirectory> <sourceDirectory>src</sourceDirectory>
<testSourceDirectory>test/src</testSourceDirectory> <testSourceDirectory>test/src</testSourceDirectory>
<directory>${project.basedir}/out/maven/</directory>
<plugins> <plugins>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
@ -66,6 +65,7 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId> <artifactId>maven-source-plugin</artifactId>
<version>3.3.1</version>
<executions> <executions>
<execution> <execution>
<id>attach-sources</id> <id>attach-sources</id>

View File

@ -4,7 +4,6 @@ import java.util.Map;
import org.atriasoft.etk.math.FMath; import org.atriasoft.etk.math.FMath;
@SuppressWarnings("preview")
//@formatter:off //@formatter:off
public record Color( public record Color(

View File

@ -5,7 +5,6 @@ package org.atriasoft.etk.math;
* sx shx tx * sx shx tx
* sy shy ty * sy shy ty
*/ */
@SuppressWarnings("preview")
public record Matrix2x3f( public record Matrix2x3f(
float sx, float sx,
float shy, float shy,

View File

@ -2,7 +2,6 @@ package org.atriasoft.etk.math;
import edu.umd.cs.findbugs.annotations.CheckReturnValue; import edu.umd.cs.findbugs.annotations.CheckReturnValue;
@SuppressWarnings("preview")
public record Matrix3f( public record Matrix3f(
float a1, float a1,
float a2, float a2,
@ -20,7 +19,8 @@ public record Matrix3f(
* @return Matrix to compute * @return Matrix to compute
*/ */
public static Matrix3f computeSkewSymmetricMatrixForCrossProduct(final Vector3f vector) { public static Matrix3f computeSkewSymmetricMatrixForCrossProduct(final Vector3f vector) {
return new Matrix3f(0.0f, -vector.z(), vector.y(), vector.z(), 0.0f, -vector.x(), -vector.y(), vector.x(), 0.0f); return new Matrix3f(0.0f, -vector.z(), vector.y(), vector.z(), 0.0f, -vector.x(), -vector.y(), vector.x(),
0.0f);
} }
/** /**
@ -34,17 +34,17 @@ public record Matrix3f(
final float sinVal = (float) Math.sin(angleRad); final float sinVal = (float) Math.sin(angleRad);
final float invVal = 1.0f - cosVal; final float invVal = 1.0f - cosVal;
// set rotation : // set rotation :
float a1 = normal.x() * normal.x() * invVal + cosVal; final float a1 = normal.x() * normal.x() * invVal + cosVal;
float a2 = normal.x() * normal.y() * invVal - normal.z() * sinVal; final float a2 = normal.x() * normal.y() * invVal - normal.z() * sinVal;
float a3 = normal.x() * normal.z() * invVal + normal.y() * sinVal; final float a3 = normal.x() * normal.z() * invVal + normal.y() * sinVal;
float b1 = normal.y() * normal.x() * invVal + normal.z() * sinVal; final float b1 = normal.y() * normal.x() * invVal + normal.z() * sinVal;
float b2 = normal.y() * normal.y() * invVal + cosVal; final float b2 = normal.y() * normal.y() * invVal + cosVal;
float b3 = normal.y() * normal.z() * invVal - normal.x() * sinVal; final float b3 = normal.y() * normal.z() * invVal - normal.x() * sinVal;
float c1 = normal.z() * normal.x() * invVal - normal.y() * sinVal; final float c1 = normal.z() * normal.x() * invVal - normal.y() * sinVal;
float c2 = normal.z() * normal.y() * invVal + normal.x() * sinVal; final float c2 = normal.z() * normal.y() * invVal + normal.x() * sinVal;
float c3 = normal.z() * normal.z() * invVal + cosVal; final float c3 = normal.z() * normal.z() * invVal + cosVal;
return new Matrix3f(a1, a2, a3, b1, b2, b3, c1, c2, c3); return new Matrix3f(a1, a2, a3, b1, b2, b3, c1, c2, c3);
} }
@ -80,7 +80,8 @@ public record Matrix3f(
* @param c2 element 2x1 * @param c2 element 2x1
* @param c3 element 2x2 * @param c3 element 2x2
*/ */
public Matrix3f(final float a1, final float a2, final float a3, final float b1, final float b2, final float b3, final float c1, final float c2, final float c3) { public Matrix3f(final float a1, final float a2, final float a3, final float b1, final float b2, final float b3,
final float c1, final float c2, final float c3) {
this.a1 = a1; this.a1 = a1;
this.a2 = a2; this.a2 = a2;
this.a3 = a3; this.a3 = a3;
@ -97,7 +98,8 @@ public record Matrix3f(
*/ */
@CheckReturnValue @CheckReturnValue
public Matrix3f abs() { public Matrix3f abs() {
return new Matrix3f(Math.abs(this.a1), Math.abs(this.a2), Math.abs(this.a3), Math.abs(this.b1), Math.abs(this.b2), Math.abs(this.b3), Math.abs(this.c1), Math.abs(this.c2), Math.abs(this.c3)); return new Matrix3f(Math.abs(this.a1), Math.abs(this.a2), Math.abs(this.a3), Math.abs(this.b1),
Math.abs(this.b2), Math.abs(this.b3), Math.abs(this.c1), Math.abs(this.c2), Math.abs(this.c3));
} }
/** /**
@ -107,7 +109,8 @@ public record Matrix3f(
*/ */
@CheckReturnValue @CheckReturnValue
public Matrix3f add(final Matrix3f obj) { public Matrix3f add(final Matrix3f obj) {
return new Matrix3f(this.a1 + obj.a1, this.a2 + obj.a2, this.a3 + obj.a3, this.b1 + obj.b1, this.b2 + obj.b2, this.b3 + obj.b3, this.c1 + obj.c1, this.c2 + obj.c2, this.c3 + obj.c3); return new Matrix3f(this.a1 + obj.a1, this.a2 + obj.a2, this.a3 + obj.a3, this.b1 + obj.b1, this.b2 + obj.b2,
this.b3 + obj.b3, this.c1 + obj.c1, this.c2 + obj.c2, this.c3 + obj.c3);
} }
// Return a skew-symmetric matrix using a given vector that can be used // Return a skew-symmetric matrix using a given vector that can be used
@ -123,7 +126,8 @@ public record Matrix3f(
*/ */
@CheckReturnValue @CheckReturnValue
public float determinant() { public float determinant() {
return this.a1 * (this.b2 * this.c3 - this.c2 * this.b3) - this.a2 * (this.b1 * this.c3 - this.c1 * this.b3) + this.a3 * (this.b1 * this.c2 - this.c1 * this.b2); return this.a1 * (this.b2 * this.c3 - this.c2 * this.b3) - this.a2 * (this.b1 * this.c3 - this.c1 * this.b3)
+ this.a3 * (this.b1 * this.c2 - this.c1 * this.b2);
} }
/** /**
@ -132,33 +136,24 @@ public record Matrix3f(
*/ */
@CheckReturnValue @CheckReturnValue
public Matrix3f divide(final float value) { public Matrix3f divide(final float value) {
return new Matrix3f(this.a1 / value, this.a2 / value, this.a3 / value, this.b1 / value, this.b2 / value, this.b3 / value, this.c1 / value, this.c2 / value, this.c3 / value); return new Matrix3f(this.a1 / value, this.a2 / value, this.a3 / value, this.b1 / value, this.b2 / value,
this.b3 / value, this.c1 / value, this.c2 / value, this.c3 / value);
} }
@CheckReturnValue @CheckReturnValue
public float get(final int iii) { public float get(final int iii) {
switch (iii) { return switch (iii) {
case 0: case 0 -> this.a1;
return this.a1; case 1 -> this.a2;
case 1: case 2 -> this.a3;
return this.a2; case 3 -> this.b1;
case 2: case 4 -> this.b2;
return this.a3; case 5 -> this.b3;
case 3: case 6 -> this.c1;
return this.b1; case 7 -> this.c2;
case 4: case 8 -> this.c3;
return this.b2; default -> 0;
case 5: };
return this.b3;
case 6:
return this.c1;
case 7:
return this.c2;
case 8:
return this.c3;
default:
return 0;
}
} }
/** /**
@ -208,9 +203,11 @@ public record Matrix3f(
public Matrix3f inverse() { public Matrix3f inverse() {
final float det = determinant(); final float det = determinant();
//assert(Math.abs(det) > MACHINEEPSILON); //assert(Math.abs(det) > MACHINEEPSILON);
return new Matrix3f((this.b2 * this.c3 - this.c2 * this.b3) / det, -(this.a2 * this.c3 - this.c2 * this.a3) / det, (this.a2 * this.b3 - this.a3 * this.b2) / det, return new Matrix3f((this.b2 * this.c3 - this.c2 * this.b3) / det,
-(this.b1 * this.c3 - this.c1 * this.b3) / det, (this.a1 * this.c3 - this.c1 * this.a3) / det, -(this.a1 * this.b3 - this.b1 * this.a3) / det, -(this.a2 * this.c3 - this.c2 * this.a3) / det, (this.a2 * this.b3 - this.a3 * this.b2) / det,
(this.b1 * this.c2 - this.c1 * this.b2) / det, -(this.a1 * this.c2 - this.c1 * this.a2) / det, (this.a1 * this.b2 - this.a2 * this.b1) / det); -(this.b1 * this.c3 - this.c1 * this.b3) / det, (this.a1 * this.c3 - this.c1 * this.a3) / det,
-(this.a1 * this.b3 - this.b1 * this.a3) / det, (this.b1 * this.c2 - this.c1 * this.b2) / det,
-(this.a1 * this.c2 - this.c1 * this.a2) / det, (this.a1 * this.b2 - this.a2 * this.b1) / det);
} }
// Overloaded operator for the negative of the matrix // Overloaded operator for the negative of the matrix
@ -227,7 +224,8 @@ public record Matrix3f(
*/ */
@CheckReturnValue @CheckReturnValue
public boolean isDifferent(final Matrix3f obj) { public boolean isDifferent(final Matrix3f obj) {
if (this.a1 != obj.a1 || this.a2 != obj.a2 || this.a3 != obj.a3 || this.b1 != obj.b1 || this.b2 != obj.b2 || this.b3 != obj.b3 || this.c1 != obj.c1 || this.c2 != obj.c2 || this.c3 != obj.c3) { if (this.a1 != obj.a1 || this.a2 != obj.a2 || this.a3 != obj.a3 || this.b1 != obj.b1 || this.b2 != obj.b2
|| this.b3 != obj.b3 || this.c1 != obj.c1 || this.c2 != obj.c2 || this.c3 != obj.c3) {
return true; return true;
} }
return false; return false;
@ -241,7 +239,8 @@ public record Matrix3f(
*/ */
@CheckReturnValue @CheckReturnValue
boolean isEqual(final Matrix3f obj) { boolean isEqual(final Matrix3f obj) {
if (this.a1 != obj.a1 || this.a2 != obj.a2 || this.a3 != obj.a3 || this.b1 != obj.b1 || this.b2 != obj.b2 || this.b3 != obj.b3 || this.c1 != obj.c1 || this.c2 != obj.c2 || this.c3 != obj.c3) { if (this.a1 != obj.a1 || this.a2 != obj.a2 || this.a3 != obj.a3 || this.b1 != obj.b1 || this.b2 != obj.b2
|| this.b3 != obj.b3 || this.c1 != obj.c1 || this.c2 != obj.c2 || this.c3 != obj.c3) {
return false; return false;
} }
return true; return true;
@ -254,7 +253,8 @@ public record Matrix3f(
*/ */
@CheckReturnValue @CheckReturnValue
public Matrix3f less(final Matrix3f obj) { public Matrix3f less(final Matrix3f obj) {
return new Matrix3f(this.a1 - obj.a1, this.a2 - obj.a2, this.a3 - obj.a3, this.b1 - obj.b1, this.b2 - obj.b2, this.b3 - obj.b3, this.c1 - obj.c1, this.c2 - obj.c2, this.c3 - obj.c3); return new Matrix3f(this.a1 - obj.a1, this.a2 - obj.a2, this.a3 - obj.a3, this.b1 - obj.b1, this.b2 - obj.b2,
this.b3 - obj.b3, this.c1 - obj.c1, this.c2 - obj.c2, this.c3 - obj.c3);
} }
/** /**
@ -264,7 +264,8 @@ public record Matrix3f(
*/ */
@CheckReturnValue @CheckReturnValue
public Matrix3f multiply(final float value) { public Matrix3f multiply(final float value) {
return new Matrix3f(this.a1 * value, this.a2 * value, this.a3 * value, this.b1 * value, this.b2 * value, this.b3 * value, this.c1 * value, this.c2 * value, this.c3 * value); return new Matrix3f(this.a1 * value, this.a2 * value, this.a3 * value, this.b1 * value, this.b2 * value,
this.b3 * value, this.c1 * value, this.c2 * value, this.c3 * value);
} }
/** /**
@ -280,9 +281,9 @@ public record Matrix3f(
final float a2 = this.a1 * obj.a2 + this.a2 * obj.b2 + this.a3 * obj.c2; final float a2 = this.a1 * obj.a2 + this.a2 * obj.b2 + this.a3 * obj.c2;
final float b2 = this.b1 * obj.a2 + this.b2 * obj.b2 + this.b3 * obj.c2; final float b2 = this.b1 * obj.a2 + this.b2 * obj.b2 + this.b3 * obj.c2;
final float c2 = this.c1 * obj.a2 + this.c2 * obj.b2 + this.c3 * obj.c2; final float c2 = this.c1 * obj.a2 + this.c2 * obj.b2 + this.c3 * obj.c2;
float tmpA3 = this.a1 * obj.a3 + this.a2 * obj.b3 + this.a3 * obj.c3; final float tmpA3 = this.a1 * obj.a3 + this.a2 * obj.b3 + this.a3 * obj.c3;
float tmpB3 = this.b1 * obj.a3 + this.b2 * obj.b3 + this.b3 * obj.c3; final float tmpB3 = this.b1 * obj.a3 + this.b2 * obj.b3 + this.b3 * obj.c3;
float tmpC3 = this.c1 * obj.a3 + this.c2 * obj.b3 + this.c3 * obj.c3; final float tmpC3 = this.c1 * obj.a3 + this.c2 * obj.b3 + this.c3 * obj.c3;
return new Matrix3f(a1, a2, tmpA3, b1, b2, tmpB3, c1, c2, tmpC3); return new Matrix3f(a1, a2, tmpA3, b1, b2, tmpB3, c1, c2, tmpC3);
} }
@ -293,16 +294,18 @@ public record Matrix3f(
*/ */
@CheckReturnValue @CheckReturnValue
public Vector3f multiply(final Vector3f point) { public Vector3f multiply(final Vector3f point) {
return new Vector3f((float) (point.x() * (double) this.a1 + point.y() * (double) this.a2 + point.z() * (double) this.a3), return new Vector3f(
(float) (point.x() * (double) this.a1 + point.y() * (double) this.a2 + point.z() * (double) this.a3),
(float) (point.x() * (double) this.b1 + point.y() * (double) this.b2 + point.z() * (double) this.b3), (float) (point.x() * (double) this.b1 + point.y() * (double) this.b2 + point.z() * (double) this.b3),
(float) (point.x() * (double) this.c1 + point.y() * (double) this.c2 + point.z() * (double) this.c3)); (float) (point.x() * (double) this.c1 + point.y() * (double) this.c2 + point.z() * (double) this.c3));
} }
@Override @Override
public String toString() { public String toString() {
return "Matrix3f(" + FMath.floatToString(this.a1) + "," + FMath.floatToString(this.a2) + "," + FMath.floatToString(this.a3) + "," + FMath.floatToString(this.b1) + "," return "Matrix3f(" + FMath.floatToString(this.a1) + "," + FMath.floatToString(this.a2) + ","
+ FMath.floatToString(this.b2) + "," + FMath.floatToString(this.b3) + "," + FMath.floatToString(this.c1) + "," + FMath.floatToString(this.c2) + "," + FMath.floatToString(this.c3) + FMath.floatToString(this.a3) + "," + FMath.floatToString(this.b1) + "," + FMath.floatToString(this.b2)
+ ")"; + "," + FMath.floatToString(this.b3) + "," + FMath.floatToString(this.c1) + ","
+ FMath.floatToString(this.c2) + "," + FMath.floatToString(this.c3) + ")";
} }
/** /**

View File

@ -2,7 +2,6 @@ package org.atriasoft.etk.math;
import edu.umd.cs.findbugs.annotations.CheckReturnValue; import edu.umd.cs.findbugs.annotations.CheckReturnValue;
@SuppressWarnings("preview")
public record Matrix4f( public record Matrix4f(
float a1, float a1,
float b1, float b1,
@ -30,23 +29,29 @@ public record Matrix4f(
* @param zFar Z maximum size of the frustum * @param zFar Z maximum size of the frustum
* @return New matrix of the transformation requested * @return New matrix of the transformation requested
*/ */
public static Matrix4f createMatrixFrustum(final float xmin, final float xmax, final float ymin, final float ymax, final float zNear, final float zFar) { public static Matrix4f createMatrixFrustum(
float a1 = (2.0f * zNear) / (xmax - xmin); final float xmin,
float b1 = 0; final float xmax,
float c1 = (xmax + xmin) / (xmax - xmin); final float ymin,
float d1 = 0; final float ymax,
float a2 = 0; final float zNear,
float b2 = (2.0f * zNear) / (ymax - ymin); final float zFar) {
float c2 = (ymax + ymin) / (ymax - ymin); final float a1 = (2.0f * zNear) / (xmax - xmin);
float d2 = 0; final float b1 = 0;
float a3 = 0; final float c1 = (xmax + xmin) / (xmax - xmin);
float b3 = 0; final float d1 = 0;
float c3 = -(zFar + zNear) / (zFar - zNear); final float a2 = 0;
float d3 = -(2.0f * zFar * zNear) / (zFar - zNear); final float b2 = (2.0f * zNear) / (ymax - ymin);
float a4 = 0; final float c2 = (ymax + ymin) / (ymax - ymin);
float b4 = 0; final float d2 = 0;
float c4 = -1.0f; final float a3 = 0;
float d4 = 0; final float b3 = 0;
final float c3 = -(zFar + zNear) / (zFar - zNear);
final float d3 = -(2.0f * zFar * zNear) / (zFar - zNear);
final float a4 = 0;
final float b4 = 0;
final float c4 = -1.0f;
final float d4 = 0;
return new Matrix4f(a1, b1, c1, d1, a2, b2, c2, d2, a3, b3, c3, d3, a4, b4, c4, d4); return new Matrix4f(a1, b1, c1, d1, a2, b2, c2, d2, a3, b3, c3, d3, a4, b4, c4, d4);
//return new Matrix4f(a1, a2, a3, a4, b1, b2, b3, b4, c1, c2, c3, c4, d1, d2, d3, d4); //return new Matrix4f(a1, a2, a3, a4, b1, b2, b3, b4, c1, c2, c3, c4, d1, d2, d3, d4);
} }
@ -65,25 +70,25 @@ public record Matrix4f(
final Vector3f up2 = xaxis.cross(forward); final Vector3f up2 = xaxis.cross(forward);
xaxis = xaxis.safeNormalize(); // TODO ?????? xaxis = xaxis.safeNormalize(); // TODO ??????
float a1 = xaxis.x(); final float a1 = xaxis.x();
float b1 = up2.x(); final float b1 = up2.x();
float c1 = forward.x(); final float c1 = forward.x();
float d1 = eye.x(); final float d1 = eye.x();
float a2 = xaxis.y(); final float a2 = xaxis.y();
float b2 = up2.y(); final float b2 = up2.y();
float c2 = forward.y(); final float c2 = forward.y();
float d2 = eye.y(); final float d2 = eye.y();
float a3 = xaxis.z(); final float a3 = xaxis.z();
float b3 = up2.z(); final float b3 = up2.z();
float c3 = forward.z(); final float c3 = forward.z();
float d3 = eye.z(); final float d3 = eye.z();
float a4 = 0.0f; final float a4 = 0.0f;
float b4 = 0.0f; final float b4 = 0.0f;
float c4 = 0.0f; final float c4 = 0.0f;
float d4 = 1.0f; final float d4 = 1.0f;
return new Matrix4f(a1, b1, c1, d1, a2, b2, c2, d2, a3, b3, c3, d3, a4, b4, c4, d4); return new Matrix4f(a1, b1, c1, d1, a2, b2, c2, d2, a3, b3, c3, d3, a4, b4, c4, d4);
} }
@ -97,24 +102,30 @@ public record Matrix4f(
* @param farVal Z far size of the camera * @param farVal Z far size of the camera
* @return New matrix of the transformation requested * @return New matrix of the transformation requested
*/ */
public static Matrix4f createMatrixOrtho(final float left, final float right, final float bottom, final float top, final float nearVal, final float farVal) { public static Matrix4f createMatrixOrtho(
float b1 = 0; final float left,
float c1 = 0; final float right,
float a2 = 0; final float bottom,
float c2 = 0; final float top,
float a3 = 0; final float nearVal,
float b3 = 0; final float farVal) {
float a4 = 0; final float b1 = 0;
float b4 = 0; final float c1 = 0;
float c4 = 0; final float a2 = 0;
final float c2 = 0;
final float a3 = 0;
final float b3 = 0;
final float a4 = 0;
final float b4 = 0;
final float c4 = 0;
float a1 = 2.0f / (right - left); final float a1 = 2.0f / (right - left);
float b2 = 2.0f / (top - bottom); final float b2 = 2.0f / (top - bottom);
float c3 = -2.0f / (farVal - nearVal); final float c3 = -2.0f / (farVal - nearVal);
float d1 = -1.0f * (right + left) / (right - left); final float d1 = -1.0f * (right + left) / (right - left);
float d2 = -1.0f * (top + bottom) / (top - bottom); final float d2 = -1.0f * (top + bottom) / (top - bottom);
float d3 = -1.0f * (farVal + nearVal) / (farVal - nearVal); final float d3 = -1.0f * (farVal + nearVal) / (farVal - nearVal);
float d4 = 1.0f; final float d4 = 1.0f;
return new Matrix4f(a1, b1, c1, d1, a2, b2, c2, d2, a3, b3, c3, d3, a4, b4, c4, d4); return new Matrix4f(a1, b1, c1, d1, a2, b2, c2, d2, a3, b3, c3, d3, a4, b4, c4, d4);
//return new Matrix4f(a1, a2, a3, a4, b1, b2, b3, b4, c1, c2, c3, c4, d1, d2, d3, d4); //return new Matrix4f(a1, a2, a3, a4, b1, b2, b3, b4, c1, c2, c3, c4, d1, d2, d3, d4);
@ -128,7 +139,11 @@ public record Matrix4f(
* @param zFar Z far size of the camera * @param zFar Z far size of the camera
* @return New matrix of the transformation requested * @return New matrix of the transformation requested
*/ */
public static Matrix4f createMatrixPerspective(final float foxy, final float aspect, final float zNear, final float zFar) { public static Matrix4f createMatrixPerspective(
final float foxy,
final float aspect,
final float zNear,
final float zFar) {
//TKDEBUG("drax perspective: foxy=" << foxy << "->" << aspect << " " << zNear << "->" << zFar); //TKDEBUG("drax perspective: foxy=" << foxy << "->" << aspect << " " << zNear << "->" << zFar);
final float xmax = zNear * (float) Math.tan(foxy / 2.0); final float xmax = zNear * (float) Math.tan(foxy / 2.0);
final float xmin = -xmax; final float xmin = -xmax;
@ -149,19 +164,19 @@ public record Matrix4f(
float a1 = 1.0f; float a1 = 1.0f;
float b1 = 0; float b1 = 0;
float c1 = 0; float c1 = 0;
float d1 = 0; final float d1 = 0;
float a2 = 0; float a2 = 0;
float b2 = 1.0f; float b2 = 1.0f;
float c2 = 0; float c2 = 0;
float d2 = 0; final float d2 = 0;
float a3 = 0; float a3 = 0;
float b3 = 0; float b3 = 0;
float c3 = 1.0f; float c3 = 1.0f;
float d3 = 0; final float d3 = 0;
float a4 = 0; final float a4 = 0;
float b4 = 0; final float b4 = 0;
float c4 = 0; final float c4 = 0;
float d4 = 1.0f; final float d4 = 1.0f;
final float cosVal = (float) Math.cos(angleRad); final float cosVal = (float) Math.cos(angleRad);
final float sinVal = (float) Math.sin(angleRad); final float sinVal = (float) Math.sin(angleRad);
@ -205,22 +220,22 @@ public record Matrix4f(
* @return New matrix of the transformation requested * @return New matrix of the transformation requested
*/ */
public static Matrix4f createMatrixTranslate(final Vector3f translate) { public static Matrix4f createMatrixTranslate(final Vector3f translate) {
float a1 = 1.0f; final float a1 = 1.0f;
float b1 = 0; final float b1 = 0;
float c1 = 0; final float c1 = 0;
float d1 = translate.x(); final float d1 = translate.x();
float a2 = 0; final float a2 = 0;
float b2 = 1.0f; final float b2 = 1.0f;
float c2 = 0; final float c2 = 0;
float d2 = translate.y(); final float d2 = translate.y();
float a3 = 0; final float a3 = 0;
float b3 = 0; final float b3 = 0;
float c3 = 1.0f; final float c3 = 1.0f;
float d3 = translate.z(); final float d3 = translate.z();
float a4 = 0; final float a4 = 0;
float b4 = 0; final float b4 = 0;
float c4 = 0; final float c4 = 0;
float d4 = 1.0f; final float d4 = 1.0f;
return new Matrix4f(a1, b1, c1, d1, a2, b2, c2, d2, a3, b3, c3, d3, a4, b4, c4, d4); return new Matrix4f(a1, b1, c1, d1, a2, b2, c2, d2, a3, b3, c3, d3, a4, b4, c4, d4);
//return new Matrix4f(a1, a2, a3, a4, b1, b2, b3, b4, c1, c2, c3, c4, d1, d2, d3, d4); //return new Matrix4f(a1, a2, a3, a4, b1, b2, b3, b4, c1, c2, c3, c4, d1, d2, d3, d4);
} }
@ -244,8 +259,9 @@ public record Matrix4f(
* @param c4 3rd colomn, 4 line value * @param c4 3rd colomn, 4 line value
* @param d4 4th colomn, 4 line value * @param d4 4th colomn, 4 line value
*/ */
public Matrix4f(final float a1, final float b1, final float c1, final float d1, final float a2, final float b2, final float c2, final float d2, final float a3, final float b3, final float c3, public Matrix4f(final float a1, final float b1, final float c1, final float d1, final float a2, final float b2,
final float d3, final float a4, final float b4, final float c4, final float d4) { final float c2, final float d2, final float a3, final float b3, final float c3, final float d3,
final float a4, final float b4, final float c4, final float d4) {
this.a1 = a1; this.a1 = a1;
this.b1 = b1; this.b1 = b1;
this.c1 = c1; this.c1 = c1;
@ -269,11 +285,13 @@ public record Matrix4f(
* @param values vector of values * @param values vector of values
*/ */
public Matrix4f(final float[] values) { public Matrix4f(final float[] values) {
this(values[0], values[1], values[2], values[3], values[4], values[5], values[6], values[7], values[8], values[9], values[10], values[11], values[12], values[13], values[14], values[15]); this(values[0], values[1], values[2], values[3], values[4], values[5], values[6], values[7], values[8],
values[9], values[10], values[11], values[12], values[13], values[14], values[15]);
} }
public Matrix4f(final Matrix3f matrix) { public Matrix4f(final Matrix3f matrix) {
this(matrix.a1(), matrix.a2(), matrix.a3(), 0, matrix.b1(), matrix.b2(), matrix.b3(), 0, matrix.c1(), matrix.c2(), matrix.c3(), 0, 0, 0, 0, 1); this(matrix.a1(), matrix.a2(), matrix.a3(), 0, matrix.b1(), matrix.b2(), matrix.b3(), 0, matrix.c1(),
matrix.c2(), matrix.c3(), 0, 0, 0, 0, 1);
} }
/** /**
@ -282,8 +300,10 @@ public record Matrix4f(
*/ */
@CheckReturnValue @CheckReturnValue
public Matrix4f add(final Matrix4f obj) { public Matrix4f add(final Matrix4f obj) {
return new Matrix4f(this.a1 + obj.a1, this.b1 + obj.b1, this.c1 + obj.c1, this.d1 + obj.d1, this.a2 + obj.a2, this.b2 + obj.b2, this.c2 + obj.c2, this.d2 + obj.d2, this.a3 + obj.a3, return new Matrix4f(this.a1 + obj.a1, this.b1 + obj.b1, this.c1 + obj.c1, this.d1 + obj.d1, this.a2 + obj.a2,
this.b3 + obj.b3, this.c3 + obj.c3, this.d3 + obj.d3, this.a4 + obj.a4, this.b4 + obj.b4, this.c4 + obj.c4, this.d4 + obj.d4); this.b2 + obj.b2, this.c2 + obj.c2, this.d2 + obj.d2, this.a3 + obj.a3, this.b3 + obj.b3,
this.c3 + obj.c3, this.d3 + obj.d3, this.a4 + obj.a4, this.b4 + obj.b4, this.c4 + obj.c4,
this.d4 + obj.d4);
} }
/** /**
@ -292,72 +312,90 @@ public record Matrix4f(
*/ */
@CheckReturnValue @CheckReturnValue
public Matrix4f decrement(final Matrix4f obj) { public Matrix4f decrement(final Matrix4f obj) {
return new Matrix4f(this.a1 - obj.a1, this.b1 - obj.b1, this.c1 - obj.c1, this.d1 - obj.d1, this.a2 - obj.a2, this.b2 - obj.b2, this.c2 - obj.c2, this.d2 - obj.d2, this.a3 - obj.a3, return new Matrix4f(this.a1 - obj.a1, this.b1 - obj.b1, this.c1 - obj.c1, this.d1 - obj.d1, this.a2 - obj.a2,
this.b3 - obj.b3, this.c3 - obj.c3, this.d3 - obj.d3, this.a4 - obj.a4, this.b4 - obj.b4, this.c4 - obj.c4, this.d4 - obj.d4); this.b2 - obj.b2, this.c2 - obj.c2, this.d2 - obj.d2, this.a3 - obj.a3, this.b3 - obj.b3,
this.c3 - obj.c3, this.d3 - obj.d3, this.a4 - obj.a4, this.b4 - obj.b4, this.c4 - obj.c4,
this.d4 - obj.d4);
} }
private float coFactorRaw0Col0() { private float coFactorRaw0Col0() {
return this.b2 * this.c3 * this.d4 - this.b2 * this.d3 * this.c4 - this.c2 * this.b3 * this.d4 + this.c2 * this.d3 * this.b4 + this.d2 * this.b3 * this.c4 - this.d2 * this.c3 * this.b4; return this.b2 * this.c3 * this.d4 - this.b2 * this.d3 * this.c4 - this.c2 * this.b3 * this.d4
+ this.c2 * this.d3 * this.b4 + this.d2 * this.b3 * this.c4 - this.d2 * this.c3 * this.b4;
} }
private float coFactorRaw0Col1() { private float coFactorRaw0Col1() {
return this.a2 * this.c3 * this.d4 - this.a2 * this.d3 * this.c4 - this.c2 * this.a3 * this.d4 + this.c2 * this.d3 * this.a4 + this.d2 * this.a3 * this.c4 - this.d2 * this.c3 * this.a4; return this.a2 * this.c3 * this.d4 - this.a2 * this.d3 * this.c4 - this.c2 * this.a3 * this.d4
+ this.c2 * this.d3 * this.a4 + this.d2 * this.a3 * this.c4 - this.d2 * this.c3 * this.a4;
} }
private float coFactorRaw0Col2() { private float coFactorRaw0Col2() {
return this.a2 * this.b3 * this.d4 - this.a2 * this.d3 * this.b4 - this.b2 * this.a3 * this.d4 + this.b2 * this.d3 * this.a4 + this.d2 * this.a3 * this.b4 - this.d2 * this.b3 * this.a4; return this.a2 * this.b3 * this.d4 - this.a2 * this.d3 * this.b4 - this.b2 * this.a3 * this.d4
+ this.b2 * this.d3 * this.a4 + this.d2 * this.a3 * this.b4 - this.d2 * this.b3 * this.a4;
} }
private float coFactorRaw0Col3() { private float coFactorRaw0Col3() {
return this.a2 * this.b3 * this.c4 - this.a2 * this.c3 * this.b4 - this.b2 * this.a3 * this.c4 + this.b2 * this.c3 * this.a4 + this.c2 * this.a3 * this.b4 - this.c2 * this.b3 * this.a4; return this.a2 * this.b3 * this.c4 - this.a2 * this.c3 * this.b4 - this.b2 * this.a3 * this.c4
+ this.b2 * this.c3 * this.a4 + this.c2 * this.a3 * this.b4 - this.c2 * this.b3 * this.a4;
} }
private float coFactorRaw1Col0() { private float coFactorRaw1Col0() {
return this.b1 * this.c3 * this.d4 - this.b1 * this.d3 * this.c4 - this.c1 * this.b3 * this.d4 + this.c1 * this.d3 * this.b4 + this.d1 * this.b3 * this.c4 - this.d1 * this.c3 * this.b4; return this.b1 * this.c3 * this.d4 - this.b1 * this.d3 * this.c4 - this.c1 * this.b3 * this.d4
+ this.c1 * this.d3 * this.b4 + this.d1 * this.b3 * this.c4 - this.d1 * this.c3 * this.b4;
} }
private float coFactorRaw1Col1() { private float coFactorRaw1Col1() {
return this.a1 * this.c3 * this.d4 - this.a1 * this.d3 * this.c4 - this.c1 * this.a3 * this.d4 + this.c1 * this.d3 * this.a4 + this.d1 * this.a3 * this.c4 - this.d1 * this.c3 * this.a4; return this.a1 * this.c3 * this.d4 - this.a1 * this.d3 * this.c4 - this.c1 * this.a3 * this.d4
+ this.c1 * this.d3 * this.a4 + this.d1 * this.a3 * this.c4 - this.d1 * this.c3 * this.a4;
} }
private float coFactorRaw1Col2() { private float coFactorRaw1Col2() {
return this.a1 * this.b3 * this.d4 - this.a1 * this.d3 * this.b4 - this.b1 * this.a3 * this.d4 + this.b1 * this.d3 * this.a4 + this.d1 * this.a3 * this.b4 - this.d1 * this.b3 * this.a4; return this.a1 * this.b3 * this.d4 - this.a1 * this.d3 * this.b4 - this.b1 * this.a3 * this.d4
+ this.b1 * this.d3 * this.a4 + this.d1 * this.a3 * this.b4 - this.d1 * this.b3 * this.a4;
} }
private float coFactorRaw1Col3() { private float coFactorRaw1Col3() {
return this.a1 * this.b3 * this.c4 - this.a1 * this.c3 * this.b4 - this.b1 * this.a3 * this.c4 + this.b1 * this.c3 * this.a4 + this.c1 * this.a3 * this.b4 - this.c1 * this.b3 * this.a4; return this.a1 * this.b3 * this.c4 - this.a1 * this.c3 * this.b4 - this.b1 * this.a3 * this.c4
+ this.b1 * this.c3 * this.a4 + this.c1 * this.a3 * this.b4 - this.c1 * this.b3 * this.a4;
} }
private float coFactorRaw2Col0() { private float coFactorRaw2Col0() {
return this.b1 * this.c2 * this.d4 - this.b1 * this.d2 * this.c4 - this.c1 * this.b2 * this.d4 + this.c1 * this.d2 * this.b4 + this.d1 * this.b2 * this.c4 - this.d1 * this.c2 * this.b4; return this.b1 * this.c2 * this.d4 - this.b1 * this.d2 * this.c4 - this.c1 * this.b2 * this.d4
+ this.c1 * this.d2 * this.b4 + this.d1 * this.b2 * this.c4 - this.d1 * this.c2 * this.b4;
} }
private float coFactorRaw2Col1() { private float coFactorRaw2Col1() {
return this.a1 * this.c2 * this.d4 - this.a1 * this.d2 * this.c4 - this.c1 * this.a2 * this.d4 + this.c1 * this.d2 * this.a4 + this.d1 * this.a2 * this.c4 - this.d1 * this.c2 * this.a4; return this.a1 * this.c2 * this.d4 - this.a1 * this.d2 * this.c4 - this.c1 * this.a2 * this.d4
+ this.c1 * this.d2 * this.a4 + this.d1 * this.a2 * this.c4 - this.d1 * this.c2 * this.a4;
} }
private float coFactorRaw2Col2() { private float coFactorRaw2Col2() {
return this.a1 * this.b2 * this.d4 - this.a1 * this.d2 * this.b4 - this.b1 * this.a2 * this.d4 + this.b1 * this.d2 * this.a4 + this.d1 * this.a2 * this.b4 - this.d1 * this.b2 * this.a4; return this.a1 * this.b2 * this.d4 - this.a1 * this.d2 * this.b4 - this.b1 * this.a2 * this.d4
+ this.b1 * this.d2 * this.a4 + this.d1 * this.a2 * this.b4 - this.d1 * this.b2 * this.a4;
} }
private float coFactorRaw2Col3() { private float coFactorRaw2Col3() {
return this.a1 * this.b2 * this.c4 - this.a1 * this.c2 * this.b4 - this.b1 * this.a2 * this.c4 + this.b1 * this.c2 * this.a4 + this.c1 * this.a2 * this.b4 - this.c1 * this.b2 * this.a4; return this.a1 * this.b2 * this.c4 - this.a1 * this.c2 * this.b4 - this.b1 * this.a2 * this.c4
+ this.b1 * this.c2 * this.a4 + this.c1 * this.a2 * this.b4 - this.c1 * this.b2 * this.a4;
} }
private float coFactorRaw3Col0() { private float coFactorRaw3Col0() {
return this.b1 * this.c2 * this.d3 - this.b1 * this.d2 * this.c3 - this.c1 * this.b2 * this.d3 + this.c1 * this.d2 * this.b3 + this.d1 * this.b2 * this.c3 - this.d1 * this.c2 * this.b3; return this.b1 * this.c2 * this.d3 - this.b1 * this.d2 * this.c3 - this.c1 * this.b2 * this.d3
+ this.c1 * this.d2 * this.b3 + this.d1 * this.b2 * this.c3 - this.d1 * this.c2 * this.b3;
} }
private float coFactorRaw3Col1() { private float coFactorRaw3Col1() {
return this.a1 * this.c2 * this.d3 - this.a1 * this.d2 * this.c3 - this.c1 * this.a2 * this.d3 + this.c1 * this.d2 * this.a3 + this.d1 * this.a2 * this.c3 - this.d1 * this.c2 * this.a3; return this.a1 * this.c2 * this.d3 - this.a1 * this.d2 * this.c3 - this.c1 * this.a2 * this.d3
+ this.c1 * this.d2 * this.a3 + this.d1 * this.a2 * this.c3 - this.d1 * this.c2 * this.a3;
} }
private float coFactorRaw3Col2() { private float coFactorRaw3Col2() {
return this.a1 * this.b2 * this.d3 - this.a1 * this.d2 * this.b3 - this.b1 * this.a2 * this.d3 + this.b1 * this.d2 * this.a3 + this.d1 * this.a2 * this.b3 - this.d1 * this.b2 * this.a3; return this.a1 * this.b2 * this.d3 - this.a1 * this.d2 * this.b3 - this.b1 * this.a2 * this.d3
+ this.b1 * this.d2 * this.a3 + this.d1 * this.a2 * this.b3 - this.d1 * this.b2 * this.a3;
} }
private float coFactorRaw3Col3() { private float coFactorRaw3Col3() {
return this.a1 * this.b2 * this.c3 - this.a1 * this.c2 * this.b3 - this.b1 * this.a2 * this.c3 + this.b1 * this.c2 * this.a3 + this.c1 * this.a2 * this.b3 - this.c1 * this.b2 * this.a3; return this.a1 * this.b2 * this.c3 - this.a1 * this.c2 * this.b3 - this.b1 * this.a2 * this.c3
+ this.b1 * this.c2 * this.a3 + this.c1 * this.a2 * this.b3 - this.c1 * this.b2 * this.a3;
} }
/** /**
@ -368,7 +406,8 @@ public record Matrix4f(
@CheckReturnValue @CheckReturnValue
public float determinant() { public float determinant() {
return this.a1 * coFactorRaw0Col0() - this.b1 * coFactorRaw0Col1() + this.c1 * coFactorRaw0Col2() - this.d1 * coFactorRaw0Col3(); return this.a1 * coFactorRaw0Col0() - this.b1 * coFactorRaw0Col1() + this.c1 * coFactorRaw0Col2()
- this.d1 * coFactorRaw0Col3();
/* /*
return a *(f *k *p f *l *o g *j *p +g *l *n +h *j *o h *k *n )b *(e *k *p e *l *o g *i *p +g *l *m +h *i *o h *k *m )+c *(e *j *p e *l *n f *i *p +f *l *m +h *i *n h *j *m )d *(e *j *o e *k *n f *i *o +f *k *m +g *i *n g *j *m ); return a *(f *k *p f *l *o g *j *p +g *l *n +h *j *o h *k *n )b *(e *k *p e *l *o g *i *p +g *l *m +h *i *o h *k *m )+c *(e *j *p e *l *n f *i *p +f *l *m +h *i *n h *j *m )d *(e *j *o e *k *n f *i *o +f *k *m +g *i *n g *j *m );
a b c d a b c d
@ -381,7 +420,7 @@ public record Matrix4f(
@CheckReturnValue @CheckReturnValue
@Deprecated @Deprecated
public float[] getTable() { public float[] getTable() {
float[] mat = new float[16]; final float[] mat = new float[16];
mat[0] = this.a1; mat[0] = this.a1;
mat[1] = this.b1; mat[1] = this.b1;
mat[2] = this.c1; mat[2] = this.c1;
@ -403,7 +442,7 @@ public record Matrix4f(
@CheckReturnValue @CheckReturnValue
public float[] asArray() { public float[] asArray() {
float[] mat = new float[16]; final float[] mat = new float[16];
mat[0] = this.a1; mat[0] = this.a1;
mat[1] = this.b1; mat[1] = this.b1;
mat[2] = this.c1; mat[2] = this.c1;
@ -425,7 +464,7 @@ public record Matrix4f(
@CheckReturnValue @CheckReturnValue
public float[] asArrayTransposed() { public float[] asArrayTransposed() {
float[] mat = new float[16]; final float[] mat = new float[16];
mat[0] = this.a1; mat[0] = this.a1;
mat[1] = this.a2; mat[1] = this.a2;
mat[2] = this.a3; mat[2] = this.a3;
@ -457,25 +496,25 @@ public record Matrix4f(
// The matrix is not invertible! Singular case! // The matrix is not invertible! Singular case!
return this; return this;
} }
float a1 = coFactorRaw0Col0() / det; final float a1 = coFactorRaw0Col0() / det;
float b1 = -coFactorRaw0Col1() / det; final float b1 = -coFactorRaw0Col1() / det;
float c1 = coFactorRaw0Col2() / det; final float c1 = coFactorRaw0Col2() / det;
float d1 = -coFactorRaw0Col3() / det; final float d1 = -coFactorRaw0Col3() / det;
float a2 = -coFactorRaw1Col0() / det; final float a2 = -coFactorRaw1Col0() / det;
float b2 = coFactorRaw1Col1() / det; final float b2 = coFactorRaw1Col1() / det;
float c2 = -coFactorRaw1Col2() / det; final float c2 = -coFactorRaw1Col2() / det;
float d2 = coFactorRaw1Col3() / det; final float d2 = coFactorRaw1Col3() / det;
float a3 = coFactorRaw2Col0() / det; final float a3 = coFactorRaw2Col0() / det;
float b3 = -coFactorRaw2Col1() / det; final float b3 = -coFactorRaw2Col1() / det;
float c3 = coFactorRaw2Col2() / det; final float c3 = coFactorRaw2Col2() / det;
float d3 = -coFactorRaw2Col3() / det; final float d3 = -coFactorRaw2Col3() / det;
float a4 = -coFactorRaw3Col0() / det; final float a4 = -coFactorRaw3Col0() / det;
float b4 = coFactorRaw3Col1() / det; final float b4 = coFactorRaw3Col1() / det;
float c4 = -coFactorRaw3Col2() / det; final float c4 = -coFactorRaw3Col2() / det;
float d4 = coFactorRaw3Col3() / det; final float d4 = coFactorRaw3Col3() / det;
return new Matrix4f(a1, b1, c1, d1, a2, b2, c2, d2, a3, b3, c3, d3, a4, b4, c4, d4); return new Matrix4f(a1, b1, c1, d1, a2, b2, c2, d2, a3, b3, c3, d3, a4, b4, c4, d4);
//return new Matrix4f(a1, b1, c1, a4, a2, b2, c2, b4, a3, b3, c3, c4, d1, d2, d3, d4); //return new Matrix4f(a1, b1, c1, a4, a2, b2, c2, b4, a3, b3, c3, c4, d1, d2, d3, d4);
@ -508,25 +547,25 @@ public record Matrix4f(
float c4 = this.c1 * obj.a4 + this.c2 * obj.b4 + this.c3 * obj.c4 + this.c3 * obj.d4; float c4 = this.c1 * obj.a4 + this.c2 * obj.b4 + this.c3 * obj.c4 + this.c3 * obj.d4;
float d4 = this.d1 * obj.a4 + this.d2 * obj.b4 + this.d3 * obj.c4 + this.d3 * obj.d4; float d4 = this.d1 * obj.a4 + this.d2 * obj.b4 + this.d3 * obj.c4 + this.d3 * obj.d4;
*/ */
float a1 = this.a1 * obj.a1 + this.b1 * obj.a2 + this.c1 * obj.a3 + this.d1 * obj.a4; final float a1 = this.a1 * obj.a1 + this.b1 * obj.a2 + this.c1 * obj.a3 + this.d1 * obj.a4;
float b1 = this.a1 * obj.b1 + this.b1 * obj.b2 + this.c1 * obj.b3 + this.d1 * obj.b4; final float b1 = this.a1 * obj.b1 + this.b1 * obj.b2 + this.c1 * obj.b3 + this.d1 * obj.b4;
float c1 = this.a1 * obj.c1 + this.b1 * obj.c2 + this.c1 * obj.c3 + this.d1 * obj.c4; final float c1 = this.a1 * obj.c1 + this.b1 * obj.c2 + this.c1 * obj.c3 + this.d1 * obj.c4;
float d1 = this.a1 * obj.d1 + this.b1 * obj.d2 + this.c1 * obj.d3 + this.d1 * obj.d4; final float d1 = this.a1 * obj.d1 + this.b1 * obj.d2 + this.c1 * obj.d3 + this.d1 * obj.d4;
float a2 = this.a2 * obj.a1 + this.b2 * obj.a2 + this.c2 * obj.a3 + this.d2 * obj.a4; final float a2 = this.a2 * obj.a1 + this.b2 * obj.a2 + this.c2 * obj.a3 + this.d2 * obj.a4;
float b2 = this.a2 * obj.b1 + this.b2 * obj.b2 + this.c2 * obj.b3 + this.d2 * obj.b4; final float b2 = this.a2 * obj.b1 + this.b2 * obj.b2 + this.c2 * obj.b3 + this.d2 * obj.b4;
float c2 = this.a2 * obj.c1 + this.b2 * obj.c2 + this.c2 * obj.c3 + this.d2 * obj.c4; final float c2 = this.a2 * obj.c1 + this.b2 * obj.c2 + this.c2 * obj.c3 + this.d2 * obj.c4;
float d2 = this.a2 * obj.d1 + this.b2 * obj.d2 + this.c2 * obj.d3 + this.d2 * obj.d4; final float d2 = this.a2 * obj.d1 + this.b2 * obj.d2 + this.c2 * obj.d3 + this.d2 * obj.d4;
float a3 = this.a3 * obj.a1 + this.b3 * obj.a2 + this.c3 * obj.a3 + this.d3 * obj.a4; final float a3 = this.a3 * obj.a1 + this.b3 * obj.a2 + this.c3 * obj.a3 + this.d3 * obj.a4;
float b3 = this.a3 * obj.b1 + this.b3 * obj.b2 + this.c3 * obj.b3 + this.d3 * obj.b4; final float b3 = this.a3 * obj.b1 + this.b3 * obj.b2 + this.c3 * obj.b3 + this.d3 * obj.b4;
float c3 = this.a3 * obj.c1 + this.b3 * obj.c2 + this.c3 * obj.c3 + this.d3 * obj.c4; final float c3 = this.a3 * obj.c1 + this.b3 * obj.c2 + this.c3 * obj.c3 + this.d3 * obj.c4;
float d3 = this.a3 * obj.d1 + this.b3 * obj.d2 + this.c3 * obj.d3 + this.d3 * obj.d4; final float d3 = this.a3 * obj.d1 + this.b3 * obj.d2 + this.c3 * obj.d3 + this.d3 * obj.d4;
float a4 = this.a4 * obj.a1 + this.b4 * obj.a2 + this.c4 * obj.a3 + this.d4 * obj.a4; final float a4 = this.a4 * obj.a1 + this.b4 * obj.a2 + this.c4 * obj.a3 + this.d4 * obj.a4;
float b4 = this.a4 * obj.b1 + this.b4 * obj.b2 + this.c4 * obj.b3 + this.d4 * obj.b4; final float b4 = this.a4 * obj.b1 + this.b4 * obj.b2 + this.c4 * obj.b3 + this.d4 * obj.b4;
float c4 = this.a4 * obj.c1 + this.b4 * obj.c2 + this.c4 * obj.c3 + this.d4 * obj.c4; final float c4 = this.a4 * obj.c1 + this.b4 * obj.c2 + this.c4 * obj.c3 + this.d4 * obj.c4;
float d4 = this.a4 * obj.d1 + this.b4 * obj.d2 + this.c4 * obj.d3 + this.d4 * obj.d4; final float d4 = this.a4 * obj.d1 + this.b4 * obj.d2 + this.c4 * obj.d3 + this.d4 * obj.d4;
return new Matrix4f(a1, b1, c1, d1, a2, b2, c2, d2, a3, b3, c3, d3, a4, b4, c4, d4); return new Matrix4f(a1, b1, c1, d1, a2, b2, c2, d2, a3, b3, c3, d3, a4, b4, c4, d4);
} }
@ -584,16 +623,17 @@ public record Matrix4f(
*/ */
@CheckReturnValue @CheckReturnValue
public Matrix4f scale(final float sx, final float sy, final float sz) { public Matrix4f scale(final float sx, final float sy, final float sz) {
float a1 = this.a1 * sx; final float a1 = this.a1 * sx;
float b1 = this.b1 * sy; final float b1 = this.b1 * sy;
float c1 = this.c1 * sz; final float c1 = this.c1 * sz;
float a2 = this.a2 * sx; final float a2 = this.a2 * sx;
float b2 = this.b2 * sy; final float b2 = this.b2 * sy;
float c2 = this.c2 * sz; final float c2 = this.c2 * sz;
float a3 = this.a3 * sx; final float a3 = this.a3 * sx;
float b3 = this.b3 * sy; final float b3 = this.b3 * sy;
float c3 = this.c3 * sz; final float c3 = this.c3 * sz;
return new Matrix4f(a1, b1, c1, this.d1, a2, b2, c2, this.d2, a3, b3, c3, this.d3, this.a4, this.b4, this.c4, this.d4); return new Matrix4f(a1, b1, c1, this.d1, a2, b2, c2, this.d2, a3, b3, c3, this.d3, this.a4, this.b4, this.c4,
this.d4);
} }
/** /**
@ -625,7 +665,8 @@ public record Matrix4f(
*/ */
@CheckReturnValue @CheckReturnValue
public Matrix4f transpose() { public Matrix4f transpose() {
return new Matrix4f(this.a1, this.a2, this.a3, this.a4, this.b1, this.b2, this.b3, this.b4, this.c1, this.c2, this.c3, this.c4, this.d1, this.d2, this.d3, this.d4); return new Matrix4f(this.a1, this.a2, this.a3, this.a4, this.b1, this.b2, this.b3, this.b4, this.c1, this.c2,
this.c3, this.c4, this.d1, this.d2, this.d3, this.d4);
} }
} }

View File

@ -2,7 +2,6 @@ package org.atriasoft.etk.math;
import edu.umd.cs.findbugs.annotations.CheckReturnValue; import edu.umd.cs.findbugs.annotations.CheckReturnValue;
@SuppressWarnings("preview")
public record Quaternion( public record Quaternion(
float x, float x,
float y, float y,
@ -132,7 +131,7 @@ public record Quaternion(
public Vector3f getAngleAxis(float angle) { public Vector3f getAngleAxis(float angle) {
final Quaternion quaternion = getUnit(); final Quaternion quaternion = getUnit();
angle = (float) Math.acos(quaternion.w) * 2.0f; angle = (float) Math.acos(quaternion.w) * 2.0f;
Vector3f rotationAxis = quaternion.getVectorV(); final Vector3f rotationAxis = quaternion.getVectorV();
return rotationAxis.normalize(); return rotationAxis.normalize();
} }
@ -157,7 +156,8 @@ public record Quaternion(
final float yys = this.y * ys; final float yys = this.y * ys;
final float yzs = this.y * zs; final float yzs = this.y * zs;
final float zzs = this.z * zs; final float zzs = this.z * zs;
return new Matrix3f(1.0f - yys - zzs, xys - wzs, xzs + wys, xys + wzs, 1.0f - xxs - zzs, yzs - wxs, xzs - wys, yzs + wxs, 1.0f - xxs - yys); return new Matrix3f(1.0f - yys - zzs, xys - wzs, xzs + wys, xys + wzs, 1.0f - xxs - zzs, yzs - wxs, xzs - wys,
yzs + wxs, 1.0f - xxs - yys);
} }
@CheckReturnValue @CheckReturnValue
@ -179,7 +179,8 @@ public record Quaternion(
final float yys = this.y * ys; final float yys = this.y * ys;
final float yzs = this.y * zs; final float yzs = this.y * zs;
final float zzs = this.z * zs; final float zzs = this.z * zs;
return new Matrix4f(1.0f - yys - zzs, xys - wzs, xzs + wys, 0, xys + wzs, 1.0f - xxs - zzs, yzs - wxs, 0, xzs - wys, yzs + wxs, 1.0f - xxs - yys, 0, 0, 0, 0, 1); return new Matrix4f(1.0f - yys - zzs, xys - wzs, xzs + wys, 0, xys + wzs, 1.0f - xxs - zzs, yzs - wxs, 0,
xzs - wys, yzs + wxs, 1.0f - xxs - yys, 0, 0, 0, 0, 1);
} }
/** Return the unit quaternion /** Return the unit quaternion
@ -199,7 +200,8 @@ public record Quaternion(
@CheckReturnValue @CheckReturnValue
public Quaternion inverse() { public Quaternion inverse() {
final float invLengthSquare = 1.0f / length2(); final float invLengthSquare = 1.0f / length2();
return new Quaternion(this.x * -invLengthSquare, this.y * -invLengthSquare, this.z * -invLengthSquare, this.w * invLengthSquare); return new Quaternion(this.x * -invLengthSquare, this.y * -invLengthSquare, this.z * -invLengthSquare,
this.w * invLengthSquare);
} }
/** In-Equality compare operator with an other object. /** In-Equality compare operator with an other object.
@ -268,10 +270,10 @@ public record Quaternion(
public Quaternion multiply(final Quaternion obj) { public Quaternion multiply(final Quaternion obj) {
final Vector3f base = getVectorV(); final Vector3f base = getVectorV();
final Vector3f crossValue = base.cross(obj.getVectorV()); final Vector3f crossValue = base.cross(obj.getVectorV());
float x = this.w * obj.x + obj.w * this.x + crossValue.x(); final float x = this.w * obj.x + obj.w * this.x + crossValue.x();
float y = this.w * obj.y + obj.w * this.y + crossValue.y(); final float y = this.w * obj.y + obj.w * this.y + crossValue.y();
float z = this.w * obj.z + obj.w * this.z + crossValue.z(); final float z = this.w * obj.z + obj.w * this.z + crossValue.z();
float w = this.w * obj.w - base.dot(obj.getVectorV()); final float w = this.w * obj.w - base.dot(obj.getVectorV());
return (new Quaternion(x, y, z, w)).safeNormalize(); return (new Quaternion(x, y, z, w)).safeNormalize();
} }
@ -332,10 +334,10 @@ public record Quaternion(
final float sinYcosZ = sinY * cosZ; final float sinYcosZ = sinY * cosZ;
final float cosYsinZ = cosY * sinZ; final float cosYsinZ = cosY * sinZ;
final float sinYsinZ = sinY * sinZ; final float sinYsinZ = sinY * sinZ;
float x = sinX * cosYcosZ - cosX * sinYsinZ; final float x = sinX * cosYcosZ - cosX * sinYsinZ;
float y = cosX * sinYcosZ + sinX * cosYsinZ; final float y = cosX * sinYcosZ + sinX * cosYsinZ;
float z = cosX * cosYsinZ - sinX * sinYcosZ; final float z = cosX * cosYsinZ - sinX * sinYcosZ;
float w = cosX * cosYcosZ + sinX * sinYsinZ; final float w = cosX * cosYcosZ + sinX * sinYsinZ;
return (new Quaternion(x, y, z, w)).normalize(); return (new Quaternion(x, y, z, w)).normalize();
} }
@ -346,14 +348,16 @@ public record Quaternion(
* @param obj The other Vector to compare with */ * @param obj The other Vector to compare with */
@CheckReturnValue @CheckReturnValue
public Quaternion max(final Quaternion obj) { public Quaternion max(final Quaternion obj) {
return new Quaternion(Math.max(this.x, obj.x), Math.max(this.y, obj.y), Math.max(this.z, obj.z), Math.max(this.w, obj.w)); return new Quaternion(Math.max(this.x, obj.x), Math.max(this.y, obj.y), Math.max(this.z, obj.z),
Math.max(this.w, obj.w));
} }
/** Set each element to the min of the current values and the values of another Vector /** Set each element to the min of the current values and the values of another Vector
* @param obj The other Vector to compare with */ * @param obj The other Vector to compare with */
@CheckReturnValue @CheckReturnValue
public Quaternion min(final Quaternion obj) { public Quaternion min(final Quaternion obj) {
return new Quaternion(Math.min(this.x, obj.x), Math.min(this.y, obj.y), Math.min(this.z, obj.z), Math.min(this.w, obj.w)); return new Quaternion(Math.min(this.x, obj.x), Math.min(this.y, obj.y), Math.min(this.z, obj.z),
Math.min(this.w, obj.w));
} }
// Compute the rotation angle (in radians) and the rotation axis // Compute the rotation angle (in radians) and the rotation axis
@ -407,6 +411,7 @@ public record Quaternion(
@Override @Override
public String toString() { public String toString() {
return "Quaternion(" + FMath.floatToString(this.x) + "," + FMath.floatToString(this.y) + "," + FMath.floatToString(this.z) + "," + FMath.floatToString(this.w) + ")"; return "Quaternion(" + FMath.floatToString(this.x) + "," + FMath.floatToString(this.y) + ","
+ FMath.floatToString(this.z) + "," + FMath.floatToString(this.w) + ")";
} }
} }

View File

@ -2,7 +2,6 @@ package org.atriasoft.etk.math;
import edu.umd.cs.findbugs.annotations.CheckReturnValue; import edu.umd.cs.findbugs.annotations.CheckReturnValue;
@SuppressWarnings("preview")
public record Transform3D( public record Transform3D(
// Position // Position
Vector3f position, Vector3f position,
@ -45,16 +44,18 @@ public record Transform3D(
@CheckReturnValue @CheckReturnValue
public Matrix4f getOpenGLMatrix() { public Matrix4f getOpenGLMatrix() {
final Matrix3f tmpMatrix = this.orientation.getMatrix(); final Matrix3f tmpMatrix = this.orientation.getMatrix();
return new Matrix4f(tmpMatrix.a1(), tmpMatrix.a2(), tmpMatrix.a3(), this.position.x(), tmpMatrix.b1(), tmpMatrix.b2(), tmpMatrix.b3(), this.position.y(), tmpMatrix.c1(), tmpMatrix.c2(), return new Matrix4f(tmpMatrix.a1(), tmpMatrix.a2(), tmpMatrix.a3(), this.position.x(), tmpMatrix.b1(),
tmpMatrix.c3(), this.position.z(), 0.0f, 0.0f, 0.0f, 1.0f); tmpMatrix.b2(), tmpMatrix.b3(), this.position.y(), tmpMatrix.c1(), tmpMatrix.c2(), tmpMatrix.c3(),
this.position.z(), 0.0f, 0.0f, 0.0f, 1.0f);
} }
/// Get the OpenGL matrix of the transform /// Get the OpenGL matrix of the transform
@CheckReturnValue @CheckReturnValue
public Matrix4f getOpenGLMatrixTransposed() { public Matrix4f getOpenGLMatrixTransposed() {
final Matrix3f tmpMatrix = this.orientation.getMatrix(); final Matrix3f tmpMatrix = this.orientation.getMatrix();
return new Matrix4f(tmpMatrix.a1(), tmpMatrix.b1(), tmpMatrix.c1(), 0.0f, tmpMatrix.a2(), tmpMatrix.b2(), tmpMatrix.c2(), 0.0f, tmpMatrix.a3(), tmpMatrix.b3(), tmpMatrix.c3(), 0.0f, return new Matrix4f(tmpMatrix.a1(), tmpMatrix.b1(), tmpMatrix.c1(), 0.0f, tmpMatrix.a2(), tmpMatrix.b2(),
this.position.x(), this.position.y(), this.position.z(), 1.0f); tmpMatrix.c2(), 0.0f, tmpMatrix.a3(), tmpMatrix.b3(), tmpMatrix.c3(), 0.0f, this.position.x(),
this.position.y(), this.position.z(), 1.0f);
} }
@CheckReturnValue @CheckReturnValue
@ -70,7 +71,8 @@ public record Transform3D(
/// Return an interpolated transform /// Return an interpolated transform
@CheckReturnValue @CheckReturnValue
public Transform3D interpolateTransforms(final Transform3D newOne, final float interpolationFactor) { public Transform3D interpolateTransforms(final Transform3D newOne, final float interpolationFactor) {
final Vector3f interPosition = this.position.multiply(1.0f - interpolationFactor).add(newOne.position.multiply(interpolationFactor)); final Vector3f interPosition = this.position.multiply(1.0f - interpolationFactor)
.add(newOne.position.multiply(interpolationFactor));
final Quaternion interOrientation = this.orientation.slerp(newOne.orientation, interpolationFactor); final Quaternion interOrientation = this.orientation.slerp(newOne.orientation, interpolationFactor);
return new Transform3D(interPosition, interOrientation); return new Transform3D(interPosition, interOrientation);
} }
@ -112,15 +114,17 @@ public record Transform3D(
/// Operator of multiplication of a transform with another one /// Operator of multiplication of a transform with another one
@CheckReturnValue @CheckReturnValue
public Transform3D multiply(final Transform3D transform2) { public Transform3D multiply(final Transform3D transform2) {
return new Transform3D(this.orientation.getMatrix().multiply(transform2.position).add(this.position), this.orientation.multiply(transform2.orientation)); return new Transform3D(this.orientation.getMatrix().multiply(transform2.position).add(this.position),
this.orientation.multiply(transform2.orientation));
} }
/// Set the transform from an OpenGL transform matrix /// Set the transform from an OpenGL transform matrix
@CheckReturnValue @CheckReturnValue
public Transform3D createFromOpenGL(final float[] matrix) { public Transform3D createFromOpenGL(final float[] matrix) {
final Matrix3f tmpMatrix = new Matrix3f(matrix[0], matrix[4], matrix[8], matrix[1], matrix[5], matrix[9], matrix[2], matrix[6], matrix[10]); final Matrix3f tmpMatrix = new Matrix3f(matrix[0], matrix[4], matrix[8], matrix[1], matrix[5], matrix[9],
Quaternion orientation = Quaternion.createFromMatrix(tmpMatrix); matrix[2], matrix[6], matrix[10]);
Vector3f position = new Vector3f(matrix[12], matrix[13], matrix[14]); final Quaternion orientation = Quaternion.createFromMatrix(tmpMatrix);
final Vector3f position = new Vector3f(matrix[12], matrix[13], matrix[14]);
return new Transform3D(position, orientation); return new Transform3D(position, orientation);
} }

View File

@ -1,17 +1,15 @@
package org.atriasoft.etk.math; package org.atriasoft.etk.math;
import org.atriasoft.etk.Uri;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import edu.umd.cs.findbugs.annotations.CheckReturnValue; import edu.umd.cs.findbugs.annotations.CheckReturnValue;
@SuppressWarnings("preview")
public record Vector2b( public record Vector2b(
boolean x, boolean x,
boolean y) { boolean y) {
final static Logger LOGGER = LoggerFactory.getLogger(Vector2b.class); final static Logger LOGGER = LoggerFactory.getLogger(Vector2b.class);
public static Vector2b valueOf(String value) { public static Vector2b valueOf(String value) {
boolean val1 = false; boolean val1 = false;
boolean val2 = false; boolean val2 = false;

View File

@ -1,13 +1,10 @@
package org.atriasoft.etk.math; package org.atriasoft.etk.math;
import org.atriasoft.etk.Uri;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import edu.umd.cs.findbugs.annotations.CheckReturnValue; import edu.umd.cs.findbugs.annotations.CheckReturnValue;
@SuppressWarnings("preview")
public record Vector2i( public record Vector2i(
int x, int x,
int y) { int y) {

View File

@ -1,17 +1,15 @@
package org.atriasoft.etk.math; package org.atriasoft.etk.math;
import org.atriasoft.etk.Uri;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import edu.umd.cs.findbugs.annotations.CheckReturnValue; import edu.umd.cs.findbugs.annotations.CheckReturnValue;
@SuppressWarnings("preview")
public record Vector3b( public record Vector3b(
boolean x, boolean x,
boolean y, boolean y,
boolean z) { boolean z) {
final static Logger LOGGER = LoggerFactory.getLogger(Vector3b.class); final static Logger LOGGER = LoggerFactory.getLogger(Vector3b.class);
public static Vector3b valueOf(String value) { public static Vector3b valueOf(String value) {
boolean val1 = false; boolean val1 = false;