Overrides - Started rework of camera
This commit is contained in:
parent
7a4595e8e8
commit
bebf54cfee
3 changed files with 126 additions and 50 deletions
4
TODO
4
TODO
|
@ -14,6 +14,7 @@ Scripting:
|
|||
* Re-execute init if shaders are changed
|
||||
(better yet, only execute the parts that are actually needed)
|
||||
* Overrides
|
||||
* Check for overrides on the same inputs when setting things up
|
||||
* Aliases
|
||||
* Display errors in UI
|
||||
* Optimizers:
|
||||
|
@ -26,6 +27,9 @@ Scripting:
|
|||
|
||||
Sync / inputs:
|
||||
* Support for overrides
|
||||
* Camera controls
|
||||
* FoV vs near plane
|
||||
* Target/angles/distance vs dir/up/left
|
||||
* Curve / timeline display
|
||||
* Display selected input values
|
||||
* Display selected overrides
|
||||
|
|
76
camera.cc
76
camera.cc
|
@ -5,12 +5,34 @@
|
|||
|
||||
/*= T_Camera =================================================================*/
|
||||
|
||||
T_Camera::T_Camera( ) noexcept
|
||||
{
|
||||
cvtFov2Np( );
|
||||
cvtAnglesToVectors( );
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
void T_Camera::cvtAnglesToVectors( ) noexcept
|
||||
{
|
||||
anglesToMatrix( &angles_.x , &rotMat_[ 0 ].x );
|
||||
dir_ = glm::vec3( 0 , 0 , -distance_ ) * rotMat_;
|
||||
up_ = glm::vec3( 0 , 1 , 0 ) * rotMat_;
|
||||
pos_ = lookAt_ - dir_;
|
||||
}
|
||||
|
||||
void T_Camera::cvtVectorsToAngles( ) noexcept
|
||||
{
|
||||
#warning implement the fuck
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------*/
|
||||
|
||||
void T_Camera::handleDND(
|
||||
ImVec2 const& move ,
|
||||
const bool hasCtrl ,
|
||||
const bool hasShift ,
|
||||
const bool lmb // Left mouse button
|
||||
)
|
||||
const bool lmb ) noexcept
|
||||
{
|
||||
if ( move.x == 0 || move.y == 0 ) {
|
||||
return;
|
||||
|
@ -21,65 +43,57 @@ void T_Camera::handleDND(
|
|||
|
||||
if ( lmb && hasShift ) {
|
||||
// Left mouse button, shift - move camera
|
||||
const auto side( glm::normalize( glm::cross( up , dir ) ) );
|
||||
lookAt += .1f * ( side * fdx + up * fdy );
|
||||
const auto side( glm::normalize( glm::cross( up_ , dir_ ) ) );
|
||||
lookAt_ += .1f * ( side * fdx + up_ * fdy );
|
||||
} else if ( lmb ) {
|
||||
// Left mouse button, no shift - change yaw/pitch
|
||||
updateAngle( angles.y , fdx );
|
||||
updateAngle( angles.x , fdy );
|
||||
updateAngle( angles_.y , fdx );
|
||||
updateAngle( angles_.x , fdy );
|
||||
} else {
|
||||
// Right mouse button - change roll
|
||||
updateAngle( angles.z , fdx );
|
||||
updateAngle( angles_.z , fdx );
|
||||
}
|
||||
update( );
|
||||
cvtAnglesToVectors( );
|
||||
}
|
||||
|
||||
void T_Camera::handleWheel(
|
||||
const float wheel ,
|
||||
const bool hasCtrl ,
|
||||
const bool hasShift
|
||||
)
|
||||
const bool hasShift ) noexcept
|
||||
{
|
||||
const float delta( wheel * ( hasCtrl ? 1.f : .1f) );
|
||||
if ( hasShift ) {
|
||||
fov = std::max( 1.f , std::min( 179.f , fov + delta ) );
|
||||
fov_ = std::max( 1.f , std::min( 179.f , fov_ + delta ) );
|
||||
cvtFov2Np( );
|
||||
} else {
|
||||
distance = std::max( .01f , distance - delta );
|
||||
distance_ = std::max( .01f , distance_ - delta );
|
||||
cvtAnglesToVectors( );
|
||||
}
|
||||
update( );
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
void T_Camera::makeUI( )
|
||||
void T_Camera::makeUI( ) noexcept
|
||||
{
|
||||
if ( !ImGui::CollapsingHeader( "Camera" ) ) {
|
||||
using namespace ImGui;
|
||||
if ( !CollapsingHeader( "Camera" ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
const bool changed[] = {
|
||||
ImGui::DragFloat3( "Look at" , &lookAt.x ) ,
|
||||
ImGui::DragFloat( "Distance" , &distance , .1f ,
|
||||
DragFloat3( "Target" , &lookAt_.x ) ,
|
||||
DragFloat( "Distance" , &distance_ , .1f ,
|
||||
.1f , 1e8 , "%.1f" ) ,
|
||||
ImGui::DragFloat3( "Angles" , &angles.x , .01f , -180 , 180 ) ,
|
||||
ImGui::DragFloat( "FoV" , &fov , .01f , .01f , 179.9f )
|
||||
DragFloat3( "Angles" , &angles_.x , .01f , -180 , 180 ) ,
|
||||
|
||||
DragFloat( "FoV" , &fov_ , .01f , .01f , 179.9f )
|
||||
};
|
||||
|
||||
for ( unsigned i = 0 ; i < sizeof( changed ) / sizeof( bool ) ; i ++ ) {
|
||||
if ( changed[ i ] ) {
|
||||
update( );
|
||||
#warning fix this shit
|
||||
// FIXME update( );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
void T_Camera::update( )
|
||||
{
|
||||
anglesToMatrix( &angles.x , &rotMat[ 0 ].x );
|
||||
dir = glm::vec3( 0 , 0 , -distance ) * rotMat;
|
||||
up = glm::vec3( 0 , 1 , 0 ) * rotMat;
|
||||
pos = lookAt - dir;
|
||||
np = 2 * tan( M_PI * ( 180. - fov ) / 360. );
|
||||
}
|
||||
|
|
96
camera.hh
96
camera.hh
|
@ -6,38 +6,96 @@
|
|||
|
||||
/*= T_Camera =================================================================*/
|
||||
|
||||
/* Data for a camera.
|
||||
*
|
||||
* For the field of view, both the near plane distance and the angle are
|
||||
* stored. Updating one causes the other to be updated.
|
||||
*
|
||||
* For the camera position and orientation, the data is stored as two different
|
||||
* sets:
|
||||
* - target, angles, distance
|
||||
* - position, direction and up vectors
|
||||
* Modifying one of the sets updates the other.
|
||||
*/
|
||||
struct T_Camera
|
||||
{
|
||||
glm::vec3 lookAt = glm::vec3( 0 );
|
||||
glm::vec3 angles = glm::vec3( 0 );
|
||||
float distance = 10;
|
||||
float fov = 90;
|
||||
T_Camera( ) noexcept;
|
||||
|
||||
// Everything below is updated by update()
|
||||
glm::vec3 dir;
|
||||
glm::vec3 up;
|
||||
glm::vec3 pos;
|
||||
float np;
|
||||
DEF_COPY( T_Camera );
|
||||
DEF_MOVE( T_Camera );
|
||||
|
||||
T_Camera()
|
||||
{ update( ); }
|
||||
// ---------------------------------------------------------------------
|
||||
// FIELD OF VIEW / NEAR PLANE
|
||||
|
||||
public:
|
||||
void fieldOfView( const float angle ) noexcept
|
||||
{
|
||||
fov_ = std::min( 179.f , std::max( 1.f , angle ) );
|
||||
cvtFov2Np( );
|
||||
}
|
||||
|
||||
void nearPlane( const float distance ) noexcept
|
||||
{
|
||||
np_ = std::max( .001f , distance );
|
||||
cvtNp2Fov( );
|
||||
}
|
||||
|
||||
float fieldOfView( ) const noexcept
|
||||
{ return fov_; }
|
||||
float nearPlane( ) const noexcept
|
||||
{ return np_; }
|
||||
|
||||
private:
|
||||
float fov_ = 90.f;
|
||||
float np_;
|
||||
|
||||
void cvtFov2Np( ) noexcept
|
||||
{ np_ = 2 * tanf( M_PI * ( 180.f - fov_ ) / 360.f ); }
|
||||
void cvtNp2Fov( ) noexcept
|
||||
{ fov_ = 180.f - atanf( .5 * np_ ) * 360.f / M_PI; }
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// POSITION AND ORIENTATION
|
||||
|
||||
public:
|
||||
void camera( glm::vec3 const& lookAt ,
|
||||
glm::vec3 const& angles ,
|
||||
float distance ) noexcept;
|
||||
void camera( glm::vec3 const& position ,
|
||||
glm::vec3 const& direction ,
|
||||
glm::vec3 const& up ) noexcept;
|
||||
|
||||
private:
|
||||
glm::vec3 lookAt_ = glm::vec3( 0 );
|
||||
glm::vec3 angles_ = glm::vec3( 0 );
|
||||
float distance_ = 10;
|
||||
|
||||
glm::vec3 dir_;
|
||||
glm::vec3 up_;
|
||||
glm::vec3 pos_;
|
||||
|
||||
glm::mat3x3 rotMat_;
|
||||
|
||||
void cvtAnglesToVectors( ) noexcept;
|
||||
void cvtVectorsToAngles( ) noexcept;
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// UI & MOUSE CONTROLS
|
||||
|
||||
public:
|
||||
void makeUI( ) noexcept;
|
||||
|
||||
void handleDND(
|
||||
ImVec2 const& move ,
|
||||
const bool hasCtrl ,
|
||||
const bool hasShift ,
|
||||
const bool lmb // Left mouse button
|
||||
);
|
||||
) noexcept;
|
||||
void handleWheel(
|
||||
const float wheel ,
|
||||
const bool hasCtrl ,
|
||||
const bool hasShift
|
||||
);
|
||||
) noexcept;
|
||||
|
||||
void makeUI( );
|
||||
|
||||
private:
|
||||
glm::mat3x3 rotMat;
|
||||
float rotationMatrix[ 9 ];
|
||||
void update( );
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue