cloth2
diff src/main.cc @ 1:dc15b741486c
exploding cloth
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Mon, 11 Jan 2016 20:24:13 +0200 |
parents | ef0c22554406 |
children | b4b8f736332b |
line diff
1.1 --- a/src/main.cc Mon Jan 11 16:51:16 2016 +0200 1.2 +++ b/src/main.cc Mon Jan 11 20:24:13 2016 +0200 1.3 @@ -19,7 +19,7 @@ 1.4 void mouse(int bn, int st, int x, int y); 1.5 void motion(int x, int y); 1.6 1.7 -float cam_theta, cam_phi, cam_dist = 8; 1.8 +float cam_theta, cam_phi = 25, cam_dist = 10; 1.9 1.10 Cloth cloth; 1.11 1.12 @@ -55,13 +55,17 @@ 1.13 //glEnable(GL_LIGHTING); 1.14 glEnable(GL_LIGHT0); 1.15 1.16 - cloth.create_rect(32, 32, 10, 10); 1.17 + cloth.create_rect(4, 4, 10, 10); 1.18 1.19 Matrix4x4 xform = Matrix4x4(1, 0, 0, 0, 1.20 0, 1, 0, 0, 1.21 0, 0, 1, 0, 1.22 - 0, 1, 0, 1); 1.23 + 0, 1, 1, 1); 1.24 cloth.transform(xform); 1.25 + cloth.set_mass(0.1); 1.26 + cloth.set_spring_constant(0.1); 1.27 + cloth.set_gravity(Vector3(0, -0.1, 0)); 1.28 + cloth.set_damping(0.1); 1.29 1.30 1.31 return true; 1.32 @@ -73,6 +77,14 @@ 1.33 1.34 void display() 1.35 { 1.36 + static unsigned int prev_upd; 1.37 + unsigned int msec = glutGet(GLUT_ELAPSED_TIME); 1.38 + 1.39 + if(!prev_upd) prev_upd = msec; 1.40 + float dt = (msec - prev_upd) / 1000.0f; 1.41 + 1.42 + cloth.step(dt); 1.43 + 1.44 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 1.45 1.46 glMatrixMode(GL_MODELVIEW);