Browse Source

Math: using Rad for Matrix4::perspectiveProjection().

Also updated dependent functions and tests.
pull/7/head
Vladimír Vondruš 13 years ago
parent
commit
d16a6259b8
  1. 6
      src/Math/Matrix4.h
  2. 2
      src/Math/Test/Matrix4Test.cpp
  3. 4
      src/SceneGraph/Camera3D.h
  4. 2
      src/SceneGraph/Camera3D.hpp

6
src/Math/Matrix4.h

@ -216,15 +216,15 @@ template<class T> class Matrix4: public Matrix<4, T> {
/** /**
* @brief 3D perspective projection matrix * @brief 3D perspective projection matrix
* @param fov Field of view angle (horizontal, in radians) * @param fov Field of view angle (horizontal)
* @param aspectRatio Aspect ratio * @param aspectRatio Aspect ratio
* @param near Near clipping plane * @param near Near clipping plane
* @param far Far clipping plane * @param far Far clipping plane
* *
* @see orthographicProjection(), Matrix3::projection() * @see orthographicProjection(), Matrix3::projection()
*/ */
static Matrix4<T> perspectiveProjection(T fov, T aspectRatio, T near, T far) { static Matrix4<T> perspectiveProjection(Rad<T> fov, T aspectRatio, T near, T far) {
T xyScale = 2*std::tan(fov/2)*near; T xyScale = 2*std::tan(T(fov)/2)*near;
return perspectiveProjection(Vector2<T>(xyScale, xyScale/aspectRatio), near, far); return perspectiveProjection(Vector2<T>(xyScale, xyScale/aspectRatio), near, far);
} }

2
src/Math/Test/Matrix4Test.cpp

@ -200,7 +200,7 @@ void Matrix4Test::perspectiveProjectionFov() {
{ 0.0f, 9.788454f, 0.0f, 0.0f}, { 0.0f, 9.788454f, 0.0f, 0.0f},
{ 0.0f, 0.0f, -1.9411764f, -1.0f}, { 0.0f, 0.0f, -1.9411764f, -1.0f},
{ 0.0f, 0.0f, -94.1176452f, 0.0f}); { 0.0f, 0.0f, -94.1176452f, 0.0f});
CORRADE_COMPARE(Matrix4::perspectiveProjection(deg(27.0f), 2.35f, 32.0f, 100), expected); CORRADE_COMPARE(Matrix4::perspectiveProjection(Deg(27.0f), 2.35f, 32.0f, 100), expected);
} }
void Matrix4Test::fromParts() { void Matrix4Test::fromParts() {

4
src/SceneGraph/Camera3D.h

@ -83,7 +83,7 @@ class MAGNUM_SCENEGRAPH_EXPORT Camera3D: public AbstractCamera<3, T> {
/** /**
* @brief Set perspective projection * @brief Set perspective projection
* @param fov Field of view angle (horizontal, in radians) * @param fov Field of view angle (horizontal)
* @param aspectRatio Aspect ratio * @param aspectRatio Aspect ratio
* @param near Near clipping plane * @param near Near clipping plane
* @param far Far clipping plane * @param far Far clipping plane
@ -91,7 +91,7 @@ class MAGNUM_SCENEGRAPH_EXPORT Camera3D: public AbstractCamera<3, T> {
* *
* @see setOrthographic(), Matrix4::perspectiveProjection() * @see setOrthographic(), Matrix4::perspectiveProjection()
*/ */
Camera3D<T>* setPerspective(T fov, T aspectRatio, T near, T far); Camera3D<T>* setPerspective(Math::Rad<T> fov, T aspectRatio, T near, T far);
/** @brief Near clipping plane */ /** @brief Near clipping plane */
inline T near() const { return _near; } inline T near() const { return _near; }

2
src/SceneGraph/Camera3D.hpp

@ -46,7 +46,7 @@ template<class T> Camera3D<T>* Camera3D<T>::setPerspective(const Math::Vector2<T
return this; return this;
} }
template<class T> Camera3D<T>* Camera3D<T>::setPerspective(T fov, T aspectRatio, T near, T far) { template<class T> Camera3D<T>* Camera3D<T>::setPerspective(Math::Rad<T> fov, T aspectRatio, T near, T far) {
/** @todo Get near/far from the matrix */ /** @todo Get near/far from the matrix */
_near = near; _near = near;
_far = far; _far = far;

Loading…
Cancel
Save