/* ============= CMod_PhysicsInit ============= */ void CMod_PhysicsInit() { Com_Printf("----- Initializing Newton Physics Engine -----\n"); Com_Printf("Initialized with Newton Version %i.%i \n", NEWTON_MAJOR_VERSION, NEWTON_MINOR_VERSION); Com_Printf("----------------------------------------------\n"); // create the Newton World bspModels.clear(); g_world = NewtonCreate (AllocMemory, FreeMemory); // use the standard x86 floating point model // Dushan - the engine will try to use the best possible hardware setting found in the current platform this is the default configuration NewtonSetPlatformArchitecture (g_world, 2); // Set up default material properties for newton defaultMaterialGroup = NewtonMaterialGetDefaultGroupID(g_world); NewtonMaterialSetDefaultFriction (g_world, defaultMaterialGroup, defaultMaterialGroup, 0.9f, 0.5f); NewtonMaterialSetDefaultElasticity (g_world, defaultMaterialGroup, defaultMaterialGroup, 0.4f); NewtonMaterialSetDefaultSoftness (g_world, defaultMaterialGroup, defaultMaterialGroup, 0.1f); NewtonMaterialSetCollisionCallback (g_world, defaultMaterialGroup, defaultMaterialGroup, NULL, NULL, NULL); NewtonMaterialSetDefaultCollidable (g_world, defaultMaterialGroup, defaultMaterialGroup, 1 ); // configure the Newton world to use iterative solve mode 0 // this is the most efficient but the less accurate mode NewtonSetSolverModel (g_world, 8); NewtonSetFrictionModel (g_world, 0); g_collision = NULL; }
bool Physics::initialize() { // init physics engine _p_world = NewtonCreate( physicsAlloc, physicsFree ); assert( _p_world ); // set minimum frame rate NewtonSetMinimumFrameRate( _p_world, 1.0f / FIX_PHYSICS_UPDATE_PERIOD ); NewtonSetSolverModel( _p_world, 0 ); // 0: exact, 1 adaptive, n linear. for games linear is ok NewtonSetFrictionModel( _p_world, 0 ); // 0: exact, 1 adaptive // setup all predefined materials setupMaterials(); return true; }
PhysicMap::PhysicMap() { float min[] = {-2000, -2000, -2000}; float max[] = {2000, 2000, 2000}; m_world = NewtonCreate(0, 0); NewtonSetWorldSize(m_world, min, max); NewtonSetSolverModel(m_world, 0); NewtonSetFrictionModel(m_world, 0); m_mapID = NewtonMaterialCreateGroupID(m_world); m_playerID = NewtonMaterialCreateGroupID(m_world); NewtonMaterialSetDefaultSoftness(m_world, m_mapID, m_playerID, 0.0f); NewtonMaterialSetDefaultElasticity(m_world, m_mapID, m_playerID, 0.2f); NewtonMaterialSetDefaultFriction(m_world, m_mapID, m_playerID, 0.5f, 0.0f); NewtonMaterialSetDefaultSoftness(m_world, m_playerID, m_playerID, 0.0f); NewtonMaterialSetDefaultElasticity(m_world, m_playerID, m_playerID, 0.2f); NewtonMaterialSetDefaultFriction(m_world, m_playerID, m_playerID, 0.5f, 0.0f); }
void world::friction(unsigned n) { NewtonSetFrictionModel(_world, n); }
// create physics scene void InitScene() { BoxPrimitive* box; BoxPrimitive* floor; NewtonBody* boxBody; NewtonBody* floorBody; NewtonCollision* collision; // create the newton world nWorld = NewtonCreate (PhysicsAlloc, PhysicsFree); // set the linear solver model for faster speed NewtonSetSolverModel (nWorld, 8); // set the adpative friction model for faster speed NewtonSetFrictionModel (nWorld, 1); // Set the termination function atexit(CleanUp); // create the the floor graphic objects dVector size (100.0f, 2.0f, 100.0f); dMatrix location (GetIdentityMatrix()); location.m_posit.m_y = -5.0f; // create a box for floor floor = new BoxPrimitive (location, size, g_floorTexture); // create the the floor collision, and body with default values collision = NewtonCreateBox (nWorld, size.m_x, size.m_y, size.m_z, NULL); floorBody = NewtonCreateBody (nWorld, collision); NewtonReleaseCollision (nWorld, collision); // set the transformation for this rigid body NewtonBodySetMatrix (floorBody, &location[0][0]); // save the pointer to the graphic object with the body. NewtonBodySetUserData (floorBody, floor); // set a destrutor for this rigid body NewtonBodySetDestructorCallback (floorBody, PhysicsBodyDestructor); // set the initial size size = dVector(0.5f, 0.5f, 0.5f); // create the collision collision = NewtonCreateBox (nWorld, size.m_x, size.m_y, size.m_z, NULL); // create 100 stacks of 10 boxes each location.m_posit.m_x = -10.0f; for (int k = 0; k < 10; k ++) { location.m_posit.m_z = 0.0f; for (int j = 0; j < 10; j ++) { location.m_posit.m_y = 2.0f; for (int i = 0; i < 10; i ++) { // create a graphic box box = new BoxPrimitive (location, size); //create the rigid body boxBody = NewtonCreateBody (nWorld, collision); // save the pointer to the graphic object with the body. NewtonBodySetUserData (boxBody, box); // set a destrutor for this rigid body NewtonBodySetDestructorCallback (boxBody, PhysicsBodyDestructor); // set the tranform call back function NewtonBodySetTransformCallback (boxBody, PhysicsSetTransform); // set the force and torque call back funtion NewtonBodySetForceAndTorqueCallback (boxBody, PhysicsApplyForceAndTorque); // set the mass matrix //NewtonBodySetMassMatrix (boxBody, 1.0f, 1.0f / 6.0f, 1.0f / 6.0f, 1.0f / 6.0f); NewtonBodySetMassMatrix (boxBody, 1.0f, 1.0f, 1.0f, 1.0f); // set the matrix for tboth the rigid nody and the graphic body NewtonBodySetMatrix (boxBody, &location[0][0]); PhysicsSetTransform (boxBody, &location[0][0]); location.m_posit.m_y += size.m_y * 2.0f; } location.m_posit.m_z -= size.m_z * 4.0f; } location.m_posit.m_x += size.m_x * 4.0f; } // release the collsion geometry when not need it NewtonReleaseCollision (nWorld, collision); }