Пример #1
0
void idle()
{
	glm::dvec3 colorFieldGradient;
	double colorFieldLaplacian;
	// Print OpenGL errors, if there are any (for debugging)
	if (GLenum err = glGetError())
	{
		std::cerr << "OpenGL ERROR: " << gluErrorString(err) << std::endl;
	}
	
	static double previous_time;
	static bool initialized = false;

	if (!initialized)
	{
		previous_time = double(clock()) / CLOCKS_PER_SEC;
		initialized = true;
	}

	double current_time = double(clock()) / CLOCKS_PER_SEC;
	double elapsed_time = current_time - previous_time;
	double dt = timestep;// elapsed_time;

	//reset force and density
	if (running)
		updateParticles(particles, partCount, h, eta, dt, sphereRadius, threshold, sigma);

	//check each particle for collision
	for (int i = 0; i < partCount; i++)
	{
		//if colliding
		if (isColliding(particles[i].x, sphereRadius)>0)
		{
			glm::dvec3 cp;
			double depth;
			glm::dvec3 normal;
			//get collision data
			collisionData(cp, depth, normal, particles[i].x, sphereRadius);

			//collision Response
			double slip = 0.0;
			particles[i].x = cp;
			particles[i].v = particles[i].v - (1.0 + slip*depth / (dt* glm::length(particles[i].v)))* glm::dot(particles[i].v, normal)*normal;		
		}
	}
	previous_time = current_time;

	if (running)
		glutSetWindowTitle("SPH running");
	else
		glutSetWindowTitle("SPH paused");
	glutPostRedisplay();
}
Пример #2
0
//-----------------------------------------------------------------------
bool CSpectacularKill::ObstacleCheck(const Vec3& vKillerPos, const Vec3& vTargetPos, const SSpectacularKillAnimation& anim) const
{
	// [*DavidR | 13/Sep/2010] ToDo: Find a way to make this asynchronously
	const float OBSTACLE_CHECK_RADIUS = 0.6f;
	const float OBSTACLE_CHECK_GROUND_OFFSET = 0.2f;

	const Vec3& vCapsuleKillerEnd = vKillerPos + anim.vKillerObstacleCheckOffset;

	primitives::capsule capsPrim;
	const Vec3& vKillerToTargetDist = vTargetPos - vCapsuleKillerEnd;
	capsPrim.axis = vKillerToTargetDist.GetNormalized();
	capsPrim.r = OBSTACLE_CHECK_RADIUS;

	// hh is actually half the total height (it's measured from the center)
	capsPrim.hh = static_cast<float>(__fsel(anim.fObstacleCheckLength, 
				(anim.fObstacleCheckLength * 0.5f) - capsPrim.r,
				(min(g_pGameCVars->g_spectacularKill.maxDistanceError, vKillerToTargetDist.GetLength()) * 0.5f) - capsPrim.r));

	capsPrim.center = vCapsuleKillerEnd + (capsPrim.axis * (capsPrim.hh + capsPrim.r));
	capsPrim.center.z += capsPrim.r + OBSTACLE_CHECK_GROUND_OFFSET;

	geom_contact* pContact = NULL;
	int collisionEntityTypes = ent_static | ent_terrain | ent_sleeping_rigid | ent_ignore_noncolliding;
	float d = gEnv->pPhysicalWorld->PrimitiveWorldIntersection(capsPrim.type, &capsPrim, Vec3Constants<float>::fVec3_Zero, collisionEntityTypes, &pContact, 0, geom_colltype0);

	bool bObstacleFound = (d != 0.0f) && pContact;

#ifndef _RELEASE
	if (bObstacleFound && (g_pGameCVars->g_spectacularKill.debug > 1))
	{
		const float fTime = 6.0f;

		// visually show why it failed
		IPersistantDebug* pPersistantDebug = BeginPersistantDebug();

		// Draw a capsule using a cylinder and two spheres
		const ColorF debugColor = Col_Coral * ColorF(1.0f, 1.0f, 1.0f, 0.6f);
		pPersistantDebug->AddCylinder(capsPrim.center, capsPrim.axis, capsPrim.r, capsPrim.hh * 2.0f, debugColor, fTime);
		pPersistantDebug->AddSphere(capsPrim.center - (capsPrim.axis * capsPrim.hh), capsPrim.r, debugColor, fTime);
		pPersistantDebug->AddSphere(capsPrim.center + (capsPrim.axis * capsPrim.hh), capsPrim.r, debugColor, fTime);

		for (int i = 0; i < (int)d; ++i)
		{
		// Draw the collision point
			geom_contact collisionData(pContact[i]);
		pPersistantDebug->AddCone(collisionData.pt, -collisionData.n, 0.1f, 0.8f, Col_Red, fTime + 2.0f);
	}
	}
#endif

	return bObstacleFound;
}