From 452c30d9fa1c156104723453781629d87cc2e03f Mon Sep 17 00:00:00 2001 From: Viktor Lidholt Date: Fri, 7 Aug 2015 12:43:34 -0700 Subject: [PATCH] Adds perspective projection to Node3D in sprites --- packages/flutter/example/game/lib/node3d.dart | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/packages/flutter/example/game/lib/node3d.dart b/packages/flutter/example/game/lib/node3d.dart index d98d471fad8..0f022c41df8 100644 --- a/packages/flutter/example/game/lib/node3d.dart +++ b/packages/flutter/example/game/lib/node3d.dart @@ -20,12 +20,25 @@ class Node3D extends Node { invalidateTransformMatrix(); } + double _projectionDepth = 500.0; + + double get projectionDepth => _projectionDepth; + + set projectionDepth(double projectionDepth) { + _projectionDepth = projectionDepth; + invalidateTransformMatrix(); + } + Matrix4 computeTransformMatrix() { // Apply normal 2d transforms Matrix4 matrix = super.computeTransformMatrix(); - - matrix.translate(0.0, 0.0, 500.0); + // Apply perspective projection + Matrix4 projection = new Matrix4(1.0, 0.0, 0.0, 0.0, + 0.0, 1.0, 0.0, 0.0, + 0.0, 0.0, 1.0, -1.0/_projectionDepth, + 0.0, 0.0, 0.0, 1.0); + matrix = matrix.multiply(projection); // Rotate around x and y axis matrix.rotateY(radians(_rotationY));