//! Lighting used by the two cockpit model views. use crate::LegacyIron3dEulerTransform; /// Additive RGB supplied by the cockpit camera in Terrain's color-only mode. pub const CAMERA_ADDITIVE: [f32; 3] = [0.0, 0.5, 0.0]; /// Per-channel floor used by CShade for the miniature. pub const LIGHTING_FLOOR: [f32; 3] = [40.0 / 255.0; 3]; /// World direction and intensity of the local lamps, preserving the repeated pair /// and the original direction lengths. pub fn lamps(orientation_radians: [f32; 3]) -> Option<[([f32; 3], f32); 4]> { let orientation = LegacyIron3dEulerTransform { translation: [0.0; 3], orientation_radians, }; // Terrain+0x2e4a0 receives both copies of the owner-local light pair. let direction = orientation.try_transform_scaled_point([-1.0, 1.0, -1.0], [1.0; 3])?; let primary = (direction, 0.25); let fill = (direction.map(|axis| -axis), 0.25 * 0.35); Some([primary, fill, primary, fill]) } #[cfg(test)] #[test] fn lamps_follow_the_model_and_keep_the_native_direction_length() { let hero = lamps([0.0; 3]).unwrap(); let primary = ([-1.0, 1.0, -1.0], 0.25); let fill = ([1.0, -1.0, 1.0], 0.0875); assert_eq!(hero, [primary, fill, primary, fill]); let bunker = lamps([0.0, 0.0, -1.6734]).unwrap(); for (actual, expected) in bunker[0].0.into_iter().zip([1.097175, 0.892305, -1.0]) { assert!((actual - expected).abs() < 0.0002); } }