Sign in to follow this  
JamesCobras

NVidia moving a convex actor.

Recommended Posts

Hi guys, got a problem with NVidia physx. I'm trying to move a convex object.
void render_frame(void)
{
    d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
    d3ddev->Clear(0, NULL, D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);

	
		
					if (KEY_DOWN(VK_UP))
					{
					gCharacterSpeed += 1;
					move = 1;
					
					}

					if (KEY_DOWN(VK_DOWN))
					{
					gCharacterSpeed += -2;
					move = 1;
					}
					
					if (KEY_DOWN(VK_LEFT))
					{
					YRotate = YRotate - 5; 
					}
					if (KEY_DOWN(VK_RIGHT))
					{
					YRotate = YRotate + 5;
					}
					if (!KEY_DOWN(VK_UP) && !KEY_DOWN(VK_DOWN))
					{
					move = 1;
					}

					if (gCharacterSpeed < 0.5)
					{
						gCharacterSpeed = 0;
						transport.Animationloop(0.0,0.145,0);
					}
					else
					{
						transport.Animationloop(0.5,0.75,0);
					}


	
	gCharacterVec = NxVec3(move*(sin (D3DXToRadian(YRotate))),0,move*(cos (D3DXToRadian(YRotate)))); bPushCharacter = true;
	PhysXtransport->addForce(gCharacterVec);
	PhysXtransport->setGlobalPose
	if (gScene)
	{

		GetPhysicsResults();
		StartPhysics();
	}

    d3ddev->BeginScene();

    // SET UP THE TRANSFORMS

	static float index = 0.0f; 
	index+= 3.0;    // an ever-increasing float value
	
	//D3DXMATRIX matCube;
	//cube->getGlobalPose().getColumnMajor44(matCube);
	//box.Transform(matCube);
	//box.Draw();

	D3DXMATRIX matModel;
	
	
	//chara = gSelectedController->GetCharacterActor();
	
	PhysXtransport->getGlobalPose().getColumnMajor44(matModel);
	transport.Transform(Rotate(0,YRotate,0)*matModel);
	
	//plane.Transform(Rotate(MRotation,LRotation,Roll)*TransSINCOS (MMove, LRotation, 0, LRotation)*plane.ModelMatrix());
	
	transport.Draw();/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	
	D3DXMATRIX matModell;
	gTerrain->getGlobalPose().getColumnMajor44(matModell);
	room.Transform(matModell);
   	room.Draw();
	
	D3DXMATRIX matView;
	
	D3DXMATRIX tempmatView;
	D3DXMATRIX tempView;
	    // the view transform matrix
	tempmatView = transport.ModelMatrix();
	tempView = Translate(0,200,0)*Rotate(0,90,0)*Translate(-500,50,0)*tempmatView;
	D3DXMatrixInverse(&matView,NULL,&tempView);

    
	/*
    D3DXMatrixLookAtLH(&matView,
    &D3DXVECTOR3 (50.0f, 600.0f, -600.0f),    // the camera position
    &D3DXVECTOR3 (0.0f, 0.0f, 300.0f),    // the look-at position
    &D3DXVECTOR3 (0.0f, 1.0f, 0.0f));    // the up direction
	*/
    d3ddev->SetTransform(D3DTS_VIEW, &matView);    // set the view transform to matView 

    D3DXMATRIX matProjection;    // the projection transform matrix
    D3DXMatrixPerspectiveFovLH(&matProjection,
                               D3DXToRadian(45),    // the horizontal field of view
                               (FLOAT)SCREEN_WIDTH / (FLOAT)SCREEN_HEIGHT,    // aspect ratio
                               1.0f,    // the near view-plane
                                              20000.0f);    // the far view-plane
    d3ddev->SetTransform(D3DTS_PROJECTION, &matProjection);    // set the projection
//float MRotation;
//float MMove;
    
    d3ddev->EndScene(); 

    d3ddev->Present(NULL, NULL, NULL, NULL);

    return;
}


Now for some reason PhysXtransport->addForce(gCharacterVec); Doesn't add the force and move the physX object. The PhysX objects all work and gravity is applied correctly to all objects. Any help/comments welcome. Jamescobras

Share this post


Link to post
Share on other sites
Just in case it's important, here the initiation of PhysX


void InitNx()
{


// Create a memory allocator
if (!gAllocator)
{
gAllocator = new UserAllocator;
assert(gAllocator);
}

// Create the physics SDK
gPhysicsSDK = NxCreatePhysicsSDK(NX_PHYSICS_SDK_VERSION, gAllocator);
if (gPhysicsSDK)
{
// connect to PVD, then you can see the physics objects inside PVD (you should start PVD before your application)
gPhysicsSDK->getFoundationSDK().getRemoteDebugger()->connect("localhost", 5425);
}

if(!gPhysicsSDK)
{
MessageBox(NULL, L"PhysX Could Not be Initalised. This could be due to it not being installed", L"PhysX Error", MB_OK);
ShellExecute(NULL, L"open", L"http://www.nvidia.com/object/physx_system_software.html",NULL, NULL, SW_SHOWNORMAL);

}

// Set the physics parameters
gPhysicsSDK->setParameter(NX_SKIN_WIDTH, 0.01);



NxSceneDesc sceneDesc;
sceneDesc.gravity = gDefaultGravity;
sceneDesc.simType = NX_SIMULATION_SW;

gScene = gPhysicsSDK->createScene(sceneDesc);



// Create the default material
NxMaterial* defaultMaterial = gScene->getMaterialFromIndex(0);
defaultMaterial->setRestitution(0.5);
defaultMaterial->setStaticFriction(0.5);
defaultMaterial->setDynamicFriction(0.5);



// Create the objects in the scene///////////////////////^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^£££££££££££££££££££££££££££££££//////////////////////////////////////////////////////////////////////////////////////

gTerrain = GenerateTriangleMesh(room.MMesh(), "room.bin");


PhysXtransport = GenerateConvexMesh(NxVec3(0,250,0),transportmesh.MMesh(),"transportmesh.bin",10.0,5.0);






// Get the current time
deltatime = UpdateTime();

// Start the first frame of the simulation
if (gScene) StartPhysics();
}




Thanks

JamesCobras

Share this post


Link to post
Share on other sites
Update!

I can get the objects to move now, but only with forces in excess of 10000000 units.

i.e.:

cube ->addForce(NxVec3(0,0,10000000));



I thought straight away that it must have something to do with timing, but gravity works fine!

Not sure where to check next, please help.

JamesCobras

Share this post


Link to post
Share on other sites
Update:

I have quite large models, this could mean that the scales are all out.
In the demos, the scales are about 0.5 (m) and i'm about 300 (m).

This could make the difference right?

Anyone have any ideas at all??

JamesCobras

Share this post


Link to post
Share on other sites
Yeah that made a difference, changed density from 10 to 0.000001.
Silly question but does this mean the weight is based on size(volume)*density in PhysX?

Therefore
1. More force needed to overcome friction.
and
2. More force needed to get it going and then to stop it.

Is this right?

JamesCobras

[Edited by - JamesCobras on May 31, 2009 2:44:57 PM]

Share this post


Link to post
Share on other sites
I guess that makes sense, the denser an object the more mass it will have. I should let someone who has more physics knowledge then me chime in but basically it boils down to F = ma, which means acceleration is relational to the mass of an object, a = F/m. So this means that in order to get any acceleration out of a heavy object you need a lot of force. Same thing goes for stopping it once it has acceleration.

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