Overrides - Further work on camera data
It *should* be ready to be used with the overrides system now.
This commit is contained in:
parent
bebf54cfee
commit
1078ff67b5
2 changed files with 50 additions and 5 deletions
53
camera.cc
53
camera.cc
|
@ -2,6 +2,8 @@
|
|||
#include "camera.hh"
|
||||
#include "utilities.hh"
|
||||
|
||||
#include <glm/gtc/matrix_access.hpp>
|
||||
|
||||
|
||||
/*= T_Camera =================================================================*/
|
||||
|
||||
|
@ -13,6 +15,28 @@ T_Camera::T_Camera( ) noexcept
|
|||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
void T_Camera::camera(
|
||||
glm::vec3 const& lookAt ,
|
||||
glm::vec3 const& angles ,
|
||||
const float distance ) noexcept
|
||||
{
|
||||
lookAt_ = lookAt;
|
||||
angles_ = angles;
|
||||
distance_ = distance;
|
||||
cvtAnglesToVectors( );
|
||||
}
|
||||
|
||||
void T_Camera::camera(
|
||||
glm::vec3 const& position ,
|
||||
glm::vec3 const& target ,
|
||||
glm::vec3 const& up ) noexcept
|
||||
{
|
||||
pos_ = position;
|
||||
up_ = up;
|
||||
lookAt_ = target;
|
||||
cvtVectorsToAngles( );
|
||||
}
|
||||
|
||||
void T_Camera::cvtAnglesToVectors( ) noexcept
|
||||
{
|
||||
anglesToMatrix( &angles_.x , &rotMat_[ 0 ].x );
|
||||
|
@ -23,7 +47,31 @@ void T_Camera::cvtAnglesToVectors( ) noexcept
|
|||
|
||||
void T_Camera::cvtVectorsToAngles( ) noexcept
|
||||
{
|
||||
#warning implement the fuck
|
||||
dir_ = lookAt_ - pos_;
|
||||
distance_ = dir_.length( );
|
||||
if ( distance_ == 0 ) {
|
||||
angles_ = glm::vec3( 0 );
|
||||
return;
|
||||
}
|
||||
|
||||
const glm::vec3 nDir{ - dir_ / distance_ };
|
||||
const glm::vec3 side{ normalize( cross( normalize( up_ ) , nDir ) ) };
|
||||
const glm::vec3 up{ normalize( cross( nDir , side ) ) };
|
||||
column( rotMat_ , 0 ) = side;
|
||||
column( rotMat_ , 1 ) = up;
|
||||
column( rotMat_ , 2 ) = nDir;
|
||||
|
||||
glm::vec3 nAngles;
|
||||
nAngles.x = atan2f( nDir.y , nDir.z );
|
||||
|
||||
const float c2{ sqrtf( side.x * side.x + side.y * side.y ) };
|
||||
nAngles.y = atan2f( -side.z , c2 );
|
||||
|
||||
const float s1{ sinf( nAngles.x ) } , c1{ cosf( nAngles.x ) };
|
||||
nAngles.z = atan2f( s1 * nDir.x - c1 * up.x ,
|
||||
c1 * up.y - s1 * nDir.y );
|
||||
|
||||
angles_ = nAngles * 360.f / float( M_PI );
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------*/
|
||||
|
@ -76,9 +124,6 @@ void T_Camera::handleWheel(
|
|||
void T_Camera::makeUI( ) noexcept
|
||||
{
|
||||
using namespace ImGui;
|
||||
if ( !CollapsingHeader( "Camera" ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
const bool changed[] = {
|
||||
DragFloat3( "Target" , &lookAt_.x ) ,
|
||||
|
|
|
@ -63,7 +63,7 @@ struct T_Camera
|
|||
glm::vec3 const& angles ,
|
||||
float distance ) noexcept;
|
||||
void camera( glm::vec3 const& position ,
|
||||
glm::vec3 const& direction ,
|
||||
glm::vec3 const& directionOrTarget ,
|
||||
glm::vec3 const& up ) noexcept;
|
||||
|
||||
private:
|
||||
|
|
Loading…
Reference in a new issue