TrueReality  v0.1.1912
Matrixd.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/Matrixd.h>
22 
23 #include <trBase/Matrixf.h>
24 
25 #include <osg/Matrixd>
26 
27 // Specialize MatrixImpl to be Matrixd
28 #define MatrixImpl Matrixd
29 
30 namespace trBase
31 {
33  Matrixd::Matrixd(const osg::Matrixd& mat)
34  : mMatrix(mat)
35  {
36  }
37 
39  Matrixd::Matrixd(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 Matrixd::Set(const Matrixf& rhs)
59  {
60  Set(rhs.Ptr());
61  }
62 
65  {}
66 
68  void Matrixd::MakeOrtho(float left, float right, float bottom, float top, float zNear, float zFar)
69  {
70  mMatrix.makeOrtho(left, right, bottom, top, zNear, zFar);
71  }
72 
74  bool Matrixd::GetOrtho(float& left, float& right, float& bottom, float& top, float& zNear, float& zFar) const
75  {
76  return mMatrix.getOrtho(left, right, bottom, top, zNear, zFar);
77  }
78 
80  void Matrixd::MakeOrtho2D(float left, float right, float bottom, float top)
81  {
82  mMatrix.makeOrtho(left, right, bottom, top, -1.0, 1.0);
83  }
84 
86  void Matrixd::MakeFrustum(float left, float right, float bottom, float top, float zNear, float zFar)
87  {
88  mMatrix.makeFrustum(left, right, bottom, top, zNear, zFar);
89  }
90 
92  bool Matrixd::GetFrustum(float& left, float& right, float& bottom, float& top, float& zNear, float& zFar) const
93  {
94  return mMatrix.getFrustum(left, right, bottom, top, zNear, zFar);
95  }
96 
98  void Matrixd::MakePerspective(float fovy, float aspectRatio, float zNear, float zFar)
99  {
100  mMatrix.makePerspective(fovy, aspectRatio, zNear, zFar);
101  }
102 
104  bool Matrixd::GetPerspective(float& fovy, float& aspectRatio, float& zNear, float& zFar) const
105  {
106  return mMatrix.getPerspective(fovy, aspectRatio, zNear, zFar);
107  }
108 
110  Matrixd Matrixd::Ortho(float left, float right, float bottom, float top, float zNear, float zFar)
111  {
112  Matrixd m;
113  m.MakeOrtho(left, right, bottom, top, zNear, zFar);
114  return m;
115  }
116 
118  Matrixd Matrixd::Ortho2D(float left, float right, float bottom, float top)
119  {
120  Matrixd m;
121  m.MakeOrtho2D(left, right, bottom, top);
122  return m;
123  }
124 
126  Matrixd Matrixd::Frustum(float left, float right, float bottom, float top, float zNear, float zFar)
127  {
128  Matrixd m;
129  m.MakeFrustum(left, right, bottom, top, zNear, zFar);
130  return m;
131  }
132 
134  Matrixd Matrixd::Perspective(float fovy, float aspectRatio, float zNear, float zFar)
135  {
136  Matrixd 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"
Matrixd & operator=(const Matrixd &rhs)
Set operator.
bool GetOrtho(double &left, double &right, double &bottom, double &top, double &zNear, double &zFar) const
Get the orthographic settings of the orthographic projection matrix.
void MakeOrtho2D(double left, double right, double bottom, double top)
Set to a 2D orthographic projection.
A float Matrix class to be used for generic matrix operations.
Definition: Matrixd.h:40
void MakePerspective(double fovy, double aspectRatio, double zNear, double zFar)
Set to a symmetrical perspective projection.
bool GetPerspective(double &fovy, double &aspectRatio, double &zNear, double &zFar) const
Get the frustum settings of a symmetric perspective projection matrix.
static Matrixd Perspective(float fovy, float aspectRatio, float zNear, float zFar)
Create a symmetrical perspective projection matrix.
Definition: Matrixd.cpp:134
void Set(const Matrixd &rhs)
Set the current Matrix from a passed in one.
static Matrixd Frustum(double left, double right, double bottom, double top, double zNear, double zFar)
Create a perspective projection matrix.
void MakeOrtho(double left, double right, double bottom, double top, double zNear, double zFar)
Set to an orthographic projection.
A float Matrix class to be used for generic matrix operations.
Definition: Matrixf.h:41
value_type * Ptr()
Pointer to the internal Matrix array.
static Matrixd Ortho(double left, double right, double bottom, double top, double zNear, double zFar)
Create an orthographic projection matrix.
static Matrixd Ortho2D(double left, double right, double bottom, double top)
Create a 2D orthographic projection matrix.
osg::Matrixd mMatrix
Definition: Matrixd.h:1750
~Matrixd()
dtor.
Definition: Matrixd.cpp:64
void MakeFrustum(double left, double right, double bottom, double top, double zNear, double zFar)
Set to a perspective projection.
bool GetFrustum(double &left, double &right, double &bottom, double &top, double &zNear, double &zFar) const
Get the frustum settings of a perspective projection matrix.