From fc436f6f9fea674f4d76b593366bc74b8f827339 Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Mon, 2 Mar 2015 17:16:56 -0500 Subject: [PATCH] #1233 Correctly handle homogeneous components in transformation matrices --- src/transform.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/transform.cc b/src/transform.cc index c86f0301..2f7a2a89 100644 --- a/src/transform.cc +++ b/src/transform.cc @@ -168,12 +168,16 @@ AbstractNode *TransformModule::instantiate(const Context *ctx, const ModuleInsta { ValuePtr v = c.lookup_variable("m"); if (v->type() == Value::VECTOR) { + Matrix4d rawmatrix = Matrix4d::Identity(); for (int i = 0; i < 16; i++) { size_t x = i / 4, y = i % 4; if (y < v->toVector().size() && v->toVector()[y].type() == Value::VECTOR && x < v->toVector()[y].toVector().size()) - v->toVector()[y].toVector()[x].getDouble(node->matrix(y, x)); + v->toVector()[y].toVector()[x].getDouble(rawmatrix(y, x)); } + double w = rawmatrix(3,3); + if (w != 1.0) node->matrix = rawmatrix / w; + else node->matrix = rawmatrix; } }