Add hackery y-flip to correct car direction

This commit is contained in:
hodasemi 2023-01-16 07:32:32 +01:00
parent 42eb47836f
commit 0e446641c5

View file

@ -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<f32>, orientation: [Vector3<f32>; 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<f32>) -> Matrix4<f32> {
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),
)
}