Browse Source

Camera: added function to retrieve size of XY projection plane.

pull/279/head
Vladimír Vondruš 14 years ago
parent
commit
924e4f82ce
  1. 11
      src/SceneGraph/Camera.h
  2. 6
      src/SceneGraph/Test/CameraTest.cpp

11
src/SceneGraph/Camera.h

@ -91,9 +91,20 @@ template<class MatrixType, class VectorType, class ObjectType, class SceneType,
*
* Projection matrix handles e.g. perspective distortion and is applied
* as last.
* @see projectionSize()
*/
inline MatrixType projectionMatrix() const { return _projectionMatrix; }
/**
* @brief Size of (near) XY plane in current projection
*
* Returns size of near XY plane computed from projection matrix.
* @see projectionMatrix()
*/
inline Vector2 projectionSize() const {
return {2.0f/rawProjectionMatrix[0].x(), 2.0f/rawProjectionMatrix[1].y()};
}
/** @brief Viewport size */
inline Math::Vector2<GLsizei> viewport() const { return _viewport; }

6
src/SceneGraph/Test/CameraTest.cpp

@ -75,11 +75,13 @@ void CameraTest::fixAspectRatio() {
void CameraTest::defaultProjection2D() {
Camera2D camera;
CORRADE_COMPARE(camera.projectionMatrix(), Matrix3());
CORRADE_COMPARE(camera.projectionSize(), Vector2(2.0f));
}
void CameraTest::defaultProjection3D() {
Camera3D camera;
CORRADE_COMPARE(camera.projectionMatrix(), Matrix4());
CORRADE_COMPARE(camera.projectionSize(), Vector2(2.0f));
}
void CameraTest::projection2D() {
@ -92,6 +94,7 @@ void CameraTest::projection2D() {
0.0f, 0.0f, 1.0f);
CORRADE_COMPARE(camera.projectionMatrix(), a);
CORRADE_COMPARE(camera.projectionSize(), projectionSize);
}
void CameraTest::orthographic() {
@ -105,6 +108,7 @@ void CameraTest::orthographic() {
0.0f, 0.0f, -1.25f, 1.0f);
CORRADE_COMPARE(camera.projectionMatrix(), a);
CORRADE_COMPARE(camera.projectionSize(), projectionSize);
Vector2 projectionSizeRectangle(5.0f, 4.0f);
camera.setOrthographic(projectionSizeRectangle, 1, 9);
@ -115,6 +119,7 @@ void CameraTest::orthographic() {
0.0f, 0.0f, -1.25f, 1.0f);
CORRADE_COMPARE(camera.projectionMatrix(), rectangle);
CORRADE_COMPARE(camera.projectionSize(), projectionSizeRectangle);
}
void CameraTest::perspective() {
@ -127,6 +132,7 @@ void CameraTest::perspective() {
0.0f, 0.0f, -94.1176452f, 0.0f);
CORRADE_COMPARE(camera.projectionMatrix(), a);
CORRADE_COMPARE(camera.projectionSize(), Vector2(0.48015756f));
}
}}}

Loading…
Cancel
Save