|
发表于 2008-5-5 03:11:00
|
显示全部楼层
Re: Re:谁在 OGRE 中使用过 PhysX 给点帮助
njw1985: Re:谁在 OGRE 中使用过 PhysX 给点帮助
有两个问题:一是怎么将OGRE里面的Mesh转化为PhysX中的数据模型;二是怎么设置Actor的body?楼主能讲讲吗?
我用AGEIA连DIRECTX直接用过,只要把Vertex,index buffer 传到trianglemesh shape description中,再设置一下参数,ageia 会cooking 出一个trianglemesh 在物理世界里面。
NXOGRE是个ageia简化接口,可能会有直接的createtrianlgemesh的函数,不用自己去写了,在ogre英文官方论坛里面找找吧。
这里是我convert我的地形为trianglemesh的代码:
NxActor * CPhysX::CreateTerrainMesh(const NxVec3& pos,const NxU32 length, const NxU32 width,IDirect3DVertexBuffer9* vb,IDirect3DIndexBuffer9* ib)//,const NxReal stride)
{
NxVec3* fsVerts = NULL;
WORD* fsFaces = NULL;
//Initialize flat surface verts
NxU32 nbVerts=length*width;
fsVerts = new NxVec3[nbVerts];
VertexPNUVT* vCol = 0;
vb->Lock(0,0,(void**)&vCol,0);
for(DWORD i=0;i<nbVerts;i++)
{
memcpy(&fsVerts, &vCol, sizeof(D3DXVECTOR3));
}
vb->Unlock();
NxU32 nbFaces = (length-1)*(width-1)*2;
fsFaces = new WORD[nbFaces*3];
WORD* pIB = NULL;
ib->Lock(0,0,(void**)&pIB,0);
memcpy(fsFaces, pIB, sizeof(WORD)*nbFaces*3);
ib->Unlock();
NxTriangleMeshDesc fsDesc;
fsDesc.numVertices = nbVerts;
fsDesc.numTriangles =nbFaces;
fsDesc.pointStrideBytes = sizeof(D3DXVECTOR3);
fsDesc.triangleStrideBytes = 3*sizeof(WORD);
fsDesc.points = fsVerts;
fsDesc.triangles = fsFaces;
fsDesc.flags =NX_MF_16_BIT_INDICES;
//because the triangle mesh is CW not CCW so must set this to ensure collision correct.
fsDesc.flags |=NX_MF_FLIPNORMALS;
NxTriangleMeshShapeDesc fsShapeDesc;
gCooking = NxGetCookingLib(NX_PHYSICS_SDK_VERSION);
bool ok = gCooking->NxInitCooking();
// Cooking from memory
MemoryWriteBuffer buf;
bool status = gCooking->NxCookTriangleMesh(fsDesc, buf);
fsShapeDesc.meshData = PhysicsSDK->createTriangleMesh(MemoryReadBuffer(buf.data));
if (fsShapeDesc.meshData)
{
NxActorDesc actorDesc;
actorDesc.shapes.pushBack(&fsShapeDesc);
actorDesc.globalPose.t = pos;
NxActor* actor = Scene->createActor(actorDesc);
//SetActorCollisionGroup(actor,3);
return actor;
// gPhysicsSDK->releaseTriangleMesh(*fsShapeDesc.meshData);
}
return NULL;
} |
|