Skip to content

Commit

Permalink
add remaining float write methods
Browse files Browse the repository at this point in the history
  • Loading branch information
iTitus committed Jun 16, 2021
1 parent aa33046 commit 9424476
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/main/java/io/github/ititus/math/matrix/Mat2f.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import io.github.ititus.data.ArrayUtil;
import io.github.ititus.math.vector.Vec2f;

import java.nio.FloatBuffer;

public final class Mat2f {

private final float m11, m12;
Expand Down Expand Up @@ -115,6 +117,11 @@ public float determinant() {
return m11 * m22 - m12 * m21;
}

public void write(FloatBuffer buffer) {
buffer.put(m11).put(m21);
buffer.put(m12).put(m22);
}

public float m(int row, int col) {
if (row < 0 || row >= 2) {
throw new IllegalArgumentException("row out of bounds");
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/io/github/ititus/math/matrix/Mat3f.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import io.github.ititus.data.ArrayUtil;
import io.github.ititus.math.vector.Vec3f;

import java.nio.FloatBuffer;

public final class Mat3f {

private final float m11, m12, m13;
Expand Down Expand Up @@ -134,6 +136,12 @@ public float determinant() {
- m13 * m22 * m31 - m12 * m21 * m33 - m11 * m23 * m32;
}

public void write(FloatBuffer buffer) {
buffer.put(m11).put(m21).put(m31);
buffer.put(m12).put(m22).put(m32);
buffer.put(m13).put(m32).put(m33);
}

public float m(int row, int col) {
if (row < 0 || row >= 3) {
throw new IllegalArgumentException("row out of bounds");
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/io/github/ititus/math/vector/Vec2f.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import io.github.ititus.data.ArrayUtil;
import io.github.ititus.math.matrix.Mat2f;

import java.nio.FloatBuffer;

public final class Vec2f {

private final float x;
Expand Down Expand Up @@ -82,6 +84,10 @@ public Vec2f normalize() {
return divide((float) Math.sqrt(lsq));
}

public void write(FloatBuffer buffer) {
buffer.put(x).put(y);
}

public float x() {
return x;
}
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/io/github/ititus/math/vector/Vec3f.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import io.github.ititus.data.ArrayUtil;
import io.github.ititus.math.matrix.Mat3f;

import java.nio.FloatBuffer;

public final class Vec3f {

private final float x;
Expand Down Expand Up @@ -91,6 +93,10 @@ public Vec3f normalize() {
return divide((float) Math.sqrt(lsq));
}

public void write(FloatBuffer buffer) {
buffer.put(x).put(y).put(z);
}

public float x() {
return x;
}
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/io/github/ititus/math/vector/Vec4f.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import io.github.ititus.math.matrix.Mat4f;
import io.github.ititus.math.quaternion.Quatf;

import java.nio.FloatBuffer;

public final class Vec4f {

private final float x;
Expand Down Expand Up @@ -95,6 +97,10 @@ public Vec4f normalize() {
return divide((float) Math.sqrt(lsq));
}

public void write(FloatBuffer buffer) {
buffer.put(x).put(y).put(z).put(w);
}

public float x() {
return x;
}
Expand Down

0 comments on commit 9424476

Please sign in to comment.