From d4413d7f58ffae57b2486409d9836d6a20b873c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Einar=20Johan=20T=2E=20S=C3=B8ma=CC=8Aen?= Date: Tue, 31 Jan 2012 16:59:09 +0100 Subject: [PATCH] MATH: Add in the inverse functions from Portalib3d --- math/matrix4.cpp | 27 +++++++++++++++++++++++++++ math/matrix4.h | 4 +++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/math/matrix4.cpp b/math/matrix4.cpp index ba2e21d887a..572580f54f7 100644 --- a/math/matrix4.cpp +++ b/math/matrix4.cpp @@ -66,5 +66,32 @@ void Matrix<4, 4>::translate(const Vector3d &vec) { operator()(2, 3) += v.z(); } +// The following functions are adapted from Portalib3d, which no longer is +// available on the net, but was used in the iconoclast-project: +// http://code.google.com/p/iconoclast/ +// Original copyright notice (license.txt was not supplied in iconoclast, +// but should match our LGPL-license): +// Author: Brett Porter +// Email: brettporter@yahoo.com +// Website: http://rsn.gamedev.net/pl3d +// Copyright (C)2000, 2001, Brett Porter. All Rights Reserved. +// This source code is released under the LGPL. See license.txt for details. + +void Matrix<4, 4>::inverseTranslate(Vector3d *v) { + v->x() = v->x() - getValue(0, 3); + v->y() = v->y() - getValue(1, 3); + v->z() = v->z() - getValue(2, 3); +} + +void Matrix<4, 4>::inverseRotate(Vector3d *v) { + Vector3d temp; + + temp.x() = v->x() * getValue(0, 0) + v->y() * getValue(1, 0) + v->z() * getValue(2, 0); + temp.y() = v->x() * getValue(0, 1) + v->y() * getValue(1, 1) + v->z() * getValue(2, 1); + temp.z() = v->x() * getValue(0, 2) + v->y() * getValue(1, 2) + v->z() * getValue(2, 2); + + *v = temp; +} + } // end of namespace Math diff --git a/math/matrix4.h b/math/matrix4.h index 3dad7a5664b..e372facdadf 100644 --- a/math/matrix4.h +++ b/math/matrix4.h @@ -37,7 +37,9 @@ public: Matrix(const MatrixBase<4, 4> &m); void transform(Vector3d *v, bool translate) const; - + void inverseTranslate(Vector3d *v); + void inverseRotate(Vector3d *v); + Vector3d getPosition() const; void setPosition(const Vector3d &v);