Skip to content

Commit

Permalink
Merge pull request #218 from johnhaddon/cameraControllerSetResolutionFix
Browse files Browse the repository at this point in the history
Fixed cropping bug in CameraController::setResolution.
  • Loading branch information
andrewkaufman committed Feb 4, 2014
2 parents ea8e07f + e8d0696 commit 566072c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/IECore/CameraController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ void CameraController::setResolution( const Imath::V2i &resolution, ScreenWindow
{
const V2f screenWindowCenter = oldScreenWindow.center();
const V2f scale = V2f( resolution ) / V2f( oldResolution );
newScreenWindow.min = (oldScreenWindow.min - screenWindowCenter) * scale;
newScreenWindow.max = (oldScreenWindow.max - screenWindowCenter) * scale;
newScreenWindow.min = screenWindowCenter + (oldScreenWindow.min - screenWindowCenter) * scale;
newScreenWindow.max = screenWindowCenter + (oldScreenWindow.max - screenWindowCenter) * scale;
}

m_data->screenWindow->writable() = newScreenWindow;
Expand Down
16 changes: 15 additions & 1 deletion test/IECore/CameraControllerTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,22 @@ def testSetResolutionCropping( self ) :
controller.setResolution( IECore.V2i( 100, 100 ), controller.ScreenWindowAdjustment.CropScreenWindow )
self.assertEqual( camera.parameters()["screenWindow"].value, IECore.Box2f( IECore.V2f( -1 ), IECore.V2f( 1 ) ) )

controller.setResolution( IECore.V2i( 100, 200 ), controller.ScreenWindowAdjustment.ScaleScreenWindow )
controller.setResolution( IECore.V2i( 100, 200 ), controller.ScreenWindowAdjustment.CropScreenWindow )
self.assertEqual( camera.parameters()["screenWindow"].value, IECore.Box2f( IECore.V2f( -1, -2 ), IECore.V2f( 1, 2 ) ) )

def testSetResolutionCroppingWithOffsetCenter( self ) :

camera = IECore.Camera()
camera.parameters()["resolution"] = IECore.V2i( 200, 100 )
camera.parameters()["screenWindow"] = IECore.Box2f( IECore.V2f( -2, -1 ), IECore.V2f( 0, 0 ) )

controller = IECore.CameraController( camera )

controller.setResolution( IECore.V2i( 100, 100 ), controller.ScreenWindowAdjustment.CropScreenWindow )
self.assertEqual( camera.parameters()["screenWindow"].value, IECore.Box2f( IECore.V2f( -1.5, -1 ), IECore.V2f( -0.5, 0 ) ) )

controller.setResolution( IECore.V2i( 100, 200 ), controller.ScreenWindowAdjustment.CropScreenWindow )
self.assertEqual( camera.parameters()["screenWindow"].value, IECore.Box2f( IECore.V2f( -1.5, -1.5 ), IECore.V2f( -0.5, 0.5 ) ) )

if __name__ == "__main__":
unittest.main()

0 comments on commit 566072c

Please sign in to comment.