4545static const float pi = 3 .1415926536f ;
4646static const float deg2rad = pi / 180 .f;
4747static const float rad2deg = 180 .f / pi;
48- static const float screen_z = 312.5 ;
48+ static const float default_screen_z = 312.5 ;
4949static const char *ambient_plane_key = " _aegi_perspective_ambient_plane" ;
5050
5151static const int BUTTON_ID_BASE = 1400 ;
@@ -129,6 +129,10 @@ std::vector<Vector2D> MakeRect(Vector2D a, Vector2D b) {
129129 });
130130}
131131
132+ float VisualToolPerspective::screenZ () const {
133+ return default_screen_z * script_res.Y () / layout_res.Y ();
134+ }
135+
132136void VisualToolPerspective::AddTool (std::string command_name, VisualToolPerspectiveSetting setting) {
133137 cmd::Command *command = cmd::get (command_name);
134138 int icon_size = OPT_GET (" App/Toolbar Icon Size" )->GetInt ();
@@ -333,7 +337,7 @@ void VisualToolPerspective::Draw() {
333337 // Transform grid
334338 gl.SetOrigin (FromScriptCoords (org));
335339 gl.SetScale (100 * video_size / script_res);
336- gl.SetRotation (angle_x, angle_y, angle_z);
340+ gl.SetRotation (angle_x, angle_y, angle_z, script_res. Y () / layout_res. Y () );
337341 gl.SetScale (fsc);
338342 gl.SetShear (fax, fay);
339343 Vector2D glScale = (bbox.second .Y () - bbox.first .Y ()) * Vector2D (1 , 1 ) / spacing / 4 ;
@@ -593,7 +597,7 @@ bool VisualToolPerspective::InnerToText() {
593597 // with the following coefficients.
594598 float a = (1 - z1) * (1 - z3);
595599 Vector2D b = z1 * v1 + z3 * v3 - z1 * z3 * (v1 + v3);
596- float c = z1 * z3 * v1.Dot (v3) + (z1 - 1 ) * (z3 - 1 ) * screen_z * screen_z ;
600+ float c = z1 * z3 * v1.Dot (v3) + (z1 - 1 ) * (z3 - 1 ) * screenZ () * screenZ () ;
597601
598602 // Our default value for t, which would put \org at the center of the quad.
599603 // We'll try to find a value for \org that's as close as possible to it.
@@ -637,10 +641,10 @@ bool VisualToolPerspective::InnerToText() {
637641 q2 = q2 - org;
638642 q3 = q3 - org;
639643
640- Vector3D r0 = Vector3D (q0, screen_z );
641- Vector3D r1 = z1 * Vector3D (q1, screen_z );
642- Vector3D r2 = (z1 + z3 - 1 ) * Vector3D (q2, screen_z );
643- Vector3D r3 = z3 * Vector3D (q3, screen_z );
644+ Vector3D r0 = Vector3D (q0, screenZ () );
645+ Vector3D r1 = z1 * Vector3D (q1, screenZ () );
646+ Vector3D r2 = (z1 + z3 - 1 ) * Vector3D (q2, screenZ () );
647+ Vector3D r3 = z3 * Vector3D (q3, screenZ () );
644648 std::vector<Vector3D> r ({r0, r1, r2, r3});
645649
646650 // Find the z coordinate of the point projecting to the origin
@@ -650,9 +654,9 @@ bool VisualToolPerspective::InnerToText() {
650654 Solve2x2 (side0.X (), side1.X (), side0.Y (), side1.Y (), -r0.X (), -r0.Y (), orgla0, orgla1);
651655 float orgz = (r0 + orgla0 * side0 + orgla1 * side1).Z ();
652656
653- // Normalize so the origin has z=screen_z , and move the screen plane to z=0
657+ // Normalize so the origin has z=screenZ , and move the screen plane to z=0
654658 for (int i = 0 ; i < 4 ; i++)
655- r[i] = r[i] * screen_z / orgz - Vector3D (0 , 0 , screen_z );
659+ r[i] = r[i] * screenZ () / orgz - Vector3D (0 , 0 , screenZ () );
656660
657661 // Find the rotations
658662 Vector3D n = (r[1 ] - r[0 ]).Cross (r[3 ] - r[0 ]);
@@ -827,7 +831,7 @@ void VisualToolPerspective::TextToPersp() {
827831 q = q.RotateX (-angle_x * deg2rad);
828832 q = q.RotateY (angle_y * deg2rad);
829833 // Project
830- q = (screen_z / (q.Z () + screen_z )) * q;
834+ q = (screenZ () / (q.Z () + screenZ () )) * q;
831835 // Move to origin
832836 Vector2D r = q.XY () + org;
833837 inner_corners[i]->pos = FromScriptCoords (r);
0 commit comments