aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/fparkan-render/src/cockpit_lighting.rs35
-rw-r--r--crates/fparkan-render/src/lib.rs1
2 files changed, 36 insertions, 0 deletions
diff --git a/crates/fparkan-render/src/cockpit_lighting.rs b/crates/fparkan-render/src/cockpit_lighting.rs
new file mode 100644
index 00000000..fa87397d
--- /dev/null
+++ b/crates/fparkan-render/src/cockpit_lighting.rs
@@ -0,0 +1,35 @@
+//! 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);
+ }
+}
diff --git a/crates/fparkan-render/src/lib.rs b/crates/fparkan-render/src/lib.rs
index 2c239061..8eaab4f9 100644
--- a/crates/fparkan-render/src/lib.rs
+++ b/crates/fparkan-render/src/lib.rs
@@ -2,6 +2,7 @@
//! Camera mathematics and graphics pipeline state.
pub mod cockpit_course;
+pub mod cockpit_lighting;
pub mod cockpit_radar;
pub mod designer_lighting;
pub mod water;