Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


chezmark

Member Since 04 Dec 2011
Offline Last Active Feb 14 2012 09:36 AM

Posts I've Made

In Topic: OpenGL and PhysiX library simulation problem

11 December 2011 - 08:13 AM

Thanks FXACE. Best wishes... Posted Image

In Topic: OpenGL and PhysiX library simulation problem

09 December 2011 - 11:01 AM

No, it is not showing in the VRD. The result is that when i run the program it crashes although it builds successfully. Let me ask you one more thing. Let's assume that i draw a cube with opengl commands for instance glutSolidCube() how can i then tell to physx to apply force to that object.

Should i have to create

1) Actor Descriptor
2) Body Descriptor
3)Shape Descriptor
4) Set Shape Descriptor (localPose.t, density, globalPose.t ... etc).

for every shape i draw with opengl functions such as glutSolidSphere(), glutSolidCone() ... etc.


Thanks.

In Topic: OpenGL and PhysiX library simulation problem

07 December 2011 - 05:49 PM

Thanks a lot FXACE for your help. Well all i have done is take your code and put it into a nxactor* function like the following




NxActor* CreateEnvironmentBox()
{
	NxVec3 verts[8] = { NxVec3(-1,-1,-1), NxVec3(-1,-1,1), NxVec3(-1,1,-1), NxVec3(-1,1,1), 
						NxVec3(1,-1,-1), NxVec3(1,-1,1), NxVec3(1,1,-1), NxVec3(1,1,1) };   // with dimensions NxVec3(1,1,1)
																							//... rescale it as you wish.

	NxU32 vertCount = 8; 

	// Create descriptor for convex mesh 

	NxConvexMeshDesc convexDesc; 

	convexDesc.numVertices = vertCount; 

	convexDesc.pointStrideBytes = sizeof(NxVec3); 

	convexDesc.points = verts; 

	convexDesc.flags = NX_CF_COMPUTE_CONVEX; 

	/*
	Here you need to add NX_CF_FLIPNORMALS flag to convexDesc 
	(because normals show in which direction of contact force would be applied)
	*/

	convexDesc.flags |= NX_CF_FLIPNORMALS;

	// See SampleCommonCode\src\Stream.cpp for MemoryWriteBuffer and MemoryReadBuffer.

	MemoryWriteBuffer buf;

	static NxCookingInterface *gCooking = NxGetCookingLib(NX_PHYSICS_SDK_VERSION);

	gCooking->NxInitCooking(); //Build physical model

	
	bool status = gCooking->NxCookConvexMesh(convexDesc, buf); 

	NxConvexMesh *mesh = gPhysicsSDK->createConvexMesh(MemoryReadBuffer(buf.data)); 

	// Now create an instance of the mesh.  

	NxConvexShapeDesc convexShapeDesc;

	NxActorDesc actorDesc; 

	convexShapeDesc.meshData = mesh;   

	actorDesc.shapes.pushBack(&convexShapeDesc); 

	actorDesc.body = 0; // Make it static

	actorDesc.density = 0.0f;  

	NxActor *enviromentBox = gScene->createActor(actorDesc);  // Define 'enviromentBox' as global variable
															//.... + place it where you want it
	assert(enviromentBox);
	return enviromentBox;
}





bu when i call it in the InitNx() it doesn't seem to do anything. Am i doing anything wrong ???




void InitNx()
{
	// Initialize camera parameters
	gCameraAspectRatio	= 1.0f;
	gCameraPos			= NxVec3(0,5,-15);
	gCameraForward		= NxVec3(0,0,1);
	gCameraRight		= NxVec3(-1,0,0);
	
	// Create the physics SDK
    gPhysicsSDK = NxCreatePhysicsSDK(NX_PHYSICS_SDK_VERSION);
    if (!gPhysicsSDK)  return;
	else if(gPhysicsSDK != NULL)
		gPhysicsSDK->getFoundationSDK().getRemoteDebugger()->connect("localhost", 5425);

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

	// Set the debug visualization parameters
	gPhysicsSDK->setParameter(NX_VISUALIZATION_SCALE, 1);
	gPhysicsSDK->setParameter(NX_VISUALIZE_COLLISION_SHAPES, 1);
	gPhysicsSDK->setParameter(NX_VISUALIZE_ACTOR_AXES, 1);

    // Create the scene
    NxSceneDesc sceneDesc;
 	sceneDesc.simType				= NX_SIMULATION_SW;
    sceneDesc.gravity               = gDefaultGravity;
    gScene = gPhysicsSDK->createScene(sceneDesc);	
	if(!gScene)
	{ 
		sceneDesc.simType			= NX_SIMULATION_SW; 
		gScene = gPhysicsSDK->createScene(sceneDesc);  
		if(!gScene) return;
	}


	// 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
	groundPlane		= CreateGroundPlane();
	gSelectedActor	= CreateBox();
	CreateBox();
	CreateEnvironmentBox();


	// Initialize HUD
	InitializeHUD();

	// Get the current time
	UpdateTime();

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

PARTNERS