Commit 452c30d9 authored by Viktor Lidholt's avatar Viktor Lidholt

Adds perspective projection to Node3D in sprites

parent 91115929
...@@ -20,12 +20,25 @@ class Node3D extends Node { ...@@ -20,12 +20,25 @@ class Node3D extends Node {
invalidateTransformMatrix(); invalidateTransformMatrix();
} }
double _projectionDepth = 500.0;
double get projectionDepth => _projectionDepth;
set projectionDepth(double projectionDepth) {
_projectionDepth = projectionDepth;
invalidateTransformMatrix();
}
Matrix4 computeTransformMatrix() { Matrix4 computeTransformMatrix() {
// Apply normal 2d transforms // Apply normal 2d transforms
Matrix4 matrix = super.computeTransformMatrix(); Matrix4 matrix = super.computeTransformMatrix();
// Apply perspective projection
matrix.translate(0.0, 0.0, 500.0); 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 // Rotate around x and y axis
matrix.rotateY(radians(_rotationY)); matrix.rotateY(radians(_rotationY));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment