Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 /*
44  * math_test.cc
45  *
46  * Created on: 22.04.2014
47  * Author: tenter
48  */
49 
50 #include <gtest/gtest.h>
51 
52 #include <ACG/Math/GLMatrixT.hh>
53 
54 
55 class MathTest : public testing::Test {
56 
57 public:
58  MathTest()
59  {
60  }
61 
62 protected:
63 
64  // This function is called before each test is run
65  virtual void SetUp() {
66  }
67 
68  // This function is called after all tests are through
69  virtual void TearDown() {
70  }
71 
72 
73 };
74 
75 TEST_F(MathTest, GLMatrixT_extract_planes ) {
76 
77  const double cmp_eps = 1e-7;
78 
79  const double near = 10.0;
80  const double far = 25.0;
81 
82  // test clipping plane extraction on perspective and orthographic matrix
84  P.identity();
85 
86  EXPECT_FALSE(P.isPerspective());
87  EXPECT_FALSE(P.isOrtho());
88 
89  P.perspective(45.0, 4.0/3.0, near, far);
90 
92 
93  EXPECT_LE(fabs(planes[0] - near), cmp_eps);
94  EXPECT_LE(fabs(planes[1] - far), cmp_eps);
95 
96  EXPECT_TRUE(P.isPerspective());
97  EXPECT_FALSE(P.isOrtho());
98 
99  // test on orthographic matrix
100 
101  P.identity();
102  P.ortho(-1.0, 1.0, -1.0, 1.0, near, far);
103 
104  planes = P.extract_planes_ortho();
105 
106  EXPECT_LE(fabs(planes[0] - near), cmp_eps);
107  EXPECT_LE(fabs(planes[1] - far), cmp_eps);
108 
109  EXPECT_FALSE(P.isPerspective());
110  EXPECT_TRUE(P.isOrtho());
111 }
bool isPerspective() const
check if the matrix is a perspective projection matrix
Definition: GLMatrixT.cc:470
VectorT< Scalar, 2 > extract_planes_perspective() const
extract near and far clipping planes from a perspective projection matrix
Definition: GLMatrixT.cc:444
bool isOrtho() const
check if the matrix is an orthographic projection matrix
Definition: GLMatrixT.cc:529
VectorT< Scalar, 2 > extract_planes_ortho() const
extract near and far clipping planes from an orthographic projection matrix
Definition: GLMatrixT.cc:457
void perspective(Scalar fovY, Scalar aspect, Scalar near_plane, Scalar far_plane)
multiply self with a perspective projection matrix
Definition: GLMatrixT.cc:283
void identity()
setup an identity matrix
Definition: Matrix4x4T.cc:256
void ortho(Scalar left, Scalar right, Scalar bottom, Scalar top, Scalar near_plane, Scalar far_plane)
multiply self with orthographic projection matrix
Definition: GLMatrixT.cc:379