Skip to content

Commit 23e97c5

Browse files
committed
render: Update perspective projection matrix
ae3d5f4 (#19532) found the form of flash.geom.PerspectiveProjection toMatrix3D() method output. Update Ruffle's rendering matrix to follow the same.
1 parent 409f68d commit 23e97c5

File tree

1 file changed

+29
-19
lines changed

1 file changed

+29
-19
lines changed

render/wgpu/src/globals.rs

+29-19
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl Globals {
4545

4646
let projection_matrix = {
4747
// TODO: Here, just the fixed default value is used.
48-
// This should support variable values derived for each display object.
48+
// This should support .transform.perspectiveProjection of each display object.
4949
let field_of_view = 55.0;
5050

5151
let focal_length = {
@@ -54,31 +54,41 @@ impl Globals {
5454
f64::cos(rad) / f64::sin(rad)
5555
};
5656

57-
let perspective_projection = {
58-
let mut m = Matrix3D::IDENTITY;
59-
m.raw_data[0] = focal_length;
60-
m.raw_data[5] = focal_length;
61-
m.raw_data[10] = focal_length;
62-
m.raw_data[11] = 1.0;
63-
m.raw_data[14] = 0.0;
64-
m.raw_data[15] = 0.0;
65-
m
57+
let perspective_projection = Matrix3D {
58+
raw_data: [
59+
//
60+
focal_length,
61+
0.0,
62+
0.0,
63+
0.0,
64+
//
65+
0.0,
66+
focal_length,
67+
0.0,
68+
0.0,
69+
//
70+
0.0,
71+
0.0,
72+
1.0,
73+
1.0,
74+
//
75+
0.0,
76+
0.0,
77+
0.0,
78+
0.0,
79+
],
6680
};
81+
82+
// TODO: Consider PerspectiveProjection.projectionCenter.
83+
6784
let move_coord = {
6885
// AS3 places Viewpoint at (0, 0, -focalLength).
69-
7086
let mut m = Matrix3D::IDENTITY;
7187
m.raw_data[14] = focal_length;
72-
// TODO: Consider PerspectiveProjection.projectionCenter.
7388
m
7489
};
75-
let move_coord_back = {
76-
let mut m = Matrix3D::IDENTITY;
77-
m.raw_data[10] = 0.0;
78-
// TODO: Consider PerspectiveProjection.projectionCenter.
79-
m
80-
};
81-
move_coord_back * perspective_projection * move_coord
90+
91+
perspective_projection * move_coord
8292
};
8393

8494
let matrix = projection_matrix * view_matrix;

0 commit comments

Comments
 (0)