©2019 by Ruchi Hendre - Past and Future works. Proudly created with Wix.com

Search
  • Ruchi Hendre

Cloth Collision with a Ball



Implemented collision of my spring mass system with a sphere.


Algorithm:

1. Find if the particle is inside the sphere.

2. If yes move it by the distance-radius.

3. Move the particle a little bit due to frictional forces. (Not Implemented Correctly)


GitHub link: https://github.com/rhendre/ClothSimulatior


Code :


void Sphere::collision(std::vector<Particle> *particles) {
	for (std::vector<Particle>::size_type i = 0; i < particles->size(); i++) {
		glm::vec3 v = (*particles)[i].position - center; //see the distance from the particles to the center of the sphere
		float distance = glm::length(v);
		if (distance < radius) {//if particle inside the sphere then put the particle in a normalized direction on the sphere
			(*particles)[i].position += glm::normalize(v) * (radius - distance);
			//correct it's distance due to frictional parameter more frictional points
			(*particles)[i].position += 0.5f;
		}
		
	}
}

5 views