Clipping and Scan ConversionJason LawrenceCS 445: GraphicsAcknowledgment: slides by Misha Kazhdan, Allison Klein, Tom Funkhouser,Adam Finkelstein and David DobkinLightingCameraTransformation3D Rendering Pipeline (for direct illumination)3D PrimitivesModelingTransformationProjectionTransformationClippingImageViewportTransformationScanConversion2D Image Coordinates3D Modeling Coordinates3D World Coordinates3D Camera Coordinates2D Screen Coordinates2D Screen Coordinates3D Camera Coordinates2D Image Coordinates3D Model2D ImageTransformationsModelingTransformationCameraTransformation2D Image CoordinatesProjectionTransformationWindow-to-ViewportTransformation3D Object Coordinates3D World Coordinates3D Camera Coordinates2D Screen Coordinatesp(x,y,z)p’(x’,y’)3D WorldCoordinates3D ObjectCoordinatesTransformationsModelingTransformationCameraTransformation2D Image CoordinatesProjectionTransformationWindow-to-ViewportTransformation3D Object Coordinates3D World Coordinates3D Camera Coordinates2D Screen Coordinatesp(x,y,z)p’(x’,y’)3D WorldCoordinatesTransform=MM := local to world transformTransformationsModelingTransformationCameraTransformation2D Image CoordinatesProjectionTransformationWindow-to-ViewportTransformation3D Object Coordinates3D World Coordinates3D Camera Coordinates2D Screen Coordinatesp(x,y,z)p’(x’,y’)3D WorldCoordinates3D CameraCoordinatesTransform=MM := local to world transformTransformationsModelingTransformationCameraTransformation2D Image CoordinatesProjectionTransformationWindow-to-ViewportTransformation3D Object Coordinates3D World Coordinates3D Camera Coordinates2D Screen Coordinatesp(x,y,z)p’(x’,y’)Camera RightCamera UpxyzCamera BackTransform=C-1MC := camera transformTransformationsModelingTransformationCameraTransformation2D Image CoordinatesProjectionTransformationWindow-to-ViewportTransformation3D Object Coordinates3D World Coordinates3D Camera Coordinates2D Screen Coordinatesp(x,y,z)p’(x’,y’)Transform=PC-1MP := projection transformTransformationsModelingTransformationCameraTransformation2D Image CoordinatesProjectionTransformationWindow-to-ViewportTransformation3D Object Coordinates3D World Coordinates3D Camera Coordinates2D Screen Coordinatesp(x,y,z)p’(x’,y’)Transform=VPC-1MV := viewport transformImageNormalized CoordsViewportWindowTransformationsModelingTransformationCameraTransformation2D Image CoordinatesProjectionTransformationWindow-to-ViewportTransformation3D Object Coordinates3D World Coordinates3D Camera Coordinates2D Screen Coordinatesp(x,y,z)p’(x’,y’)vx1vx2vy1vy2wx1wx2wy1wy2Window ViewportScreen CoordinatesImage Coordinates(wx,wy) (vx,vy)Transform=VPC-1MV := viewport transform3D Rendering Pipeline (for direct illumination)3D Model2D Viewport2D ScreenModelingTransformationCameraTransformation2D Image CoordinatesProjectionTransformationWindow-to-ViewportTransformation3D Object Coordinates3D World Coordinates3D Camera Coordinates2D Screen Coordinatesp(x,y,z)p’(x’,y’)LightingCameraTransformation3D Rendering Pipeline (for direct illumination)3D PrimitivesModelingTransformationProjectionTransformationClippingImageViewportTransformationScanConversion2D Image Coordinates3D Modeling Coordinates3D World Coordinates3D Camera Coordinates2D Screen Coordinates2D Screen Coordinates3D Camera Coordinates2D Image CoordinatesClipping• Avoid drawing parts of primitives outside windowoWindow defines part of scene being viewed oMust draw geometric primitives only inside windowScreen CoordinatesWindowClipping• Avoid drawing parts of primitives outside windowoPoints oLine SegmentsoPolygonsScreen CoordinatesWindowPoint ClippingWindowwx1 wx2wy2wy1(x,y)• Is point (x,y) inside the clip window?Point ClippingWindowwx1 wx2wy2wy1(x,y)• Is point (x,y) inside the clip window?inside = (x >= wx1) && (x <= wx2) && (y >= wy1) && (y <= wy2);Clipping• Avoid drawing parts of primitives outside windowoPointsoLine SegmentsoPolygonsScreen CoordinatesWindowLine Segment Clipping• Find the part of a line inside the clip windowP1P10P9P8P7P4P3P6P5P2Before ClippingP’8P’7P4P3P6P’5After ClippingLine Segment Clipping• Find the part of a line inside the clip window"Cohen-Sutherland Line Clipping• Use simple tests to classify easy cases firstP1P10P9P8P7P4P3P6P5P2Cohen-Sutherland Line Clipping• If both outcodes are 0, line segment is inside• If AND of outcodes not 0, line segment is outside• Otherwise clip and testBit 1 Bit 2Bit 3Bit 40000 010010000001 010110010010 01101010P1P10P9P8P7P4P3P6P5P2Cohen-Sutherland Line Clipping• If both outcodes are 0, line segment is inside• If AND of outcodes not 0, line segment is outside• Otherwise clip and testBit 1 Bit 2Bit 3Bit 40000 010010000001 010110010010 01101010P10P9P8P7P4P3P6P5P1P2Cohen-Sutherland Line Clipping• If both outcodes are 0, line segment is inside• If AND of outcodes not 0, line segment is outside• Otherwise clip and testBit 1 Bit 2Bit 3Bit 40000 010010000001 010110010010 01101010P1P10P9P8P7P6P5P2P4P3Cohen-Sutherland Line Clipping• If both outcodes are 0, line segment is inside• If AND of outcodes not 0, line segment is outside• Otherwise clip and testBit 1 Bit 2Bit 3Bit 40000 010010000001 010110010010 01101010P10P9P8P7P6P5P4P3Cohen-Sutherland Line Clipping• If both outcodes are 0, line segment is inside• If AND of outcodes not 0, line segment is outside• Otherwise clip and testBit 1 Bit 2Bit 3Bit 40000 010010000001 010110010010 01101010P10P9P8P7P4P3P6P5Cohen-Sutherland Line Clipping• If both outcodes are 0, line segment is inside• If AND of outcodes not 0, line segment is outside• Otherwise clip and testBit 1 Bit 2Bit 3Bit 40000 010010000001 010110010010 01101010P10P9P8P7P4P3P6P5Cohen-Sutherland Line Clipping• If both outcodes are 0, line segment is inside• If AND of outcodes not 0, line segment is outside• Otherwise clip and testBit 1 Bit 2Bit 3Bit 40000 010010000001 010110010010 01101010P10P9P8P7P4P3P6P’50000 010010000001 010110010010 01101010Cohen-Sutherland Line Clipping• If both outcodes are 0, line segment is inside• If AND of outcodes not 0, line segment is outside• Otherwise clip and testBit 1 Bit 2Bit 3Bit 4P10P9P8P7P4P3P6P’50000 010010000001 010110010010 01101010Cohen-Sutherland Line Clipping• If both outcodes are 0, line segment is inside• If AND of outcodes not 0, line segment is outside• Otherwise clip and testBit 1 Bit 2Bit 3Bit 4P10P9P8P7P4P3P6P’50000 010010000001 010110010010 01101010Cohen-Sutherland
View Full Document