aboutsummaryrefslogtreecommitdiff
path: root/demo/scenes/rigidrotation.h
blob: 6d2e1d744578113a4bd260e572f4a3d77d8abf8a (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
57
58
class RigidRotation : public Scene
{
public:

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

	void Initialize()
	{
		float radius = 0.1f;

		float dimx = 3.0f;
		float dimy = 3.0f;
		float dimz = 3.0f;

		CreateParticleShape(GetFilePathByPlatform("../../data/box.ply").c_str(), Vec3(0.0f, 1.0f, 0.0f), Vec3(dimx, dimy, dimz)*radius, 0.0f, radius, Vec3(0.0f), 1.0f, true, 1.0f, 0, true, 0.0f, 0.0f, 0.0f);

		g_params.radius = radius;
		g_params.gravity[1] = 0;

		g_params.numIterations = 1;
		g_numSubsteps = 3;

		g_pause = true;

		g_drawBases = true;
	}

	void Update()
	{
		if (g_frame == 0)
		{
			// rotate particles by 90 degrees
			Vec3 lower, upper;
			GetParticleBounds(lower, upper);

			Vec3 center = (lower + upper)*0.5f;

			//Matrix44 rotation = RotationMatrix(DegToRad(40.0f), Vec3(0.0f, 0.0f, 1.0f));

			for (int i = 0; i < int(g_buffers->positions.size()); ++i)
			{
				Vec3 delta = Vec3(g_buffers->positions[i]) - center;

				//delta = Vec3(rotation*Vec4(delta, 1.0f));

				//g_buffers->positions[i].x = center.x + delta.x;
				//g_buffers->positions[i].y = center.y + delta.y;
				//g_buffers->positions[i].z = center.z + delta.z;

				g_buffers->velocities[i] = Cross(delta, Vec3(0.0f, 0.0f, 1.0f))*10.0f;
			}
		}
	}
};