Consequences of the plane change + change perspective

The perspective matrix now as in glm (because the near frustum plane was
wrong). So there is a factor "2" on the component w and the skybox must
be changed in consequence.


Former-commit-id: 09dd049c177532b9ace34a5a60b1b96014652297
This commit is contained in:
Gawaboumga
2015-08-21 12:01:52 +02:00
parent f2b80bfe64
commit 282bdf9864
8 changed files with 865 additions and 35 deletions

View File

@@ -180,7 +180,7 @@ NzFrustum<T>& NzFrustum<T>::Extract(const NzMatrix4<T>& clipMatrix)
plane[0] *= invLength;
plane[1] *= invLength;
plane[2] *= invLength;
plane[3] *= invLength;
plane[3] *= -invLength;
m_planes[nzFrustumPlane_Right].Set(plane);
@@ -195,7 +195,7 @@ NzFrustum<T>& NzFrustum<T>::Extract(const NzMatrix4<T>& clipMatrix)
plane[0] *= invLength;
plane[1] *= invLength;
plane[2] *= invLength;
plane[3] *= invLength;
plane[3] *= -invLength;
m_planes[nzFrustumPlane_Left].Set(plane);
@@ -210,7 +210,7 @@ NzFrustum<T>& NzFrustum<T>::Extract(const NzMatrix4<T>& clipMatrix)
plane[0] *= invLength;
plane[1] *= invLength;
plane[2] *= invLength;
plane[3] *= invLength;
plane[3] *= -invLength;
m_planes[nzFrustumPlane_Bottom].Set(plane);
@@ -225,7 +225,7 @@ NzFrustum<T>& NzFrustum<T>::Extract(const NzMatrix4<T>& clipMatrix)
plane[0] *= invLength;
plane[1] *= invLength;
plane[2] *= invLength;
plane[3] *= invLength;
plane[3] *= -invLength;
m_planes[nzFrustumPlane_Top].Set(plane);
@@ -240,7 +240,7 @@ NzFrustum<T>& NzFrustum<T>::Extract(const NzMatrix4<T>& clipMatrix)
plane[0] *= invLength;
plane[1] *= invLength;
plane[2] *= invLength;
plane[3] *= invLength;
plane[3] *= -invLength;
m_planes[nzFrustumPlane_Far].Set(plane);
@@ -255,7 +255,7 @@ NzFrustum<T>& NzFrustum<T>::Extract(const NzMatrix4<T>& clipMatrix)
plane[0] *= invLength;
plane[1] *= invLength;
plane[2] *= invLength;
plane[3] *= invLength;
plane[3] *= -invLength;
m_planes[nzFrustumPlane_Near].Set(plane);
@@ -332,10 +332,7 @@ NzFrustum<T>& NzFrustum<T>::Extract(const NzMatrix4<T>& clipMatrix)
template<typename T>
NzFrustum<T>& NzFrustum<T>::Extract(const NzMatrix4<T>& view, const NzMatrix4<T>& projection)
{
NzMatrix4<T> clipMatrix(view);
clipMatrix *= projection;
return Extract(clipMatrix);
return Extract(NzMatrix4<T>::Concatenate(view, projection));
}
template<typename T>

View File

@@ -578,6 +578,21 @@ NzMatrix4<T>& NzMatrix4<T>::MakeIdentity()
return *this;
}
template<typename T>
NzMatrix4<T>& NzMatrix4<T>::MakeLookAt(const NzVector3<T>& eye, const NzVector3<T>& target, const NzVector3<T>& up)
{
NzVector3<T> f = NzVector3<T>::Normalize(target - eye);
NzVector3<T> s = NzVector3<T>::Normalize(f.CrossProduct(up));
NzVector3<T> u = s.CrossProduct(f);
Set(s.x, u.x, -f.x, T(0.0),
s.y, u.y, -f.y, T(0.0),
s.z, u.z, -f.z, T(0.0),
-s.DotProduct(eye), -u.DotProduct(eye), f.DotProduct(eye), T(1.0));
return *this;
}
template<typename T>
NzMatrix4<T>& NzMatrix4<T>::MakeOrtho(T left, T right, T top, T bottom, T zNear, T zFar)
{
@@ -590,22 +605,6 @@ NzMatrix4<T>& NzMatrix4<T>::MakeOrtho(T left, T right, T top, T bottom, T zNear,
return *this;
}
template<typename T>
NzMatrix4<T>& NzMatrix4<T>::MakeLookAt(const NzVector3<T>& eye, const NzVector3<T>& target, const NzVector3<T>& up)
{
NzVector3<T> f = NzVector3<T>::Normalize(target - eye);
NzVector3<T> u(up.GetNormal());
NzVector3<T> s = NzVector3<T>::Normalize(f.CrossProduct(u));
u = s.CrossProduct(f);
Set(s.x, u.x, -f.x, T(0.0),
s.y, u.y, -f.y, T(0.0),
s.z, u.z, -f.z, T(0.0),
-s.DotProduct(eye), -u.DotProduct(eye), f.DotProduct(eye), T(1.0));
return *this;
}
template<typename T>
NzMatrix4<T>& NzMatrix4<T>::MakePerspective(T angle, T ratio, T zNear, T zFar)
{
@@ -616,12 +615,12 @@ NzMatrix4<T>& NzMatrix4<T>::MakePerspective(T angle, T ratio, T zNear, T zFar)
angle = NzDegreeToRadian(angle/F(2.0));
#endif
T yScale = F(1.0) / std::tan(angle);
T yScale = std::tan(M_PI_2 - angle);
Set(yScale / ratio, F(0.0), F(0.0), F(0.0),
F(0.0), yScale, F(0.0), F(0.0),
F(0.0), F(0.0), zFar / (zNear-zFar), F(-1.0),
F(0.0), F(0.0), (zNear*zFar) / (zNear-zFar), F(0.0));
F(0.0), F(0.0), - (zFar + zNear) / (zFar - zNear), F(-1.0),
F(0.0), F(0.0), F(-2.0) * (zNear * zFar) / (zFar - zNear), F(0.0));
return *this;
}
@@ -696,7 +695,7 @@ NzMatrix4<T>& NzMatrix4<T>::MakeViewMatrix(const NzVector3<T>& translation, cons
// Une matrice de vue doit appliquer une transformation opposée à la matrice "monde"
NzQuaternion<T> invRot = rotation.GetConjugate(); // Inverse de la rotation
return MakeTransform(-(invRot*translation), invRot);
return MakeTransform(-(invRot * translation), invRot);
}
template<typename T>
@@ -821,9 +820,9 @@ NzString NzMatrix4<T>::ToString() const
{
NzStringStream ss;
return ss << "Matrix4(" << m11 << ", " << m12 << ", " << m13 << ", " << m14 << ",\n"
<< " " << m21 << ", " << m22 << ", " << m23 << ", " << m24 << ",\n"
<< " " << m31 << ", " << m32 << ", " << m33 << ", " << m34 << ",\n"
<< " " << m41 << ", " << m42 << ", " << m43 << ", " << m44 << ')';
<< " " << m21 << ", " << m22 << ", " << m23 << ", " << m24 << ",\n"
<< " " << m31 << ", " << m32 << ", " << m33 << ", " << m34 << ",\n"
<< " " << m41 << ", " << m42 << ", " << m43 << ", " << m44 << ')';
}
template<typename T>