Skip to content

Commit 784b498

Browse files
committed
make the hands move continuously, by cheesing out a bit
1 parent a2458c4 commit 784b498

File tree

1 file changed

+12
-14
lines changed
  • basics/game-objects-and-scripts/src

1 file changed

+12
-14
lines changed

basics/game-objects-and-scripts/src/main.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ fn draw_model(state: &State, view_proj: Mat4) {
289289
},
290290
fs_params
291291
);
292-
292+
293293
unsafe {
294294
sg::draw($start_i as Int, ($end_i - $start_i) as Int, 1);
295295
}
@@ -322,23 +322,21 @@ fn draw_model(state: &State, view_proj: Mat4) {
322322
use std::time::SystemTime;
323323

324324
let (hour, minute, second) = match SystemTime::now().duration_since(SystemTime::UNIX_EPOCH) {
325-
Ok(n) => {
326-
let total_seconds = n.as_secs();
327-
328-
(
329-
(total_seconds / (60 * 60)) % 12,
330-
(total_seconds / 60) % 60,
331-
total_seconds % 60,
332-
)
333-
},
325+
// There's probably a better way to avoid f32 precision issues, but this
326+
// works, at least right now.
327+
Ok(n) => (
328+
((n / (60 * 60)).as_secs_f64() % 12.) as f32,
329+
((n / 60).as_secs_f64() % 60.) as f32,
330+
(n.as_secs_f64() % 60.) as f32,
331+
),
334332
// We don't really care about edges cases like this right now either.
335-
Err(_) => (0, 0, 0),
333+
Err(_) => (0., 0., 0.),
336334
};
337335

338336
// Hour hand
339337
{
340338
let model =
341-
Mat4::rotation(Radians(hour as f32 * -TAU / 12.), vec3!(z)) *
339+
Mat4::rotation(Radians(hour * -TAU / 12.), vec3!(z)) *
342340
Mat4::translate(vec3!(0., T_K, 0.35 * T_K)) *
343341
Mat4::scale(vec3!(0.3, 2.5, 0.1));
344342

@@ -348,7 +346,7 @@ fn draw_model(state: &State, view_proj: Mat4) {
348346
// Minute hand
349347
{
350348
let model =
351-
Mat4::rotation(Radians(minute as f32 * -TAU / 60.), vec3!(z)) *
349+
Mat4::rotation(Radians(minute * -TAU / 60.), vec3!(z)) *
352350
Mat4::translate(vec3!(0., 0.75 * T_K, 0.25 * T_K)) *
353351
Mat4::scale(vec3!(0.2, 4., 0.1));
354352

@@ -358,7 +356,7 @@ fn draw_model(state: &State, view_proj: Mat4) {
358356
// Second hand
359357
{
360358
let model =
361-
Mat4::rotation(Radians(second as f32 * -TAU / 60.), vec3!(z)) *
359+
Mat4::rotation(Radians(second * -TAU / 60.), vec3!(z)) *
362360
Mat4::translate(vec3!(0., 1.25 * T_K, 0.45 * T_K)) *
363361
Mat4::scale(vec3!(0.1, 5., 0.1));
364362

0 commit comments

Comments
 (0)