Mercurial > repos > public > sbplib
comparison +anim/animate.m @ 133:43f8df3595cf
Prepared for dynamic workload in animation.
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Fri, 05 Feb 2016 11:29:19 +0100 |
parents | 6ec2248b83c4 |
children | 2fe13db674da |
comparison
equal
deleted
inserted
replaced
132:6ec2248b83c4 | 133:43f8df3595cf |
---|---|
17 | 17 |
18 time_modifier_bound = time_modifier; | 18 time_modifier_bound = time_modifier; |
19 dTau_target = 1/target_frame_rate; % Real time between frames | 19 dTau_target = 1/target_frame_rate; % Real time between frames |
20 | 20 |
21 rs = util.ReplaceableString(); | 21 rs = util.ReplaceableString(); |
22 rs.appendFormat(' tau: %d\n'); | 22 rs.appendFormat(' tau: %d\n'); |
23 rs.appendFormat(' target tau: %d\n'); | 23 rs.appendFormat(' target tau: %d\n'); |
24 rs.appendFormat(' Target fps: %.2f\n'); | 24 rs.appendFormat(' Target fps: %.2f\n'); |
25 rs.appendFormat(' Actual fps: %.2f\n'); | 25 rs.appendFormat(' Actual fps: %.2f\n'); |
26 | 26 rs.appendFormat('Target time_modifier: %d\n'); |
27 frameId = 0; | 27 rs.appendFormat('actual time_modifier: %d\n'); |
28 NframeAvg = 20; | |
29 frameTimes = ones(1,NframeAvg); | |
30 | 28 |
31 animation_start = tic(); | 29 animation_start = tic(); |
32 prevTau = 0; | 30 prevTau = 0; |
33 targetTau = 0; | 31 targetTau = 0; |
32 tauFrameStart = -dTau_target; | |
34 t = F(tstart); | 33 t = F(tstart); |
35 | 34 |
36 while t < tend | 35 while t < tend |
37 % Sleep until the frame should start | 36 % Sleep until the frame should start |
38 pause(targetTau-toc(animation_start)); | 37 pause(targetTau-toc(animation_start)); |
39 tauFrameStart = targetTau; | 38 tau = toc(animation_start); |
39 dTau = tau - tauFrameStart; | |
40 | |
41 % Calculate error in tau | |
42 e_Tau = tau - targetTau; | |
43 | |
44 % Regulate time_modifier based on e_Tau | |
45 % time_modifier = min(time_modifier_bound, max(0.5, abs(1-e_Tau/dTau)) * time_modifier); | |
46 | |
47 % Mark the start of the frame | |
48 tauFrameStart = tau; | |
40 | 49 |
41 dt_target = dTau_target*time_modifier; % Targeted simulation time between frames | 50 dt_target = dTau_target*time_modifier; % Targeted simulation time between frames |
42 | 51 |
43 t_prev = t; | 52 t_prev = t; |
44 t = F(t + dt_target); % Run simulation | 53 t = F(t + dt_target); % Run simulation |
45 | 54 |
46 | |
47 % Calculate when this frame should end and the next start. (this depends on what simulation time we ended up on) | 55 % Calculate when this frame should end and the next start. (this depends on what simulation time we ended up on) |
48 dt = t-t_prev; | 56 dt = t-t_prev; |
49 targetTau = targetTau + dt/time_modifier; | 57 % targetTau = targetTau + dt/time_modifier; |
58 targetTau = targetTau + dTau_target; | |
50 | 59 |
51 % Update information about this frame | 60 % Update information about this frame |
52 tau = toc(animation_start); | 61 tau = toc(animation_start); |
53 rs.updateParam(tau, targetTau, 1/dTau_target, 1/(targetTau-tauFrameStart)); | 62 rs.updateParam(tau, targetTau, 1/dTau_target, 1/dTau, time_modifier_bound, time_modifier); |
54 end | 63 end |
55 | 64 |
56 | 65 |
57 % Final time reporting | 66 % Final time reporting |
58 time_to_animate = toc(animation_start); | 67 time_to_animate = toc(animation_start); |