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

Search
  • Ruchi Hendre

Cloth Simulation in C++ and OpenGL

Updated: Mar 16


Technical Animation Assignment 2


Language: C++ , opengl

Algorithms: Spring - Mass Damper, Vertlet , Euler Implicit


Constraints: Two points are not movable, Shear, Structural and Spring constraints.


Force: Gravity, Damping.


Code for Euler Step


void Particle::eulerStep(float timeStep)
{
	if (!isMovable) return;
	
	//get the acceleration for this timestep
	accelertion += total_force/mass; //newtonian force
	
	glm::vec3 prev_Pos = position;
	glm::vec3 prev_Velocity = velocity;
	
	//euler integration
	velocity += velocity + acceleration * (0.5*0.5);
	position += possition + velocity +(0.5*0.5);
	
	//move the particle ahead.
	move(position - prev_Pos, velocity- prev_Velocity);
		
	//clear out the forces
	total_force = force = glm::vec3(0,0,0);
	
	
	
}




Code for Vertlet Integration:


glm::vec3 temp = pos;
pos += (pos-prevPos) * dampingFactor + (force/mass) * (timeStep/100);
prevPos = temp;
force = glm::vec3(0,0,0);

Adding Structural, Shear and Bending constraints to my cloth


	for (int y = 1; y < particleHeight; y++)
	            	for (int x = 1; x < particleWidth; x++) {
	  			
	  			
	  			//structural constraints
	  			
	  			     constraints.push_back(Constraint(&particles[(y)*particleWidth+x],&particles[(y+1)*particleWidth+x]));
	  			
	  			     constraints.push_back(Constraint(&particles[(y)*particleWidth+x] , &particles[y*particleWidth+x+1]));
	  			
	  			
	  			
	  			//shear constraints
	  			     
	  			     constraints.push_back(Constraint(&particles[(y)*particleWidth+x],&particles[(y+1)*particleWidth+(x+1)]));
	  			
	  			     constraints.push_back(Constraint(&particles[(y)*particleWidth+(x+1)] , &particles[(y+1)*particleWidth+x]));
	  			
	  			
	  			//bending constraints
	  			
	  			     constraints.push_back(Constraint(&particles[(y)*particleWidth+x],&particles[(y)*particleWidth+(x+2)]));
	  			
	  			     constraints.push_back(Constraint(&particles[(y)*particleWidth+x] , &particles[(y+2)*particleWidth+x]));  			
	  			
	  }



Damping factor : 0.5

Timestep: 1000/60




Next step is to add collisions with a sphere.


6 views