TrueReality  v0.1.1912
Matrixf.cpp
Go to the documentation of this file.
1 /*
2 * True Reality Open Source Game and Simulation Engine
3 * Copyright © 2021 Acid Rain Studios LLC
4 *
5 * This library is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU Lesser General Public License as published by the Free
7 * Software Foundation; either version 3.0 of the License, or (at your option)
8 * any later version.
9 *
10 * This library is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13 * details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this library; if not, write to the Free Software Foundation, Inc.,
17 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * @author Maxim Serebrennik
20 */
21 #include <trBase/Matrixf.h>
22 
23 #include <trBase/Matrixd.h>
24 
25 #include <osg/Matrixf>
26 
27 // Specialize MatrixImpl to be Matrixf
28 #define MatrixImpl Matrixf
29 
30 namespace trBase
31 {
33  Matrixf::Matrixf(const osg::Matrixd& mat)
34  : mMatrix(mat)
35  {
36  }
37 
39  Matrixf::Matrixf(const osg::Matrixf& mat)
40  : mMatrix(mat)
41  {
42  }
43 
46  : mMatrix(mat)
47  {
48  }
49 
52  {
53  Set(rhs.Ptr());
54  return *this;
55  }
56 
58  void Matrixf::Set(const Matrixd& rhs)
59  {
60  Set(rhs.Ptr());
61  }
62 
65  {}
66 
68  void Matrixf::MakeOrtho(double left, double right, double bottom, double top, double zNear, double zFar)
69  {
70  mMatrix.makeOrtho(left, right, bottom, top, zNear, zFar);
71  }
72 
74  bool Matrixf::GetOrtho(double& left, double& right, double& bottom, double& top, double& zNear, double& zFar) const
75  {
76  return mMatrix.getOrtho(left, right, bottom, top, zNear, zFar);
77  }
78 
80  void Matrixf::MakeOrtho2D(double left, double right, double bottom, double top)
81  {
82  mMatrix.makeOrtho(left, right, bottom, top, -1.0, 1.0);
83  }
84 
86  void Matrixf::MakeFrustum(double left, double right, double bottom, double top, double zNear, double zFar)
87  {
88  mMatrix.makeFrustum(left, right, bottom, top, zNear, zFar);
89  }
90 
92  bool Matrixf::GetFrustum(double& left, double& right, double& bottom, double& top, double& zNear, double& zFar) const
93  {
94  return mMatrix.getFrustum(left, right, bottom, top, zNear, zFar);
95  }
96 
98  void Matrixf::MakePerspective(double fovy, double aspectRatio, double zNear, double zFar)
99  {
100  mMatrix.makePerspective(fovy, aspectRatio, zNear, zFar);
101  }
102 
104  bool Matrixf::GetPerspective(double& fovy, double& aspectRatio, double& zNear, double& zFar) const
105  {
106  return mMatrix.getPerspective(fovy, aspectRatio, zNear, zFar);
107  }
108 
110  Matrixf Matrixf::Ortho(double left, double right, double bottom, double top, double zNear, double zFar)
111  {
112  Matrixf m;
113  m.MakeOrtho(left, right, bottom, top, zNear, zFar);
114  return m;
115  }
116 
118  Matrixf Matrixf::Ortho2D(double left, double right, double bottom, double top)
119  {
120  Matrixf m;
121  m.MakeOrtho2D(left, right, bottom, top);
122  return m;
123  }
124 
126  Matrixf Matrixf::Frustum(double left, double right, double bottom, double top, double zNear, double zFar)
127  {
128  Matrixf m;
129  m.MakeFrustum(left, right, bottom, top, zNear, zFar);
130  return m;
131  }
132 
134  Matrixf Matrixf::Perspective(double fovy, double aspectRatio, double zNear, double zFar)
135  {
136  Matrixf m;
137  m.MakePerspective(fovy, aspectRatio, zNear, zFar);
138  return m;
139  }
140 }
141 
142 // Now compile up Matrix via MatrixImpl
143 #include "MatrixImpl.cpp"
bool GetOrtho(double &left, double &right, double &bottom, double &top, double &zNear, double &zFar) const
Get the orthographic settings of the orthographic projection matrix.
Definition: Matrixf.cpp:74
void MakeOrtho(double left, double right, double bottom, double top, double zNear, double zFar)
Set to an orthographic projection.
Definition: Matrixf.cpp:68
osg::Matrixf mMatrix
Definition: Matrixf.h:1753
void MakePerspective(double fovy, double aspectRatio, double zNear, double zFar)
Set to a symmetrical perspective projection.
Definition: Matrixf.cpp:98
A float Matrix class to be used for generic matrix operations.
Definition: Matrixd.h:40
Matrixf & operator=(const Matrixf &rhs)
Set operator.
void MakeOrtho2D(double left, double right, double bottom, double top)
Set to a 2D orthographic projection.
Definition: Matrixf.cpp:80
bool GetFrustum(double &left, double &right, double &bottom, double &top, double &zNear, double &zFar) const
Get the frustum settings of a perspective projection matrix.
Definition: Matrixf.cpp:92
~Matrixf()
dtor.
Definition: Matrixf.cpp:64
A float Matrix class to be used for generic matrix operations.
Definition: Matrixf.h:41
bool GetPerspective(double &fovy, double &aspectRatio, double &zNear, double &zFar) const
Get the frustum settings of a symmetric perspective projection matrix.
Definition: Matrixf.cpp:104
static Matrixf Ortho(double left, double right, double bottom, double top, double zNear, double zFar)
Create an orthographic projection matrix.
Definition: Matrixf.cpp:110
static Matrixf Perspective(float fovy, float aspectRatio, float zNear, float zFar)
Create a symmetrical perspective projection matrix.
void Set(const Matrixf &rhs)
Set the current Matrix from a passed in one.
void MakeFrustum(double left, double right, double bottom, double top, double zNear, double zFar)
Set to a perspective projection.
Definition: Matrixf.cpp:86
static Matrixf Frustum(double left, double right, double bottom, double top, double zNear, double zFar)
Create a perspective projection matrix.
Definition: Matrixf.cpp:126
static Matrixf Ortho2D(double left, double right, double bottom, double top)
Create a 2D orthographic projection matrix.
Definition: Matrixf.cpp:118
value_type * Ptr()
Pointer to the internal Matrix array.