From 0e446641c5de26050ca7191f2f3c5b86a3bfdb9f Mon Sep 17 00:00:00 2001 From: hodasemi Date: Mon, 16 Jan 2023 07:32:32 +0100 Subject: [PATCH] Add hackery y-flip to correct car direction --- src/overlay/rfactor_data.rs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/overlay/rfactor_data.rs b/src/overlay/rfactor_data.rs index 59a69f4..16c61ee 100644 --- a/src/overlay/rfactor_data.rs +++ b/src/overlay/rfactor_data.rs @@ -1,5 +1,5 @@ use anyhow::Result; -use cgmath::{ortho, vec2, vec3, Deg, InnerSpace, Matrix4, Rad, Vector2, Vector3}; +use cgmath::{ortho, vec2, vec3, vec4, Deg, InnerSpace, Matrix4, Rad, Vector2, Vector3}; use rfactor_sm_reader::*; use vulkan_rs::prelude::*; @@ -69,14 +69,15 @@ impl RFactorData { write_log!(" =================== create RFactorData ==================="); let radar_extent = width as f32 * 0.075 * config.radar_scale; - let car_height = radar_extent * 0.2; - let car_width = car_height * 0.5; + let car_height = radar_extent * 0.15; + let car_width = car_height / 2.5; let radar_center = vec2( width as f32 / 2.0, - height as f32 / 2.0 + height as f32 * 0.25, + height as f32 / 2.0 - height as f32 * 0.25, ); - let ortho = ortho(0.0, width as f32, 0.0, height as f32, -1.0, 1.0); + let flip_y = matrix4_from_diagonal(vec3(1.0, -1.0, 1.0)); + let ortho = flip_y * ortho(0.0, width as f32, 0.0, height as f32, -1.0, 1.0); let start_time = Instant::now(); Ok(Self { @@ -379,7 +380,7 @@ impl CarPosition { fn new(position: Vector3, orientation: [Vector3; 3]) -> Self { Self { position, - rotation: Rad(orientation[2].x.atan2(orientation[2].y)), + rotation: Rad(orientation[2].x.atan2(orientation[2].z)), } } } @@ -392,3 +393,12 @@ impl Default for CarPosition { } } } + +const fn matrix4_from_diagonal(diagonal: Vector3) -> Matrix4 { + Matrix4::from_cols( + vec4(diagonal.x, 0.0, 0.0, 0.0), + vec4(0.0, diagonal.y, 0.0, 0.0), + vec4(0.0, 0.0, diagonal.z, 0.0), + vec4(0.0, 0.0, 0.0, 1.0), + ) +}