Skip to content

Commit

Permalink
Fixed issue #17
Browse files Browse the repository at this point in the history
  • Loading branch information
tzaeschke committed Oct 28, 2014
1 parent 777fdac commit 9445d77
Show file tree
Hide file tree
Showing 19 changed files with 120 additions and 93 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@

0.3.1
=====
- Fixed issue #17
- Fixed NPE in DemoBoxStack-'x'
- Added newArray(size) methods to DVector3 and DMatrix3


0.3.0
=====
Migration to 0.13.1
Expand Down
13 changes: 13 additions & 0 deletions core/src/main/java/org/ode4j/math/DMatrix3.java
Original file line number Diff line number Diff line change
Expand Up @@ -967,4 +967,17 @@ public void getColumn1(DVector3 result) {
public void getColumn2(DVector3 result) {
result.set(get02(), get12(), get22());
}

/**
* Create an array of DVector instances.
* @param size
* @return AN array of DVector
*/
public final static DMatrix3[] newArray(int size) {
DMatrix3[] a = new DMatrix3[size];
for (int i = 0; i < size; i++) {
a[i] = new DMatrix3();
}
return a;
}
}
13 changes: 13 additions & 0 deletions core/src/main/java/org/ode4j/math/DVector3.java
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,19 @@ public final void eqProd(DMatrix3C m, DVector3C v2) {
set1( m.get10()*v2.get0()+ m.get11()*v2.get1()+ m.get12()*v2.get2() );
set2( m.get20()*v2.get0()+ m.get21()*v2.get1()+ m.get22()*v2.get2() );
}

/**
* Create an array of DVector instances.
* @param size
* @return AN array of DVector
*/
public final static DVector3[] newArray(int size) {
DVector3[] a = new DVector3[size];
for (int i = 0; i < size; i++) {
a[i] = new DVector3();
}
return a;
}
}


44 changes: 21 additions & 23 deletions core/src/main/java/org/ode4j/ode/internal/CollideCylinderBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,10 @@ private void _cldInitCylinderBox()

// temp index
int i = 0;
DVector3[] vTempBoxVertices = new DVector3[8];
DVector3[] vTempBoxVertices = DVector3.newArray(8);
// transform vertices in absolute space
for(i=0; i < 8; i++)
{
vTempBoxVertices[i] = new DVector3();
dMultiplyMat3Vec3(m_mBoxRot,m_avBoxVertices[i], vTempBoxVertices[i]);
dVector3Add(vTempBoxVertices[i], m_vBoxPos, m_avBoxVertices[i]);
}
Expand Down Expand Up @@ -898,24 +897,23 @@ private void _cldClipBoxToCylinder()
}

// find the vertices of box polygon
DVector3[] avPoints = new DVector3[4];
DVector3[] avTempArray1 = new DVector3[MAX_CYLBOX_CLIP_POINTS];
DVector3[] avTempArray2 = new DVector3[MAX_CYLBOX_CLIP_POINTS];
for (int ii = 0; ii < avPoints.length; ii++) avPoints[ii] = new DVector3();

int i=0;
for(i=0; i<MAX_CYLBOX_CLIP_POINTS; i++)
{
// avTempArray1[i][0] = (0.0);
// avTempArray1[i][1] = (0.0);
// avTempArray1[i][2] = (0.0);
avTempArray1[i] = new DVector3();

// avTempArray2[i][0] = (0.0);
// avTempArray2[i][1] = (0.0);
// avTempArray2[i][2] = (0.0);
avTempArray2[i] = new DVector3();
}
DVector3[] avPoints = DVector3.newArray(4);
DVector3[] avTempArray1 = DVector3.newArray(MAX_CYLBOX_CLIP_POINTS);
DVector3[] avTempArray2 = DVector3.newArray(MAX_CYLBOX_CLIP_POINTS);

// int i=0;
// for(i=0; i<MAX_CYLBOX_CLIP_POINTS; i++)
// {
//// avTempArray1[i][0] = (0.0);
//// avTempArray1[i][1] = (0.0);
//// avTempArray1[i][2] = (0.0);
// avTempArray1[i] = new DVector3();
//
//// avTempArray2[i][0] = (0.0);
//// avTempArray2[i][1] = (0.0);
//// avTempArray2[i][2] = (0.0);
// avTempArray2[i] = new DVector3();
// }

DVector3 vAxis1 = new DVector3(), vAxis2 = new DVector3();

Expand Down Expand Up @@ -950,7 +948,7 @@ private void _cldClipBoxToCylinder()
DMatrix3 mCylinderInv = new DMatrix3();
dMatrix3Inv(m_mCylinderRot,mCylinderInv);

for(i=0; i<4; i++)
for(int i=0; i<4; i++)
{
dVector3Subtract(avPoints[i],vCylinderCirclePos,vTemp);
dMultiplyMat3Vec3(mCylinderInv,vTemp,avPoints[i]);
Expand Down Expand Up @@ -991,7 +989,7 @@ private void _cldClipBoxToCylinder()

if (nCircleSegment % 2 != 0)
{
for( i=0; i<iTmpCounter2; i++)
for(int i=0; i<iTmpCounter2; i++)
{
dMultiply0_331(vPoint,m_mCylinderRot,avTempArray2[i]);
// vPoint[0] += vCylinderCirclePos[0];
Expand Down Expand Up @@ -1027,7 +1025,7 @@ private void _cldClipBoxToCylinder()
}
else
{
for( i=0; i<iTmpCounter1; i++)
for(int i=0; i<iTmpCounter1; i++)
{
dMultiply0_331(vPoint,m_mCylinderRot,avTempArray1[i]);
// vPoint[0] += vCylinderCirclePos[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -796,15 +796,11 @@ void _cldClipCylinderToTriangle(
{
int i = 0;
DVector3[] avPoints = { new DVector3(), new DVector3(), new DVector3() };//[3];
DVector3[] avTempArray1 = new DVector3[nMAX_CYLINDER_TRIANGLE_CLIP_POINTS];
DVector3[] avTempArray2 = new DVector3[nMAX_CYLINDER_TRIANGLE_CLIP_POINTS];
DVector3[] avTempArray1 = DVector3.newArray(nMAX_CYLINDER_TRIANGLE_CLIP_POINTS);
DVector3[] avTempArray2 = DVector3.newArray(nMAX_CYLINDER_TRIANGLE_CLIP_POINTS);

// dSetZero(avTempArray1[0][0],nMAX_CYLINDER_TRIANGLE_CLIP_POINTS * 4);
// dSetZero(avTempArray2[0][0],nMAX_CYLINDER_TRIANGLE_CLIP_POINTS * 4);
for (int ii = 0; ii < nMAX_CYLINDER_TRIANGLE_CLIP_POINTS; ii++) {
avTempArray1[ii] = new DVector3();
avTempArray2[ii] = new DVector3();
}

// setup array of triangle vertices
dVector3Copy(v0,avPoints[0]);
Expand Down
52 changes: 26 additions & 26 deletions core/src/main/java/org/ode4j/ode/internal/CollideTrimeshBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -973,25 +973,25 @@ void _cldClipping(final DVector3C v0, final DVector3C v1, final DVector3C v2, fi
avPoints[3].eqSum( vRotCol, tz1, vRotCol2, tz2).add (vCenter);

// clip Box face with 4 planes of triangle (1 face plane, 3 egde planes)
DVector3[] avTempArray1 = new DVector3[9];
DVector3[] avTempArray2 = new DVector3[9];
DVector3[] avTempArray1 = DVector3.newArray(9);
DVector3[] avTempArray2 = DVector3.newArray(9);
DVector4 plPlane = new DVector4();

RefInt iTempCnt1 = new RefInt(0);
RefInt iTempCnt2 = new RefInt(0);

// zeroify vectors - necessary?
for(int i=0; i<9; i++) {
// avTempArray1[i][0]=0;
// avTempArray1[i][1]=0;
// avTempArray1[i][2]=0;
avTempArray1[i] = new DVector3();

// avTempArray2[i][0]=0;
// avTempArray2[i][1]=0;
// avTempArray2[i][2]=0;
avTempArray2[i] = new DVector3();
}
// for(int i=0; i<9; i++) {
// // avTempArray1[i][0]=0;
// // avTempArray1[i][1]=0;
// // avTempArray1[i][2]=0;
// avTempArray1[i] = new DVector3();
//
// // avTempArray2[i][0]=0;
// // avTempArray2[i][1]=0;
// // avTempArray2[i][2]=0;
// avTempArray2[i] = new DVector3();
// }


// Normal plane
Expand Down Expand Up @@ -1102,23 +1102,23 @@ void _cldClipping(final DVector3C v0, final DVector3C v1, final DVector3C v2, fi

// CLIP Polygons
// define temp data for clipping
DVector3[] avTempArray1 = new DVector3[9];
DVector3[] avTempArray2 = new DVector3[9];
DVector3[] avTempArray1 = DVector3.newArray(9);
DVector3[] avTempArray2 = DVector3.newArray(9);

RefInt iTempCnt1 = new RefInt(), iTempCnt2 = new RefInt();

// zeroify vectors - necessary?
for(int i=0; i<9; i++) {
// avTempArray1[i][0]=0;
// avTempArray1[i][1]=0;
// avTempArray1[i][2]=0;
avTempArray1[i] = new DVector3();

// avTempArray2[i][0]=0;
// avTempArray2[i][1]=0;
// avTempArray2[i][2]=0;
avTempArray2[i] = new DVector3();
}
// for(int i=0; i<9; i++) {
// // avTempArray1[i][0]=0;
// // avTempArray1[i][1]=0;
// // avTempArray1[i][2]=0;
// avTempArray1[i] = new DVector3();
//
// // avTempArray2[i][0]=0;
// // avTempArray2[i][1]=0;
// // avTempArray2[i][2]=0;
// avTempArray2[i] = new DVector3();
// }

// clip triangle with 5 box planes (1 face plane, 4 edge planes)

Expand Down
8 changes: 2 additions & 6 deletions core/src/main/java/org/ode4j/ode/internal/DxBody.java
Original file line number Diff line number Diff line change
Expand Up @@ -818,12 +818,8 @@ void dBodySetAutoDisableAverageSamplesCount (int average_samples_count)
}
if(adis.average_samples > 0)
{
average_lvel_buffer = new DVector3[adis.average_samples];
for (int i = 0; i < average_lvel_buffer.length; i++)
average_lvel_buffer[i] = new DVector3();
average_avel_buffer = new DVector3[adis.average_samples];
for (int i = 0; i < average_avel_buffer.length; i++)
average_avel_buffer[i] = new DVector3();
average_lvel_buffer = DVector3.newArray(adis.average_samples);
average_avel_buffer = DVector3.newArray(adis.average_samples);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ AMotorMode dJointGetAMotorMode()

void dJointAddAMotorTorques( double torque1, double torque2, double torque3 )
{
DVector3[] axes = new DVector3[3];
DVector3[] axes = new DVector3[]{new DVector3(), new DVector3(), new DVector3()};

if ( _num == 0 )
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,7 @@ void getSureMaxInfo( SureMaxInfo info )
getInfo2( double worldFPS, double worldERP, DxJoint.Info2Descr info )
{
int row = 0;
DVector3[] ax = new DVector3[3];
for (int i = 0; i<3; i++ ) {
ax[i] = new DVector3();
}
DVector3[] ax = new DVector3[]{new DVector3(), new DVector3(), new DVector3()};

computeGlobalAxes( ax );

Expand Down
5 changes: 2 additions & 3 deletions demo/src/main/java/org/ode4j/demo/DemoBoxstack.java
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,8 @@ public void command (char cmd)
DMass m2 = OdeHelper.createMass();
m.setZero();

DVector3[] dpos = new DVector3[GPB]; // delta-positions for encapsulated geometries
DMatrix3[] drot = new DMatrix3[GPB];
DVector3[] dpos = DVector3.newArray(GPB); // delta-positions for encapsulated geometries
DMatrix3[] drot = DMatrix3.newArray(GPB);

// set random delta positions
for (j=0; j<GPB; j++) {
Expand All @@ -369,7 +369,6 @@ public void command (char cmd)
m2.setCapsule(DENSITY,3,radius,length);
}

drot[k] = new DMatrix3();
dRFromAxisAndAngle (drot[k],dRandReal()*2.0-1.0,dRandReal()*2.0-1.0,
dRandReal()*2.0-1.0,dRandReal()*10.0-5.0);
m2.rotate(drot[k]);
Expand Down
3 changes: 1 addition & 2 deletions demo/src/main/java/org/ode4j/demo/DemoCollision.java
Original file line number Diff line number Diff line change
Expand Up @@ -1193,8 +1193,7 @@ private static boolean testBoxesTouch2 (final DVector3 p1, final DMatrix3 R1,
if (fd==0) { k1 = 1; k2 = 2; }
if (fd==1) { k1 = 0; k2 = 2; }
if (fd==2) { k1 = 0; k2 = 1; }
DVector3 fp[]=new DVector3[4],tmp=new DVector3();
for (int z=0; z < fp.length; z++) fp[z] = new DVector3();
DVector3 fp[] = DVector3.newArray(4), tmp=new DVector3();
k=0;
for (j1=-1; j1<=1; j1+=2) {
for (j2=-1; j2<=1; j2+=2) {
Expand Down
6 changes: 2 additions & 4 deletions demo/src/main/java/org/ode4j/demo/DemoHeightfield.java
Original file line number Diff line number Diff line change
Expand Up @@ -370,14 +370,12 @@ public void command (char cmd) {
DMass m2 = OdeHelper.createMass();
m.setZero ();

DVector3[] dpos = new DVector3[GPB]; // delta-positions for encapsulated geometries
DMatrix3[] drot = new DMatrix3[GPB];
DVector3[] dpos = DVector3.newArray(GPB); // delta-positions for encapsulated geometries
DMatrix3[] drot = DMatrix3.newArray(GPB);

// set random delta positions
for (j=0; j<GPB; j++) {
dpos[j] = new DVector3();
for (k=0; k<3; k++) dpos[j].set(k, dRandReal()*0.3-0.15);
drot[j] = new DMatrix3();
}

for (k=0; k<GPB; k++) {
Expand Down
3 changes: 1 addition & 2 deletions demo/src/main/java/org/ode4j/demo/DemoI.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,14 @@ private static void reset_test()
int i;
DMass m = OdeHelper.createMass(), anchor_m=OdeHelper.createMass();
//float q[NUM][3], pm[NUM]; // particle positions and masses
DVector3[] q = new DVector3[NUM];
DVector3[] q = DVector3.newArray(NUM);
DVectorN pm = new DVectorN(NUM);
DVector3 pos1 = new DVector3(1,0,1); // point of reference (POR)
DVector3 pos2 = new DVector3(-1,0,1); // point of reference (POR)

// make random particle positions (relative to POR) and masses
for (i=0; i<NUM; i++) {
pm.set(i, dRandReal()+0.1);
q[i] = new DVector3();
q[i].set0(dRandReal()-0.5);
q[i].set1(dRandReal()-0.5);
q[i].set2(dRandReal()-0.5);
Expand Down
6 changes: 2 additions & 4 deletions demo/src/main/java/org/ode4j/demo/DemoMovingTrimesh.java
Original file line number Diff line number Diff line change
Expand Up @@ -255,14 +255,12 @@ else if (cmd == 'x') {
DMass m2 = OdeHelper.createMass();
m.setZero ();

DVector3[] dpos = new DVector3[GPB];//[3]; // delta-positions for encapsulated geometries
DMatrix3[] drot = new DMatrix3[GPB];
DVector3[] dpos = DVector3.newArray(GPB);//[3]; // delta-positions for encapsulated geometries
DMatrix3[] drot = DMatrix3.newArray(GPB);

// set random delta positions
for (j=0; j<GPB; j++) {
dpos[j] = new DVector3();
for (k=0; k<3; k++) dpos[j].set(k, dRandReal()*0.3-0.15 );
drot[j] = new DMatrix3();
}

for (k=0; k<GPB; k++) {
Expand Down
3 changes: 1 addition & 2 deletions demo/src/main/java/org/ode4j/demo/DemoOde.java
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,7 @@ private void testMassFunctions()
int i,j;
// double q[NUMP][3]; // particle positions
//double[][] q = new double[NUMP][3]; // particle positions
DVector3[] q = new DVector3[NUMP]; // particle positions
DVector3[] q = DVector3.newArray(NUMP); // particle positions
// double pm[NUMP]; // particle masses
double[] pm = new double[NUMP]; // particle masses
DMass m1 = new DxMass(),m2 = new DxMass();
Expand Down Expand Up @@ -887,7 +887,6 @@ private void testMassFunctions()
// translate and repeat.
for (i=0; i<NUMP; i++) {
pm[i] = dRandReal()+0.5;
q[i] = new DVector3();
for (j=0; j<3; j++) {
q[i].set(j, 2.0*(dRandReal()-0.5) );
}
Expand Down
8 changes: 3 additions & 5 deletions demo/src/main/java/org/ode4j/demo/DemoSpaceStress.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
public class DemoSpaceStress extends dsFunctions {
// some constants

private static final int NUM = 10000; // max number of objects
private static final int NUM = 2000; // max number of objects
private static final float DENSITY = 5.0f; // density of all objects
private static final int GPB = 3; // maximum number of geometries per body
private static final int MAX_CONTACTS = 4; // maximum number of contact points per body
Expand Down Expand Up @@ -246,16 +246,14 @@ public void command (char cmd) {
DMass m2 = OdeHelper.createMass();
m.setZero ();

DVector3[] dpos = new DVector3[GPB]; // delta-positions for encapsulated geometries
DMatrix3[] drot = new DMatrix3[GPB];
DVector3[] dpos = DVector3.newArray(GPB); // delta-positions for encapsulated geometries
DMatrix3[] drot = DMatrix3.newArray(GPB);

// set random delta positions
for (j=0; j<GPB; j++) {
dpos[j] = new DVector3();
for (k=0; k<3; k++) {
dpos[j].set(k, dRandReal()*0.3-0.15 );
}
drot[j] = new DMatrix3();
}

for (k=0; k<GPB; k++) {
Expand Down

0 comments on commit 9445d77

Please sign in to comment.