Skip to content

Commit a5673b4

Browse files
committed
add hour hand and translation constant T_K
1 parent 67ccc92 commit a5673b4

File tree

1 file changed

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

1 file changed

+37
-12
lines changed

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

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,12 @@ fn draw_model(state: &State, view_proj: Mat4) {
244244

245245
let diffuse_colour = vec3!(1., 1., 1.);
246246

247+
// Translation constant. An observed but currently not well understood scaling
248+
// that is needed to make the numbers from the tutorial produce the expected
249+
// translation amounts.
250+
const T_K: f32 = 1./4.;
251+
252+
// Clock face
247253
{
248254
let model = Mat4::scale(vec3!(10., 10., 0.2));
249255

@@ -261,26 +267,45 @@ fn draw_model(state: &State, view_proj: Mat4) {
261267
}
262268
}
263269

270+
macro_rules! cube {
271+
($model_matrix: expr) => {{
272+
let model = $model_matrix;
273+
274+
textured_lit::apply_uniforms(
275+
textured_lit::VSParams {
276+
model,
277+
mvp: view_proj * model,
278+
diffuse_colour,
279+
},
280+
fs_params
281+
);
282+
283+
unsafe {
284+
sg::draw(CUBE_INDEX_START as Int, CUBE_INDEX_ONE_PAST_END as Int, 1);
285+
}
286+
}}
287+
}
288+
289+
// Hour markers
264290
for i in 0..12 {
265291
let angle = i as f32 * TAU / 12.;
266292

267293
let model =
268294
Mat4::rotation(Radians(angle), vec3!(z)) *
269-
Mat4::translate(vec3!(0., 1., 3./64.)) *
295+
Mat4::translate(vec3!(0., 4. * T_K, 0.25 * T_K)) *
270296
Mat4::scale(vec3!(0.5, 1., 0.1));
271297

272-
textured_lit::apply_uniforms(
273-
textured_lit::VSParams {
274-
model,
275-
mvp: view_proj * model,
276-
diffuse_colour,
277-
},
278-
fs_params
279-
);
298+
cube!(model)
299+
}
280300

281-
unsafe {
282-
sg::draw(CUBE_INDEX_START as Int, CUBE_INDEX_ONE_PAST_END as Int, 1);
283-
}
301+
// Hour hand
302+
{
303+
let model =
304+
Mat4::rotation(Radians(0.), vec3!(z)) *
305+
Mat4::translate(vec3!(0., 0.75 * T_K, 0.25 * T_K)) *
306+
Mat4::scale(vec3!(0.3, 2.5, 0.1));
307+
308+
cube!(model)
284309
}
285310
}
286311

0 commit comments

Comments
 (0)