提交 f1cc0efd 编写于 作者: V Viktor Lidholt

Merge pull request #437 from vlidholt/master

Refactors matrix handling in sprites
...@@ -102,7 +102,7 @@ class Node { ...@@ -102,7 +102,7 @@ class Node {
void set rotation(double rotation) { void set rotation(double rotation) {
assert(rotation != null); assert(rotation != null);
_rotation = rotation; _rotation = rotation;
_invalidateTransformMatrix(); invalidateTransformMatrix();
} }
/// The position of this node relative to its parent. /// The position of this node relative to its parent.
...@@ -113,7 +113,7 @@ class Node { ...@@ -113,7 +113,7 @@ class Node {
void set position(Point position) { void set position(Point position) {
assert(position != null); assert(position != null);
_position = position; _position = position;
_invalidateTransformMatrix(); invalidateTransformMatrix();
} }
/// The draw order of this node compared to its parent and its siblings. /// The draw order of this node compared to its parent and its siblings.
...@@ -147,7 +147,7 @@ class Node { ...@@ -147,7 +147,7 @@ class Node {
void set scale(double scale) { void set scale(double scale) {
assert(scale != null); assert(scale != null);
_scaleX = _scaleY = scale; _scaleX = _scaleY = scale;
_invalidateTransformMatrix(); invalidateTransformMatrix();
} }
/// The horizontal scale of this node relative its parent. /// The horizontal scale of this node relative its parent.
...@@ -158,7 +158,7 @@ class Node { ...@@ -158,7 +158,7 @@ class Node {
void set scaleX(double scaleX) { void set scaleX(double scaleX) {
assert(scaleX != null); assert(scaleX != null);
_scaleX = scaleX; _scaleX = scaleX;
_invalidateTransformMatrix(); invalidateTransformMatrix();
} }
/// The vertical scale of this node relative its parent. /// The vertical scale of this node relative its parent.
...@@ -169,7 +169,7 @@ class Node { ...@@ -169,7 +169,7 @@ class Node {
void set scaleY(double scaleY) { void set scaleY(double scaleY) {
assert(scaleY != null); assert(scaleY != null);
_scaleY = scaleY; _scaleY = scaleY;
_invalidateTransformMatrix(); invalidateTransformMatrix();
} }
/// A list of the children of this node. /// A list of the children of this node.
...@@ -264,10 +264,13 @@ class Node { ...@@ -264,10 +264,13 @@ class Node {
/// ///
/// Matrix4 matrix = myNode.transformMatrix; /// Matrix4 matrix = myNode.transformMatrix;
Matrix4 get transformMatrix { Matrix4 get transformMatrix {
if (_transformMatrix != null) { if (_transformMatrix == null) {
return _transformMatrix; _transformMatrix = computeTransformMatrix();
} }
return _transformMatrix;
}
Matrix4 computeTransformMatrix() {
double cx, sx, cy, sy; double cx, sx, cy, sy;
if (_rotation == 0.0) { if (_rotation == 0.0) {
...@@ -287,15 +290,15 @@ class Node { ...@@ -287,15 +290,15 @@ class Node {
} }
// Create transformation matrix for scale, position and rotation // Create transformation matrix for scale, position and rotation
_transformMatrix = new Matrix4(cy * _scaleX, sy * _scaleX, 0.0, 0.0, Matrix4 matrix = new Matrix4(cy * _scaleX, sy * _scaleX, 0.0, 0.0,
-sx * _scaleY, cx * _scaleY, 0.0, 0.0, -sx * _scaleY, cx * _scaleY, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0,
_position.x, _position.y, 0.0, 1.0); _position.x, _position.y, 0.0, 1.0);
return _transformMatrix; return matrix;
} }
void _invalidateTransformMatrix() { void invalidateTransformMatrix() {
_transformMatrix = null; _transformMatrix = null;
_invalidateToBoxTransformMatrix(); _invalidateToBoxTransformMatrix();
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册