Developer Documentation

math_test.cc
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4 * Copyright (c) 2001-2015, RWTH-Aachen University *
5 * Department of Computer Graphics and Multimedia *
6 * All rights reserved. *
7 * www.openflipper.org *
8 * *
9 *---------------------------------------------------------------------------*
10 * This file is part of OpenFlipper. *
11 *---------------------------------------------------------------------------*
12 * *
13 * Redistribution and use in source and binary forms, with or without *
14 * modification, are permitted provided that the following conditions *
15 * are met: *
16 * *
17 * 1. Redistributions of source code must retain the above copyright notice, *
18 * this list of conditions and the following disclaimer. *
19 * *
20 * 2. Redistributions in binary form must reproduce the above copyright *
21 * notice, this list of conditions and the following disclaimer in the *
22 * documentation and/or other materials provided with the distribution. *
23 * *
24 * 3. Neither the name of the copyright holder nor the names of its *
25 * contributors may be used to endorse or promote products derived from *
26 * this software without specific prior written permission. *
27 * *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 \*===========================================================================*/
41
42
43 #include <gtest/gtest.h>
44
45 #include <ACG/Math/GLMatrixT.hh>
46
47
48 class MathTest : public testing::Test {
49
50 public:
51 MathTest()
52 {
53 }
54
55 protected:
56
57 // This function is called before each test is run
58 virtual void SetUp() {
59 }
60
61 // This function is called after all tests are through
62 virtual void TearDown() {
63 }
64
65
66 };
67
68 TEST_F(MathTest, GLMatrixT_extract_planes ) {
69
70 const double cmp_eps = 1e-7;
71
72 const double near = 10.0;
73 const double far = 25.0;
74
75 // test clipping plane extraction on perspective and orthographic matrix
76 ACG::GLMatrixd P;
77 P.identity();
78
79 EXPECT_FALSE(P.isPerspective());
80 EXPECT_FALSE(P.isOrtho());
81
82 P.perspective(45.0, 4.0/3.0, near, far);
83
84 ACG::Vec2d planes = P.extract_planes_perspective();
85
86 EXPECT_LE(fabs(planes[0] - near), cmp_eps);
87 EXPECT_LE(fabs(planes[1] - far), cmp_eps);
88
89 EXPECT_TRUE(P.isPerspective());
90 EXPECT_FALSE(P.isOrtho());
91
92 // test on orthographic matrix
93
94 P.identity();
95 P.ortho(-1.0, 1.0, -1.0, 1.0, near, far);
96
97 planes = P.extract_planes_ortho();
98
99 EXPECT_LE(fabs(planes[0] - near), cmp_eps);
100 EXPECT_LE(fabs(planes[1] - far), cmp_eps);
101
102 EXPECT_FALSE(P.isPerspective());
103 EXPECT_TRUE(P.isOrtho());
104 }
ACG::GLMatrixT::isPerspective
bool isPerspective() const
check if the matrix is a perspective projection matrix
Definition: GLMatrixT_impl.hh:464
ACG::GLMatrixT::extract_planes_perspective
VectorT< Scalar, 2 > extract_planes_perspective() const
extract near and far clipping planes from a perspective projection matrix
Definition: GLMatrixT_impl.hh:438
ACG::GLMatrixT< double >
MathTest
Definition: math_test.cc:48
ACG::GLMatrixT::ortho
void ortho(Scalar left, Scalar right, Scalar bottom, Scalar top, Scalar near_plane, Scalar far_plane)
multiply self with orthographic projection matrix
Definition: GLMatrixT_impl.hh:373
ACG::GLMatrixT::perspective
void perspective(Scalar fovY, Scalar aspect, Scalar near_plane, Scalar far_plane)
multiply self with a perspective projection matrix
Definition: GLMatrixT_impl.hh:277
OpenMesh::VectorT
Definition: Vector11T.hh:83
ACG::Matrix4x4T::identity
void identity()
setup an identity matrix
Definition: Matrix4x4T_impl.hh:250
ACG::GLMatrixT::extract_planes_ortho
VectorT< Scalar, 2 > extract_planes_ortho() const
extract near and far clipping planes from an orthographic projection matrix
Definition: GLMatrixT_impl.hh:451
ACG::GLMatrixT::isOrtho
bool isOrtho() const
check if the matrix is an orthographic projection matrix
Definition: GLMatrixT_impl.hh:523