# T3 Calcuate acceleration and velocity

#### Find velocity calcuation

Search **\[TODO 3]** in ClothSim.cpp

You should be able to find the following

```cpp
void ClothSim::forwardEulerIntegration(float dt) {

	// [TODO 3]: calculate acceleration and velocities using forces
	for (int v = 0; v < mesh->vertices.size(); v++) {
		glm::vec3 acceleration = forces[v] * 1.0f; // mass

		// 3.1 update velocity using acceleration
		// velocities[v] = damping_factor * velocities[v] + ??;

		// 3.2 update position using velocity
		// mesh->vertices[v].pos = ??;
	}
}
```

#### Complete 3.1

uncomment the line under 3.1 and

add the scalar product of acceleration vector and duration dt to the vertex velocity

#### Complete 3.2

uncomment the line under 3.2 and&#x20;

update the vertex position by adding the scalar product of the vertex velocity and duration dt

### Build and Run

Build your program, run it.

Press the **Space Bar**, you should be able to see your cloth falls downward and dissappear, as there are no ground collision detection to prevent the cloth fall further.

We can add boundary checking after updating the position to prevent it falling through

```cpp
		// add ground checking
		if (mesh->vertices[v].pos.y < -5.0)
			mesh->vertices[v].pos.y = -5.0;
```

You are going to see the following:

<figure><img src="https://3464970502-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3JUKGJZ67JX02QZdPhsy%2Fuploads%2F1xOTOUqQJOxk44ucqAJT%2Fimage.png?alt=media&#x26;token=e5a15309-0246-4701-8e27-04021c1e46fc" alt="" width="375"><figcaption></figcaption></figure>
