Skip to content

Commit

Permalink
Add Matrix4x3d.get4x4(Buffer)
Browse files Browse the repository at this point in the history
  • Loading branch information
httpdigest committed Oct 26, 2016
1 parent cfc502d commit 65a08cd
Show file tree
Hide file tree
Showing 4 changed files with 178 additions and 3 deletions.
48 changes: 46 additions & 2 deletions src/org/joml/Matrix4x3d.java
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,22 @@ public float[] get(float[] arr) {
return delegate.get(arr);
}

public DoubleBuffer get4x4(DoubleBuffer buffer) {
return delegate.get4x4(buffer);
}

public DoubleBuffer get4x4(int index, DoubleBuffer buffer) {
return delegate.get4x4(index, buffer);
}

public ByteBuffer get4x4(ByteBuffer buffer) {
return delegate.get4x4(buffer);
}

public ByteBuffer get4x4(int index, ByteBuffer buffer) {
return delegate.get4x4(index, buffer);
}

public DoubleBuffer getTransposed(DoubleBuffer buffer) {
return delegate.getTransposed(buffer);
}
Expand Down Expand Up @@ -609,8 +625,6 @@ public Vector3d getEulerAnglesZYX(Vector3d dest) {
double m30, m31, m32;

byte properties;
private static final byte PROPERTY_IDENTITY = 1<<2;
private static final byte PROPERTY_TRANSLATION = 1<<3;

/**
* Create a new {@link Matrix4x3d} and set it to {@link #identity() identity}.
Expand Down Expand Up @@ -2252,6 +2266,36 @@ public float[] get(float[] arr) {
return get(arr, 0);
}

/* (non-Javadoc)
* @see org.joml.Matrix4x3dc#get4x4(java.nio.DoubleBuffer)
*/
public DoubleBuffer get4x4(DoubleBuffer buffer) {
return get4x4(buffer.position(), buffer);
}

/* (non-Javadoc)
* @see org.joml.Matrix4x3dc#get4x4(int, java.nio.DoubleBuffer)
*/
public DoubleBuffer get4x4(int index, DoubleBuffer buffer) {
MemUtil.INSTANCE.put4x4(this, index, buffer);
return buffer;
}

/* (non-Javadoc)
* @see org.joml.Matrix4x3dc#get4x4(java.nio.ByteBuffer)
*/
public ByteBuffer get4x4(ByteBuffer buffer) {
return get4x4(buffer.position(), buffer);
}

/* (non-Javadoc)
* @see org.joml.Matrix4x3dc#get4x4(int, java.nio.ByteBuffer)
*/
public ByteBuffer get4x4(int index, ByteBuffer buffer) {
MemUtil.INSTANCE.put4x4(this, index, buffer);
return buffer;
}

/* (non-Javadoc)
* @see org.joml.Matrix4x3dc#getTransposed(java.nio.DoubleBuffer)
*/
Expand Down
64 changes: 64 additions & 0 deletions src/org/joml/Matrix4x3dc.java
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,70 @@ public interface Matrix4x3dc {
*/
float[] get(float[] arr);

/**
* Store a 4x4 matrix in column-major order into the supplied {@link DoubleBuffer} at the current
* buffer {@link DoubleBuffer#position() position}, where the upper 4x3 submatrix is <code>this</code> and the last row is <tt>(0, 0, 0, 1)</tt>.
* <p>
* This method will not increment the position of the given DoubleBuffer.
* <p>
* In order to specify the offset into the DoubleBuffer at which
* the matrix is stored, use {@link #get4x4(int, DoubleBuffer)}, taking
* the absolute position as parameter.
*
* @see #get4x4(int, DoubleBuffer)
*
* @param buffer
* will receive the values of this matrix in column-major order at its current position
* @return the passed in buffer
*/
DoubleBuffer get4x4(DoubleBuffer buffer);

/**
* Store a 4x4 matrix in column-major order into the supplied {@link DoubleBuffer} starting at the specified
* absolute buffer position/index, where the upper 4x3 submatrix is <code>this</code> and the last row is <tt>(0, 0, 0, 1)</tt>.
* <p>
* This method will not increment the position of the given DoubleBuffer.
*
* @param index
* the absolute position into the DoubleBuffer
* @param buffer
* will receive the values of this matrix in column-major order
* @return the passed in buffer
*/
DoubleBuffer get4x4(int index, DoubleBuffer buffer);

/**
* Store a 4x4 matrix in column-major order into the supplied {@link ByteBuffer} at the current
* buffer {@link ByteBuffer#position() position}, where the upper 4x3 submatrix is <code>this</code> and the last row is <tt>(0, 0, 0, 1)</tt>.
* <p>
* This method will not increment the position of the given ByteBuffer.
* <p>
* In order to specify the offset into the ByteBuffer at which
* the matrix is stored, use {@link #get4x4(int, ByteBuffer)}, taking
* the absolute position as parameter.
*
* @see #get4x4(int, ByteBuffer)
*
* @param buffer
* will receive the values of this matrix in column-major order at its current position
* @return the passed in buffer
*/
ByteBuffer get4x4(ByteBuffer buffer);

/**
* Store a 4x4 matrix in column-major order into the supplied {@link ByteBuffer} starting at the specified
* absolute buffer position/index, where the upper 4x3 submatrix is <code>this</code> and the last row is <tt>(0, 0, 0, 1)</tt>.
* <p>
* This method will not increment the position of the given ByteBuffer.
*
* @param index
* the absolute position into the ByteBuffer
* @param buffer
* will receive the values of this matrix in column-major order
* @return the passed in buffer
*/
ByteBuffer get4x4(int index, ByteBuffer buffer);

/**
* Store this matrix in row-major order into the supplied {@link DoubleBuffer} at the current
* buffer {@link DoubleBuffer#position() position}.
Expand Down
2 changes: 1 addition & 1 deletion src/org/joml/Matrix4x3fc.java
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ public interface Matrix4x3fc {
* the matrix is stored, use {@link #get4x4(int, ByteBuffer)}, taking
* the absolute position as parameter.
*
* @see #get(int, ByteBuffer)
* @see #get4x4(int, ByteBuffer)
*
* @param buffer
* will receive the values of this matrix in column-major order at its current position
Expand Down
67 changes: 67 additions & 0 deletions src/org/joml/MemUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ private static final MemUtil createInstance() {
public abstract void put(Matrix4x3f m, int offset, ByteBuffer dest);
public abstract void put4x4(Matrix4x3f m, int offset, FloatBuffer dest);
public abstract void put4x4(Matrix4x3f m, int offset, ByteBuffer dest);
public abstract void put4x4(Matrix4x3d m, int offset, DoubleBuffer dest);
public abstract void put4x4(Matrix4x3d m, int offset, ByteBuffer dest);
public abstract void putTransposed(Matrix4f m, int offset, FloatBuffer dest);
public abstract void putTransposed(Matrix4f m, int offset, ByteBuffer dest);
public abstract void put4x3Transposed(Matrix4f m, int offset, FloatBuffer dest);
Expand Down Expand Up @@ -306,6 +308,44 @@ public final void put4x4(Matrix4x3f m, int offset, ByteBuffer dest) {
dest.putFloat(offset+60, 1.0f);
}

public final void put4x4(Matrix4x3d m, int offset, DoubleBuffer dest) {
dest.put(offset, m.m00);
dest.put(offset+1, m.m01);
dest.put(offset+2, m.m02);
dest.put(offset+3, 0.0);
dest.put(offset+4, m.m10);
dest.put(offset+5, m.m11);
dest.put(offset+6, m.m12);
dest.put(offset+7, 0.0);
dest.put(offset+8, m.m20);
dest.put(offset+9, m.m21);
dest.put(offset+10, m.m22);
dest.put(offset+11, 0.0);
dest.put(offset+12, m.m30);
dest.put(offset+13, m.m31);
dest.put(offset+14, m.m32);
dest.put(offset+15, 1.0);
}

public final void put4x4(Matrix4x3d m, int offset, ByteBuffer dest) {
dest.putDouble(offset, m.m00);
dest.putDouble(offset+4, m.m01);
dest.putDouble(offset+8, m.m02);
dest.putDouble(offset+12, 0.0);
dest.putDouble(offset+16, m.m10);
dest.putDouble(offset+20, m.m11);
dest.putDouble(offset+24, m.m12);
dest.putDouble(offset+28, 0.0);
dest.putDouble(offset+32, m.m20);
dest.putDouble(offset+36, m.m21);
dest.putDouble(offset+40, m.m22);
dest.putDouble(offset+44, 0.0);
dest.putDouble(offset+48, m.m30);
dest.putDouble(offset+52, m.m31);
dest.putDouble(offset+56, m.m32);
dest.putDouble(offset+60, 1.0);
}

public final void putTransposed(Matrix4f m, int offset, FloatBuffer dest) {
dest.put(offset, m.m00);
dest.put(offset+1, m.m10);
Expand Down Expand Up @@ -2237,6 +2277,25 @@ public final void put4x4(Matrix4x3f m, long destAddr) {
UNSAFE.putFloat(null, destAddr + 60, 1.0f);
}

public final void put4x4(Matrix4x3d m, long destAddr) {
UNSAFE.putDouble(null, destAddr, m.m00);
UNSAFE.putDouble(null, destAddr + 8, m.m01);
UNSAFE.putDouble(null, destAddr + 16, m.m02);
UNSAFE.putDouble(null, destAddr + 24, 0.0);
UNSAFE.putDouble(null, destAddr + 32, m.m10);
UNSAFE.putDouble(null, destAddr + 40, m.m11);
UNSAFE.putDouble(null, destAddr + 48, m.m12);
UNSAFE.putDouble(null, destAddr + 56, 0.0);
UNSAFE.putDouble(null, destAddr + 64, m.m20);
UNSAFE.putDouble(null, destAddr + 72, m.m21);
UNSAFE.putDouble(null, destAddr + 80, m.m22);
UNSAFE.putDouble(null, destAddr + 88, 0.0);
UNSAFE.putDouble(null, destAddr + 96, m.m30);
UNSAFE.putDouble(null, destAddr + 104, m.m31);
UNSAFE.putDouble(null, destAddr + 112, m.m32);
UNSAFE.putDouble(null, destAddr + 120, 1.0);
}

public final void putTransposed(Matrix4f m, long destAddr) {
UNSAFE.putFloat(null, destAddr, m.m00);
UNSAFE.putFloat(null, destAddr + 4, m.m10);
Expand Down Expand Up @@ -3056,6 +3115,14 @@ public final void put4x4(Matrix4x3f m, int offset, ByteBuffer dest) {
put4x4(m, addressOf(dest) + offset);
}

public final void put4x4(Matrix4x3d m, int offset, DoubleBuffer dest) {
put4x4(m, addressOf(dest) + (offset << 3));
}

public final void put4x4(Matrix4x3d m, int offset, ByteBuffer dest) {
put4x4(m, addressOf(dest) + offset);
}

public final void putTransposed(Matrix4f m, int offset, FloatBuffer dest) {
putTransposed(m, addressOf(dest) + (offset << 2));
}
Expand Down

0 comments on commit 65a08cd

Please sign in to comment.