PhysX Candywrapper and MOgre

Jo0oker

11-11-2010 20:10:18

[]Hello,

i am on trying to convert the following Code into C#/Mogre/Eyecm Wrapper:


NxHeightFieldDesc heightFieldDesc;
heightFieldDesc.nbColumns = desc.nbColumns;//65 in my case
heightFieldDesc.nbRows = desc.nbRows;//65 in my case
heightFieldDesc.convexEdgeThreshold = 0;
heightFieldDesc.thickness=0;

// allocate storage for samples
heightFieldDesc.samples = new NxU32[desc.nbColumns*desc.nbRows];
heightFieldDesc.sampleStride = sizeof(NxU32);
NxU8* currentByte = (NxU8*)heightFieldDesc.samples;

for (NxU32 row=0;row<desc.nbRows; row++)
{
for (NxU32 col = 0; col < desc.nbColumns; col++)
{
NxHeightFieldSample* currentSample = (NxHeightFieldSample*)currentByte;
currentSample->height =(NxI16)*pTerrain->getHeightData(row,desc.nbColumns-1-col); //I have to reverse the colomn to make the physx and graph match
currentByte += heightFieldDesc.sampleStride;
}
}
NxHeightField* heightField = GetPhysicsSDK()->createHeightField(heightFieldDesc);
// data has been copied, we can free our buffer
delete [] heightFieldDesc.samples;

NxHeightFieldShapeDesc heightFieldShapeDesc;
heightFieldShapeDesc.heightField = heightField;
heightFieldShapeDesc.shapeFlags = NX_SF_FEATURE_INDICES ;
heightFieldShapeDesc.heightScale = 1;
heightFieldShapeDesc.rowScale = desc.size.z / NxReal(desc.nbRows-1);//in my case,desc.size is the terrainworldsize 400*400
heightFieldShapeDesc.columnScale = desc.size.x / NxReal(desc.nbColumns-1);//in my case,desc.size is the terrainworldsize 400*400
heightFieldShapeDesc.materialIndexHighBits = 0;

assert(heightFieldShapeDesc.isValid());
actorDesc.shapes.pushBack(&heightFieldShapeDesc);
actorDesc.body = NULL;
actorDesc.globalPose.t.setx(desc.pos.x);
actorDesc.globalPose.t.setz(desc.pos.z);
actorDesc.globalPose.t.sety(desc.pos.y);

assert(actorDesc.isValid());
pscene->createActor(actorDesc);





Can some one help me?

My First try failed:

HeightFieldDesc myHeightFieldDesc = new HeightFieldDesc();
UInt32 myCols, myRows;

myCols = myRows = Size;

Vector3 myScale = new Vector3(1, 1, 1);
myHeightFieldDesc.ColumnCount = myCols;
myHeightFieldDesc.RowCount = myRows;

myHeightFieldDesc.ConvexEdgeThreshold = 0;
myHeightFieldDesc.MakePinnedSampleArray2D(myCols, myRows);
myHeightFieldDesc.SamplesByteStride = sizeof(UInt32);

IntPtr currentByte = myHeightFieldDesc.SamplesPtr;


It would be very nice, if some one can help me!

lg,
Jo0oker

issingle

12-11-2010 13:06:12

in c#,pin some means pin the object's address ,and gc'll not move it,then you can access it using pointer.
in this case,after call HeightFieldSample[,] sampledata=myHeightFieldDesc.MakePinnedSampleArray2D(myCols, myRows);
u can fill data into sampledata through for statement.

for(int i=0;i<myCols;i++){
for(int j=0;j<myRows;j++){
sampleData[i,j].Height=terrian.GetHeightData(...)
}
}

after fill data,then unpinall()