From 7911c22eff3395dd137b7371b6f40709a5879c9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 26 Feb 2012 22:34:06 +0100 Subject: [PATCH] Removed convenience functions with "unwrapped" Vector parameters. With C++11, objects can be passed nearly as easy as without these convenience functions, for example: Matrix4::scaling({0.5f, 1.0f, 0.5f}); which is nearly the same as the following, using convenience function: Matrix4::scaling(0.5f, 1.0f, 0.5f); Convenience functions can also be pretty confusing, for example: Matrix4::rotation(1.0f, -1.0f, 2.0f, 2.0f); // wtf? Matrix4::rotation(1.0f, {-1.0f, 2.0f, 2.0f}); // ah, okay! There are also a few neat tricks, which cannot be done using convenience functions, for example: Matrix4::translate(Vector3::xAxis(3.0f)); // {3.0f, 0.0f, 0.0f} Camera::setClearColor({0.1f, 0.1f, 0.1f}); // default 1.0f for alpha --- src/Camera.cpp | 16 ++++++++-------- src/Camera.h | 10 ---------- src/Math/Matrix4.h | 33 --------------------------------- src/Math/Test/Matrix4Test.cpp | 6 +++--- src/Object.h | 16 +--------------- 5 files changed, 12 insertions(+), 69 deletions(-) diff --git a/src/Camera.cpp b/src/Camera.cpp index fd90620fc..81bbb5061 100644 --- a/src/Camera.cpp +++ b/src/Camera.cpp @@ -29,10 +29,10 @@ void Camera::setOrthographic(GLfloat size, GLfloat near, GLfloat far) { /* Scale the volume down so it fits in (-1, 1) in all directions */ GLfloat xyScale = 2/size; GLfloat zScale = 2/(far-near); - rawProjectionMatrix = Matrix4::scaling(xyScale, xyScale, -zScale); + rawProjectionMatrix = Matrix4::scaling({xyScale, xyScale, -zScale}); /* Move the volume on z into (-1, 1) range */ - rawProjectionMatrix = Matrix4::translation(0, 0, -1-near*zScale)*rawProjectionMatrix; + rawProjectionMatrix = Matrix4::translation(Vector3::zAxis(-1-near*zScale))*rawProjectionMatrix; fixAspectRatio(); } @@ -42,7 +42,7 @@ void Camera::setPerspective(GLfloat fov, GLfloat near, GLfloat far) { _far = far; /* First move the volume on z in (-1, 1) range */ - rawProjectionMatrix = Matrix4::translation(0, 0, 2*far*near/(far+near)); + rawProjectionMatrix = Matrix4::translation(Vector3::zAxis(2*far*near/(far+near))); /* Then apply magic perspective matrix (with reversed Z) */ static GLfloat a[] = { 1, 0, 0, 0, @@ -54,7 +54,7 @@ void Camera::setPerspective(GLfloat fov, GLfloat near, GLfloat far) { /* Then scale the volume down so it fits in (-1, 1) in all directions */ GLfloat xyScale = 1/tan(fov/2); GLfloat zScale = 1+2*near/(far-near); - rawProjectionMatrix = Matrix4::scaling(xyScale, xyScale, zScale)*rawProjectionMatrix; + rawProjectionMatrix = Matrix4::scaling({xyScale, xyScale, zScale})*rawProjectionMatrix; /* And... another magic */ rawProjectionMatrix.set(3, 3, 0); @@ -85,15 +85,15 @@ void Camera::fixAspectRatio() { /* Extend on larger side = scale larger side down */ if(_aspectRatioPolicy == Extend) { _projectionMatrix = ((_viewport.x() > _viewport.y()) ? - Matrix4::scaling(static_cast(_viewport.y())/_viewport.x(), 1, 1) : - Matrix4::scaling(1, static_cast(_viewport.x())/_viewport.y(), 1) + Matrix4::scaling({static_cast(_viewport.y())/_viewport.x(), 1, 1}) : + Matrix4::scaling({1, static_cast(_viewport.x())/_viewport.y(), 1}) )*rawProjectionMatrix; /* Clip on smaller side = scale smaller side up */ } else if(_aspectRatioPolicy == Clip) { _projectionMatrix = ((_viewport.x() > _viewport.y()) ? - Matrix4::scaling(1, static_cast(_viewport.x())/_viewport.y(), 1) : - Matrix4::scaling(static_cast(_viewport.y())/_viewport.x(), 1, 1) + Matrix4::scaling({1, static_cast(_viewport.x())/_viewport.y(), 1}) : + Matrix4::scaling({static_cast(_viewport.y())/_viewport.x(), 1, 1}) )*rawProjectionMatrix; /* Don't preserve anything */ diff --git a/src/Camera.h b/src/Camera.h index 4e4dbac98..0199ac03c 100644 --- a/src/Camera.h +++ b/src/Camera.h @@ -113,22 +113,12 @@ class MAGNUM_EXPORT Camera: public Object { */ virtual void setViewport(const Math::Vector2& size); - /** @copydoc setViewport(const Math::Vector2& size); */ - inline void setViewport(GLsizei width, GLsizei height) { - setViewport({width, height}); - } - /** @brief Clear color */ inline Vector4 clearColor() const { return _clearColor; } /** @brief Set clear color */ void setClearColor(const Vector4& color); - /** @copydoc setClearColor(const Vector4&) */ - inline void setClearColor(GLfloat r, GLfloat g, GLfloat b, GLfloat a) { - setClearColor(Vector4(r, g, b, a)); - } - /** * @brief Draw the scene * diff --git a/src/Math/Matrix4.h b/src/Math/Matrix4.h index d72db4966..84159f04d 100644 --- a/src/Math/Matrix4.h +++ b/src/Math/Matrix4.h @@ -27,24 +27,12 @@ namespace Magnum { namespace Math { /** * @brief 4x4 matrix * - * @todo @c PERFORMANCE - make (T,T,T) - (Vec3<T>) alternatives calling - * direction based on statistics, which is used more frequently * @todo Rotation with Euler angles * @todo Shearing * @todo Reflection */ template class Matrix4: public Matrix { public: - /** - * @brief Translation matrix - * @param x Translation along X - * @param y Translation along Y - * @param z Translation along Z - */ - inline static Matrix4 translation(T x, T y, T z) { - return translation(Vector3(x, y, z)); - } - /** * @brief Translation matrix * @param vec Translation vector @@ -57,16 +45,6 @@ template class Matrix4: public Matrix { return out; } - /** - * @brief Scaling matrix - * @param x Scaling along X - * @param y Scaling along Y - * @param z Scaling along Z - */ - inline static Matrix4 scaling(T x, T y, T z) { - return scaling(Vector3(x, y, z)); - } - /** * @brief Scaling matrix * @param vec Scaling vector @@ -79,17 +57,6 @@ template class Matrix4: public Matrix { return out; } - /** - * @brief Rotation matrix - * @param angle Rotation angle (counterclockwise, in radians) - * @param x Rotation axis X coordinates - * @param y Rotation axis Y coordinates - * @param z Rotation axis Z coordinates - */ - inline static Matrix4 rotation(T angle, T x, T y, T z) { - return rotation(angle, Vector3(x, y, z)); - } - /** * @brief Rotation matrix * @param angle Rotation angle (counterclockwise, in radians) diff --git a/src/Math/Test/Matrix4Test.cpp b/src/Math/Test/Matrix4Test.cpp index 7cc38adcd..0da2b4af4 100644 --- a/src/Math/Test/Matrix4Test.cpp +++ b/src/Math/Test/Matrix4Test.cpp @@ -38,7 +38,7 @@ void Matrix4Test::translation() { 3.0f, 1.0f, 2.0f, 1.0f }; - QVERIFY(Matrix4::translation(3.0f, 1.0f, 2.0f) == Matrix4(matrix)); + QVERIFY(Matrix4::translation({3.0f, 1.0f, 2.0f}) == Matrix4(matrix)); } void Matrix4Test::scaling() { @@ -49,7 +49,7 @@ void Matrix4Test::scaling() { 0.0f, 0.0f, 0.0f, 1.0f }; - QVERIFY(Matrix4::scaling(3.0f, 1.5f, 2.0f) == Matrix4(matrix)); + QVERIFY(Matrix4::scaling({3.0f, 1.5f, 2.0f}) == Matrix4(matrix)); } void Matrix4Test::rotation() { @@ -60,7 +60,7 @@ void Matrix4Test::rotation() { 0.0f, 0.0f, 0.0f, 1.0f }; - QVERIFY(Matrix4::rotation(deg(-74.0f), -1.0f, 2.0f, 2.0f) == Matrix4(matrix)); + QVERIFY(Matrix4::rotation(deg(-74.0f), {-1.0f, 2.0f, 2.0f}) == Matrix4(matrix)); } void Matrix4Test::debug() { diff --git a/src/Object.h b/src/Object.h index dc21c373d..257b430f6 100644 --- a/src/Object.h +++ b/src/Object.h @@ -134,11 +134,6 @@ class MAGNUM_EXPORT Object { multiplyTransformation(Matrix4::translation(vec), global); } - /** @copydoc translate(Vector3, bool) */ - inline void translate(GLfloat x, GLfloat y, GLfloat z, bool global = true) { - translate(Vector3(x, y, z), global); - } - /** * @brief Scale object * @@ -148,15 +143,11 @@ class MAGNUM_EXPORT Object { multiplyTransformation(Matrix4::scaling(vec), global); } - /** @copydoc scale(Vector3, bool) */ - inline void scale(GLfloat x, GLfloat y, GLfloat z, bool global = true) { - scale(Vector3(x, y, z), global); - } - /** * @copydoc scale(Vector3, bool) * * Scales the object proportionally in all dimensions. + * @todo Make this functionality in Math::Vector3? */ inline void scale(GLfloat xyz, bool global = true) { scale({xyz, xyz, xyz}, global); @@ -171,11 +162,6 @@ class MAGNUM_EXPORT Object { multiplyTransformation(Matrix4::rotation(angle, vec), global); } - /** @copydoc rotate(GLfloat, Vector3, bool) */ - inline void rotate(GLfloat angle, GLfloat x, GLfloat y, GLfloat z, bool global = true) { - rotate(angle, Vector3(x, y, z), global); - } - /** @{ @name Caching helpers * * If the object transformation is used many times when drawing (such