Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
d5777b6a
Unverified
Commit
d5777b6a
authored
Oct 18, 2018
by
Stanislav Baranov
Committed by
GitHub
Oct 18, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement correct orthographic projection (#22985)
parent
bbe8cf60
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
5 deletions
+26
-5
box.dart
packages/flutter/lib/src/rendering/box.dart
+21
-1
transform_test.dart
packages/flutter/test/rendering/transform_test.dart
+5
-4
No files found.
packages/flutter/lib/src/rendering/box.dart
View file @
d5777b6a
...
...
@@ -1989,6 +1989,9 @@ abstract class RenderBox extends RenderObject {
/// Convert the given point from the global coordinate system in logical pixels
/// to the local coordinate system for this box.
///
/// This method will un-project the point from the screen onto the widget,
/// which makes it different from [MatrixUtils.transformPoint].
///
/// If the transform from global coordinates to local coordinates is
/// degenerate, this function returns [Offset.zero].
///
...
...
@@ -1998,11 +2001,28 @@ abstract class RenderBox extends RenderObject {
///
/// This method is implemented in terms of [getTransformTo].
Offset
globalToLocal
(
Offset
point
,
{
RenderObject
ancestor
})
{
// We want to find point (p) that corresponds to a given point on the
// screen (s), but that also physically resides on the local render plane,
// so that it is useful for visually accurate gesture processing in the
// local space. For that, we can't simply transform 2D screen point to
// the 3D local space since the screen space lacks the depth component |z|,
// and so there are many 3D points that correspond to the screen point.
// We must first unproject the screen point onto the render plane to find
// the true 3D point that corresponds to the screen point.
// We do orthogonal unprojection after undoing perspective, in local space.
// The render plane is specified by renderBox offset (o) and Z axis (n).
// Unprojection is done by finding the intersection of the view vector (d)
// with the local X-Y plane: (o-s).dot(n) == (p-s).dot(n), (p-s) == |z|*d.
final
Matrix4
transform
=
getTransformTo
(
ancestor
);
final
double
det
=
transform
.
invert
();
if
(
det
==
0.0
)
return
Offset
.
zero
;
return
MatrixUtils
.
transformPoint
(
transform
,
point
);
final
Vector3
n
=
Vector3
(
0.0
,
0.0
,
1.0
);
final
Vector3
i
=
transform
.
perspectiveTransform
(
Vector3
(
0.0
,
0.0
,
0.0
));
final
Vector3
d
=
transform
.
perspectiveTransform
(
Vector3
(
0.0
,
0.0
,
1.0
))
-
i
;
final
Vector3
s
=
transform
.
perspectiveTransform
(
Vector3
(
point
.
dx
,
point
.
dy
,
0.0
));
final
Vector3
p
=
s
-
d
*
(
n
.
dot
(
s
)
/
n
.
dot
(
d
));
return
Offset
(
p
.
x
,
p
.
y
);
}
/// Convert the given point from the local coordinate system for this box to
...
...
packages/flutter/test/rendering/transform_test.dart
View file @
d5777b6a
...
...
@@ -143,10 +143,11 @@ void main() {
expect
(
round
(
inner
.
globalToLocal
(
const
Offset
(
25.0
,
50.0
))),
equals
(
const
Offset
(
25.0
,
50.0
)));
expect
(
inner
.
globalToLocal
(
const
Offset
(
25.0
,
17.0
)).
dy
,
greaterThan
(
0.0
));
expect
(
inner
.
globalToLocal
(
const
Offset
(
25.0
,
17.0
)).
dy
,
lessThan
(
10.0
));
expect
(
inner
.
globalToLocal
(
const
Offset
(
25.0
,
73.0
)).
dy
,
greaterThan
(
90.0
));
expect
(
inner
.
globalToLocal
(
const
Offset
(
25.0
,
73.0
)).
dy
,
lessThan
(
100.0
));
expect
(
inner
.
globalToLocal
(
const
Offset
(
25.0
,
17.0
)).
dy
,
equals
(-
inner
.
globalToLocal
(
const
Offset
(
25.0
,
73.0
)).
dy
));
},
skip:
true
);
// https://github.com/flutter/flutter/issues/6080
expect
(
inner
.
globalToLocal
(
const
Offset
(
25.0
,
83.0
)).
dy
,
greaterThan
(
90.0
));
expect
(
inner
.
globalToLocal
(
const
Offset
(
25.0
,
83.0
)).
dy
,
lessThan
(
100.0
));
expect
(
round
(
inner
.
globalToLocal
(
const
Offset
(
25.0
,
17.0
))).
dy
,
equals
(
100
-
round
(
inner
.
globalToLocal
(
const
Offset
(
25.0
,
83.0
))).
dy
));
});
test
(
'RenderTransform - perspective - localToGlobal'
,
()
{
RenderBox
inner
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment