I just started with Nvidia Physx and the Fulcrum plug-in and I have a problem. When I start the demo the sphere's fall and have physics, but if I copy the code and copile the code the spheres don't fall. Can someone tell me why?
Here's the code:
#include "DarkGDK.h"
#include "FulcrumPhy.h"
void createWorld();
void createGround();
void createCharacter();
void createStairs();
void createBalls();
void createWall();
void createUprights();
void colourObjects();
void reset();
void moveCharacterControllerWithMouseAndKeys();
void displayData();
// Object numbers
int groundID = 1;
int characterID = 2;
int stairsFirstStepID = 3;
int numberOfSteps = 50; //3-52
int firstBallID = 53;
int numberOfBalls = 100; //53-152
int firstWallBlockID = 153;
int numberOfWallBlocks = 200; //154-352
int upright1ID = 353;
int upright2ID = 354;
int upright3ID = 355;
int upright4ID = 356;
int terrainID = 357;
FulcrumPhy myPhysics;
void DarkGDK ( void )
{
// PHYSICS
myPhysics.start(true);
myPhysics.setGravity(0, -15, 0);
createWorld();
dbSyncOn ( );
dbSyncRate ( 60 );
dbPositionCamera ( 0, 0, -10 );
dbMakeLight(1);
dbPositionLight(1, 0, 100, 100);
//TERRAIN
dbLoadImage ( "texture.jpg", 1 );
dbLoadImage ( "detail.jpg", 2 );
dbSetupTerrain ( );
dbMakeObjectTerrain ( terrainID );
dbSetTerrainHeightMap ( terrainID, "map.bmp" );
dbSetTerrainScale ( terrainID, 3.0f, 0.6f, 3.0f );
dbSetTerrainLight ( terrainID, 1.0f, -0.25f, 0.0f, 1.0f, 1.0f, 0.78f, 0.5f );
dbSetTerrainTexture ( terrainID, 1, 2 );
dbBuildTerrain ( terrainID );
dbPositionObject(terrainID, -200, -100, -200);
myPhysics.makeTriangleMesh(terrainID);
myPhysics.simulate();
while ( LoopGDK ( ) )
{
if(dbSpaceKey()) reset();
myPhysics.update();
moveCharacterControllerWithMouseAndKeys(); // Put after update(), more so if you are applying forces
displayData();
dbUpdateTerrain();
dbSync ( );
}
myPhysics.stop();
return;
}
void createWorld()
{
createGround();
createCharacter();
createStairs();
createBalls();
createWall();
createUprights();
colourObjects();
}
void createGround()
{
dbMakeObjectBox(groundID, 200, 0, 200);
myPhysics.makeBox(groundID, false, 0);
}
void createCharacter()
{
// This is where you would load in your character model, I will use a box
dbMakeObjectBox(characterID, 1, 3, 1);
// I will offset the box as if it had been loaded in with its base(not centre)
// at (0, 0, 0), this is what the character controller expects and how most models
// are positioned in their local space
dbOffsetLimb(characterID, 0, 0, 1.5, 0); // Half of height(3), 1.5
dbPositionObject(characterID, 90, 0.1, 0); // place just above ground
myPhysics.makeControllerBox(characterID, 1.0, 45.0,true);
}
void createStairs()
{
for(int i = stairsFirstStepID; i < stairsFirstStepID + numberOfSteps; i++)
{
dbMakeObjectBox(i, 50, 1, 20);
dbPositionObject(i, 0, i - stairsFirstStepID + 0.5, 30 + i);
myPhysics.makeBox(i, false, 0);
}
}
void createBalls()
{
for(int i = firstBallID; i < firstBallID + numberOfBalls; i++)
{
dbMakeObjectSphere(i, 4, 20, 20);
dbPositionObject(i, 35 - dbRnd(i - firstBallID + 40), 100 + dbRnd(200), 45 + dbRnd(10));
myPhysics.makeSphere(i, true, 10.0f);
myPhysics.applyForce(i, 0, 0, 15);
}
}
void createWall()
{
int x;
int y;
int blockCount = firstWallBlockID;
for(x = 0; x < 20; x++)
{
for(y = 0; y < 10; y++)
{
// 200 blocks, 20 * 10
dbMakeObjectBox(blockCount, 2, 2, 2);
dbPositionObject(blockCount, x * 2 - 20, y * 2 + 1, -30);
myPhysics.makeBox(blockCount, true, 1.0f);
blockCount++;
}
}
}
void createUprights()
{
// First two convex meshes are static, therefore
// desity value is not used, just set to zero.
// Convex meshes have a maximum of 256 polygons.
dbMakeObjectCylinder(upright1ID, 20);
dbPositionObject(upright1ID, 75, 10, 75);
myPhysics.makeConvexMesh(upright1ID, false, 0);
dbMakeObjectCylinder(upright2ID, 20);
dbPositionObject(upright2ID, -75, 10, 75);
myPhysics.makeConvexMesh(upright2ID, false, 0);
// Next two convex meshes are dynamic
// Convex meshes have a maximum of 256 polygons.
dbMakeObjectCylinder(upright3ID, 5);
dbPositionObject(upright3ID, -10, 2.5, 0);
myPhysics.makeConvexMesh(upright3ID, true, 1.0f);
dbMakeObjectCylinder(upright4ID, 5);
dbPositionObject(upright4ID, 10, 2.5, 0);
myPhysics.makeConvexMesh(upright4ID, true, 1.0f);
}
void colourObjects()
{
for(int i = groundID; i < upright4ID + 1; i++)
{
if(i != 2)
dbColorObject(i, dbRGB(dbRND(255), dbRND(255), dbRND(255)));
}
}
void reset()
{
// You would not really delete everything and create everything again for a reset,
// but it is simpler and also a good way to test the release commands.
dbDeleteObject(groundID);
myPhysics.releaseActor(groundID);
dbDeleteObject(characterID);
myPhysics.releaseController(characterID);
for(int i = stairsFirstStepID; i < upright4ID + 1 ; i++)
{
dbDeleteObject(i);
myPhysics.releaseActor(i);
}
// Start again
createWorld();
}
void displayData()
{
dbText(0, 0, "Fulcrum Physics v1.1 demo (powered by PhysX)");
dbText(0, 30, "Use mouse and arrow keys to move, Space key to reset.");
dbText(0, 60, "FPS: ");
dbText(150, 60, dbStr(dbScreenFPS()));
dbText(0, 75, "Poly Count: ");
dbText(150, 75, dbStr(dbStatistic(1)));
}
void moveCharacterControllerWithMouseAndKeys()
{
float speed = 0;
// KEYS
if (dbUpKey())
{
speed = 0.2;
}
if (dbDownKey())
{
speed = -0.2;
}
// Move controller
// Controller is not controlled by physics so you need to add gravity yourself
float gravity = -0.5;
float angleY = dbObjectAngleY(characterID);
float moveX = dbSin(angleY); // Calculate X component
float moveZ = dbCos(angleY); // Calculate Z component
myPhysics.moveCharacterController(characterID, moveX * speed, gravity, moveZ * speed);
// MOUSE
static float YAngle = 0;
YAngle = YAngle + dbMouseMoveY() / 5;
static float XAngle = 0;
XAngle = XAngle + dbMouseMoveX() / 5;
// CAMERA
dbYRotateObject(characterID, dbCurveValue(XAngle, dbObjectAngleY(characterID), 10));
dbXRotateCamera(dbCurveValue(YAngle, dbCameraAngleX(), 10));
dbSetCameraToFollow(dbObjectPositionX(characterID), dbObjectPositionY(characterID), dbObjectPositionZ(characterID), dbObjectAngleY(characterID) - 15, 5, 3 + (dbCameraAngleX() / 20), 1, 0);
dbYRotateCamera(dbObjectAngleY(characterID));
}
Forward thanks!