Skip to content

Commit 0b6c47b

Browse files
committed
Use center of screen as origin for transformations
1 parent 192986f commit 0b6c47b

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

screenlayouts/build.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@ pub fn get_screen_layouts() -> Vec<[[f32; 9]; 4]> {
1515
let mut layouts = Vec::new();
1616

1717
{
18-
let half_width = HOST_SCREEN_WIDTH as f32 / 2.0;
19-
let half_width_scale = half_width / GUEST_SCREEN_WIDTH as f32;
20-
let half_height = GUEST_SCREEN_HEIGHT as f32 * half_width_scale;
21-
let half_height_space = HOST_SCREEN_HEIGHT as f32 - half_height;
22-
let mtx = Matrix3::new_translation(&Vector2::new(0.0, half_height_space / 2.0)) * Matrix3::new_scaling(half_width_scale);
23-
let b_trans = Matrix3::new_translation(&Vector2::new(half_width, 0.0));
18+
let guest_width = HOST_SCREEN_WIDTH as f32 / 2.0;
19+
let width_scale = guest_width / GUEST_SCREEN_WIDTH as f32;
20+
let guest_height = GUEST_SCREEN_HEIGHT as f32 * width_scale;
21+
let height_remaining_space = HOST_SCREEN_HEIGHT as f32 - guest_height;
22+
let mtx = Matrix3::new_translation(&Vector2::new(0.0, height_remaining_space / 2.0))
23+
* Matrix3::new_translation(&Vector2::new(guest_width / 2.0, guest_height / 2.0))
24+
* Matrix3::new_scaling(width_scale);
25+
let b_trans = Matrix3::new_translation(&Vector2::new(guest_width, 0.0));
2426

2527
layouts.push([mtx, b_trans * mtx]);
2628
}
@@ -30,7 +32,9 @@ pub fn get_screen_layouts() -> Vec<[[f32; 9]; 4]> {
3032
let full_height_scale = HOST_SCREEN_HEIGHT as f32 / GUEST_SCREEN_WIDTH as f32;
3133
let guest_height = GUEST_SCREEN_HEIGHT as f32 * full_height_scale;
3234
let half_width_space = half_width - guest_height;
33-
let mtx = Matrix3::new_translation(&Vector2::new(half_width_space, HOST_SCREEN_HEIGHT as f32)) * Matrix3::new_rotation(PI + PI / 2.0) * Matrix3::new_scaling(full_height_scale);
35+
let mtx = Matrix3::new_translation(&Vector2::new(guest_height / 2.0 + half_width_space, HOST_SCREEN_HEIGHT as f32 / 2.0))
36+
* Matrix3::new_rotation(PI + PI / 2.0)
37+
* Matrix3::new_scaling(full_height_scale);
3438
let b_trans = Matrix3::new_translation(&Vector2::new(guest_height, 0.0));
3539

3640
layouts.push([mtx, b_trans * mtx]);
@@ -43,8 +47,9 @@ pub fn get_screen_layouts() -> Vec<[[f32; 9]; 4]> {
4347
let guest_bottom_scale = width_remaining_space / GUEST_SCREEN_WIDTH as f32;
4448
let guest_bottom_height = GUEST_SCREEN_HEIGHT as f32 * guest_bottom_scale;
4549
let height_remaining_space = HOST_SCREEN_HEIGHT as f32 - guest_bottom_height;
46-
let top_mtx = Matrix3::new_scaling(full_height_scale);
47-
let bottom_mtx = Matrix3::new_translation(&Vector2::new(guest_top_width, height_remaining_space / 2.0)) * Matrix3::new_scaling(guest_bottom_scale);
50+
let top_mtx = Matrix3::new_translation(&Vector2::new(guest_top_width / 2.0, HOST_SCREEN_HEIGHT as f32 / 2.0)) * Matrix3::new_scaling(full_height_scale);
51+
let bottom_mtx =
52+
Matrix3::new_translation(&Vector2::new(width_remaining_space / 2.0 + guest_top_width, guest_bottom_height / 2.0 + height_remaining_space / 2.0)) * Matrix3::new_scaling(guest_bottom_scale);
4853

4954
layouts.push([top_mtx, bottom_mtx]);
5055
}
@@ -53,7 +58,7 @@ pub fn get_screen_layouts() -> Vec<[[f32; 9]; 4]> {
5358
let full_height_scale = HOST_SCREEN_HEIGHT as f32 / GUEST_SCREEN_HEIGHT as f32;
5459
let guest_top_width = GUEST_SCREEN_WIDTH as f32 * full_height_scale;
5560
let width_remaining_space = HOST_SCREEN_WIDTH as f32 - guest_top_width;
56-
let top_mtx = Matrix3::new_translation(&Vector2::new(width_remaining_space / 2.0, 0.0)) * Matrix3::new_scaling(full_height_scale);
61+
let top_mtx = Matrix3::new_translation(&Vector2::new(guest_top_width / 2.0 + width_remaining_space / 2.0, HOST_SCREEN_HEIGHT as f32 / 2.0)) * Matrix3::new_scaling(full_height_scale);
5762

5863
layouts.push([top_mtx, Matrix3::zeros()]);
5964
}

src/screen_layouts.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ impl ScreenLayout {
1818

1919
pub fn new(index: usize, swap: bool) -> Self {
2020
const GUEST_DISPLAY_DIM_MTX: [[f32; 3]; 4] = [
21-
[0.0, 0.0, 1.0],
22-
[DISPLAY_WIDTH as f32, 0.0, 1.0],
23-
[DISPLAY_WIDTH as f32, DISPLAY_HEIGHT as f32, 1.0],
24-
[0.0, DISPLAY_HEIGHT as f32, 1.0],
21+
[-(DISPLAY_WIDTH as f32 / 2.0), -(DISPLAY_HEIGHT as f32 / 2.0), 1.0],
22+
[DISPLAY_WIDTH as f32 / 2.0, -(DISPLAY_HEIGHT as f32 / 2.0), 1.0],
23+
[DISPLAY_WIDTH as f32 / 2.0, DISPLAY_HEIGHT as f32 / 2.0, 1.0],
24+
[-(DISPLAY_WIDTH as f32 / 2.0), DISPLAY_HEIGHT as f32 / 2.0, 1.0],
2525
];
2626
let a_mtx = &SCREEN_LAYOUTS[index][if swap { 1 } else { 0 }];
2727
let b_mtx = &SCREEN_LAYOUTS[index][if swap { 0 } else { 1 }];
@@ -87,6 +87,6 @@ impl ScreenLayout {
8787
pub fn normalize_touch_points(&self, x: i16, y: i16) -> (i16, i16) {
8888
let mut touch_points = [x as f32, y as f32, 1.0];
8989
unsafe { math::neon::matvec3_neon(self.get_bottom_inverse_mtx().as_ptr() as _, touch_points.as_ptr() as _, touch_points.as_mut_ptr() as _) };
90-
(touch_points[0] as i16, touch_points[1] as i16)
90+
(touch_points[0] as i16 + DISPLAY_WIDTH as i16 / 2, touch_points[1] as i16 + DISPLAY_HEIGHT as i16 / 2)
9191
}
9292
}

0 commit comments

Comments
 (0)