[FEAT] continue maven integration
This commit is contained in:
parent
b60809bc81
commit
5a5e7de99d
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<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"/>
|
||||
</fileset>
|
||||
</fileset-config>
|
||||
|
28
.classpath
28
.classpath
@ -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>
|
46
.project
46
.project
@ -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><project>/.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>
|
8
pom.xml
8
pom.xml
@ -32,17 +32,17 @@
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>2.0.7</version>
|
||||
<version>2.1.0-alpha1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.spotbugs</groupId>
|
||||
<artifactId>spotbugs-annotations</artifactId>
|
||||
<version>4.7.3</version>
|
||||
<version>4.8.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-api</artifactId>
|
||||
<version>5.9.3</version>
|
||||
<version>5.11.0-M2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
@ -50,7 +50,6 @@
|
||||
<build>
|
||||
<sourceDirectory>src</sourceDirectory>
|
||||
<testSourceDirectory>test/src</testSourceDirectory>
|
||||
<directory>${project.basedir}/out/maven/</directory>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
@ -66,6 +65,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<version>3.3.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-sources</id>
|
||||
|
@ -4,7 +4,6 @@ import java.util.Map;
|
||||
|
||||
import org.atriasoft.etk.math.FMath;
|
||||
|
||||
@SuppressWarnings("preview")
|
||||
|
||||
//@formatter:off
|
||||
public record Color(
|
||||
|
@ -5,7 +5,6 @@ package org.atriasoft.etk.math;
|
||||
* sx shx tx
|
||||
* sy shy ty
|
||||
*/
|
||||
@SuppressWarnings("preview")
|
||||
public record Matrix2x3f(
|
||||
float sx,
|
||||
float shy,
|
||||
|
@ -2,7 +2,6 @@ package org.atriasoft.etk.math;
|
||||
|
||||
import edu.umd.cs.findbugs.annotations.CheckReturnValue;
|
||||
|
||||
@SuppressWarnings("preview")
|
||||
public record Matrix3f(
|
||||
float a1,
|
||||
float a2,
|
||||
@ -13,16 +12,17 @@ public record Matrix3f(
|
||||
float c1,
|
||||
float c2,
|
||||
float c3) {
|
||||
|
||||
|
||||
/**
|
||||
* create a skew-symmetric matrix using a given vector that can be used to compute cross product with another vector using matrix multiplication
|
||||
* @param vector Vector to comute
|
||||
* @return Matrix to compute
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a matrix 3D with a simple rotation
|
||||
* @param normal vector aroud witch apply the rotation
|
||||
@ -33,33 +33,33 @@ public record Matrix3f(
|
||||
final float cosVal = (float) Math.cos(angleRad);
|
||||
final float sinVal = (float) Math.sin(angleRad);
|
||||
final float invVal = 1.0f - cosVal;
|
||||
// set rotation :
|
||||
float a1 = normal.x() * normal.x() * invVal + cosVal;
|
||||
float a2 = normal.x() * normal.y() * invVal - normal.z() * sinVal;
|
||||
float a3 = normal.x() * normal.z() * invVal + normal.y() * sinVal;
|
||||
|
||||
float b1 = normal.y() * normal.x() * invVal + normal.z() * sinVal;
|
||||
float b2 = normal.y() * normal.y() * invVal + cosVal;
|
||||
float b3 = normal.y() * normal.z() * invVal - normal.x() * sinVal;
|
||||
|
||||
float c1 = normal.z() * normal.x() * invVal - normal.y() * sinVal;
|
||||
float c2 = normal.z() * normal.y() * invVal + normal.x() * sinVal;
|
||||
float c3 = normal.z() * normal.z() * invVal + cosVal;
|
||||
// set rotation :
|
||||
final float a1 = normal.x() * normal.x() * invVal + cosVal;
|
||||
final float a2 = normal.x() * normal.y() * invVal - normal.z() * sinVal;
|
||||
final float a3 = normal.x() * normal.z() * invVal + normal.y() * sinVal;
|
||||
|
||||
final float b1 = normal.y() * normal.x() * invVal + normal.z() * sinVal;
|
||||
final float b2 = normal.y() * normal.y() * invVal + cosVal;
|
||||
final float b3 = normal.y() * normal.z() * invVal - normal.x() * sinVal;
|
||||
|
||||
final float c1 = normal.z() * normal.x() * invVal - normal.y() * sinVal;
|
||||
final float c2 = normal.z() * normal.y() * invVal + normal.x() * sinVal;
|
||||
final float c3 = normal.z() * normal.z() * invVal + cosVal;
|
||||
return new Matrix3f(a1, a2, a3, b1, b2, b3, c1, c2, c3);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* create a Identity matrix
|
||||
* @return created new matrix
|
||||
*/
|
||||
public static final Matrix3f IDENTITY = new Matrix3f(1, 0, 0, 0, 1, 0, 0, 0, 1);
|
||||
|
||||
|
||||
/**
|
||||
* create a ZERO matrix
|
||||
* @return created new matrix
|
||||
*/
|
||||
public static final Matrix3f ZERO = new Matrix3f(0, 0, 0, 0, 0, 0, 0, 0, 0);
|
||||
|
||||
|
||||
/**
|
||||
* Configuration constructorwith single value.
|
||||
* @param value single value
|
||||
@ -67,7 +67,7 @@ public record Matrix3f(
|
||||
public Matrix3f(final float value) {
|
||||
this(value, value, value, value, value, value, value, value, value);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Configuration constructor.
|
||||
* @param a1 element 0x0
|
||||
@ -80,7 +80,8 @@ public record Matrix3f(
|
||||
* @param c2 element 2x1
|
||||
* @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.a2 = a2;
|
||||
this.a3 = a3;
|
||||
@ -91,15 +92,16 @@ public record Matrix3f(
|
||||
this.c2 = c2;
|
||||
this.c3 = c3;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* absolutise the matrix
|
||||
*/
|
||||
@CheckReturnValue
|
||||
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));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Operator+= Addition an other matrix with this one
|
||||
* @param obj Reference on the external object
|
||||
@ -107,60 +109,53 @@ public record Matrix3f(
|
||||
*/
|
||||
@CheckReturnValue
|
||||
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
|
||||
// to compute cross product with another vector using matrix multiplication
|
||||
@CheckReturnValue
|
||||
public Matrix3f computeSkewSymmetricMatrixForCrossProductNew(final Vector3f vector) {
|
||||
return new Matrix3f(0.0f, -vector.z(), vector.y(), vector.z(), 0, -vector.x(), -vector.y(), vector.x(), 0.0f);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Computes the determinant of the matrix.
|
||||
* @return The determinent Value.
|
||||
*/
|
||||
@CheckReturnValue
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* devide a value
|
||||
* @param value value to devide all the matrix
|
||||
*/
|
||||
@CheckReturnValue
|
||||
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
|
||||
public float get(final int iii) {
|
||||
switch (iii) {
|
||||
case 0:
|
||||
return this.a1;
|
||||
case 1:
|
||||
return this.a2;
|
||||
case 2:
|
||||
return this.a3;
|
||||
case 3:
|
||||
return this.b1;
|
||||
case 4:
|
||||
return this.b2;
|
||||
case 5:
|
||||
return this.b3;
|
||||
case 6:
|
||||
return this.c1;
|
||||
case 7:
|
||||
return this.c2;
|
||||
case 8:
|
||||
return this.c3;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return switch (iii) {
|
||||
case 0 -> this.a1;
|
||||
case 1 -> this.a2;
|
||||
case 2 -> this.a3;
|
||||
case 3 -> this.b1;
|
||||
case 4 -> this.b2;
|
||||
case 5 -> this.b3;
|
||||
case 6 -> this.c1;
|
||||
case 7 -> this.c2;
|
||||
case 8 -> this.c3;
|
||||
default -> 0;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get the colom id values
|
||||
* @param iii Id of the colomn
|
||||
@ -175,7 +170,7 @@ public record Matrix3f(
|
||||
}
|
||||
return new Vector3f(this.a3, this.b3, this.c3);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get the row id values
|
||||
* @param iii Id of the row
|
||||
@ -190,7 +185,7 @@ public record Matrix3f(
|
||||
}
|
||||
return new Vector3f(this.c1, this.c2, this.c3);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calculate the trace of the matrix
|
||||
* @return value of addition of all element in the diagonal
|
||||
@ -199,7 +194,7 @@ public record Matrix3f(
|
||||
public float getTrace() {
|
||||
return (this.a1 + this.b2 + this.c3);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Inverts the current matrix.
|
||||
* @note The determinant must be != 0, otherwithe the matrix can't be inverted.
|
||||
@ -208,17 +203,19 @@ public record Matrix3f(
|
||||
public Matrix3f inverse() {
|
||||
final float det = determinant();
|
||||
//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,
|
||||
-(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);
|
||||
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,
|
||||
-(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
|
||||
@CheckReturnValue
|
||||
public Matrix3f invert() {
|
||||
return new Matrix3f(-this.a1, -this.a2, -this.a3, -this.b1, -this.b2, -this.b3, -this.c1, -this.c2, -this.c3);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* In-Equality compare operator with an other object.
|
||||
* @param obj Reference on the comparing object
|
||||
@ -227,12 +224,13 @@ public record Matrix3f(
|
||||
*/
|
||||
@CheckReturnValue
|
||||
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 false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Equality compare operator with an other object.
|
||||
* @param obj Reference on the comparing object
|
||||
@ -241,12 +239,13 @@ public record Matrix3f(
|
||||
*/
|
||||
@CheckReturnValue
|
||||
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 true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Operator-= Decrement an other matrix with this one
|
||||
* @param obj Reference on the external object
|
||||
@ -254,9 +253,10 @@ public record Matrix3f(
|
||||
*/
|
||||
@CheckReturnValue
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Operator*= Multiplication a value
|
||||
* @param value value to multiply all the matrix
|
||||
@ -264,9 +264,10 @@ public record Matrix3f(
|
||||
*/
|
||||
@CheckReturnValue
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Operator*= Multiplication an other matrix with this one
|
||||
* @param obj Reference on the external object
|
||||
@ -280,12 +281,12 @@ public record Matrix3f(
|
||||
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 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;
|
||||
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 tmpA3 = this.a1 * obj.a3 + this.a2 * obj.b3 + this.a3 * obj.c3;
|
||||
final float tmpB3 = this.b1 * obj.a3 + this.b2 * obj.b3 + this.b3 * 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);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Operator* apply matrix on a vector
|
||||
* @param point Point value to apply the matrix
|
||||
@ -293,18 +294,20 @@ public record Matrix3f(
|
||||
*/
|
||||
@CheckReturnValue
|
||||
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.c1 + point.y() * (double) this.c2 + point.z() * (double) this.c3));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Matrix3f(" + FMath.floatToString(this.a1) + "," + FMath.floatToString(this.a2) + "," + 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)
|
||||
+ ")";
|
||||
return "Matrix3f(" + FMath.floatToString(this.a1) + "," + FMath.floatToString(this.a2) + ","
|
||||
+ 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) + ")";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get a transpose matrix of this one.
|
||||
* @return the transpose matrix
|
||||
|
@ -2,7 +2,6 @@ package org.atriasoft.etk.math;
|
||||
|
||||
import edu.umd.cs.findbugs.annotations.CheckReturnValue;
|
||||
|
||||
@SuppressWarnings("preview")
|
||||
public record Matrix4f(
|
||||
float a1,
|
||||
float b1,
|
||||
@ -30,27 +29,33 @@ public record Matrix4f(
|
||||
* @param zFar Z maximum size of the frustum
|
||||
* @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) {
|
||||
float a1 = (2.0f * zNear) / (xmax - xmin);
|
||||
float b1 = 0;
|
||||
float c1 = (xmax + xmin) / (xmax - xmin);
|
||||
float d1 = 0;
|
||||
float a2 = 0;
|
||||
float b2 = (2.0f * zNear) / (ymax - ymin);
|
||||
float c2 = (ymax + ymin) / (ymax - ymin);
|
||||
float d2 = 0;
|
||||
float a3 = 0;
|
||||
float b3 = 0;
|
||||
float c3 = -(zFar + zNear) / (zFar - zNear);
|
||||
float d3 = -(2.0f * zFar * zNear) / (zFar - zNear);
|
||||
float a4 = 0;
|
||||
float b4 = 0;
|
||||
float c4 = -1.0f;
|
||||
float d4 = 0;
|
||||
public static Matrix4f createMatrixFrustum(
|
||||
final float xmin,
|
||||
final float xmax,
|
||||
final float ymin,
|
||||
final float ymax,
|
||||
final float zNear,
|
||||
final float zFar) {
|
||||
final float a1 = (2.0f * zNear) / (xmax - xmin);
|
||||
final float b1 = 0;
|
||||
final float c1 = (xmax + xmin) / (xmax - xmin);
|
||||
final float d1 = 0;
|
||||
final float a2 = 0;
|
||||
final float b2 = (2.0f * zNear) / (ymax - ymin);
|
||||
final float c2 = (ymax + ymin) / (ymax - ymin);
|
||||
final float d2 = 0;
|
||||
final float a3 = 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, a2, a3, a4, b1, b2, b3, b4, c1, c2, c3, c4, d1, d2, d3, d4);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create projection matrix with camera property (camera view in -z axis)
|
||||
* @param eye Optical center of the camera
|
||||
@ -64,29 +69,29 @@ public record Matrix4f(
|
||||
xaxis = xaxis.safeNormalize();
|
||||
final Vector3f up2 = xaxis.cross(forward);
|
||||
xaxis = xaxis.safeNormalize(); // TODO ??????
|
||||
|
||||
float a1 = xaxis.x();
|
||||
float b1 = up2.x();
|
||||
float c1 = forward.x();
|
||||
float d1 = eye.x();
|
||||
|
||||
float a2 = xaxis.y();
|
||||
float b2 = up2.y();
|
||||
float c2 = forward.y();
|
||||
float d2 = eye.y();
|
||||
|
||||
float a3 = xaxis.z();
|
||||
float b3 = up2.z();
|
||||
float c3 = forward.z();
|
||||
float d3 = eye.z();
|
||||
|
||||
float a4 = 0.0f;
|
||||
float b4 = 0.0f;
|
||||
float c4 = 0.0f;
|
||||
float d4 = 1.0f;
|
||||
|
||||
final float a1 = xaxis.x();
|
||||
final float b1 = up2.x();
|
||||
final float c1 = forward.x();
|
||||
final float d1 = eye.x();
|
||||
|
||||
final float a2 = xaxis.y();
|
||||
final float b2 = up2.y();
|
||||
final float c2 = forward.y();
|
||||
final float d2 = eye.y();
|
||||
|
||||
final float a3 = xaxis.z();
|
||||
final float b3 = up2.z();
|
||||
final float c3 = forward.z();
|
||||
final float d3 = eye.z();
|
||||
|
||||
final float a4 = 0.0f;
|
||||
final float b4 = 0.0f;
|
||||
final float c4 = 0.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);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create orthogonal projection matrix with the box parameter (camera view in -z axis)
|
||||
* @param left left size of the camera
|
||||
@ -97,29 +102,35 @@ public record Matrix4f(
|
||||
* @param farVal Z far size of the camera
|
||||
* @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) {
|
||||
float b1 = 0;
|
||||
float c1 = 0;
|
||||
float a2 = 0;
|
||||
float c2 = 0;
|
||||
float a3 = 0;
|
||||
float b3 = 0;
|
||||
float a4 = 0;
|
||||
float b4 = 0;
|
||||
float c4 = 0;
|
||||
|
||||
float a1 = 2.0f / (right - left);
|
||||
float b2 = 2.0f / (top - bottom);
|
||||
float c3 = -2.0f / (farVal - nearVal);
|
||||
float d1 = -1.0f * (right + left) / (right - left);
|
||||
float d2 = -1.0f * (top + bottom) / (top - bottom);
|
||||
float d3 = -1.0f * (farVal + nearVal) / (farVal - nearVal);
|
||||
float d4 = 1.0f;
|
||||
public static Matrix4f createMatrixOrtho(
|
||||
final float left,
|
||||
final float right,
|
||||
final float bottom,
|
||||
final float top,
|
||||
final float nearVal,
|
||||
final float farVal) {
|
||||
final float b1 = 0;
|
||||
final float c1 = 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;
|
||||
|
||||
final float a1 = 2.0f / (right - left);
|
||||
final float b2 = 2.0f / (top - bottom);
|
||||
final float c3 = -2.0f / (farVal - nearVal);
|
||||
final float d1 = -1.0f * (right + left) / (right - left);
|
||||
final float d2 = -1.0f * (top + bottom) / (top - bottom);
|
||||
final float d3 = -1.0f * (farVal + nearVal) / (farVal - nearVal);
|
||||
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, a2, a3, a4, b1, b2, b3, b4, c1, c2, c3, c4, d1, d2, d3, d4);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create projection matrix with human repensentation view (camera view in -z axis)
|
||||
* @param foxy Focal in radian of the camera
|
||||
@ -128,17 +139,21 @@ public record Matrix4f(
|
||||
* @param zFar Z far size of the camera
|
||||
* @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);
|
||||
final float xmax = zNear * (float) Math.tan(foxy / 2.0);
|
||||
final float xmin = -xmax;
|
||||
|
||||
|
||||
final float ymin = xmin / aspect;
|
||||
final float ymax = xmax / aspect;
|
||||
//TKDEBUG("drax perspective: " << xmin << "->" << xmax << " & " << ymin << "->" << ymax << " " << zNear << "->" << zFar);
|
||||
return createMatrixFrustum(xmin, xmax, ymin, ymax, zNear, zFar);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a matrix 3D with a simple rotation
|
||||
* @param normal vector aroud witch apply the rotation
|
||||
@ -149,20 +164,20 @@ public record Matrix4f(
|
||||
float a1 = 1.0f;
|
||||
float b1 = 0;
|
||||
float c1 = 0;
|
||||
float d1 = 0;
|
||||
final float d1 = 0;
|
||||
float a2 = 0;
|
||||
float b2 = 1.0f;
|
||||
float c2 = 0;
|
||||
float d2 = 0;
|
||||
final float d2 = 0;
|
||||
float a3 = 0;
|
||||
float b3 = 0;
|
||||
float c3 = 1.0f;
|
||||
float d3 = 0;
|
||||
float a4 = 0;
|
||||
float b4 = 0;
|
||||
float c4 = 0;
|
||||
float d4 = 1.0f;
|
||||
|
||||
final float d3 = 0;
|
||||
final float a4 = 0;
|
||||
final float b4 = 0;
|
||||
final float c4 = 0;
|
||||
final float d4 = 1.0f;
|
||||
|
||||
final float cosVal = (float) Math.cos(angleRad);
|
||||
final float sinVal = (float) Math.sin(angleRad);
|
||||
final float invVal = 1.0f - cosVal;
|
||||
@ -170,22 +185,22 @@ public record Matrix4f(
|
||||
a1 = normal.x() * normal.x() * invVal + cosVal;
|
||||
b1 = normal.x() * normal.y() * invVal - normal.z() * sinVal;
|
||||
c1 = normal.x() * normal.z() * invVal + normal.y() * sinVal;
|
||||
|
||||
|
||||
a2 = normal.y() * normal.x() * invVal + normal.z() * sinVal;
|
||||
b2 = normal.y() * normal.y() * invVal + cosVal;
|
||||
c2 = normal.y() * normal.z() * invVal - normal.x() * sinVal;
|
||||
|
||||
|
||||
a3 = normal.z() * normal.x() * invVal - normal.y() * sinVal;
|
||||
b3 = normal.z() * normal.y() * invVal + normal.x() * sinVal;
|
||||
c3 = normal.z() * normal.z() * invVal + cosVal;
|
||||
return new Matrix4f(a1, b1, c1, d1, a2, b2, c2, d2, a3, b3, c3, d3, a4, b4, c4, d4);
|
||||
}
|
||||
|
||||
|
||||
//! @notindoc
|
||||
public static Matrix4f createMatrixRotate2(final Vector3f vect) {
|
||||
return createMatrixLookAt(vect, new Vector3f(0, 0, 0), new Vector3f(0, 1, 0));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a matrix 3D with a simple scale
|
||||
* @param scale 3 dimension scale
|
||||
@ -194,37 +209,37 @@ public record Matrix4f(
|
||||
public static Matrix4f createMatrixScale(final Vector3f scale) {
|
||||
return new Matrix4f(scale.x(), 0, 0, 0, 0, scale.y(), 0, 0, 0, 0, scale.z(), 0, 0, 0, 0, 1);
|
||||
}
|
||||
|
||||
|
||||
public static Matrix4f createMatrixScale(final float xxx, final float yyy, final float zzz) {
|
||||
return new Matrix4f(xxx, 0, 0, 0, 0, yyy, 0, 0, 0, 0, zzz, 0, 0, 0, 0, 1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a matrix 3D with a simple translation
|
||||
* @param translate 3 dimention translation
|
||||
* @return New matrix of the transformation requested
|
||||
*/
|
||||
public static Matrix4f createMatrixTranslate(final Vector3f translate) {
|
||||
float a1 = 1.0f;
|
||||
float b1 = 0;
|
||||
float c1 = 0;
|
||||
float d1 = translate.x();
|
||||
float a2 = 0;
|
||||
float b2 = 1.0f;
|
||||
float c2 = 0;
|
||||
float d2 = translate.y();
|
||||
float a3 = 0;
|
||||
float b3 = 0;
|
||||
float c3 = 1.0f;
|
||||
float d3 = translate.z();
|
||||
float a4 = 0;
|
||||
float b4 = 0;
|
||||
float c4 = 0;
|
||||
float d4 = 1.0f;
|
||||
final float a1 = 1.0f;
|
||||
final float b1 = 0;
|
||||
final float c1 = 0;
|
||||
final float d1 = translate.x();
|
||||
final float a2 = 0;
|
||||
final float b2 = 1.0f;
|
||||
final float c2 = 0;
|
||||
final float d2 = translate.y();
|
||||
final float a3 = 0;
|
||||
final float b3 = 0;
|
||||
final float c3 = 1.0f;
|
||||
final float d3 = translate.z();
|
||||
final float a4 = 0;
|
||||
final float b4 = 0;
|
||||
final float c4 = 0;
|
||||
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, a2, a3, a4, b1, b2, b3, b4, c1, c2, c3, c4, d1, d2, d3, d4);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Configuration constructor.
|
||||
* @param a1 1st colomn, 1 line value
|
||||
@ -244,8 +259,9 @@ public record Matrix4f(
|
||||
* @param c4 3rd 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,
|
||||
final float d3, final float a4, final float b4, final float c4, final float d4) {
|
||||
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, final float d3,
|
||||
final float a4, final float b4, final float c4, final float d4) {
|
||||
this.a1 = a1;
|
||||
this.b1 = b1;
|
||||
this.c1 = c1;
|
||||
@ -263,112 +279,135 @@ public record Matrix4f(
|
||||
this.c4 = c4;
|
||||
this.d4 = d4;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Configuration constructor.
|
||||
* @param values vector of 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) {
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Operator+= Addition an other matrix with this one
|
||||
* @param obj Reference on the external object
|
||||
*/
|
||||
@CheckReturnValue
|
||||
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,
|
||||
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);
|
||||
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, 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);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Operator-= Decrement an other matrix with this one
|
||||
* @param obj Reference on the external object
|
||||
*/
|
||||
@CheckReturnValue
|
||||
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,
|
||||
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);
|
||||
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, 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() {
|
||||
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() {
|
||||
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() {
|
||||
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() {
|
||||
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() {
|
||||
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() {
|
||||
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() {
|
||||
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() {
|
||||
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() {
|
||||
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() {
|
||||
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() {
|
||||
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() {
|
||||
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() {
|
||||
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() {
|
||||
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() {
|
||||
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() {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Computes the determinant of the matrix.
|
||||
* @return The determinent Value.
|
||||
*/
|
||||
// https://www.dcode.fr/determinant-matrice
|
||||
|
||||
|
||||
@CheckReturnValue
|
||||
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 );
|
||||
a b c d
|
||||
@ -377,11 +416,11 @@ public record Matrix4f(
|
||||
m n o p
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
@CheckReturnValue
|
||||
@Deprecated
|
||||
public float[] getTable() {
|
||||
float[] mat = new float[16];
|
||||
final float[] mat = new float[16];
|
||||
mat[0] = this.a1;
|
||||
mat[1] = this.b1;
|
||||
mat[2] = this.c1;
|
||||
@ -400,10 +439,10 @@ public record Matrix4f(
|
||||
mat[15] = this.d4;
|
||||
return mat;
|
||||
}
|
||||
|
||||
|
||||
@CheckReturnValue
|
||||
public float[] asArray() {
|
||||
float[] mat = new float[16];
|
||||
final float[] mat = new float[16];
|
||||
mat[0] = this.a1;
|
||||
mat[1] = this.b1;
|
||||
mat[2] = this.c1;
|
||||
@ -422,10 +461,10 @@ public record Matrix4f(
|
||||
mat[15] = this.d4;
|
||||
return mat;
|
||||
}
|
||||
|
||||
|
||||
@CheckReturnValue
|
||||
public float[] asArrayTransposed() {
|
||||
float[] mat = new float[16];
|
||||
final float[] mat = new float[16];
|
||||
mat[0] = this.a1;
|
||||
mat[1] = this.a2;
|
||||
mat[2] = this.a3;
|
||||
@ -444,7 +483,7 @@ public record Matrix4f(
|
||||
mat[15] = this.d4;
|
||||
return mat;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Inverts the matrix.
|
||||
* @note The determinant must be != 0, otherwithe the matrix can't be inverted.
|
||||
@ -457,30 +496,30 @@ public record Matrix4f(
|
||||
// The matrix is not invertible! Singular case!
|
||||
return this;
|
||||
}
|
||||
float a1 = coFactorRaw0Col0() / det;
|
||||
float b1 = -coFactorRaw0Col1() / det;
|
||||
float c1 = coFactorRaw0Col2() / det;
|
||||
float d1 = -coFactorRaw0Col3() / det;
|
||||
|
||||
float a2 = -coFactorRaw1Col0() / det;
|
||||
float b2 = coFactorRaw1Col1() / det;
|
||||
float c2 = -coFactorRaw1Col2() / det;
|
||||
float d2 = coFactorRaw1Col3() / det;
|
||||
|
||||
float a3 = coFactorRaw2Col0() / det;
|
||||
float b3 = -coFactorRaw2Col1() / det;
|
||||
float c3 = coFactorRaw2Col2() / det;
|
||||
float d3 = -coFactorRaw2Col3() / det;
|
||||
|
||||
float a4 = -coFactorRaw3Col0() / det;
|
||||
float b4 = coFactorRaw3Col1() / det;
|
||||
float c4 = -coFactorRaw3Col2() / det;
|
||||
float d4 = coFactorRaw3Col3() / det;
|
||||
|
||||
final float a1 = coFactorRaw0Col0() / det;
|
||||
final float b1 = -coFactorRaw0Col1() / det;
|
||||
final float c1 = coFactorRaw0Col2() / det;
|
||||
final float d1 = -coFactorRaw0Col3() / det;
|
||||
|
||||
final float a2 = -coFactorRaw1Col0() / det;
|
||||
final float b2 = coFactorRaw1Col1() / det;
|
||||
final float c2 = -coFactorRaw1Col2() / det;
|
||||
final float d2 = coFactorRaw1Col3() / det;
|
||||
|
||||
final float a3 = coFactorRaw2Col0() / det;
|
||||
final float b3 = -coFactorRaw2Col1() / det;
|
||||
final float c3 = coFactorRaw2Col2() / det;
|
||||
final float d3 = -coFactorRaw2Col3() / det;
|
||||
|
||||
final float a4 = -coFactorRaw3Col0() / det;
|
||||
final float b4 = coFactorRaw3Col1() / det;
|
||||
final float c4 = -coFactorRaw3Col2() / 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, a4, a2, b2, c2, b4, a3, b3, c3, c4, d1, d2, d3, d4);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Operator*= Multiplication an other matrix with this one
|
||||
* @param obj Reference on the external object
|
||||
@ -492,45 +531,45 @@ public record Matrix4f(
|
||||
float b1 = this.b1 * obj.a1 + this.b2 * obj.b1 + this.b3 * obj.c1 + this.b3 * obj.d1;
|
||||
float c1 = this.c1 * obj.a1 + this.c2 * obj.b1 + this.c3 * obj.c1 + this.c3 * obj.d1;
|
||||
float d1 = this.d1 * obj.a1 + this.d2 * obj.b1 + this.d3 * obj.c1 + this.d3 * obj.d1;
|
||||
|
||||
|
||||
float a2 = this.a1 * obj.a2 + this.a2 * obj.b2 + this.a3 * obj.c2 + this.a3 * obj.d2;
|
||||
float b2 = this.b1 * obj.a2 + this.b2 * obj.b2 + this.b3 * obj.c2 + this.b3 * obj.d2;
|
||||
float c2 = this.c1 * obj.a2 + this.c2 * obj.b2 + this.c3 * obj.c2 + this.c3 * obj.d2;
|
||||
float d2 = this.d1 * obj.a2 + this.d2 * obj.b2 + this.d3 * obj.c2 + this.d3 * obj.d2;
|
||||
|
||||
|
||||
float a3 = this.a1 * obj.a3 + this.a2 * obj.b3 + this.a3 * obj.c3 + this.a3 * obj.d3;
|
||||
float b3 = this.b1 * obj.a3 + this.b2 * obj.b3 + this.b3 * obj.c3 + this.b3 * obj.d3;
|
||||
float c3 = this.c1 * obj.a3 + this.c2 * obj.b3 + this.c3 * obj.c3 + this.c3 * obj.d3;
|
||||
float d3 = this.d1 * obj.a3 + this.d2 * obj.b3 + this.d3 * obj.c3 + this.d3 * obj.d3;
|
||||
|
||||
|
||||
float a4 = this.a1 * obj.a4 + this.a2 * obj.b4 + this.a3 * obj.c4 + this.a3 * obj.d4;
|
||||
float b4 = this.b1 * obj.a4 + this.b2 * obj.b4 + this.b3 * obj.c4 + this.b3 * 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 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;
|
||||
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;
|
||||
|
||||
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;
|
||||
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;
|
||||
|
||||
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;
|
||||
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;
|
||||
|
||||
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;
|
||||
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 a1 = this.a1 * obj.a1 + this.b1 * obj.a2 + this.c1 * obj.a3 + this.d1 * obj.a4;
|
||||
final float b1 = this.a1 * obj.b1 + this.b1 * obj.b2 + this.c1 * obj.b3 + this.d1 * obj.b4;
|
||||
final float c1 = this.a1 * obj.c1 + this.b1 * obj.c2 + this.c1 * obj.c3 + this.d1 * obj.c4;
|
||||
final float d1 = this.a1 * obj.d1 + this.b1 * obj.d2 + this.c1 * obj.d3 + this.d1 * obj.d4;
|
||||
|
||||
final float a2 = this.a2 * obj.a1 + this.b2 * obj.a2 + this.c2 * obj.a3 + this.d2 * obj.a4;
|
||||
final float b2 = this.a2 * obj.b1 + this.b2 * obj.b2 + this.c2 * obj.b3 + this.d2 * obj.b4;
|
||||
final float c2 = this.a2 * obj.c1 + this.b2 * obj.c2 + this.c2 * obj.c3 + this.d2 * obj.c4;
|
||||
final float d2 = this.a2 * obj.d1 + this.b2 * obj.d2 + this.c2 * obj.d3 + this.d2 * obj.d4;
|
||||
|
||||
final float a3 = this.a3 * obj.a1 + this.b3 * obj.a2 + this.c3 * obj.a3 + this.d3 * obj.a4;
|
||||
final float b3 = this.a3 * obj.b1 + this.b3 * obj.b2 + this.c3 * obj.b3 + this.d3 * obj.b4;
|
||||
final float c3 = this.a3 * obj.c1 + this.b3 * obj.c2 + this.c3 * obj.c3 + this.d3 * obj.c4;
|
||||
final float d3 = this.a3 * obj.d1 + this.b3 * obj.d2 + this.c3 * obj.d3 + this.d3 * obj.d4;
|
||||
|
||||
final float a4 = this.a4 * obj.a1 + this.b4 * obj.a2 + this.c4 * obj.a3 + this.d4 * obj.a4;
|
||||
final float b4 = this.a4 * obj.b1 + this.b4 * obj.b2 + this.c4 * obj.b3 + this.d4 * obj.b4;
|
||||
final float c4 = this.a4 * obj.c1 + this.b4 * obj.c2 + this.c4 * obj.c3 + this.d4 * obj.c4;
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Operator* apply matrix on a vector
|
||||
* @param point Point value to apply the matrix
|
||||
@ -542,7 +581,7 @@ public record Matrix4f(
|
||||
this.a2 * point.x() + this.b2 * point.y() + this.c2 * point.z() + this.d2, // Y
|
||||
this.a3 * point.x() + this.b3 * point.y() + this.c3 * point.z() + this.d3); // Z
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Operator* apply matrix on a vector
|
||||
* @param point Point value to apply the matrix
|
||||
@ -555,7 +594,7 @@ public record Matrix4f(
|
||||
this.a3 * point.x() + this.b3 * point.y() + this.c3 * point.z() + this.d3 * point.w(), // Z
|
||||
this.a4 * point.x() + this.b4 * point.y() + this.c4 * point.z() + this.d4 * point.w()); // W
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Makes a rotation matrix about an arbitrary axis.
|
||||
* @param vect vector to apply the angle.
|
||||
@ -566,7 +605,7 @@ public record Matrix4f(
|
||||
final Matrix4f tmpMat = createMatrixRotate(vect, angleRad);
|
||||
return this.multiply(tmpMat);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Scale the current Matrix in all direction with 1 value.
|
||||
* @param scale Scale XYZ value to apply.
|
||||
@ -575,7 +614,7 @@ public record Matrix4f(
|
||||
public Matrix4f scale(final float scale) {
|
||||
return scale(scale, scale, scale);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Scale the current Matrix.
|
||||
* @param sx Scale X value to apply.
|
||||
@ -584,18 +623,19 @@ public record Matrix4f(
|
||||
*/
|
||||
@CheckReturnValue
|
||||
public Matrix4f scale(final float sx, final float sy, final float sz) {
|
||||
float a1 = this.a1 * sx;
|
||||
float b1 = this.b1 * sy;
|
||||
float c1 = this.c1 * sz;
|
||||
float a2 = this.a2 * sx;
|
||||
float b2 = this.b2 * sy;
|
||||
float c2 = this.c2 * sz;
|
||||
float a3 = this.a3 * sx;
|
||||
float b3 = this.b3 * sy;
|
||||
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);
|
||||
final float a1 = this.a1 * sx;
|
||||
final float b1 = this.b1 * sy;
|
||||
final float c1 = this.c1 * sz;
|
||||
final float a2 = this.a2 * sx;
|
||||
final float b2 = this.b2 * sy;
|
||||
final float c2 = this.c2 * sz;
|
||||
final float a3 = this.a3 * sx;
|
||||
final float b3 = this.b3 * sy;
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Scale the current Matrix.
|
||||
* @param vect Scale vector to apply.
|
||||
@ -604,12 +644,12 @@ public record Matrix4f(
|
||||
public Matrix4f scale(final Vector3f vect) {
|
||||
return scale(vect.x(), vect.y(), vect.z());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* configure identity of the matrix
|
||||
*/
|
||||
public static final Matrix4f IDENTITY = new Matrix4f(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
|
||||
|
||||
|
||||
/**
|
||||
* Makes a translation of the matrix
|
||||
* @param vect Translation to apply.
|
||||
@ -619,13 +659,14 @@ public record Matrix4f(
|
||||
final Matrix4f tmpMat = createMatrixTranslate(vect);
|
||||
return this.multiply(tmpMat);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Transpose the current matix (usefull for OpenGL display)
|
||||
*/
|
||||
@CheckReturnValue
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package org.atriasoft.etk.math;
|
||||
|
||||
import edu.umd.cs.findbugs.annotations.CheckReturnValue;
|
||||
|
||||
@SuppressWarnings("preview")
|
||||
public record Quaternion(
|
||||
float x,
|
||||
float y,
|
||||
@ -14,7 +13,7 @@ public record Quaternion(
|
||||
final Quaternion inv = a.inverse();
|
||||
return inv.multiply(b);
|
||||
}
|
||||
|
||||
|
||||
/* void checkValues() { if ( isinf(this.x) == true || isnan(this.x) == true || isinf(this.y) == true || isnan(this.y) == true || isinf(this.z) == true || isnan(this.z) == true || isinf(this.w) ==
|
||||
* true || isnan(this.w) == true) { TKCRITICAL(" set transform: (" << this.x << "," << this.y << "," << this.z << "," << this.w << ")"); } } */
|
||||
/**
|
||||
@ -29,7 +28,7 @@ public record Quaternion(
|
||||
this.z = z;
|
||||
this.w = w;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Constructor with the component w and a vector 3D.
|
||||
* @param www W value
|
||||
@ -38,7 +37,7 @@ public record Quaternion(
|
||||
public Quaternion(final float www, final Vector3f vec) {
|
||||
this(vec.x(), vec.y(), vec.z(), www);
|
||||
}
|
||||
|
||||
|
||||
/** Create a unit quaternion from a rotation matrix
|
||||
* @param matrix generic matrix */
|
||||
public static Quaternion createFromMatrix(final Matrix3f matrix) {
|
||||
@ -86,13 +85,13 @@ public record Quaternion(
|
||||
}
|
||||
return new Quaternion(x, y, z, w);
|
||||
}
|
||||
|
||||
|
||||
/** Set the absolute values of each element */
|
||||
@CheckReturnValue
|
||||
public Quaternion absolute() {
|
||||
return new Quaternion(Math.abs(this.x), Math.abs(this.y), Math.abs(this.z), Math.abs(this.w));
|
||||
}
|
||||
|
||||
|
||||
/** Add a vector to this one.
|
||||
* @param obj The vector to add to this one
|
||||
* @return New vector containing the value */
|
||||
@ -100,13 +99,13 @@ public record Quaternion(
|
||||
public Quaternion add(final Quaternion obj) {
|
||||
return new Quaternion(this.x + obj.x, this.y + obj.y, this.z + obj.z, this.w + obj.w);
|
||||
}
|
||||
|
||||
|
||||
/** Conjugate the quaternion */
|
||||
@CheckReturnValue
|
||||
public Quaternion conjugate() {
|
||||
return new Quaternion(this.x * -1.0f, this.y * -1.0f, this.z * -1.0f, this.w);
|
||||
}
|
||||
|
||||
|
||||
/** Inversely scale the quaternion
|
||||
* @param val Scale factor to divide by.
|
||||
* @return New quaternion containing the value */
|
||||
@ -116,7 +115,7 @@ public record Quaternion(
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/** Return the dot product
|
||||
* @param obj The other quaternion in the dot product
|
||||
* @return Dot result value */
|
||||
@ -124,7 +123,7 @@ public record Quaternion(
|
||||
public float dot(final Quaternion obj) {
|
||||
return this.x * obj.x + this.y * obj.y + this.z * obj.z + this.w * obj.w;
|
||||
}
|
||||
|
||||
|
||||
/** Compute the rotation angle (in radians) and the rotation axis
|
||||
* @param angle Angle of the quaternion
|
||||
* @return Axis of the quaternion */
|
||||
@ -132,10 +131,10 @@ public record Quaternion(
|
||||
public Vector3f getAngleAxis(float angle) {
|
||||
final Quaternion quaternion = getUnit();
|
||||
angle = (float) Math.acos(quaternion.w) * 2.0f;
|
||||
Vector3f rotationAxis = quaternion.getVectorV();
|
||||
final Vector3f rotationAxis = quaternion.getVectorV();
|
||||
return rotationAxis.normalize();
|
||||
}
|
||||
|
||||
|
||||
/** Get the orientation matrix corresponding to this quaternion
|
||||
* @return the 3x3 transformation matrix */
|
||||
@CheckReturnValue
|
||||
@ -157,9 +156,10 @@ public record Quaternion(
|
||||
final float yys = this.y * ys;
|
||||
final float yzs = this.y * 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
|
||||
public Matrix4f getMatrix4() {
|
||||
final float nQ = this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
|
||||
@ -179,29 +179,31 @@ public record Quaternion(
|
||||
final float yys = this.y * ys;
|
||||
final float yzs = this.y * 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 Quaternion unitarised */
|
||||
@CheckReturnValue
|
||||
public Quaternion getUnit() {
|
||||
return normalize();
|
||||
}
|
||||
|
||||
|
||||
/** get x, y, z in a Vector3f */
|
||||
@CheckReturnValue
|
||||
public Vector3f getVectorV() {
|
||||
return new Vector3f(this.x, this.y, this.z);
|
||||
}
|
||||
|
||||
|
||||
/** Inverse the quaternion */
|
||||
@CheckReturnValue
|
||||
public Quaternion inverse() {
|
||||
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.
|
||||
* @param obj Reference on the comparing object
|
||||
* @return true The Objects are NOT identical
|
||||
@ -210,7 +212,7 @@ public record Quaternion(
|
||||
public boolean isDifferent(final Quaternion obj) {
|
||||
return ((this.w != obj.w) || (this.z != obj.z) || (this.y != obj.y) || (this.x != obj.x));
|
||||
}
|
||||
|
||||
|
||||
/** Equality compare operator with an other object.
|
||||
* @param obj Reference on the comparing object
|
||||
* @return true The Objects are identical
|
||||
@ -219,7 +221,7 @@ public record Quaternion(
|
||||
public boolean isEqual(final Quaternion obj) {
|
||||
return ((this.w == obj.w) && (this.z == obj.z) && (this.y == obj.y) && (this.x == obj.x));
|
||||
}
|
||||
|
||||
|
||||
/** Check if the quaternion is equal to (0,0,0,0)
|
||||
* @return true The value is equal to (0,0,0,0)
|
||||
* @return false The value is NOT equal to (0,0,0,0) */
|
||||
@ -227,21 +229,21 @@ public record Quaternion(
|
||||
public boolean isZero() {
|
||||
return this.x == 0 && this.y == 0 && this.z == 0 && this.w == 0;
|
||||
}
|
||||
|
||||
|
||||
/** Return the length of the quaternion
|
||||
* @return Length value */
|
||||
@CheckReturnValue
|
||||
public float length() {
|
||||
return (float) Math.sqrt(length2());
|
||||
}
|
||||
|
||||
|
||||
/** Return the squared length of the quaternion.
|
||||
* @return Squared length value. */
|
||||
@CheckReturnValue
|
||||
public float length2() {
|
||||
return dot(this);
|
||||
}
|
||||
|
||||
|
||||
/** Subtract a vector from this one
|
||||
* @param obj The vector to subtract
|
||||
* @return New quaternion containing the value */
|
||||
@ -249,7 +251,7 @@ public record Quaternion(
|
||||
public Quaternion less(final Quaternion obj) {
|
||||
return new Quaternion(this.x - obj.x, this.y - obj.y, this.z - obj.z, this.w - obj.w);
|
||||
}
|
||||
|
||||
|
||||
@CheckReturnValue
|
||||
public Vector3f multiply(final float xxx, final float yyy, final float zzz) {
|
||||
final Vector3f point = new Vector3f(xxx, yyy, zzz);
|
||||
@ -260,7 +262,7 @@ public record Quaternion(
|
||||
uuv = uuv.multiply(2.0f);
|
||||
return uv.add(point).add(uuv);
|
||||
}
|
||||
|
||||
|
||||
/** Multiply this quaternion by the other.
|
||||
* @param obj The other quaternion
|
||||
* @return Local reference of the quaternion */
|
||||
@ -268,13 +270,13 @@ public record Quaternion(
|
||||
public Quaternion multiply(final Quaternion obj) {
|
||||
final Vector3f base = getVectorV();
|
||||
final Vector3f crossValue = base.cross(obj.getVectorV());
|
||||
float x = this.w * obj.x + obj.w * this.x + crossValue.x();
|
||||
float y = this.w * obj.y + obj.w * this.y + crossValue.y();
|
||||
float z = this.w * obj.z + obj.w * this.z + crossValue.z();
|
||||
float w = this.w * obj.w - base.dot(obj.getVectorV());
|
||||
final float x = this.w * obj.x + obj.w * this.x + crossValue.x();
|
||||
final float y = this.w * obj.y + obj.w * this.y + crossValue.y();
|
||||
final float z = this.w * obj.z + obj.w * this.z + crossValue.z();
|
||||
final float w = this.w * obj.w - base.dot(obj.getVectorV());
|
||||
return (new Quaternion(x, y, z, w)).safeNormalize();
|
||||
}
|
||||
|
||||
|
||||
/** Operator* with a vector. This methods rotates a point given the rotation of a quaternion
|
||||
* @param point Point to move
|
||||
* @return Point with the updated position */
|
||||
@ -287,7 +289,7 @@ public record Quaternion(
|
||||
uuv = uuv.multiply(2.0f);
|
||||
return uv.add(point).add(uuv);
|
||||
}
|
||||
|
||||
|
||||
/** Scale the quaternion
|
||||
* @param val Scale factor
|
||||
* @return New quaternion containing the value */
|
||||
@ -295,7 +297,7 @@ public record Quaternion(
|
||||
public Quaternion multiply(final float val) {
|
||||
return new Quaternion(this.x * val, this.y * val, this.z * val, this.w * val);
|
||||
}
|
||||
|
||||
|
||||
/** Normalize this quaternion x^2 + y^2 + z^2 + w^2 = 1
|
||||
* @return Local reference of the quaternion normalized */
|
||||
@CheckReturnValue
|
||||
@ -303,7 +305,7 @@ public record Quaternion(
|
||||
final float invLength = 1.0f / length();
|
||||
return new Quaternion(this.x * invLength, this.y * invLength, this.z * invLength, this.w * invLength);
|
||||
}
|
||||
|
||||
|
||||
/** Normalize this quaternion x^2 + y^2 + z^2 + w^2 = 1
|
||||
* @return Local reference of the quaternion normalized */
|
||||
@CheckReturnValue
|
||||
@ -314,7 +316,7 @@ public record Quaternion(
|
||||
}
|
||||
return normalize();
|
||||
}
|
||||
|
||||
|
||||
/** Configure the quaternion with euler angles.
|
||||
* @param angles Eular angle of the quaternion. */
|
||||
@CheckReturnValue
|
||||
@ -332,30 +334,32 @@ public record Quaternion(
|
||||
final float sinYcosZ = sinY * cosZ;
|
||||
final float cosYsinZ = cosY * sinZ;
|
||||
final float sinYsinZ = sinY * sinZ;
|
||||
float x = sinX * cosYcosZ - cosX * sinYsinZ;
|
||||
float y = cosX * sinYcosZ + sinX * cosYsinZ;
|
||||
float z = cosX * cosYsinZ - sinX * sinYcosZ;
|
||||
float w = cosX * cosYcosZ + sinX * sinYsinZ;
|
||||
final float x = sinX * cosYcosZ - cosX * sinYsinZ;
|
||||
final float y = cosX * sinYcosZ + sinX * cosYsinZ;
|
||||
final float z = cosX * cosYsinZ - sinX * sinYcosZ;
|
||||
final float w = cosX * cosYcosZ + sinX * sinYsinZ;
|
||||
return (new Quaternion(x, y, z, w)).normalize();
|
||||
}
|
||||
|
||||
|
||||
/** Set identity value at the quaternion */
|
||||
public static final Quaternion IDENTITY = new Quaternion(0, 0, 0, 1);
|
||||
|
||||
|
||||
/** Set each element to the max of the current values and the values of another Vector
|
||||
* @param obj The other Vector to compare with */
|
||||
@CheckReturnValue
|
||||
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
|
||||
* @param obj The other Vector to compare with */
|
||||
@CheckReturnValue
|
||||
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
|
||||
// This method is used to get the rotation angle (in radian) and the unit
|
||||
// rotation axis of an orientation quaternion.
|
||||
@ -379,9 +383,9 @@ public record Quaternion(
|
||||
return axis.set(rotationAxis);
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
public static final Quaternion ZERO = new Quaternion(0, 0, 0, 0);
|
||||
|
||||
|
||||
/** Compute the spherical linear interpolation between two quaternions.
|
||||
* @param obj1 First quaternion
|
||||
* @param obj2 Second quaternion
|
||||
@ -404,9 +408,10 @@ public record Quaternion(
|
||||
final float coeff2 = (float) Math.sin(ttt * theta) / sineTheta * invert;
|
||||
return this.multiply(coeff1).add(obj2.multiply(coeff2));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
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) + ")";
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package org.atriasoft.etk.math;
|
||||
|
||||
import edu.umd.cs.findbugs.annotations.CheckReturnValue;
|
||||
|
||||
@SuppressWarnings("preview")
|
||||
public record Transform3D(
|
||||
// Position
|
||||
Vector3f position,
|
||||
@ -12,69 +11,72 @@ public record Transform3D(
|
||||
* Get the identity of the transformation
|
||||
*/
|
||||
public static final Transform3D IDENTITY = new Transform3D(Vector3f.ZERO, Quaternion.IDENTITY);
|
||||
|
||||
|
||||
public Transform3D(final Vector3f position) {
|
||||
this(position, Quaternion.IDENTITY);
|
||||
}
|
||||
|
||||
|
||||
public Transform3D(final Vector3f position, final Matrix3f orientation) {
|
||||
this(position, Quaternion.createFromMatrix(orientation));
|
||||
}
|
||||
|
||||
|
||||
public Transform3D(final Vector3f position, final Quaternion orientation) {
|
||||
this.position = position;
|
||||
this.orientation = orientation;
|
||||
}
|
||||
|
||||
|
||||
@CheckReturnValue
|
||||
public Transform3D rotate(final Quaternion rotation) {
|
||||
return new Transform3D(this.position, this.orientation.multiply(rotation));
|
||||
}
|
||||
|
||||
|
||||
@CheckReturnValue
|
||||
public Transform3D withOrientation(final Quaternion orientation) {
|
||||
return new Transform3D(this.position, orientation);
|
||||
}
|
||||
|
||||
|
||||
@CheckReturnValue
|
||||
public Transform3D withPosition(final Vector3f position) {
|
||||
return new Transform3D(position, this.orientation);
|
||||
}
|
||||
|
||||
|
||||
/// Get the OpenGL matrix of the transform
|
||||
@CheckReturnValue
|
||||
public Matrix4f getOpenGLMatrix() {
|
||||
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(),
|
||||
tmpMatrix.c3(), this.position.z(), 0.0f, 0.0f, 0.0f, 1.0f);
|
||||
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(), tmpMatrix.c3(),
|
||||
this.position.z(), 0.0f, 0.0f, 0.0f, 1.0f);
|
||||
}
|
||||
|
||||
|
||||
/// Get the OpenGL matrix of the transform
|
||||
@CheckReturnValue
|
||||
public Matrix4f getOpenGLMatrixTransposed() {
|
||||
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,
|
||||
this.position.x(), this.position.y(), this.position.z(), 1.0f);
|
||||
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, this.position.x(),
|
||||
this.position.y(), this.position.z(), 1.0f);
|
||||
}
|
||||
|
||||
|
||||
@CheckReturnValue
|
||||
public Quaternion getOrientation() {
|
||||
return this.orientation;
|
||||
}
|
||||
|
||||
|
||||
@CheckReturnValue
|
||||
public Vector3f getPosition() {
|
||||
return this.position;
|
||||
}
|
||||
|
||||
|
||||
/// Return an interpolated transform
|
||||
@CheckReturnValue
|
||||
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);
|
||||
return new Transform3D(interPosition, interOrientation);
|
||||
}
|
||||
|
||||
|
||||
/// Return the inverse of the transform
|
||||
@CheckReturnValue
|
||||
public Transform3D inverseNew() {
|
||||
@ -82,25 +84,25 @@ public record Transform3D(
|
||||
final Matrix3f invMatrix = invQuaternion.getMatrix();
|
||||
return new Transform3D(invMatrix.multiply(this.position.multiply(-1)), invQuaternion);
|
||||
}
|
||||
|
||||
|
||||
/// Return true if the two transforms are different
|
||||
@CheckReturnValue
|
||||
public boolean isDifferent(final Transform3D transform2) {
|
||||
return this.position.isDifferent(transform2.position) || this.orientation.isDifferent(transform2.orientation);
|
||||
}
|
||||
|
||||
|
||||
/// Return true if the two transforms are equal
|
||||
@CheckReturnValue
|
||||
public boolean isEqual(final Transform3D transform2) {
|
||||
return this.position.isEqual(transform2.position) && this.orientation.isEqual(transform2.orientation);
|
||||
}
|
||||
|
||||
|
||||
/// Return the transformed vector
|
||||
@CheckReturnValue
|
||||
public Vector3f multiply(final Vector3f vector) {
|
||||
return this.orientation.getMatrix().multiply(vector).add(this.position);
|
||||
}
|
||||
|
||||
|
||||
/// Operator of multiplication of a transform with another one
|
||||
/*
|
||||
@CheckReturnValue
|
||||
@ -112,18 +114,20 @@ public record Transform3D(
|
||||
/// Operator of multiplication of a transform with another one
|
||||
@CheckReturnValue
|
||||
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
|
||||
@CheckReturnValue
|
||||
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]);
|
||||
Quaternion orientation = Quaternion.createFromMatrix(tmpMatrix);
|
||||
Vector3f position = new Vector3f(matrix[12], matrix[13], matrix[14]);
|
||||
final Matrix3f tmpMatrix = new Matrix3f(matrix[0], matrix[4], matrix[8], matrix[1], matrix[5], matrix[9],
|
||||
matrix[2], matrix[6], matrix[10]);
|
||||
final Quaternion orientation = Quaternion.createFromMatrix(tmpMatrix);
|
||||
final Vector3f position = new Vector3f(matrix[12], matrix[13], matrix[14]);
|
||||
return new Transform3D(position, orientation);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Transform3D(" + this.position + " & " + this.orientation + ")";
|
||||
|
@ -1,17 +1,15 @@
|
||||
package org.atriasoft.etk.math;
|
||||
|
||||
import org.atriasoft.etk.Uri;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import edu.umd.cs.findbugs.annotations.CheckReturnValue;
|
||||
|
||||
@SuppressWarnings("preview")
|
||||
public record Vector2b(
|
||||
boolean x,
|
||||
boolean y) {
|
||||
final static Logger LOGGER = LoggerFactory.getLogger(Vector2b.class);
|
||||
|
||||
public static Vector2b valueOf(String value) {
|
||||
boolean val1 = false;
|
||||
boolean val2 = false;
|
||||
@ -37,19 +35,19 @@ public record Vector2b(
|
||||
}
|
||||
return new Vector2b(val1, val2);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* **************************************************** Constructor
|
||||
*****************************************************/
|
||||
public Vector2b() {
|
||||
this(false, false);
|
||||
}
|
||||
|
||||
|
||||
public Vector2b(final boolean x, final boolean y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* In-Equality compare operator with an other object.
|
||||
* @param obj Reference on the comparing object
|
||||
@ -60,7 +58,7 @@ public record Vector2b(
|
||||
public boolean isDifferent(final Vector2b obj) {
|
||||
return (obj.x != this.x || obj.y != this.y);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Equality compare operator with an other object.
|
||||
* @param obj Reference on the comparing object
|
||||
@ -71,24 +69,24 @@ public record Vector2b(
|
||||
public boolean isEqual(final Vector2b obj) {
|
||||
return (obj.x == this.x && obj.y == this.y);
|
||||
}
|
||||
|
||||
|
||||
public static final Vector2b FALSE = new Vector2b(false, false);
|
||||
public static final Vector2b TRUE = new Vector2b(true, true);
|
||||
public static final Vector2b FALSE_FALSE = FALSE;
|
||||
public static final Vector2b TRUE_TRUE = TRUE;
|
||||
public static final Vector2b TRUE_FALSE = new Vector2b(true, false);
|
||||
public static final Vector2b FALSE_TRUE = new Vector2b(false, true);
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "(" + this.x + "," + this.y + ")";
|
||||
}
|
||||
|
||||
|
||||
@CheckReturnValue
|
||||
public Vector2b withX(final boolean xxx) {
|
||||
return new Vector2b(xxx, this.y);
|
||||
}
|
||||
|
||||
|
||||
@CheckReturnValue
|
||||
public Vector2b withY(final boolean yyy) {
|
||||
return new Vector2b(this.x, yyy);
|
||||
|
@ -1,18 +1,15 @@
|
||||
package org.atriasoft.etk.math;
|
||||
|
||||
import org.atriasoft.etk.Uri;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import edu.umd.cs.findbugs.annotations.CheckReturnValue;
|
||||
|
||||
@SuppressWarnings("preview")
|
||||
public record Vector2i(
|
||||
int x,
|
||||
int y) {
|
||||
final static Logger LOGGER = LoggerFactory.getLogger(Vector2i.class);
|
||||
|
||||
|
||||
public static Vector2i valueOf(String value) throws NumberFormatException {
|
||||
int val1 = 0;
|
||||
int val2 = 0;
|
||||
@ -38,27 +35,27 @@ public record Vector2i(
|
||||
}
|
||||
return new Vector2i(val1, val2);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* **************************************************** Constructor
|
||||
*****************************************************/
|
||||
public Vector2i() {
|
||||
this(0, 0);
|
||||
}
|
||||
|
||||
|
||||
public Vector2i(final int x, final int y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
|
||||
public static Vector2i max(final Vector2i obj1, final Vector2i obj2) {
|
||||
return new Vector2i(Math.max(obj1.x, obj2.x), Math.max(obj1.y, obj2.y));
|
||||
}
|
||||
|
||||
|
||||
public static Vector2i min(final Vector2i obj1, final Vector2i obj2) {
|
||||
return new Vector2i(Math.min(obj1.x, obj2.x), Math.min(obj1.y, obj2.y));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return a vector will the absolute values of each element
|
||||
* @return New vector containing the value
|
||||
@ -67,22 +64,22 @@ public record Vector2i(
|
||||
public Vector2i absolute() {
|
||||
return new Vector2i(Math.abs(this.x), Math.abs(this.y));
|
||||
}
|
||||
|
||||
|
||||
@CheckReturnValue
|
||||
public Vector2i add(final int val) {
|
||||
return new Vector2i(this.x + val, this.y + val);
|
||||
}
|
||||
|
||||
|
||||
@CheckReturnValue
|
||||
public Vector2i add(final Vector2i obj) {
|
||||
return new Vector2i(this.x + obj.x, this.y + obj.y);
|
||||
}
|
||||
|
||||
|
||||
@CheckReturnValue
|
||||
public Vector2i add(final int xxx, final int yyy) {
|
||||
return new Vector2i(this.x + xxx, this.y + yyy);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the axis with the largest ABSOLUTE value
|
||||
* @return values 0,1 for x or y
|
||||
@ -91,7 +88,7 @@ public record Vector2i(
|
||||
public int closestAxis() {
|
||||
return absolute().maxAxis();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the cross product / determinant
|
||||
* @param obj The other vector in the cross product
|
||||
@ -101,7 +98,7 @@ public record Vector2i(
|
||||
public int cross(final Vector2i obj) {
|
||||
return this.x * obj.y - this.y * obj.x;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Decrementation of this vector (-1 of 2 elements)
|
||||
*/
|
||||
@ -109,17 +106,17 @@ public record Vector2i(
|
||||
public Vector2i decrement() {
|
||||
return new Vector2i(this.x - 1, this.y - 1);
|
||||
}
|
||||
|
||||
|
||||
@CheckReturnValue
|
||||
public Vector2i devide(final int val) {
|
||||
return new Vector2i(this.x / val, this.y / val);
|
||||
}
|
||||
|
||||
|
||||
@CheckReturnValue
|
||||
public Vector2i devide(final Vector2i obj) {
|
||||
return new Vector2i(this.x / obj.x, this.y / obj.y);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the distance between the ends of this and another vector This
|
||||
* is symantically treating the vector like a point
|
||||
@ -130,7 +127,7 @@ public record Vector2i(
|
||||
public int distance(final Vector2i obj) {
|
||||
return (int) Math.sqrt(distance2(obj));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the distance squared between the ends of this and another
|
||||
* vector This is symantically treating the vector like a point
|
||||
@ -143,7 +140,7 @@ public record Vector2i(
|
||||
final int deltaY = obj.y - this.y;
|
||||
return deltaX * deltaX + deltaY * deltaY;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the dot product
|
||||
* @param obj The other vector in the dot product
|
||||
@ -153,7 +150,7 @@ public record Vector2i(
|
||||
public int dot(final Vector2i obj) {
|
||||
return this.x * obj.x + this.y * obj.y;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the axis with the smallest ABSOLUTE value
|
||||
* @return values 0,1 for x, or z
|
||||
@ -162,7 +159,7 @@ public record Vector2i(
|
||||
public int furthestAxis() {
|
||||
return absolute().minAxis();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Incrementation of this vector (+1 of 2 elements)
|
||||
*/
|
||||
@ -170,7 +167,7 @@ public record Vector2i(
|
||||
public Vector2i increment() {
|
||||
return new Vector2i(this.x + 1, this.y + 1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* In-Equality compare operator with an other object.
|
||||
* @param obj Reference on the comparing object
|
||||
@ -181,7 +178,7 @@ public record Vector2i(
|
||||
public boolean isDifferent(final Vector2i obj) {
|
||||
return (obj.x != this.x || obj.y != this.y);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Equality compare operator with an other object.
|
||||
* @param obj Reference on the comparing object
|
||||
@ -192,27 +189,27 @@ public record Vector2i(
|
||||
public boolean isEqual(final Vector2i obj) {
|
||||
return (obj.x == this.x && obj.y == this.y);
|
||||
}
|
||||
|
||||
|
||||
@CheckReturnValue
|
||||
public boolean isGreater(final Vector2i obj) {
|
||||
return (this.x > obj.x && this.y > obj.y);
|
||||
}
|
||||
|
||||
|
||||
@CheckReturnValue
|
||||
public boolean isGreaterOrEqual(final Vector2i obj) {
|
||||
return (this.x >= obj.x && this.y >= obj.y);
|
||||
}
|
||||
|
||||
|
||||
@CheckReturnValue
|
||||
public boolean isLower(final Vector2i obj) {
|
||||
return (this.x < obj.x && this.y < obj.y);
|
||||
}
|
||||
|
||||
|
||||
@CheckReturnValue
|
||||
public boolean isLowerOrEqual(final Vector2i obj) {
|
||||
return (this.x <= obj.x && this.y <= obj.y);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if the vector is equal to (0,0)
|
||||
* @return true The value is equal to (0,0)
|
||||
@ -222,7 +219,7 @@ public record Vector2i(
|
||||
public boolean isZero() {
|
||||
return this.x == 0 && this.y == 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the length of the vector
|
||||
* @return Length value
|
||||
@ -231,7 +228,7 @@ public record Vector2i(
|
||||
public int length() {
|
||||
return (int) Math.sqrt(length2());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the length of the vector squared
|
||||
* @return Squared length value.
|
||||
@ -240,22 +237,22 @@ public record Vector2i(
|
||||
public int length2() {
|
||||
return dot(this);
|
||||
}
|
||||
|
||||
|
||||
@CheckReturnValue
|
||||
public Vector2i less(final int val) {
|
||||
return new Vector2i(this.x - val, this.y - val);
|
||||
}
|
||||
|
||||
|
||||
@CheckReturnValue
|
||||
public Vector2i less(final int xxx, final int yyy) {
|
||||
return new Vector2i(this.x - xxx, this.y - yyy);
|
||||
}
|
||||
|
||||
|
||||
@CheckReturnValue
|
||||
public Vector2i less(final Vector2i obj) {
|
||||
return new Vector2i(this.x - obj.x, this.y - obj.y);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the axis with the largest value
|
||||
* @return values are 0,1 for x or y
|
||||
@ -264,7 +261,7 @@ public record Vector2i(
|
||||
public int maxAxis() {
|
||||
return this.x < this.y ? 1 : 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the axis with the smallest value
|
||||
* @return values are 0,1 for x or y
|
||||
@ -273,17 +270,17 @@ public record Vector2i(
|
||||
public int minAxis() {
|
||||
return this.x < this.y ? 0 : 1;
|
||||
}
|
||||
|
||||
|
||||
@CheckReturnValue
|
||||
public Vector2i multiply(final int val) {
|
||||
return new Vector2i(this.x * val, this.y * val);
|
||||
}
|
||||
|
||||
|
||||
@CheckReturnValue
|
||||
public Vector2i multiply(final Vector2i obj) {
|
||||
return new Vector2i(this.x * obj.x, this.y * obj.y);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Normalize this vector x^2 + y^2 = 1
|
||||
* @return New vector containing the value
|
||||
@ -292,7 +289,7 @@ public record Vector2i(
|
||||
public Vector2i normalize() {
|
||||
return this.devide(length());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Normalize this vector x^2 + y^2 = 1 (check if not deviding by 0, if it
|
||||
* is the case ==> return (1,0))
|
||||
@ -306,17 +303,17 @@ public record Vector2i(
|
||||
}
|
||||
return new Vector2i(1, 0);
|
||||
};
|
||||
|
||||
|
||||
@CheckReturnValue
|
||||
public Vector2i max(final int xxx, final int yyy) {
|
||||
return new Vector2i(Math.max(this.x, xxx), Math.max(this.y, yyy));
|
||||
}
|
||||
|
||||
|
||||
@CheckReturnValue
|
||||
public Vector2i min(final int xxx, final int yyy) {
|
||||
return new Vector2i(Math.min(this.x, xxx), Math.min(this.y, yyy));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set 0 value on all the vector
|
||||
*/
|
||||
@ -332,17 +329,17 @@ public record Vector2i(
|
||||
public static final Vector2i VALUE_256 = new Vector2i(256, 256);
|
||||
public static final Vector2i VALUE_512 = new Vector2i(512, 512);
|
||||
public static final Vector2i VALUE_1024 = new Vector2i(1024, 1024);
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Vector2i(" + this.x + "," + this.y + ")";
|
||||
}
|
||||
|
||||
|
||||
@CheckReturnValue
|
||||
public Vector2i withX(final int xxx) {
|
||||
return new Vector2i(xxx, this.y);
|
||||
}
|
||||
|
||||
|
||||
@CheckReturnValue
|
||||
public Vector2i withY(final int yyy) {
|
||||
return new Vector2i(this.x, yyy);
|
||||
|
@ -1,17 +1,15 @@
|
||||
package org.atriasoft.etk.math;
|
||||
|
||||
import org.atriasoft.etk.Uri;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import edu.umd.cs.findbugs.annotations.CheckReturnValue;
|
||||
|
||||
@SuppressWarnings("preview")
|
||||
public record Vector3b(
|
||||
boolean x,
|
||||
boolean y,
|
||||
boolean z) {
|
||||
|
||||
final static Logger LOGGER = LoggerFactory.getLogger(Vector3b.class);
|
||||
public static Vector3b valueOf(String value) {
|
||||
boolean val1 = false;
|
||||
@ -45,20 +43,20 @@ public record Vector3b(
|
||||
}
|
||||
return new Vector3b(val1, val2, val3);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* **************************************************** Constructor
|
||||
*****************************************************/
|
||||
public Vector3b() {
|
||||
this(false, false, false);
|
||||
}
|
||||
|
||||
|
||||
public Vector3b(final boolean x, final boolean y, final boolean z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* In-Equality compare operator with an other object.
|
||||
* @param obj Reference on the comparing object
|
||||
@ -69,7 +67,7 @@ public record Vector3b(
|
||||
public boolean isDifferent(final Vector3b obj) {
|
||||
return (obj.x != this.x || obj.y != this.y || obj.z != this.z);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Equality compare operator with an other object.
|
||||
* @param obj Reference on the comparing object
|
||||
@ -80,7 +78,7 @@ public record Vector3b(
|
||||
public boolean isEqual(final Vector3b obj) {
|
||||
return (obj.x == this.x && obj.y == this.y && obj.z == this.z);
|
||||
}
|
||||
|
||||
|
||||
public static final Vector3b FALSE = new Vector3b(false, false, false);
|
||||
public static final Vector3b TRUE = new Vector3b(true, true, true);
|
||||
public static final Vector3b FALSE_FALSE_FALSE = FALSE;
|
||||
@ -88,22 +86,22 @@ public record Vector3b(
|
||||
public static final Vector3b TRUE_FALSE_FALSE = new Vector3b(true, false, false);
|
||||
public static final Vector3b FALSE_TRUE_FALSE = new Vector3b(false, true, false);
|
||||
public static final Vector3b FALSE_FALSE_TRUE = new Vector3b(false, false, true);
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "(" + this.x + "," + this.y + ")";
|
||||
}
|
||||
|
||||
|
||||
@CheckReturnValue
|
||||
public Vector3b withX(final boolean xxx) {
|
||||
return new Vector3b(xxx, this.y, this.z);
|
||||
}
|
||||
|
||||
|
||||
@CheckReturnValue
|
||||
public Vector3b withY(final boolean yyy) {
|
||||
return new Vector3b(this.x, yyy, this.z);
|
||||
}
|
||||
|
||||
|
||||
@CheckReturnValue
|
||||
public Vector3b withZ(final boolean zzz) {
|
||||
return new Vector3b(this.x, this.y, zzz);
|
||||
|
Loading…
Reference in New Issue
Block a user