mirror of https://github.com/AxioDL/zeus.git
Fix lookAt
This commit is contained in:
parent
e572a46949
commit
a427e0a8a2
16
src/Math.cpp
16
src/Math.cpp
|
@ -167,14 +167,20 @@ CTransform lookAt(const CVector3f& pos, const CVector3f& lookPos, const CVector3
|
||||||
CVector3f vLook, vRight, vUp;
|
CVector3f vLook, vRight, vUp;
|
||||||
|
|
||||||
vLook = lookPos - pos;
|
vLook = lookPos - pos;
|
||||||
if (vLook.magnitude() < FLT_EPSILON)
|
if (vLook.magnitude() <= FLT_EPSILON)
|
||||||
vLook = {0.f, 1.f, 0.f};
|
vLook = {0.f, 1.f, 0.f};
|
||||||
|
else
|
||||||
vLook.normalize();
|
vLook.normalize();
|
||||||
|
|
||||||
vRight = vLook.cross(up);
|
vUp = up - vLook * clamp(-1.f, up.dot(vLook), 1.f);
|
||||||
vRight.normalize();
|
if (vUp.magnitude() <= FLT_EPSILON)
|
||||||
|
{
|
||||||
vUp = vRight.cross(vLook);
|
vUp = CVector3f(0.f, 0.f, 1.f) - vLook * vLook.z;
|
||||||
|
if (vUp.magnitude() <= FLT_EPSILON)
|
||||||
|
vUp = CVector3f(0.f, 1.f, 0.f) - vLook * vLook.y;
|
||||||
|
}
|
||||||
|
vUp.normalize();
|
||||||
|
vRight = vLook.cross(vUp);
|
||||||
|
|
||||||
CMatrix3f rmBasis(vRight, vLook, vUp);
|
CMatrix3f rmBasis(vRight, vLook, vUp);
|
||||||
return CTransform(rmBasis, pos);
|
return CTransform(rmBasis, pos);
|
||||||
|
|
Loading…
Reference in New Issue