better error messages for Transform::lookAt()
parent
1a2580faab
commit
5fc2db6387
|
@ -189,6 +189,13 @@ template <typename T> inline TVector1<T> normalize(const TVector1<T> &v) {
|
|||
return v / v.length();
|
||||
}
|
||||
|
||||
template <typename T> inline TVector1<T> normalizeStrict(const TVector1<T> &v, const char *errMsg) {
|
||||
Float length = v.length();
|
||||
if (length == 0)
|
||||
SLog(EError, "normalizeStrict(): %s", errMsg);
|
||||
return v / length;
|
||||
}
|
||||
|
||||
template <> inline TVector1<int> TVector1<int>::operator/(int s) const {
|
||||
#ifdef MTS_DEBUG
|
||||
if (s == 0)
|
||||
|
@ -380,6 +387,13 @@ template <typename T> inline TVector2<T> normalize(const TVector2<T> &v) {
|
|||
return v / v.length();
|
||||
}
|
||||
|
||||
template <typename T> inline TVector2<T> normalizeStrict(const TVector2<T> &v, const char *errMsg) {
|
||||
Float length = v.length();
|
||||
if (length == 0)
|
||||
SLog(EError, "normalizeStrict(): %s", errMsg);
|
||||
return v / length;
|
||||
}
|
||||
|
||||
template <> inline TVector2<int> TVector2<int>::operator/(int s) const {
|
||||
#ifdef MTS_DEBUG
|
||||
if (s == 0)
|
||||
|
@ -582,6 +596,13 @@ template <typename T> inline TVector3<T> normalize(const TVector3<T> &v) {
|
|||
return v / v.length();
|
||||
}
|
||||
|
||||
template <typename T> inline TVector3<T> normalizeStrict(const TVector3<T> &v, const char *errMsg) {
|
||||
Float length = v.length();
|
||||
if (length == 0)
|
||||
SLog(EError, "normalizeStrict(): %s", errMsg);
|
||||
return v / length;
|
||||
}
|
||||
|
||||
template <> inline TVector3<int> TVector3<int>::operator/(int s) const {
|
||||
#ifdef MTS_DEBUG
|
||||
if (s == 0)
|
||||
|
@ -781,6 +802,13 @@ template <typename T> inline TVector4<T> normalize(const TVector4<T> &v) {
|
|||
return v / v.length();
|
||||
}
|
||||
|
||||
template <typename T> inline TVector4<T> normalizeStrict(const TVector4<T> &v, const char *errMsg) {
|
||||
Float length = v.length();
|
||||
if (length == 0)
|
||||
SLog(EError, "normalizeStrict(): %s", errMsg);
|
||||
return v / length;
|
||||
}
|
||||
|
||||
template <> inline TVector4<int> TVector4<int>::operator/(int s) const {
|
||||
#ifdef MTS_DEBUG
|
||||
if (s == 0)
|
||||
|
|
|
@ -189,8 +189,8 @@ Transform Transform::glOrthographic(Float clipLeft, Float clipRight,
|
|||
}
|
||||
|
||||
Transform Transform::lookAt(const Point &p, const Point &t, const Vector &up) {
|
||||
Vector dir = normalize(t-p);
|
||||
Vector left = normalize(cross(up, dir));
|
||||
Vector dir = normalizeStrict(t-p, "lookAt(): 'origin' and 'target' coincide!");
|
||||
Vector left = normalizeStrict(cross(up, dir), "lookAt(): the forward and upward direction must be linearly independent!");
|
||||
Vector newUp = cross(dir, left);
|
||||
|
||||
Matrix4x4 result, inverse;
|
||||
|
|
Loading…
Reference in New Issue