Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

This kind of extensions implement camera lenses. This class is defined in mx_cameraextension.h. 

Code Block
languagecpp
class CcameraLensExtension : public CbaseExtension
{
public:
    virtual bool initializeForRendering( Cmaxwell::Ccamera& camera, Cmaxwell* pMaxwell ) = 0;
    
    virtual bool getCameraRay( Cpoint& origin, Cvector& direction, const Cvector2D& bufferPoint ) = 0;

    virtual bool hasArea( void ) const
    {
        return ( false );
    }

    virtual bool supportsBPT( void ) const
    {
        return ( false );
    }

    virtual real onLensToFilm( Cvector2D& filmPoint, const Cvector& direction )
    {
        return ( 0.0 );
    }
};

...

PDF of the given input direction.

 

cpp
Code Block
language
titleLens Test Example
class LensExtensionTest : public CcameraLensExtension
{
    DECLARE_EXTENSION_METHODS( "Lens Test", LensExtensionTest, 1 )
public:
    LensExtensionTest();
    ~LensExtensionTest()    { cleanup( pMaxwell_ );    }
    bool initializeForRendering( Cmaxwell::Ccamera& camera, Cmaxwell* pMaxwell );
    void cleanup( Cmaxwell* pMaxwell ){}
    bool getCameraRay( Cpoint& origin, Cvector& direction, const Cvector2D& onDevice );
    bool hasArea( void ) const
    {
        return ( false );
    }
    bool supportsBPT( void ) const
    {
        return ( true );
    }
    /// DATA
    Cmaxwell* pMaxwell_;
    Cbase base_;
    Cpoint to_;
    real scaleToWindow_;
};

Cbase getCameraBase( Cmaxwell::Ccamera& camera, const dword& iStep, Cbase& base, Cpoint& to )
{
    Cpoint from;
    Cvector up;
    real fl, fStop, stepTime;
    camera.getStep( iStep, from, to, up, fl, fStop, stepTime );
    // Calculate base 
    real    cosAng;
    Cpoint focal;
    base.origin = from;
    focal.assign( to );

    base.zAxis.substract( from, to );
    real focalDistance = base.zAxis.norm();
    base.zAxis.scale( 1.0 / focalDistance );
    cosAng = fabs( up.dot( base.zAxis ) );
    if( cosAng > 1.0 - Cnumeric::tolerance )
    {
        up.assign( 0.0, 1.0, 0.0 );
        cosAng = fabs( up.dot( base.zAxis ) );
        if( cosAng > 1.0 - Cnumeric::tolerance )
        {
            up.assign( 0.0, 0.0, 1.0 );
        }
    }
    base.xAxis.cross( up, base.zAxis );
    base.xAxis.normalize();
    base.yAxis.cross( base.zAxis, base.xAxis );
    return ( base );
}

void getFilmData( Cmaxwell::Ccamera& camera, const dword& iStep, real& scaleToWindow, real& scaleToFilm )
{
    if( camera.isNull() )
        return;
    Cpoint from, to;
    Cvector up;
    real fl, fStop, stepTime;
    camera.getStep( iStep, from, to, up, fl, fStop, stepTime );
    Cvector fromToDist;
    fromToDist.substract( from, to ); // FIXED: new base
    real focalDistance = fromToDist.norm();
    real focalLength = fl;

    real radius = 0.5 * ( focalLength / fStop );
    real radius2 = radius * radius;
    real filmDistance = fabs( ( focalLength * focalDistance ) / ( focalDistance - focalLength ) );
    scaleToWindow = 1.0 - ( focalDistance + filmDistance ) / filmDistance;
    scaleToFilm = 1.0 - ( focalDistance + filmDistance ) / focalDistance;
}

LensExtensionText::LensExtensionText()
{
    pMaxwell_ = NULL;
}

bool LensExtensionText::initializeForRendering( Cmaxwell::Ccamera& camera, Cmaxwell* pMaxwell )
{
    pMaxwell_ = pMaxwell;
    real scaleToFilm;
    base_ = getCameraBase( camera, 0, base_, to_ );
    getFilmData( camera, 0, scaleToWindow_, scaleToFilm );
    return ( true );
}

bool LensExtensionText::getCameraRay( Cpoint& origin, Cvector& direction, const Cvector2D& filmPoint )
{
    // Just a simple pinhole lens test
    origin.assign( base_.origin );
    Cvector2D   scale;
    scale.x = filmPoint.x * scaleToWindow_;
    scale.y = filmPoint.y * scaleToWindow_;
    Cpoint onWindow;
    onWindow.x = to_.x + base_.xAxis.x * scale.x + base_.yAxis.x * scale.y;
    onWindow.y = to_.y + base_.xAxis.y * scale.x + base_.yAxis.y * scale.y;
    onWindow.z = to_.z + base_.xAxis.z * scale.x + base_.yAxis.z * scale.y;
    direction.x = onWindow.x - base_.origin.x;
    direction.y = onWindow.y - base_.origin.y;
    direction.z = onWindow.z - base_.origin.z;
    direction.normalize();
    return ( true );
}

...