aboutsummaryrefslogtreecommitdiff
path: root/demo/scenes/granularpile.h
blob: d71c7a91779f1011f3aa6711f3a66739f0a94e47 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
class GranularPile : public Scene
{
public:

	GranularPile(const char* name) : Scene(name) {}

	virtual void Initialize()
	{
		// granular pile
		float radius = 0.075f;

		Vec3 lower(8.0f, 4.0f, 2.0f);

		CreateParticleShape(GetFilePathByPlatform("../../data/sphere.ply").c_str(), lower, 1.0f, 0.0f, radius, 0.0f, 0.f, true, 1.0f, NvFlexMakePhase(1, 0), true, 0.00f);
		g_numSolidParticles = g_buffers->positions.size();

		CreateParticleShape(GetFilePathByPlatform("../../data/sandcastle.obj").c_str(), Vec3(-2.0f, -radius*0.15f, 0.0f), 4.0f, 0.0f, radius*1.0001f, 0.0f, 1.0f, false, 0.0f, NvFlexMakePhase(0, eNvFlexPhaseSelfCollide), false, 0.00f);

		g_numSubsteps = 2;
	
		g_params.radius = radius;
		g_params.staticFriction = 1.0f;
		g_params.dynamicFriction = 0.5f;
		g_params.viscosity = 0.0f;
		g_params.numIterations = 12;
		g_params.particleCollisionMargin = g_params.radius*0.25f;	// 5% collision margin
		g_params.sleepThreshold = g_params.radius*0.25f;
		g_params.shockPropagation = 6.f;
		g_params.restitution = 0.2f;
		g_params.relaxationFactor = 1.f;
		g_params.damping = 0.14f;
		g_params.numPlanes = 1;
		
		// draw options
		g_drawPoints = true;		
		g_warmup = false;

		// hack, change the color of phase 0 particles to 'sand'		
		g_colors[0] = Colour(0.805f, 0.702f, 0.401f);		
	}

	void Update()
	{
		// launch ball after 3 seconds
		if (g_frame == 180)
		{
			for (int i=0; i < g_numSolidParticles; ++i)
			{
				g_buffers->positions[i].w = 0.9f;
				g_buffers->velocities[i] = Vec3(-15.0f, 0.0f, 0.0f);
			}
		}
	}
};