//! The constructor's local lamps, evaluated in the unrotated model's coordinates. /// Elevation of the preview camera, equivalent to the original model pitch. pub const ELEVATION: f32 = 0.5; /// RGB of each original directional lamp. pub const LIGHT_RGB: [f32; 3] = [2.0; 3]; /// Returns the two lamp directions with the inverse of the model's spin and pitch applied. #[must_use] pub fn light_directions(yaw: f64) -> [[f32; 3]; 2] { let (sin_yaw, cos_yaw) = yaw.sin_cos(); let (sin_elevation, cos_elevation) = ELEVATION.sin_cos(); let diagonal = std::f32::consts::FRAC_1_SQRT_2; // iron3d+0x9e780 supplies normalized (-1, 0, -1) and (1, 0, -1). [-diagonal, diagonal].map(|x| { let tilted_x = cos_elevation * x - sin_elevation * diagonal; let z = -sin_elevation * x - cos_elevation * diagonal; [tilted_x * cos_yaw as f32, -tilted_x * sin_yaw as f32, z] }) } #[cfg(test)] mod tests { use super::*; #[test] fn lamps_match_the_native_light_setter_before_and_after_rotation() { // Terrain.dll+0x4c4d0 with the preview's mode-2 transform. for (yaw, expected) in [ ( 0.0, [[-0.959550, 0.0, -0.281539], [0.281539, 0.0, -0.959550]], ), ( 0.75, [ [-0.702092, 0.654066, -0.281539], [0.205999, -0.191908, -0.959550], ], ), ] { for (actual, expected) in light_directions(yaw) .into_iter() .flatten() .zip(expected.into_iter().flatten()) { assert!((actual - expected).abs() < 1.0e-6, "{actual} != {expected}"); } } } }