Overrides - Fixed NaN in camera handling
This commit is contained in:
parent
aa58b016c2
commit
75af2c15c7
1 changed files with 10 additions and 5 deletions
15
camera.cc
15
camera.cc
|
@ -48,14 +48,19 @@ void T_Camera::cvtAnglesToVectors( ) noexcept
|
||||||
void T_Camera::cvtVectorsToAngles( ) noexcept
|
void T_Camera::cvtVectorsToAngles( ) noexcept
|
||||||
{
|
{
|
||||||
dir_ = lookAt_ - pos_;
|
dir_ = lookAt_ - pos_;
|
||||||
distance_ = glm::length( dir_ );
|
const float distance{ length( dir_ ) };
|
||||||
if ( distance_ == 0 ) {
|
if ( distance == 0 || length( up_ ) == 0 ) {
|
||||||
angles_ = glm::vec3( 0 );
|
return;
|
||||||
|
}
|
||||||
|
distance_ = distance;
|
||||||
|
|
||||||
|
const glm::vec3 nDir{ - dir_ / distance_ };
|
||||||
|
const glm::vec3 nUp{ normalize( up_ ) };
|
||||||
|
if ( abs( dot( nUp , nDir ) ) == 1 ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const glm::vec3 nDir{ - dir_ / distance_ };
|
const glm::vec3 side{ normalize( cross( nUp , nDir ) ) };
|
||||||
const glm::vec3 side{ normalize( cross( normalize( up_ ) , nDir ) ) };
|
|
||||||
const glm::vec3 up{ normalize( cross( nDir , side ) ) };
|
const glm::vec3 up{ normalize( cross( nDir , side ) ) };
|
||||||
column( rotMat_ , 0 ) = side;
|
column( rotMat_ , 0 ) = side;
|
||||||
column( rotMat_ , 1 ) = up;
|
column( rotMat_ , 1 ) = up;
|
||||||
|
|
Loading…
Reference in a new issue