void CreateScene (NewtonWorld* world, SceneManager* sceneManager) { Entity* floor; NewtonBody* floorBody; NewtonCollision* shape; // initialize the camera InitCamera (dVector (-15.0f, 5.0f, 0.0f, 0.0f), dVector (1.0f, 0.0f, 0.0f)); // Create a large body to be the floor floor = sceneManager->CreateEntity(); floor->LoadMesh ("FloorBox.dat"); // add static floor Physics shape = CreateNewtonBox (world, floor, 0); floorBody = CreateRigidBody (world, floor, shape, 0.0f); NewtonDestroyCollision(shape); // set the Transformation Matrix for this rigid body dMatrix matrix (floor->m_curRotation, floor->m_curPosition); NewtonBodySetMatrix (floorBody, &matrix[0][0]); // find the floor base, and add some distance up; dFloat floorY = FindFloor (world, 0.0f, 0.0f) + 2.0f; // this is the width of the Box; dFloat boxWidth = 0.42f; // Make a small pyramid of Boxes for (int i = 0; i < PYRAMID_BASE + 1; i ++) { for (int j = 0; j < PYRAMID_BASE - i; j ++) { Entity* smilly; NewtonBody* smillyBody; // crate a visual Box and place in a pyramid formation above the floor smilly = sceneManager->CreateEntity(); smilly->LoadMesh ("Smilly.dat"); smilly->m_curPosition.m_x = 0.0f; smilly->m_curPosition.m_z = dFloat (j) * boxWidth + dFloat (i) * (boxWidth * 0.5f); smilly->m_curPosition.m_y = floorY + dFloat (i) * boxWidth; smilly->m_prevPosition = smilly->m_curPosition; // add a body with a box shape shape = CreateNewtonBox (world, smilly, 0); smillyBody = CreateRigidBody (world, smilly, shape, 10.0f); NewtonDestroyCollision(shape); // we want some nice object placement, with zero penetration and and zero jitter // therefore we are going use use a Convex Cast function to snap the Box to the closest contact surface ConvexCastPlacement (smillyBody); } } }
//static void UnstableStruture (SceneManager& system, dVector location, int high) static void BreakableStruture (SceneManager& system, dVector location, int high) { dFloat plankMass; dFloat columnMass; // ///////////////////////////////////////////////////////////////////// // // Build a parking lot type structure dVector columnBoxSize (3.0f, 1.0f, 1.0f); // dVector columnBoxSize (3.0f, 3.0f, 1.0f); dVector plankBoxSize (6.0f, 1.0f, 6.0f); // create the stack dMatrix baseMatrix (GetIdentityMatrix()); // get the floor position in from o the camera baseMatrix.m_posit = location; baseMatrix.m_posit.m_y += columnBoxSize.m_x; // set realistic (extremes in this case for 24 bits precision) masses for the different components // note how the newton engine handle different masses ratios without compromising stability, // we recommend the application keep this ration under 100 for contacts and 50 for joints columnMass = 1.0f; plankMass = 20.0f; // plankMass = 1.0f; // create a material carrier to to cou collision wit ethsi obejted int defaultMaterialID; defaultMaterialID = NewtonMaterialGetDefaultGroupID (system.m_world); dMatrix columAlignment (dRollMatrix(3.1416f * 0.5f)); for (int i = 0; i < high; i ++) { NewtonBody* body; RenderPrimitive* primitive; dMatrix matrix(columAlignment * baseMatrix); // add the 4 column matrix.m_posit.m_x -= (columnBoxSize.m_z - plankBoxSize.m_x) * 0.5f; matrix.m_posit.m_z -= (columnBoxSize.m_z - plankBoxSize.m_z) * 0.5f; body = CreateGenericSolid (system.m_world, &system, columnMass, matrix, columnBoxSize, _RANDOM_CONVEX_HULL_PRIMITIVE, defaultMaterialID); primitive = (RenderPrimitive*) NewtonBodyGetUserData (body); SetBreakValue (body, 50.0f); ConvexCastPlacement (body); matrix.m_posit.m_x += columnBoxSize.m_z - plankBoxSize.m_x; body = CreateGenericSolid (system.m_world, &system, columnMass, matrix, columnBoxSize, _RANDOM_CONVEX_HULL_PRIMITIVE, defaultMaterialID); primitive = (RenderPrimitive*) NewtonBodyGetUserData (body); SetBreakValue (body, 30.0f); ConvexCastPlacement (body); matrix.m_posit.m_z += columnBoxSize.m_z - plankBoxSize.m_z; body = CreateGenericSolid (system.m_world, &system, columnMass, matrix, columnBoxSize, _RANDOM_CONVEX_HULL_PRIMITIVE, defaultMaterialID); primitive = (RenderPrimitive*) NewtonBodyGetUserData (body); SetBreakValue (body, 30.0f); ConvexCastPlacement (body); matrix.m_posit.m_x -= columnBoxSize.m_z - plankBoxSize.m_x; body = CreateGenericSolid (system.m_world, &system, columnMass, matrix, columnBoxSize, _RANDOM_CONVEX_HULL_PRIMITIVE, defaultMaterialID); primitive = (RenderPrimitive*) NewtonBodyGetUserData (body); SetBreakValue (body, 30.0f); ConvexCastPlacement (body); // add a plank dVector size (plankBoxSize); size.m_x *= 0.85f; size.m_z *= 0.85f; body = CreateGenericSolid (system.m_world, &system, plankMass, baseMatrix, size, _BOX_PRIMITIVE, defaultMaterialID); primitive = (RenderPrimitive*) NewtonBodyGetUserData (body); SetBreakValue (body, 1.0f); ConvexCastPlacement (body); // set up for another level baseMatrix.m_posit.m_y += (columnBoxSize.m_x + plankBoxSize.m_y); } dFloat mass; NewtonBody* body; RenderPrimitive* primitive; PrimitiveType type = _BOX_PRIMITIVE; dVector size (1.0f, 2.0f, 1.0f); dMatrix matrix (GetIdentityMatrix()); mass = 10.0f; matrix.m_posit = location; matrix.m_posit.m_y = FindFloor (system.m_world, matrix.m_posit.m_x, matrix.m_posit.m_z) + baseMatrix.m_posit.m_y + 35.0f; body = CreateGenericSolid (system.m_world, &system, mass, matrix, size, type, defaultMaterialID); primitive = (RenderPrimitive*) NewtonBodyGetUserData (body); }