Skip to content

Commit

Permalink
Cleaned up DVector3 etc (#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
tzaeschke authored May 14, 2023
1 parent d3f2dca commit 4c8bc7a
Show file tree
Hide file tree
Showing 20 changed files with 226 additions and 143 deletions.
12 changes: 6 additions & 6 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ TODO for 0.5.0
Check:
- Demo -> Test? E.g. DemoI? DemoSpace(-Stress)? DemoStep? ....

DxHeightfield.tempPlaneBuffer should probably just be a simple array. ALso check tempHeightBuffer.
DxTrimeshHeightfield.tempHeightBuffer??
DxGimpactData.check().edges

Bug: Dropping first box on Heightfield is wrong.
-> Cylinder is also often iffy, but that is the same in C++ -> e.g. 7. cylinder (java) or 11th (c++)!

Fix ENABLE_CONTACT_SORTING / Issue #22
0.6.0
=====
- TODO remove deprecations for 0.6.0

0.5.0 (unreleased)
=====
- DVector3/DQuaternion/...: Better support for call chaining. [#108](https://github.com/tzaeschke/ode4j/pull/108)
- DVector3/DQuaternion/...: Better support for call chaining, added isEq(x, y, z, eps) and deprecated clone() and
DQuaternion.*Euler*().
[#108](https://github.com/tzaeschke/ode4j/pull/108)
- DVector3/DQuaternion/...: Deprecated hashCode(). [#107](https://github.com/tzaeschke/ode4j/pull/107)
- Removed unnecessary ObjArray from heightfield. [#106](https://github.com/tzaeschke/ode4j/pull/106)
- Added linter and fixed some lint. [#105](https://github.com/tzaeschke/ode4j/pull/105)
Expand Down
102 changes: 69 additions & 33 deletions core/src/main/java/org/ode4j/math/DMatrix3.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,25 @@ public DMatrix3 set(DMatrix3C m) {
set20( m.get20() ); set21( m.get21() ); set22( m.get22() );
return this;
}


/**
* Returns a clone of this Matrix.
*/
@Override
@Deprecated
public DMatrix3 clone() {
return new DMatrix3(this);
}


/**
* Returns a copy of this Matrix.
*/
@Override
public DMatrix3 copy() {
return new DMatrix3(this);
}


@Override
public String toString() {
Expand All @@ -158,30 +167,38 @@ public String toString() {
b.append(get22()).append("]]");
return b.toString();
}
public void setOfs(int ofs, DVector3 v3) {

public DMatrix3 setOfs(int ofs, DVector3 v3) {
v[ofs] = v3.get0(); v[ofs+1] = v3.get1(); v[ofs+2] = v3.get2(); //v[ofs+3] = 0;//v3.v[3];
return this;
}
public void setCol(int i, DVector3 v3) {

public DMatrix3 setCol(int i, DVector3 v3) {
int ofs = i*4;
v[ofs] = v3.get0(); v[ofs+1] = v3.get1(); v[ofs+2] = v3.get2(); //v[ofs+3] = 0;//v3.v[3];
return this;
}
public void set(double i, double j, double k, double l, double m,

public DMatrix3 set(double i, double j, double k, double l, double m,
double n, double o, double p, double q) {
// v[0] = i; v[1] = j; v[2] = k;
// v[4] = l; v[5] = m; v[6] = n;
// v[8] = o; v[9] = p; v[10] = q;
set00( i ); set01( j ); set02( k );
set10( l ); set11( m ); set12( n );
set20( o ); set21( p ); set22( q );
return this;
}
/**

/**
* Initialises this matrix from a 3*4 double [] with 12 fields, ignoring
* the 4th, 8th and 12th field. This is useful when using padded arrays.
* @param da Initialisztion matrix
* @param da_ofs Reading offset
*/
public void set12(double[] da, int da_ofs) {
public DMatrix3 set12(double[] da, int da_ofs) {
System.arraycopy(da, da_ofs, v, 0, da.length);
return this;
}

public double get(int i) {
Expand Down Expand Up @@ -213,10 +230,11 @@ public DMatrix3 add(DMatrix3C m) {
}


public void scale(double scale) {
public DMatrix3 scale(double scale) {
for (int i = 0; i < v.length; i++) {
v[i] *= scale;
}
return this;
}

/**
Expand All @@ -230,11 +248,13 @@ public void scale(double scale) {
* @param B source B
* @param C source C
*/
public void dMultiply0 (final DMatrix3C B,
public DMatrix3 dMultiply0 (final DMatrix3C B,
final DMatrix3C C) {
eqMul(B, C);
}
public void eqMul (final DMatrix3C B,
return this;
}

public DMatrix3 eqMul (final DMatrix3C B,
final DMatrix3C C)
{
// dMatrix3 B2 = (dMatrix3) B;
Expand Down Expand Up @@ -271,6 +291,7 @@ public void eqMul (final DMatrix3C B,
set20( B.get20()*C.get00() + B.get21()*C.get10() + B.get22()*C.get20() );
set21( B.get20()*C.get01() + B.get21()*C.get11() + B.get22()*C.get21() );
set22( B.get20()*C.get02() + B.get21()*C.get12() + B.get22()*C.get22() );
return this;
}


Expand Down Expand Up @@ -431,12 +452,12 @@ public double get2() {
public void set0(double d) {
v[_column] = d;
}

@Override
public void set1(double d) {
v[1 * MAX_J + _column] = d;
}

@Override
public void set2(double d) {
v[2 * MAX_J + _column] = d;
Expand Down Expand Up @@ -577,57 +598,66 @@ public final double get22() {
}


public final void set00(double d) {
public DMatrix3 set00(double d) {
v[0] = d;
return this;
}


public final void set01(double d) {
public DMatrix3 set01(double d) {
v[1] = d;
return this;
}


public final void set02(double d) {
public DMatrix3 set02(double d) {
v[2] = d;
return this;
}


public final void set10(double d) {
public DMatrix3 set10(double d) {
v[1*MAX_J + 0] = d;
return this;
}


public final void set11(double d) {
public DMatrix3 set11(double d) {
v[1*MAX_J + 1] = d;
return this;
}


public final void set12(double d) {
public DMatrix3 set12(double d) {
v[1*MAX_J + 2] = d;
return this;
}


public final void set20(double d) {
public DMatrix3 set20(double d) {
v[2*MAX_J + 0] = d;
return this;
}


public final void set21(double d) {
public DMatrix3 set21(double d) {
v[2*MAX_J + 1] = d;
return this;
}


public final void set22(double d) {
public DMatrix3 set22(double d) {
v[2*MAX_J + 2] = d;
return this;
}


public final int dimI() {
public int dimI() {
return MAX_I;
}


public final int dimJ() {
public int dimJ() {
//TODO MAX_J, once MAX_J==3
return 3;
}
Expand All @@ -637,7 +667,7 @@ public final int dimJ() {
* This is marginally faster than <tt>equals(Object o)</tt>.
*/
@Override
public final boolean isEq(DMatrix3C m, double epsilon) {
public boolean isEq(DMatrix3C m, double epsilon) {
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (Math.abs(get(i, j) - m.get(i, j)) > epsilon) return false;
Expand Down Expand Up @@ -703,11 +733,12 @@ public int hashCode() {
* Make the matrix an identity matrix.
* Same as setIdenity().
*/
public final void eqIdentity() {
public DMatrix3 eqIdentity() {
eqZero();
set00(1);
set11(1);
set22(1);
return this;
}


Expand All @@ -716,7 +747,7 @@ public final void eqIdentity() {
* Same as eqIdenity().
* @return This matrix.
*/
public final DMatrix3 setIdentity() {
public DMatrix3 setIdentity() {
eqIdentity();
return this;
}
Expand All @@ -726,19 +757,21 @@ public final DMatrix3 setIdentity() {
* Set the matrix to zero.
* Same as setZero().
*/
public final void eqZero() {
public DMatrix3 eqZero() {
for (int i = 0; i < v.length; i++) {
v[i] = 0;
}
return this;
}


/**
* Set the matrix to zero.
* Same as eqZero().
*/
public final void setZero() {
public DMatrix3 setZero() {
eqZero();
return this;
}


Expand Down Expand Up @@ -977,18 +1010,21 @@ public double get(int i, int j) {
* @param j column
* @param a value at (i,j)
*/
public void set(int i, int j, double a) {
public DMatrix3 set(int i, int j, double a) {
v[i*MAX_J + j] = a;
return this;
}


public void add(int i, int j, double d) {
public DMatrix3 add(int i, int j, double d) {
v[i*MAX_J + j] += d;
return this;
}


public void sub(int i, int j, double d) {
public DMatrix3 sub(int i, int j, double d) {
v[i*MAX_J + j] -= d;
return this;
}


Expand Down
11 changes: 10 additions & 1 deletion core/src/main/java/org/ode4j/math/DMatrix3C.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,16 @@ public interface DMatrix3C {
public double get22();
public float[] toFloatArray();
public float[] toFloatArray12();
public DMatrix3 clone();
/**
* Please use @see #copy() instead. This is deprecated because we don't implement Cloneable.
* @return A clone() of this object.
*/
@Deprecated // TODO deprecated. Should be removed. Plese use copy() instead. To be removed in 0.6.0.
DMatrix3 clone();
/**
* @return A mutable copy of this object.
*/
DMatrix3 copy();
public DVector3ColView viewCol(int _col);
public double dotCol(int col, DVector3C b);
public double dotRow(int row, DVector3C b);
Expand Down
Loading

0 comments on commit 4c8bc7a

Please sign in to comment.