Commit 580fc9c6 authored by Robert Menzel's avatar Robert Menzel

added more options to set the focal length

parent fbbddb3d
......@@ -288,15 +288,25 @@ class GenericCamera
void setStateFromString( const std::string &_state );
/// The focal length is coupled to the sensor size in real cameras. As this camera does not model a
/// sensor size, the focal length is given in pixels and is in relation to the viewports resolution.
/// sensor size in mm, the focal length is given in pixels and is in relation to the viewports resolution.
/// This model is also used by bundler.
/// Note that this gives only useful results if the viewports aspect ratio is the same as the
/// projections aspect ratio!
float getFocalLenght();
float getFocalLenghtInPixel() const;
/// Sets the focal length in pixel relative to the viewport dimension. This will change the FoV.
/// See getFocalLenght() for more information.
void setFocalLength( float _focalLengthInPixel );
/// See getFocalLenghtInPixel() for more information.
void setFocalLengthInPixel( float _focalLengthInPixel );
/// The focal length is coupled to the sensor size in real cameras. As this camera does not model a
/// sensor size in mm (yet), a 135 (35mm) film size is assumed (framesize of 36*24mm).
/// The assumed sensor size might change in case other formats get supported later on but
/// 24mm height should be the default.
float getFocalLenghtInMM() const;
/// Sets the focal length in mm assuming a 135 film. This will change the FoV.
/// See getFocalLenghtInMM() for more information.
void setFocalLengthInMM( float _focalLengthInMM );
private:
/// the Matrix with the camera position/orientation.
......
......@@ -485,14 +485,27 @@ void GenericCamera::setStateFromString( const std::string &_state )
mViewportSize = toUvec2( token[pos++] );
}
float GenericCamera::getFocalLenght()
float GenericCamera::getFocalLenghtInPixel() const
{
return ( (float) mViewportSize.y ) / ( 2.0f * tan( calcDegToRad(0.5f * mHorizontalFieldOfView) ) );
return ( (float) mViewportSize.x ) / ( 2.0f * tan( calcDegToRad(0.5f * mHorizontalFieldOfView) ) );
}
void GenericCamera::setFocalLength( float _focalLengthInPixel )
void GenericCamera::setFocalLengthInPixel( float _focalLengthInPixel )
{
float hFoVrad = 2.0f * atan( ( 0.5f * mViewportSize.y ) * (1.0f / _focalLengthInPixel ) );
float hFoVrad = 2.0f * atan( ( 0.5f * mViewportSize.x ) * (1.0f / _focalLengthInPixel ) );
setHorizontalFieldOfView( calcRadToDeg( hFoVrad ) );
}
float GenericCamera::getFocalLenghtInMM() const
{
glm::vec2 sensorSize = glm::vec2( 36.0f/mAspectRatio, 24.0f ); // in mm
return ( sensorSize.x ) / ( 2.0f * tan( calcDegToRad(0.5f * mHorizontalFieldOfView) ) );
}
void GenericCamera::setFocalLengthInMM( float _focalLengthInMM )
{
glm::vec2 sensorSize = glm::vec2( 36.0f/mAspectRatio, 24.0f ); // in mm
float hFoVrad = 2.0f * atan( ( 0.5f * sensorSize.x ) * (1.0f / _focalLengthInMM ) );
setHorizontalFieldOfView( calcRadToDeg( hFoVrad ) );
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment