Sign in to follow this  
LExTER

PhysX cubes problem

Recommended Posts

Hi, I'm making a DirectX application with PhysX, and I have a problem.. Firstly, look at the screenshot: http://img381.imageshack.us/img381/7812/physx1fd2.jpg I use the following options: Gravity down (0,-100,0) NX_SKIN_WIDTH = 0.005 Material: Restitution = 0 StaticFriction = 0.5 DynamicFriction = 0.5 Plane (0,1,0), d=0 Now to the problem, as you can see in the screenshot, the top blue cube is staying and doesn't fall even there is nothing below it.. I render ALL of the actors using a loop, so I miss no actors.. And I really don't know what is the problem.. Here is some code: CODE START: //Init PhysX p=NxCreatePhysicsSDK(NX_PHYSICS_SDK_VERSION); p->setParameter(NX_SKIN_WIDTH, 0.005f); scened.gravity = NxVec3(0,-100,0); scene = p->createScene(scened); NxMaterial* defaultMaterial = scene->getMaterialFromIndex(0); defaultMaterial->setRestitution(0.0f); defaultMaterial->setStaticFriction(0.5f); defaultMaterial->setDynamicFriction(0.5f); NxPlaneShapeDesc planeDesc; NxActorDesc actorDesc; actorDesc.shapes.pushBack(&planeDesc); scene->createActor(actorDesc); //Adding cube function (happends when the user hits 'Space' at position 0,150,0) void AddCube(float x,float y,float z) { void* tmpVB; Mesh1->LockVertexBuffer(0,&tmpVB); D3DXVECTOR3 leftdown,rightup; if (FAILED(D3DXComputeBoundingBox((D3DXVECTOR3*)tmpVB,Mesh1->GetNumVertices(),Mesh1->GetNumBytesPerVertex(),&leftdown,&rightup))) { return; } float width,height,depth; width = abs(leftdown.x - rightup.x); height = abs(leftdown.y - rightup.y); depth = abs(leftdown.z - rightup.z); width/=2; height/=2; depth/=2; NxActor *cube; NxActorDesc cubedesc; NxBodyDesc cubebodydesc; NxBoxShapeDesc cubeshapedesc; cubeshapedesc.dimensions.set(width,height,depth); cubedesc.shapes.pushBack(&cubeshapedesc); cubedesc.body = &cubebodydesc; cubedesc.density = 1000; cubedesc.globalPose.t = NxVec3(x,y,z); cube = scene->createActor(cubedesc); cube->userData = Mesh1; } //Rendering the actors for (int i=1;i<scene->getNbActors();i++) //i=1 because I don't want to include the plane { ID3DXMesh* tmpMesh; NxActor* tmpActor = tmpActors[i]; float Mat[16]; tmpActor->getGlobalPose().getColumnMajor44(Mat); D3DXMATRIX TmpMat(Mat); VertexShader_CT->SetMatrix(d3dDevice,"WorldM",&TmpMat); //Setting world matrix to my Vertex Shader tmpMesh = (ID3DXMesh*)tmpActor->userData; if (i == 1) { d3dDevice->SetTexture(0,Tex1); } else { d3dDevice->SetTexture(0,Tex2); } tmpMesh->DrawSubset(0); } END OF CODE If you need more details please ask for them.. I'm really desperate, I've tried everything.. Thank you very much.. :)

Share this post


Link to post
Share on other sites
For some reason, if I use D3DXCreateBox to create the mesh I'm using - it works perfectly, but if I load my own cube model from .X file then the problems start.


Do you know why?

Thanks

Share this post


Link to post
Share on other sites
Quote:
Original post by jezham
Possibly your box is being created as a static actor somehow?

After NxBodyDesc cubebodydesc; try setting the mass there (rather than the density method): cubebodydesc.mass = 1000;


Thanks for answering..
I checked and the cubes are not static, they're all dynamic actors.
The 'mass' property didn't change anything, the cubes still behave strangly.

Thanks

Share this post


Link to post
Share on other sites
The collisions are 99% fine but sometimes the boxes get in each other,
And sometimes, there are some "invisible" cubes and the cubes are higher than other cubes without a reason (a cube below).

Thanks.

Share this post


Link to post
Share on other sites
The meshes were not placed correctly (the center of the cube was not the same as the mesh's).
I'll remodel the mesh again and center it correctly.

Thank you very much!!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this