Overrides - Fixed NaN in camera handling

This commit is contained in:
Emmanuel BENOîT 2017-11-20 11:26:53 +01:00
parent aa58b016c2
commit 75af2c15c7

View file

@ -48,14 +48,19 @@ void T_Camera::cvtAnglesToVectors( ) noexcept
void T_Camera::cvtVectorsToAngles( ) noexcept
{
dir_ = lookAt_ - pos_;
distance_ = glm::length( dir_ );
if ( distance_ == 0 ) {
angles_ = glm::vec3( 0 );
const float distance{ length( dir_ ) };
if ( distance == 0 || length( up_ ) == 0 ) {
return;
}
distance_ = distance;
const glm::vec3 nDir{ - dir_ / distance_ };
const glm::vec3 nUp{ normalize( up_ ) };
if ( abs( dot( nUp , nDir ) ) == 1 ) {
return;
}
const glm::vec3 nDir{ - dir_ / distance_ };
const glm::vec3 side{ normalize( cross( normalize( up_ ) , nDir ) ) };
const glm::vec3 side{ normalize( cross( nUp , nDir ) ) };
const glm::vec3 up{ normalize( cross( nDir , side ) ) };
column( rotMat_ , 0 ) = side;
column( rotMat_ , 1 ) = up;