Physx and GUI

hello,
I am a physx newbie and so far I have managed to setup the SDK properly and assign basic physics properties to my objects, nothing fancy just spheres, boxes and capsules. So far so good.

I have also successfully created triangle mesh actors (I can see them in the Visual debugger).

However I have an issue and I have a bit of a hard time in solving it.

I have re-created the classic “camera cube tool” (as seen i.e. in 3DStudioMax) and my intent with it is to control the camera of my editor.

For that purpose I am rendering a 3D object in 2D space (orthogonal rendering) on the top right corner of my screen. The rendering is okay but I can’t figure out how to associate my physics object (triangle mesh) to the correct location.

The reason why I want to associate my camera cube tool with a series of physX actors is that I’d like to be able to let physics raycasts do the picking for me (i.e. click on top left corner triangle mesh or click on front face of cube etc).

I can see the triangle meshes of my camera cube tool in the visual debugger but they are on the complete opposite side of my camera (which for debug purposes i associae a sphere so I can see the camera in the Visual Debugger tool as well).

Maybe I am thinking of all this in a wrong way but I believe the problem is that the position that physX attributes to my Camera cube tool actor is somehow taking the wrong transform so I need to somehow bring it back into world space (the position of my camera cube tool is obviously in screen space and uses a 2D view matrix as well as an orthogonal projection to be rendered).

I would gladly post some code if someone is interested in more detail what I am trying to do.

hello,

I am still stuck on this and so I decided to give some more info.

here a screenshot from what I see on screen (the correctly rendered camera cube tool)
(when I turn off physx associated with my meshes)

External Media

and here what I see in the physx visual debugger

(note the red bubble is where the camera is located)

I have tried different things to try and project my 3D meshes into world space so that physx can “see” them.

here some code that I have tried.

const cMesh* pMesh = pModel->GetMesh(i);
		
		PxTriangleMeshDesc meshDesc;
		meshDesc.points.count	= pMesh->GetVertexCount();
		meshDesc.triangles.count	= pMesh->GetIndexCount() / 3;
		meshDesc.points.stride	= 4*3;
		meshDesc.triangles.stride	= 4*3;
		meshDesc.points.data	= pMesh->GetPureVertices();
		meshDesc.triangles.data	= pMesh->GetIndices();

		cPxMemoryOutputStream writeBuffer;
		bool ok = pPxCooker->cookTriangleMesh(meshDesc, writeBuffer);

		if(ok)
		{
			cPxMemoryInputData readBuffer(writeBuffer.getData(), writeBuffer.getSize());
			PxTriangleMesh* triangleMesh = pPxPhysics->createTriangleMesh(readBuffer);
			if(triangleMesh)
			{
				D3DXVECTOR3 meshPos = pStaticObject->GetPosition();

				D3DXMATRIX pm = GetProjectionMatrix();
				D3DXMATRIX vm = GetViewMatrix(false); //false = not 2D viewMat
				D3DXMATRIX wm = GetWorldMatrix();
				D3D10_VIEWPORT* vp = reinterpret_cast<D3D10_VIEWPORT*>(&pAWRender->GetViewPort());
				
				D3DXVECTOR3 worldMeshPos;
				D3DXVec3Unproject(&worldMeshPos, &D3DXVECTOR3(meshPos.x, meshPos.y, -100.0f), vp, &pm, &vm, &wm);

				//worldMeshPos += pAWRender->GetCamera()->GetViewDirection() * 10.0f;

			PxMeshScale scale(PxVec3(1.0f / scale.x, 1.0f / scale.y, 1.0f / scale.z), PxQuat::createIdentity());
  				PxTriangleMeshGeometry triGeom(triangleMesh,scale);

				D3DXVECTOR3 meshPosition = worldMeshPos;
				PxTransform transform;
 				transform.p = PxVec3(meshPosition.x, meshPosition.y, meshPosition.z);
                                    //I know here I am loosing my object orientation but I will worry about that when I have solved the correct position of my object in world space
 				transform.q = PxQuat::createIdentity();

				PxRigidStatic* pPxRigidStatic = pPxPhysics->createRigidStatic(transform);
                                    //here the pPxRigidStatic can be NULL sometimes, it would be nice to have an error message instead :(
				if(pPxRigidStatic)
				{
					PxShape* shape = pPxRigidStatic->createShape(triGeom, *pPxDefaultMaterial);
					mpPxScene->addActor(*pPxRigidStatic);
					pStaticObject->AddPhysicsObject(pPxRigidStatic);
				}

If anyone could tell me where I am going wrong I would be immensly grateful.