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
95f5d8d7
Commit
95f5d8d7
authored
Jun 21, 2017
by
Alan
Committed by
Ian Hickson
Jun 21, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement Matrix4Tween.lerp() (#10829)
parent
3f3a3678
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
6 deletions
+38
-6
implicit_animations.dart
packages/flutter/lib/src/widgets/implicit_animations.dart
+15
-6
tween_test.dart
packages/flutter/test/animation/tween_test.dart
+23
-0
No files found.
packages/flutter/lib/src/widgets/implicit_animations.dart
View file @
95f5d8d7
...
...
@@ -111,12 +111,21 @@ class Matrix4Tween extends Tween<Matrix4> {
Matrix4
lerp
(
double
t
)
{
assert
(
begin
!=
null
);
assert
(
end
!=
null
);
// TODO(abarth): We should use [Matrix4.decompose] and animate the
// decomposed parameters instead of just animating the translation.
final
Vector3
beginT
=
begin
.
getTranslation
();
final
Vector3
endT
=
end
.
getTranslation
();
final
Vector3
lerpT
=
beginT
*(
1.0
-
t
)
+
endT
*
t
;
return
new
Matrix4
.
identity
()..
translate
(
lerpT
);
final
Vector3
beginTranslation
=
new
Vector3
.
zero
();
final
Vector3
endTranslation
=
new
Vector3
.
zero
();
final
Quaternion
beginRotation
=
new
Quaternion
.
identity
();
final
Quaternion
endRotation
=
new
Quaternion
.
identity
();
final
Vector3
beginScale
=
new
Vector3
.
zero
();
final
Vector3
endScale
=
new
Vector3
.
zero
();
begin
.
decompose
(
beginTranslation
,
beginRotation
,
beginScale
);
end
.
decompose
(
endTranslation
,
endRotation
,
endScale
);
final
Vector3
lerpTranslation
=
beginTranslation
*
(
1.0
-
t
)
+
endTranslation
*
t
;
// TODO(alangardner): Implement slerp for constant rotation
final
Quaternion
lerpRotation
=
(
beginRotation
.
scaled
(
1.0
-
t
)
+
endRotation
.
scaled
(
t
)).
normalized
();
final
Vector3
lerpScale
=
beginScale
*
(
1.0
-
t
)
+
endScale
*
t
;
return
new
Matrix4
.
compose
(
lerpTranslation
,
lerpRotation
,
lerpScale
);
}
}
...
...
packages/flutter/test/animation/tween_test.dart
View file @
95f5d8d7
...
...
@@ -5,6 +5,7 @@
import
'package:flutter_test/flutter_test.dart'
;
import
'package:flutter/animation.dart'
;
import
'package:flutter/widgets.dart'
;
import
'package:vector_math/vector_math_64.dart'
;
void
main
(
)
{
test
(
'Can chain tweens'
,
()
{
...
...
@@ -49,4 +50,26 @@ void main() {
expect
(
tween
.
lerp
(
0.5
),
equals
(
Rect
.
lerp
(
a
,
b
,
0.5
)));
expect
(
tween
,
hasOneLineDescription
);
});
test
(
'Matrix4Tween'
,
()
{
final
Matrix4
a
=
new
Matrix4
.
identity
();
final
Matrix4
b
=
a
.
clone
()..
translate
(
6.0
,
-
8.0
,
0.0
)..
scale
(
0.5
,
1.0
,
5.0
);
final
Matrix4Tween
tween
=
new
Matrix4Tween
(
begin:
a
,
end:
b
);
expect
(
tween
.
lerp
(
0.0
),
equals
(
a
));
expect
(
tween
.
lerp
(
1.0
),
equals
(
b
));
expect
(
tween
.
lerp
(
0.5
),
equals
(
a
.
clone
()..
translate
(
3.0
,
-
4.0
,
0.0
)..
scale
(
0.75
,
1.0
,
3.0
))
);
final
Matrix4
c
=
a
.
clone
()..
rotateZ
(
1.0
);
final
Matrix4Tween
rotationTween
=
new
Matrix4Tween
(
begin:
a
,
end:
c
);
expect
(
rotationTween
.
lerp
(
0.0
),
equals
(
a
));
expect
(
rotationTween
.
lerp
(
1.0
),
equals
(
c
));
expect
(
rotationTween
.
lerp
(
0.5
).
absoluteError
(
a
.
clone
()..
rotateZ
(
0.5
)
),
moreOrLessEquals
(
0.0
)
);
});
}
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