[ODE] Terrain and Contribution

Bob Cober AzCoder at cox.net
Sat May 22 19:25:32 MST 2004


I just got the Terrain and Cone contribution from Benoit Chaperot 
working - and it works great....thanks Benoit.

In order to compile the Terrain and Cone test_boxstackb.cpp contribution 
in Linux with PRECISION=DOUBLE, I had to make some very minor additions 
to drawstuff.cpp and drawstuff.h.  The change is basically adding 
dsDrawTerrainZD and dsDrawTerrainYD that accept doubles instead of 
floats.  I also removed some #include "windows.h" that are not needed 
throughout the rest of the files.

My question is how to contribute these back?  Terrain and Cone is yet in 
the core cvs code, but rather in the contrib folder.

Here are the prototypes added to drawstuff.cpp:
void dsDrawTerrainYD(int x,int y,float vLength,float vNodeLength,int 
nNumNodesPerSide,double *pHeights,const double *pR,const double *ppos);
void dsDrawTerrainZD(int x,int y,float vLength,float vNodeLength,int 
nNumNodesPerSide,double *pHeights,const double *pR,const double *ppos);


Here are the new functions in  drawstuff.cpp:
void dsDrawTerrainYD(int x,int z,float vLength,float vNodeLength,int 
nNumNodesPerSide,double *pHeights,const double *pR,const double *ppos)
{
   double A[3],B[3],C[3],D[3];
   double R[12]={0};
   double pos[3]={0};
     if (pR)
       memcpy(R,pR,sizeof(R));
   else
   {
       memset(R,0,sizeof(R));
       R[0] = 1.f;
       R[5] = 1.f;
       R[10] = 1.f;
   }
     if (ppos)
       memcpy(pos,ppos,sizeof(pos));
   else
       memset(pos,0,sizeof(pos));

   double vx,vz;
   vx = vLength * x;
   vz = vLength * z;
     int i;
   for (i=0;i<nNumNodesPerSide;i++)
   {
       for (int j=0;j<nNumNodesPerSide;j++)
       {
           A[0] = i * vNodeLength + vx;
           A[2] = j * vNodeLength + vz;
           A[1] = GetHeightD(i,j,nNumNodesPerSide,pHeights);
           B[0] = (i+1) * vNodeLength + vx;
           B[2] = j * vNodeLength + vz;
           B[1] = GetHeightD(i+1,j,nNumNodesPerSide,pHeights);
           C[0] = i * vNodeLength + vx;
           C[2] = (j+1) * vNodeLength + vz;
           C[1] = GetHeightD(i,j+1,nNumNodesPerSide,pHeights);
           D[0] = (i+1) * vNodeLength + vx;
           D[2] = (j+1) * vNodeLength + vz;
           D[1] = GetHeightD(i+1,j+1,nNumNodesPerSide,pHeights);
           dsDrawTriangleD(pos,R,C,B,A,1);
           dsDrawTriangleD(pos,R,D,B,C,1);
       }
   }
}

void dsDrawTerrainZD(int x,int z,float vLength,float vNodeLength,int 
nNumNodesPerSide,double *pHeights,const double *pR,const double *ppos)
{
   double A[3],B[3],C[3],D[3];
   double R[12];
   double pos[3];
   if (pR)
       memcpy(R,pR,sizeof(R));
   else
   {
       memset(R,0,sizeof(R));
       R[0] = 1.f;
       R[5] = 1.f;
       R[10] = 1.f;
   }
     if (ppos)
       memcpy(pos,ppos,sizeof(pos));
   else
       memset(pos,0,sizeof(pos));
     double vx,vz;
   vx = vLength * x;
   vz = vLength * z;
     int i;
   for (i=0;i<nNumNodesPerSide;i++)
   {
       for (int j=0;j<nNumNodesPerSide;j++)
       {
           A[0] = i * vNodeLength + vx;
           A[1] = j * vNodeLength + vz;
           A[2] = GetHeightD(i,j,nNumNodesPerSide,pHeights);
           B[0] = (i+1) * vNodeLength + vx;
           B[1] = j * vNodeLength + vz;
           B[2] = GetHeightD(i+1,j,nNumNodesPerSide,pHeights);
           C[0] = i * vNodeLength + vx;
           C[1] = (j+1) * vNodeLength + vz;
           C[2] = GetHeightD(i,j+1,nNumNodesPerSide,pHeights);
           D[0] = (i+1) * vNodeLength + vx;
           D[1] = (j+1) * vNodeLength + vz;
           D[2] = GetHeightD(i+1,j+1,nNumNodesPerSide,pHeights);
           dsDrawTriangleD(pos,R,C,A,B,1);
           dsDrawTriangleD(pos,R,D,C,B,1);
       }
   }
}


and of course the changes to test_boxstackb.cpp:
// select correct drawing functions
#ifdef dDOUBLE
#define dsDrawBox dsDrawBoxD
#define dsDrawSphere dsDrawSphereD
#define dsDrawCylinder dsDrawCylinderD
#define dsDrawCappedCylinder dsDrawCappedCylinderD
#define dsDrawTerrainY dsDrawTerrainYD  //added
#define dsDrawTerrainZ dsDrawTerrainZD  //added
#endif


Hopefully this might help someone....




More information about the ODE mailing list