Content summary:
- Utilizing dialog-based MFC projects
- Implement mouse click to draw polygons
- Implement scanline algorithm to fill polygons
For the source code, see Yushan-Ji/ComputerGraphics: ECNU2023 Fall Computer Graphics Course Experiment Code (github.com)
Experimental content
- Polygon input via mouse interaction
- Fill various polygons, including boundary self-intersections
Algorithm description
Polygon drawing
- Use the
OnLButtonDown
andOnRButtonDown
functions to implement:- Left click: Start drawing the polygon and connect the previous vertex to the currently clicked vertex
- Right-click: End drawing the polygon and connect the previous vertex to the first vertex
Among them, theMoveTo
andLineTo
functions are used to draw the connection between vertices.
- In addition, in order to prevent the program from still responding to mouse click events after the polygon is drawn, it is necessary to add a Boolean variable
IsCompleted
to monitor whether the current polygon has been drawn
Therefore, at the beginning of theOnLButtonDown
andOnRButtonDown
functions, a conditional judgment statement needs to be added. IfIsCompleted
isTRUE
, It indicates that the polygon has been drawn and the function returns directly - Save all vertex information in
vector
to facilitate subsequent calculation of edge informationpoints
Scan line filling