/* ============= 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; }
void cPhysicsMaterialNewton::UpdateMaterials() { cPhysicsMaterialIterator MatIt = mpWorld->GetMaterialIterator(); while(MatIt.HasNext()) { cPhysicsMaterialNewton* pMat = static_cast<cPhysicsMaterialNewton*>(MatIt.Next()); ePhysicsMaterialCombMode frictionMode = (ePhysicsMaterialCombMode) std::max(mFrictionMode, pMat->mFrictionMode); ePhysicsMaterialCombMode elasticityMode = (ePhysicsMaterialCombMode) std::max(mElasticityMode, pMat->mElasticityMode); //If the material is the same do not blend. if(pMat == this){ frictionMode = ePhysicsMaterialCombMode_Average; elasticityMode = ePhysicsMaterialCombMode_Average; } NewtonMaterialSetDefaultElasticity(mpNewtonWorld,mlMaterialId,pMat->mlMaterialId, Combine(elasticityMode,mfElasticity, pMat->mfElasticity)); NewtonMaterialSetDefaultFriction(mpNewtonWorld,mlMaterialId,pMat->mlMaterialId, Combine(frictionMode,mfStaticFriction, pMat->mfStaticFriction), Combine(frictionMode,mfKineticFriction, pMat->mfKineticFriction)); NewtonMaterialSetContinuousCollisionMode(mpNewtonWorld,mlMaterialId,pMat->mlMaterialId, 1); NewtonMaterialSetCollisionCallback(mpNewtonWorld,mlMaterialId,pMat->mlMaterialId, (void*)NULL,BeginContactCallback,ProcessContactCallback); } }
void DynamicRagdoll(DemoEntityManager* const scene) { // load the sky box scene->CreateSkyBox(); CreateLevelMesh(scene, "flatPlane.ngd", true); dDynamicRagdollManager* const manager = new dDynamicRagdollManager(scene); NewtonWorld* const world = scene->GetNewton(); int defaultMaterialID = NewtonMaterialGetDefaultGroupID(world); NewtonMaterialSetDefaultFriction(world, defaultMaterialID, defaultMaterialID, 1.0f, 1.0f); NewtonMaterialSetDefaultElasticity(world, defaultMaterialID, defaultMaterialID, 0.0f); dMatrix origin (dYawMatrix(0.0f * dDegreeToRad)); origin.m_posit.m_y = 2.0f; manager->CreateRagdollExperiment_0(origin); /* // int count = 10; // count = 1; //origin = dGetIdentityMatrix(); origin.m_posit.m_x = 2.0f; // origin.m_posit.m_y = 2.1f; origin.m_posit.m_y = 3.0f; for (int i = 0; i < count; i++) { manager->CreateRagDoll(scene, origin); //manager->CreateRagDoll (scene, origin1); origin.m_posit.m_x += 1.0f; } */ origin.m_posit.m_x = -3.0f; origin.m_posit.m_y = 1.0f; origin.m_posit.m_z = 0.0f; scene->SetCameraMatrix(dGetIdentityMatrix(), origin.m_posit); }
void iPhysics::setFriction(iPhysicsMaterialCombo* materialCombo, float32 staticFriction, float32 kineticFriction) { con_assert(staticFriction >= 0.0 && staticFriction <= 2.0, "out of range"); con_assert(kineticFriction >= 0.0 && kineticFriction <= 2.0, "out of range"); con_assert(kineticFriction <= staticFriction, "out of range"); NewtonMaterialSetDefaultFriction(static_cast<const NewtonWorld*>(_defaultWorld), materialCombo->getMaterial0(), materialCombo->getMaterial1(), staticFriction, kineticFriction); }
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 Hexapod(DemoEntityManager* const scene) { // load the sky box scene->CreateSkyBox(); CreateLevelMesh (scene, "flatPlane.ngd", true); //CreateHeightFieldTerrain(scene, HEIGHTFIELD_DEFAULT_SIZE, HEIGHTFIELD_DEFAULT_CELLSIZE, 1.5f, 0.3f, 200.0f, -50.0f); NewtonWorld* const world = scene->GetNewton(); int defaultMaterialID = NewtonMaterialGetDefaultGroupID(world); dHexapodManager* const robotManager = new dHexapodManager(scene); NewtonMaterialSetDefaultFriction(world, defaultMaterialID, defaultMaterialID, 1.0f, 1.0f); NewtonMaterialSetDefaultElasticity(world, defaultMaterialID, defaultMaterialID, 0.1f); dMatrix location (dGetIdentityMatrix()); location.m_posit = dVector(FindFloor(world, dVector(-0.0f, 50.0f, 0.0f, 1.0f), 2.0f * 50.0f)); location.m_posit.m_y += 1.0f; int count = 5; //count = 1; dMatrix location1(location); dFloat x0 = location.m_posit.m_x; for (int j = 0; j < 1; j++) { location.m_posit.m_z += 2.0f; location.m_posit.m_x = x0; for (int i = 0; i < count; i++) { location.m_posit.m_x += 2.0f; //location1.m_posit.m_x += 2.0f; robotManager->MakeHexapod(scene, location); //robotManager->MakeHexapod (scene, location1); } } location.m_posit = dVector(FindFloor(scene->GetNewton(), dVector(-0.0f, 50.0f, 0.0f, 1.0f), 2.0f * 50.0f)); dVector origin(FindFloor(world, dVector(-4.0f, 50.0f, 0.0f, 1.0f), 2.0f * 50.0f)); origin.m_y += 2.5f; // dVector size(3.0f, 0.125f, 3.0f, 0.0f); // dMatrix shapeOffsetMatrix (dGetIdentityMatrix()); // AddPrimitiveArray(scene, 50.0f, location.m_posit, size, count, count, 6.0f, _BOX_PRIMITIVE, defaultMaterialID, shapeOffsetMatrix); dQuaternion rot; scene->SetCameraMatrix(rot, origin); }
void Physics::setupMaterials() { assert( _p_world ); // get the default material ID int defaultID = NewtonMaterialGetDefaultGroupID( _p_world ); // set default material properties NewtonMaterialSetDefaultSoftness( _p_world, defaultID, defaultID, 0.05f ); NewtonMaterialSetDefaultElasticity( _p_world, defaultID, defaultID, 0.4f ); NewtonMaterialSetDefaultCollidable( _p_world, defaultID, defaultID, 1 ); NewtonMaterialSetDefaultFriction( _p_world, defaultID, defaultID, 1.0f, 0.5f ); NewtonMaterialSetCollisionCallback( _p_world, defaultID, defaultID, &defaultCollStruct, genericContactBegin, genericContactProcess, genericContactEnd ); // create all predefined materials IDs int nocolID = NewtonMaterialCreateGroupID( _p_world ); int wallID = NewtonMaterialCreateGroupID( _p_world ); int levelID = NewtonMaterialCreateGroupID( _p_world ); int woodID = NewtonMaterialCreateGroupID( _p_world ); int metalID = NewtonMaterialCreateGroupID( _p_world ); int stoneID = NewtonMaterialCreateGroupID( _p_world ); int grassID = NewtonMaterialCreateGroupID( _p_world ); _materials.insert( std::make_pair( "default", defaultID ) ); _materials.insert( std::make_pair( "wall" , wallID ) ); _materials.insert( std::make_pair( "nocol" , nocolID ) ); _materials.insert( std::make_pair( "level" , levelID ) ); _materials.insert( std::make_pair( "wood" , woodID ) ); _materials.insert( std::make_pair( "metal" , metalID ) ); _materials.insert( std::make_pair( "stone" , stoneID ) ); _materials.insert( std::make_pair( "grass" , grassID ) ); // set non-colliding pairs NewtonMaterialSetDefaultCollidable( _p_world, nocolID, defaultID, 0 ); NewtonMaterialSetDefaultCollidable( _p_world, nocolID, wallID, 0 ); NewtonMaterialSetDefaultCollidable( _p_world, nocolID, levelID, 0 ); NewtonMaterialSetDefaultCollidable( _p_world, nocolID, woodID, 0 ); NewtonMaterialSetDefaultCollidable( _p_world, nocolID, metalID, 0 ); NewtonMaterialSetDefaultCollidable( _p_world, nocolID, grassID, 0 ); NewtonMaterialSetDefaultCollidable( _p_world, nocolID, stoneID, 0 ); // set the material properties for level on wood NewtonMaterialSetDefaultElasticity( _p_world, levelID, woodID, 0.5f ); NewtonMaterialSetDefaultFriction ( _p_world, levelID, woodID, 0.7f, 0.6f); NewtonMaterialSetCollisionCallback( _p_world, levelID, woodID, &level_woodCollStruct, genericContactBegin, levelContactProcess, genericContactEnd ); // set the material properties for level on metal NewtonMaterialSetDefaultElasticity( _p_world, levelID, metalID, 0.5f ); NewtonMaterialSetDefaultFriction ( _p_world, levelID, metalID, 0.8f, 0.6f ); NewtonMaterialSetCollisionCallback( _p_world, levelID, metalID, &level_metalCollStruct, genericContactBegin, levelContactProcess, genericContactEnd ); // set the material properties for level on grass NewtonMaterialSetDefaultElasticity( _p_world, levelID, grassID, 0.3f ); NewtonMaterialSetDefaultFriction ( _p_world, levelID, grassID, 0.9f, 0.7f ); NewtonMaterialSetCollisionCallback( _p_world, levelID, grassID, &level_grassCollStruct, genericContactBegin, levelContactProcess, genericContactEnd ); // set the material properties for level on stone NewtonMaterialSetDefaultElasticity( _p_world, levelID, stoneID, 0.45f ); NewtonMaterialSetDefaultFriction ( _p_world, levelID, stoneID, 0.8f, 0.7f ); NewtonMaterialSetCollisionCallback( _p_world, levelID, stoneID, &level_stoneCollStruct, genericContactBegin, levelContactProcess, genericContactEnd ); //------ // set the material properties for wood on wood NewtonMaterialSetDefaultElasticity( _p_world, woodID, woodID, 0.3f ); NewtonMaterialSetDefaultFriction ( _p_world, woodID, woodID, 1.1f, 0.7f); NewtonMaterialSetCollisionCallback( _p_world, woodID, woodID, &wood_woodCollStruct, genericContactBegin, genericContactProcess, genericContactEnd ); // set the material properties for wood on metal NewtonMaterialSetDefaultElasticity( _p_world, woodID, metalID, 0.5f ); NewtonMaterialSetDefaultFriction ( _p_world, woodID, metalID, 0.8f, 0.6f ); NewtonMaterialSetCollisionCallback( _p_world, woodID, metalID, &wood_metalCollStruct, genericContactBegin, genericContactProcess, genericContactEnd ); // set the material properties for wood on grass NewtonMaterialSetDefaultElasticity( _p_world, woodID, grassID, 0.2f ); NewtonMaterialSetDefaultFriction ( _p_world, woodID, grassID, 0.9f, 0.7f ); NewtonMaterialSetCollisionCallback( _p_world, woodID, grassID, &wood_grassCollStruct, genericContactBegin, genericContactProcess, genericContactEnd ); // set the material properties for wood on stone NewtonMaterialSetDefaultElasticity( _p_world, woodID, stoneID, 0.45f ); NewtonMaterialSetDefaultFriction ( _p_world, woodID, stoneID, 0.7f, 0.6f ); NewtonMaterialSetCollisionCallback( _p_world, woodID, stoneID, &wood_stoneCollStruct, genericContactBegin, genericContactProcess, genericContactEnd ); //------ // set the material properties for metal on metal NewtonMaterialSetDefaultElasticity( _p_world, metalID, metalID, 0.7f ); NewtonMaterialSetDefaultFriction ( _p_world, metalID, metalID, 0.5f, 0.2f ); NewtonMaterialSetCollisionCallback( _p_world, metalID, metalID, &metal_metalCollStruct, genericContactBegin, genericContactProcess, genericContactEnd ); // set the material properties for metal on grass NewtonMaterialSetDefaultElasticity( _p_world, metalID, grassID, 0.2f ); NewtonMaterialSetDefaultFriction ( _p_world, metalID, grassID, 0.6f, 0.5f ); NewtonMaterialSetCollisionCallback( _p_world, metalID, grassID, &metal_grassCollStruct, genericContactBegin, genericContactProcess, genericContactEnd ); // set the material properties for metal on stone NewtonMaterialSetDefaultElasticity( _p_world, metalID, stoneID, 0.6f ); NewtonMaterialSetDefaultFriction ( _p_world, metalID, stoneID, 0.5f, 0.4f ); NewtonMaterialSetCollisionCallback( _p_world, metalID, stoneID, &metal_stoneCollStruct, genericContactBegin, genericContactProcess, genericContactEnd ); //------ // set the material properties for stone on stone NewtonMaterialSetDefaultElasticity( _p_world, stoneID, stoneID, 0.8f ); NewtonMaterialSetDefaultFriction ( _p_world, stoneID, stoneID, 0.5f, 0.2f ); NewtonMaterialSetCollisionCallback( _p_world, stoneID, stoneID, &stone_stoneCollStruct, genericContactBegin, genericContactProcess, genericContactEnd ); // set the material properties for stone on grass NewtonMaterialSetDefaultElasticity( _p_world, stoneID, grassID, 0.2f ); NewtonMaterialSetDefaultFriction ( _p_world, stoneID, grassID, 0.7f, 0.6f ); NewtonMaterialSetCollisionCallback( _p_world, stoneID, grassID, &stone_grassCollStruct, genericContactBegin, genericContactProcess, genericContactEnd ); //------ // set the material properties for grass on grass ( may we need this!? ) NewtonMaterialSetDefaultElasticity( _p_world, grassID, grassID, 0.1f ); NewtonMaterialSetDefaultFriction ( _p_world, grassID, grassID, 0.9f, 0.8f ); NewtonMaterialSetCollisionCallback( _p_world, grassID, grassID, &grass_grassCollStruct, genericContactBegin, genericContactProcess, genericContactEnd ); }
void tContact::SetFriction(float static_, float kinetic_) { NewtonMaterialSetDefaultFriction(tWorld::Instance()->_getNewtonWorld(), mId0->GetId(), mId1->GetId(), static_, kinetic_); }
static void BuildFloorAndSceneRoot (SceneManager& system) { NewtonWorld* world; RenderPrimitive* floor; NewtonBody* floorBody; NewtonCollision* floorCollision; OGLMesh* meshInstance; world = system.m_world; // ///////////////////////////////////////////////////////////////////// // // create the sky box, system.AddModel (new SkyBox ()); // create the the floor graphic objects dVector floorSize (100.0f, 2.0f, 100.0f); dMatrix location (GetIdentityMatrix()); location.m_posit.m_y = -5.0f; // create a box for floor floorCollision = NewtonCreateBox (world, floorSize.m_x, floorSize.m_y, floorSize.m_z, 0, NULL); // meshInstance = OGLMesh::MakeBox (world, size.m_x, size.m_y, size.m_z, "GrassAndDirt.tga"); meshInstance = new OGLMesh (floorCollision, "GrassAndDirt.tga", "metal_30.tga", "metal_30.tga"); floor = new RenderPrimitive (location, meshInstance); system.AddModel (floor); meshInstance->Release(); // create the the floor collision, and body with default values floorBody = NewtonCreateBody (world, floorCollision); NewtonReleaseCollision (world, floorCollision); // 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 destructor for this rigid body NewtonBodySetDestructorCallback (floorBody, PhysicsBodyDestructor); // get the default material ID int defaultID; defaultID = NewtonMaterialGetDefaultGroupID (world); // set default material properties NewtonMaterialSetDefaultSoftness (world, defaultID, defaultID, 0.05f); NewtonMaterialSetDefaultElasticity (world, defaultID, defaultID, 0.4f); NewtonMaterialSetDefaultCollidable (world, defaultID, defaultID, 1); NewtonMaterialSetDefaultFriction (world, defaultID, defaultID, 1.0f, 0.5f); NewtonMaterialSetCollisionCallback (world, defaultID, defaultID, NULL, NULL, GenericContactProcess); // NewtonMaterialSetSurfaceThickness(world, materialID, materialID, 0.1f); NewtonMaterialSetSurfaceThickness(world, defaultID, defaultID, 0.0f); // set the island update callback NewtonSetIslandUpdateEvent (world, PhysicsIslandUpdate); // save the callback SetDemoCallbacks (system); InitEyePoint (dVector (1.0f, 0.0f, 0.0f), dVector (-40.0f, 10.0f, 0.0f)); }
// create physics scene void PuckSlide (DemoEntityManager* const scene) { scene->CreateSkyBox(); NewtonWorld* const world = scene->GetNewton(); int materialGroupIDs[SB_NUM_MATERIALS]; // Create groups for (int i = 0; i < SB_NUM_MATERIALS; i++) { materialGroupIDs[i] = NewtonMaterialCreateGroupID(world); } // Setup the material data NewtonMaterialSetDefaultSoftness(world, materialGroupIDs[SBMaterial_WEIGHT], materialGroupIDs[SBMaterial_SURFACE], 0.15f); NewtonMaterialSetDefaultElasticity(world, materialGroupIDs[SBMaterial_WEIGHT], materialGroupIDs[SBMaterial_SURFACE], 0.30f); NewtonMaterialSetDefaultFriction(world, materialGroupIDs[SBMaterial_WEIGHT], materialGroupIDs[SBMaterial_SURFACE], 0.05f, 0.04f); // setup callbacks for collisions between two material groups NewtonMaterialSetCollisionCallback(world,materialGroupIDs[SBMaterial_WEIGHT],materialGroupIDs[SBMaterial_SURFACE],NULL,PhysicsNewton_CollisionPuckSurfaceCB); /////// // Add table { dVector tableSize(TABLE_LENGTH, TABLE_HEIGHT, TABLE_WIDTH, 0.0f); // create the shape and visual mesh as a common data to be re used NewtonCollision* const collision = CreateConvexCollision (world, dGetIdentityMatrix(), tableSize, _BOX_PRIMITIVE, materialGroupIDs[SBMaterial_SURFACE]); DemoMesh* const geometry = new DemoMesh("cylinder_1", collision, "wood_3.tga", "wood_3.tga", "wood_3.tga"); dMatrix matrix = dGetIdentityMatrix(); matrix.m_posit.m_x = 0.0f; matrix.m_posit.m_z = 0.0f; matrix.m_posit.m_y = 0.0f; NewtonBody* const tableBody = CreateSimpleSolid (scene, geometry, 0.0, matrix, collision, materialGroupIDs[SBMaterial_SURFACE]); // this is deprecated, use NewtonBodySetMassProperties //NewtonBodySetMassMatrix(tableBody, 0.0f, 1.0f, 1.0f, 1.0f); NewtonBodySetMassProperties(tableBody, 0.0f, NewtonBodyGetCollision(tableBody)); NewtonBodySetMaterialGroupID(tableBody, materialGroupIDs[SBMaterial_SURFACE]); // it is not wise to se static body to continuous collision mode //NewtonBodySetContinuousCollisionMode(tableBody, 1); // do not forget to release the assets geometry->Release(); // the collision need to be destroy, the body is using an instance no a reference NewtonDestroyCollision (collision); } /////// // Add puck { new PuckEntity (scene, materialGroupIDs[SBMaterial_WEIGHT]); } // place camera into position dMatrix camMatrix (dPitchMatrix(20.0f * 3.1416f /180.0f)); dQuaternion rot (camMatrix); dVector origin (CAMERA_Z, CAMERA_Y, CAMERA_X, 0.0f); scene->SetCameraMatrix(rot, origin); }
void PhysWorld3D::SetMaterialDefaultFriction(int firstMaterial, int secondMaterial, float staticFriction, float kineticFriction) { NewtonMaterialSetDefaultFriction(m_world, firstMaterial, secondMaterial, staticFriction, kineticFriction); }