This kind of extensions implement camera lenses. This class is defined in mx_cameraextension.h.
Code Block | ||
---|---|---|
| ||
class CcameraLensExtension : public CbaseExtension { public: virtual bool initializeForRendering( Cmaxwell::Ccamera& camera, Cmaxwell* pMaxwell ) = 0; // Returns camera origin and direction (normalized) in world coordinates, given a point in the 2D buffer (in [0,xRes-1],[0,yRes-1] range) virtual bool getCameraRay( Cpoint& origin, Cvector& direction, const Cvector2D& bufferPoint ) = 0; // Returns true if the lens has real area or false if this is an ideal lens (pinhole, spherical, etc) virtual bool hasArea( void ) const { return ( false ); } // Returns true if the lens supports Bidirectional Path Tracing virtual bool supportsBPT( void ) const { return ( false ); } // Returns by reference a 2D point in the film in [1,1] coordinates // Returns by value the PDF associated to the given input direction // If returned PDF is 0.0 the direction is not valid virtual real onLensToFilm( Cvector2D& filmPoint, const Cvector& direction ) { return ( 0.0 ); } }; |
...
PDF of the given input direction.
Code Block | |||
---|---|---|---|
| |||
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; } LensExtensionTextLensExtensionTest::LensExtensionTextLensExtensionTest() { pMaxwell_ = NULL; } bool LensExtensionTextLensExtensionTest::initializeForRendering( Cmaxwell::Ccamera& camera, Cmaxwell* pMaxwell ) { pMaxwell_ = pMaxwell; real scaleToFilm; base_ = getCameraBase( camera, 0, base_, to_ ); getFilmData( camera, 0, scaleToWindow_, scaleToFilm ); return ( true ); } bool LensExtensionTextLensExtensionTest::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 ); } extern "C" ALWAYSEXPORT int getSdkVersion() { return MAXWELL_SDK_VERSION; } extern "C" ALWAYSEXPORT int StartExtension( CextensionManager& extensionManager ) { int i = 0; if( extensionManager.registerCameraLensExtension( new LensExtensionText ) ) i++; return i; } |