static void Magnets (NewtonFrame& system, dFloat strength)
{
	NewtonWorld* world;
	LevelPrimitive* scene;

	world = system.m_world;

	// create the sky box and the floor,
	scene = LoadLevelAndSceneRoot (system, "playground.dae", 1);

	dVector posit (0.0f, 0.0f, 0.0f, 1.0f);
	posit.m_y = FindFloor (world, posit.m_x, posit.m_z) + 5.0f;

	InitEyePoint (dVector (1.0f, 0.0f, 0.0f), posit);

	// create a material carrier to colliding with this objects
	int defaultMaterialID;
	int magneticFieldID;
	int magneticPicesID;
	defaultMaterialID = NewtonMaterialGetDefaultGroupID (world);
	magneticFieldID = NewtonMaterialCreateGroupID (world);
	magneticPicesID = NewtonMaterialCreateGroupID (world);

	NewtonMaterialSetCollisionCallback (world, magneticPicesID, magneticFieldID, NULL, NULL, Magnet::MagneticField); 
	

	// create a spherical object to serve are the magnet core
	dMatrix matrix (GetIdentityMatrix());
	matrix.m_posit = posit;
	matrix.m_posit.m_x += 7.0f;
	new Magnet (system, matrix, 20.0f, defaultMaterialID, magneticFieldID, strength);

	// add a material to control the buoyancy
	dVector size (1.0f, 0.25f, 0.5f);
	dVector sphSize (1.0f, 1.0f, 1.0f);
	dVector capSize (1.25f, 0.4f, 1.0f);
	dVector location (cameraEyepoint + cameraDir.Scale (10.0f));

	AddBoxes (&system, 1.0f, location, sphSize, 3, 3, 5.0f, _SPHERE_PRIMITIVE, magneticPicesID);
	AddBoxes (&system, 1.0f, location, size, 3, 3, 5.0f, _BOX_PRIMITIVE, magneticPicesID);
	AddBoxes (&system, 1.0f, location, size, 3, 3, 5.0f, _CONE_PRIMITIVE, magneticPicesID);
	AddBoxes (&system, 1.0f, location, size, 3, 3, 5.0f, _CYLINDER_PRIMITIVE, magneticPicesID);
	AddBoxes (&system, 1.0f, location, capSize, 3, 3, 5.0f, _CAPSULE_PRIMITIVE, magneticPicesID);
	AddBoxes (&system, 1.0f, location, size, 3, 3, 5.0f, _CHAMFER_CYLINDER_PRIMITIVE, magneticPicesID);
	AddBoxes (&system, 1.0f, location, size, 3, 3, 5.0f, _RANDOM_CONVEX_HULL_PRIMITIVE, magneticPicesID);
	AddBoxes (&system, 1.0f, location, size, 3, 3, 5.0f, _REGULAR_CONVEX_HULL_PRIMITIVE, magneticPicesID);

	posit.m_x -= 10.0f;
	InitEyePoint (dVector (1.0f, 0.0f, 0.0f), posit);
}
예제 #2
0
void Restitution (DemoEntityManager* const scene)
{
	scene->CreateSkyBox();

	// customize the scene after loading
	// set a user friction variable in the body for variable friction demos
	// later this will be done using LUA script
	NewtonWorld* const world = scene->GetNewton();
	dMatrix offsetMatrix (dGetIdentityMatrix());

	int defaultMaterialID = NewtonMaterialGetDefaultGroupID (world);
	NewtonMaterialSetCollisionCallback (world, defaultMaterialID, defaultMaterialID, NULL, UserContactRestitution); 


	CreateLevelMesh (scene, "flatPlane.ngd", 0);

	dVector location (0.0f, 0.0f, 0.0f, 0.0f);
	dVector size (0.5f, 0.5f, 1.0f, 0.0f);

	// create some spheres 
	dVector sphSize (1.0f, 1.0f, 1.0f, 0.0f);
	NewtonCollision* const sphereCollision = CreateConvexCollision (world, offsetMatrix, sphSize, _SPHERE_PRIMITIVE, 0);
	DemoMesh* const sphereMesh = new DemoMesh("sphere", sphereCollision, "smilli.tga", "smilli.tga", "smilli.tga");

	// create some boxes too
	dVector boxSize (1.0f, 0.5f, 2.0f, 0.0f);
	NewtonCollision* const boxCollision = CreateConvexCollision (world, offsetMatrix, boxSize, _BOX_PRIMITIVE, 0);
	DemoMesh* const boxMesh = new DemoMesh("box", boxCollision, "smilli.tga", "smilli.tga", "smilli.tga");


	int zCount = 10;
	dFloat spacing = 4.0f;
	dMatrix matrix (dGetIdentityMatrix());
	dVector origin (matrix.m_posit);
	origin.m_x -= 0.0f;

	// create a simple scene
	for (int i = 0; i < zCount; i ++) {
		dFloat z;
		dFloat x;
		dFloat mass;
		dVector size (1.0f, 0.5f, 2.0f, 0.0f);

		x = origin.m_x;
		z = origin.m_z + (i - zCount / 2) * spacing;

		mass = 1.0f;
		matrix.m_posit = FindFloor (world, dVector (x, 100.0f, z), 200.0f);
		matrix.m_posit.m_w = 1.0f;
		
		float restitution;
		NewtonBody* body;
		NewtonCollision* collision;
		

		matrix.m_posit.m_y += 4.0f;
		body = CreateSimpleSolid (scene, sphereMesh, mass, matrix, sphereCollision, defaultMaterialID);
		NewtonBodySetLinearDamping (body, 0.0f);
		collision = NewtonBodyGetCollision(body);
		restitution = i * 0.1f + 0.083f;
		NewtonCollisionSetUserData (collision, *((void**)&restitution));

		matrix.m_posit.m_y += 4.0f;
		//body = CreateSimpleSolid (scene, sphereMesh, mass, matrix, sphereCollision, defaultMaterialID, shapeOffsetMatrix);
		body = CreateSimpleSolid (scene, boxMesh, mass, matrix, boxCollision, defaultMaterialID);
		NewtonBodySetLinearDamping (body, 0.0f);
		collision = NewtonBodyGetCollision(body);
		restitution = i * 0.1f + 0.083f;
		NewtonCollisionSetUserData (collision, *((void**)&restitution));

		matrix.m_posit.m_y += 4.0f;
		body = CreateSimpleSolid (scene, sphereMesh, mass, matrix, sphereCollision, defaultMaterialID);
		NewtonBodySetLinearDamping (body, 0.0f);
		collision = NewtonBodyGetCollision(body);
		restitution = i * 0.1f + 0.083f;
		NewtonCollisionSetUserData (collision, *((void**)&restitution));

		matrix.m_posit.m_y += 4.0f;
		dVector boxSize (1.0f, 0.5f, 2.0f, 0.0f);
		body = CreateSimpleSolid (scene, boxMesh, mass, matrix, boxCollision, defaultMaterialID);
		NewtonBodySetLinearDamping (body, 0.0f);
		collision = NewtonBodyGetCollision(body);
		restitution = i * 0.1f + 0.083f;
		NewtonCollisionSetUserData (collision, *((void**)&restitution));
	}

	boxMesh->Release();
	sphereMesh->Release();
	NewtonDestroyCollision(boxCollision);
	NewtonDestroyCollision(sphereCollision);


	dMatrix camMatrix (dGetIdentityMatrix());
	dQuaternion rot (camMatrix);
	origin = dVector (-25.0f, 5.0f, 0.0f, 0.0f);
	scene->SetCameraMatrix(rot, origin);

}