Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "OVR_Math.h"
00017
00018 #include <float.h>
00019
00020 namespace OVR {
00021
00022
00023
00024
00025
00026
00027
00028 const float Math<float>::Pi = 3.1415926f;
00029 const float Math<float>::TwoPi = 3.1415926f * 2;
00030 const float Math<float>::PiOver2 = 3.1415926f / 2.0f;
00031 const float Math<float>::PiOver4 = 3.1415926f / 4.0f;
00032 const float Math<float>::E = 2.7182818f;
00033
00034 const float Math<float>::MaxValue = FLT_MAX;
00035 const float Math<float>::MinPositiveValue = FLT_MIN;
00036
00037 const float Math<float>::RadToDegreeFactor = 360.0f / Math<float>::TwoPi;
00038 const float Math<float>::DegreeToRadFactor = Math<float>::TwoPi / 360.0f;
00039
00040 const float Math<float>::Tolerance = 0.00001f;
00041 const float Math<float>::SingularityRadius = 0.0000001f;
00042
00043
00044
00045 const double Math<double>::Pi = 3.14159265358979;
00046 const double Math<double>::TwoPi = 3.14159265358979 * 2;
00047 const double Math<double>::PiOver2 = 3.14159265358979 / 2.0;
00048 const double Math<double>::PiOver4 = 3.14159265358979 / 4.0;
00049 const double Math<double>::E = 2.71828182845905;
00050
00051 const double Math<double>::MaxValue = DBL_MAX;
00052 const double Math<double>::MinPositiveValue = DBL_MIN;
00053
00054 const double Math<double>::RadToDegreeFactor = 360.0 / Math<double>::TwoPi;
00055 const double Math<double>::DegreeToRadFactor = Math<double>::TwoPi / 360.0;
00056
00057 const double Math<double>::Tolerance = 0.00001;
00058 const double Math<double>::SingularityRadius = 0.000000000001;
00059
00060
00061
00062
00063
00064
00065
00066 Matrix4f Matrix4f::LookAtRH(const Vector3f& eye, const Vector3f& at, const Vector3f& up)
00067 {
00068 Vector3f z = (eye - at).Normalized();
00069 Vector3f x = up.Cross(z).Normalized();
00070 Vector3f y = z.Cross(x);
00071
00072 Matrix4f m(x.x, x.y, x.z, -(x * eye),
00073 y.x, y.y, y.z, -(y * eye),
00074 z.x, z.y, z.z, -(z * eye),
00075 0, 0, 0, 1 );
00076 return m;
00077 }
00078
00079 Matrix4f Matrix4f::LookAtLH(const Vector3f& eye, const Vector3f& at, const Vector3f& up)
00080 {
00081 Vector3f z = (at - eye).Normalized();
00082 Vector3f x = up.Cross(z).Normalized();
00083 Vector3f y = z.Cross(x);
00084
00085 Matrix4f m(x.x, x.y, x.z, -(x * eye),
00086 y.x, y.y, y.z, -(y * eye),
00087 z.x, z.y, z.z, -(z * eye),
00088 0, 0, 0, 1 );
00089 return m;
00090 }
00091
00092
00093 Matrix4f Matrix4f::PerspectiveLH(float yfov, float aspect, float znear, float zfar)
00094 {
00095 Matrix4f m;
00096 float tanHalfFov = tan(yfov * 0.5f);
00097
00098 m.M[0][0] = 1.0f / (aspect * tanHalfFov);
00099 m.M[1][1] = 1.0f / tanHalfFov;
00100 m.M[2][2] = zfar / (zfar - znear);
00101 m.M[3][2] = 1.0f;
00102 m.M[2][3] = (zfar * znear) / (znear - zfar);
00103 m.M[3][3] = 0.0f;
00104
00105
00106
00107 return m;
00108 }
00109
00110
00111 Matrix4f Matrix4f::PerspectiveRH(float yfov, float aspect, float znear, float zfar)
00112 {
00113 Matrix4f m;
00114 float tanHalfFov = tan(yfov * 0.5f);
00115
00116 m.M[0][0] = 1.0f / (aspect * tanHalfFov);
00117 m.M[1][1] = 1.0f / tanHalfFov;
00118 m.M[2][2] = zfar / (znear - zfar);
00119
00120 m.M[3][2] = -1.0f;
00121 m.M[2][3] = (zfar * znear) / (znear - zfar);
00122 m.M[3][3] = 0.0f;
00123
00124
00125
00126
00127 return m;
00128 }
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142 Matrix4f Matrix4f::Ortho2D(float w, float h)
00143 {
00144 Matrix4f m;
00145 m.M[0][0] = 2.0f/w;
00146 m.M[1][1] = -2.0f/h;
00147 m.M[0][3] = -1.0;
00148 m.M[1][3] = 1.0;
00149 m.M[2][2] = 0;
00150 return m;
00151 }
00152
00153 }