예제 #1
0
NewtonBody* AddSphere(CScene *pScene, NewtonWorld *pWorld, Vector3 pos, float radius, float mass)
{
	static map<float, CGeometry*> geometries;
	static CMaterial *material = NULL;

	if (!material)
	{
		material = new CMaterial();
		material->features = EShaderFeature::LIGHT | EShaderFeature::FOG | EShaderFeature::SHADOW;
	}

	if (geometries.find(radius) == geometries.end())
	{
		CGeometry *g = new CSphereGeometry(radius);
		g->materials.AddToTail(material);
		geometries[radius] = g;
	}

	CMesh *sphere = new CMesh( geometries[radius] );
	sphere->SetPosition(pos);
	NewtonBody *body = CPhysics::CreateSphere(pWorld, sphere, radius, mass);
	pScene->Add(sphere);
	NewtonBodySetForceAndTorqueCallback(body, BoxGravityCallback);
	return body;
}
예제 #2
0
NewtonBody* AddBox(CScene *pScene, NewtonWorld *pWorld, Vector3 pos, Vector3 size, Vector3 rot, float mass)
{
	static map<string, CGeometry*> geometries;
	static CMaterial *material = NULL;

	if (!material)
	{
		material = new CMaterial();
		//material->features = EShaderFeature::LIGHT | EShaderFeature::FOG;// | EShaderFeature::SHADOW;
		//material->transparent = true;
		
	}


	string name = str("%f_%f_%f", size.x, size.y, size.z);
	if (geometries.find(name) == geometries.end())
	{
		CGeometry *g = new CCubeGeometry(size.x, size.y, size.z);
		g->materials.AddToTail(material);
		geometries[name] = g;		
	}

	CMesh *box = new CMesh( geometries[name] );

	box->SetPosition(pos);
	box->SetRotation(rot);	
	//box->matrixModel.SetEulerAngles(box->rotation);
	NewtonBody *body = CPhysics::CreateBox(pWorld, box, size.x, size.y, size.z, mass);

	box->color = SRGB(clamp(pos.x*255.0f/32.0f,0,255)*0.9f, clamp(pos.y*255.0f/32.0f,0,255)*0.9f, clamp(pos.z*255.0f/32.0f,0,255)*0.9f);


	//NewtonBodySetMaterialGroupID(body, gLevelBlocksMaterialID);							// ENABLED COLLISION 
	pScene->Add(box);
	NewtonBodySetForceAndTorqueCallback(body, BoxGravityCallback);
	NewtonBodySetAutoSleep(body, 1);			// make boxes go to sleep automatically (default)
	return body;
}