├── show ├── fill.gif ├── select.gif ├── storage.gif ├── draw_line.gif ├── draw_point.gif ├── draw_polygon.gif ├── draw_circle_oval.gif ├── transform_rotate.gif ├── transform_scale.gif ├── draw_circle_perfect.gif ├── transform_symmetry.gif └── transform_translate.gif ├── MFCOpenGL01 ├── MainFrm.h ├── stdafx.h ├── ClassView.h ├── FileView.h ├── MainFrm.cpp ├── ViewTree.h ├── resource.h ├── stdafx.cpp ├── targetver.h ├── ClassView.cpp ├── DialogBezier.h ├── DialogFill.cpp ├── DialogFill.h ├── DialogLine.cpp ├── DialogLine.h ├── DialogPoint.h ├── FileView.cpp ├── MFCOpenGL01.h ├── MFCOpenGL01.rc ├── UserImages.bmp ├── ViewTree.cpp ├── res │ ├── sort.bmp │ ├── Toolbar.bmp │ ├── bitmap1.bmp │ ├── bmp00001.bmp │ ├── bmp00002.bmp │ ├── bmp00003.bmp │ ├── bmp00004.bmp │ ├── cur00001.cur │ ├── cursor1.cur │ ├── explorer.bmp │ ├── fileview.bmp │ ├── sort_hc.bmp │ ├── toolbar1.bmp │ ├── toolbar2.bmp │ ├── MFCOpenGL01.ico │ ├── MFCOpenGL01.rc2 │ ├── Toolbar256.bmp │ ├── class_view.ico │ ├── classview.bmp │ ├── explorer_hc.bmp │ ├── file_view.ico │ ├── fileview_hc.bmp │ ├── menuimages.bmp │ ├── output_wnd.ico │ ├── properties.bmp │ ├── class_view_hc.ico │ ├── classview_hc.bmp │ ├── file_view_hc.ico │ ├── menuimages_hc.bmp │ ├── output_wnd_hc.ico │ ├── properties_hc.bmp │ ├── MFCOpenGL01Doc.ico │ ├── properties_wnd.ico │ └── properties_wnd_hc.ico ├── DialogBezier.cpp ├── DialogPoint.cpp ├── DialogPolygon.h ├── MFCOpenGL01.cpp ├── MFCOpenGL01Doc.h ├── DialogCircleOval.h ├── DialogPolygon.cpp ├── MFCOpenGL01View.cpp ├── MFCOpenGL01View.h ├── DialogCircleOval.cpp ├── DialogCirclePerfect.h ├── DialogCirclePerfect.cpp ├── packages.config ├── ReadMe.txt ├── MFCOpenGL01.vcxproj.filters ├── MFCOpenGL01.vcxproj └── MFCOpenGL01Doc.cpp ├── README.md ├── LICENSE ├── MFCOpenGL01.sln ├── .gitattributes └── .gitignore /show/fill.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/show/fill.gif -------------------------------------------------------------------------------- /show/select.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/show/select.gif -------------------------------------------------------------------------------- /show/storage.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/show/storage.gif -------------------------------------------------------------------------------- /show/draw_line.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/show/draw_line.gif -------------------------------------------------------------------------------- /MFCOpenGL01/MainFrm.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/MFCOpenGL01/MainFrm.h -------------------------------------------------------------------------------- /MFCOpenGL01/stdafx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/MFCOpenGL01/stdafx.h -------------------------------------------------------------------------------- /show/draw_point.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/show/draw_point.gif -------------------------------------------------------------------------------- /show/draw_polygon.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/show/draw_polygon.gif -------------------------------------------------------------------------------- /MFCOpenGL01/ClassView.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/MFCOpenGL01/ClassView.h -------------------------------------------------------------------------------- /MFCOpenGL01/FileView.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/MFCOpenGL01/FileView.h -------------------------------------------------------------------------------- /MFCOpenGL01/MainFrm.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/MFCOpenGL01/MainFrm.cpp -------------------------------------------------------------------------------- /MFCOpenGL01/ViewTree.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/MFCOpenGL01/ViewTree.h -------------------------------------------------------------------------------- /MFCOpenGL01/resource.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/MFCOpenGL01/resource.h -------------------------------------------------------------------------------- /MFCOpenGL01/stdafx.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/MFCOpenGL01/stdafx.cpp -------------------------------------------------------------------------------- /MFCOpenGL01/targetver.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/MFCOpenGL01/targetver.h -------------------------------------------------------------------------------- /MFCOpenGL01/ClassView.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/MFCOpenGL01/ClassView.cpp -------------------------------------------------------------------------------- /MFCOpenGL01/DialogBezier.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/MFCOpenGL01/DialogBezier.h -------------------------------------------------------------------------------- /MFCOpenGL01/DialogFill.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/MFCOpenGL01/DialogFill.cpp -------------------------------------------------------------------------------- /MFCOpenGL01/DialogFill.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/MFCOpenGL01/DialogFill.h -------------------------------------------------------------------------------- /MFCOpenGL01/DialogLine.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/MFCOpenGL01/DialogLine.cpp -------------------------------------------------------------------------------- /MFCOpenGL01/DialogLine.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/MFCOpenGL01/DialogLine.h -------------------------------------------------------------------------------- /MFCOpenGL01/DialogPoint.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/MFCOpenGL01/DialogPoint.h -------------------------------------------------------------------------------- /MFCOpenGL01/FileView.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/MFCOpenGL01/FileView.cpp -------------------------------------------------------------------------------- /MFCOpenGL01/MFCOpenGL01.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/MFCOpenGL01/MFCOpenGL01.h -------------------------------------------------------------------------------- /MFCOpenGL01/MFCOpenGL01.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/MFCOpenGL01/MFCOpenGL01.rc -------------------------------------------------------------------------------- /MFCOpenGL01/UserImages.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/MFCOpenGL01/UserImages.bmp -------------------------------------------------------------------------------- /MFCOpenGL01/ViewTree.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/MFCOpenGL01/ViewTree.cpp -------------------------------------------------------------------------------- /MFCOpenGL01/res/sort.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/MFCOpenGL01/res/sort.bmp -------------------------------------------------------------------------------- /show/draw_circle_oval.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/show/draw_circle_oval.gif -------------------------------------------------------------------------------- /show/transform_rotate.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/show/transform_rotate.gif -------------------------------------------------------------------------------- /show/transform_scale.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/show/transform_scale.gif -------------------------------------------------------------------------------- /MFCOpenGL01/DialogBezier.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/MFCOpenGL01/DialogBezier.cpp -------------------------------------------------------------------------------- /MFCOpenGL01/DialogPoint.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/MFCOpenGL01/DialogPoint.cpp -------------------------------------------------------------------------------- /MFCOpenGL01/DialogPolygon.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/MFCOpenGL01/DialogPolygon.h -------------------------------------------------------------------------------- /MFCOpenGL01/MFCOpenGL01.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/MFCOpenGL01/MFCOpenGL01.cpp -------------------------------------------------------------------------------- /MFCOpenGL01/MFCOpenGL01Doc.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/MFCOpenGL01/MFCOpenGL01Doc.h -------------------------------------------------------------------------------- /MFCOpenGL01/res/Toolbar.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/MFCOpenGL01/res/Toolbar.bmp -------------------------------------------------------------------------------- /MFCOpenGL01/res/bitmap1.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/MFCOpenGL01/res/bitmap1.bmp -------------------------------------------------------------------------------- /MFCOpenGL01/res/bmp00001.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/MFCOpenGL01/res/bmp00001.bmp -------------------------------------------------------------------------------- /MFCOpenGL01/res/bmp00002.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/MFCOpenGL01/res/bmp00002.bmp -------------------------------------------------------------------------------- /MFCOpenGL01/res/bmp00003.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/MFCOpenGL01/res/bmp00003.bmp -------------------------------------------------------------------------------- /MFCOpenGL01/res/bmp00004.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/MFCOpenGL01/res/bmp00004.bmp -------------------------------------------------------------------------------- /MFCOpenGL01/res/cur00001.cur: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/MFCOpenGL01/res/cur00001.cur -------------------------------------------------------------------------------- /MFCOpenGL01/res/cursor1.cur: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/MFCOpenGL01/res/cursor1.cur -------------------------------------------------------------------------------- /MFCOpenGL01/res/explorer.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/MFCOpenGL01/res/explorer.bmp -------------------------------------------------------------------------------- /MFCOpenGL01/res/fileview.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/MFCOpenGL01/res/fileview.bmp -------------------------------------------------------------------------------- /MFCOpenGL01/res/sort_hc.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/MFCOpenGL01/res/sort_hc.bmp -------------------------------------------------------------------------------- /MFCOpenGL01/res/toolbar1.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/MFCOpenGL01/res/toolbar1.bmp -------------------------------------------------------------------------------- /MFCOpenGL01/res/toolbar2.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/MFCOpenGL01/res/toolbar2.bmp -------------------------------------------------------------------------------- /show/draw_circle_perfect.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/show/draw_circle_perfect.gif -------------------------------------------------------------------------------- /show/transform_symmetry.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/show/transform_symmetry.gif -------------------------------------------------------------------------------- /show/transform_translate.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/show/transform_translate.gif -------------------------------------------------------------------------------- /MFCOpenGL01/DialogCircleOval.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/MFCOpenGL01/DialogCircleOval.h -------------------------------------------------------------------------------- /MFCOpenGL01/DialogPolygon.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/MFCOpenGL01/DialogPolygon.cpp -------------------------------------------------------------------------------- /MFCOpenGL01/MFCOpenGL01View.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/MFCOpenGL01/MFCOpenGL01View.cpp -------------------------------------------------------------------------------- /MFCOpenGL01/MFCOpenGL01View.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/MFCOpenGL01/MFCOpenGL01View.h -------------------------------------------------------------------------------- /MFCOpenGL01/res/MFCOpenGL01.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/MFCOpenGL01/res/MFCOpenGL01.ico -------------------------------------------------------------------------------- /MFCOpenGL01/res/MFCOpenGL01.rc2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/MFCOpenGL01/res/MFCOpenGL01.rc2 -------------------------------------------------------------------------------- /MFCOpenGL01/res/Toolbar256.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/MFCOpenGL01/res/Toolbar256.bmp -------------------------------------------------------------------------------- /MFCOpenGL01/res/class_view.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/MFCOpenGL01/res/class_view.ico -------------------------------------------------------------------------------- /MFCOpenGL01/res/classview.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/MFCOpenGL01/res/classview.bmp -------------------------------------------------------------------------------- /MFCOpenGL01/res/explorer_hc.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/MFCOpenGL01/res/explorer_hc.bmp -------------------------------------------------------------------------------- /MFCOpenGL01/res/file_view.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/MFCOpenGL01/res/file_view.ico -------------------------------------------------------------------------------- /MFCOpenGL01/res/fileview_hc.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/MFCOpenGL01/res/fileview_hc.bmp -------------------------------------------------------------------------------- /MFCOpenGL01/res/menuimages.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/MFCOpenGL01/res/menuimages.bmp -------------------------------------------------------------------------------- /MFCOpenGL01/res/output_wnd.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/MFCOpenGL01/res/output_wnd.ico -------------------------------------------------------------------------------- /MFCOpenGL01/res/properties.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/MFCOpenGL01/res/properties.bmp -------------------------------------------------------------------------------- /MFCOpenGL01/DialogCircleOval.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/MFCOpenGL01/DialogCircleOval.cpp -------------------------------------------------------------------------------- /MFCOpenGL01/DialogCirclePerfect.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/MFCOpenGL01/DialogCirclePerfect.h -------------------------------------------------------------------------------- /MFCOpenGL01/res/class_view_hc.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/MFCOpenGL01/res/class_view_hc.ico -------------------------------------------------------------------------------- /MFCOpenGL01/res/classview_hc.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/MFCOpenGL01/res/classview_hc.bmp -------------------------------------------------------------------------------- /MFCOpenGL01/res/file_view_hc.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/MFCOpenGL01/res/file_view_hc.ico -------------------------------------------------------------------------------- /MFCOpenGL01/res/menuimages_hc.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/MFCOpenGL01/res/menuimages_hc.bmp -------------------------------------------------------------------------------- /MFCOpenGL01/res/output_wnd_hc.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/MFCOpenGL01/res/output_wnd_hc.ico -------------------------------------------------------------------------------- /MFCOpenGL01/res/properties_hc.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/MFCOpenGL01/res/properties_hc.bmp -------------------------------------------------------------------------------- /MFCOpenGL01/DialogCirclePerfect.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/MFCOpenGL01/DialogCirclePerfect.cpp -------------------------------------------------------------------------------- /MFCOpenGL01/res/MFCOpenGL01Doc.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/MFCOpenGL01/res/MFCOpenGL01Doc.ico -------------------------------------------------------------------------------- /MFCOpenGL01/res/properties_wnd.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/MFCOpenGL01/res/properties_wnd.ico -------------------------------------------------------------------------------- /MFCOpenGL01/res/properties_wnd_hc.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ultronxr/MFCOpenGL01/HEAD/MFCOpenGL01/res/properties_wnd_hc.ico -------------------------------------------------------------------------------- /MFCOpenGL01/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MFC简单绘图程序 2 | 3 | 基于C++、MFC单文档编程; 4 | 5 | 仓库中不包含编译结果; 6 | 7 | 8 | ## 功能列表 9 | 10 | 1. 绘制点,并控制点的种类、尺寸、颜色; 11 | 2. 绘制直线,并控制线宽、线颜色; 12 | 3. 绘制正圆,并控制线宽、线颜色; 13 | 4. 绘制椭圆(任意圆),并控制线宽、线颜色; 14 | 5. 绘制多边形,并控制线宽、线颜色; 15 | 6. 绘制贝塞尔曲线,并控制线宽、线颜色; 16 | 7. 填充封闭图形,并控制填充颜色; 17 | 8. 单独选中图形,进行平移、旋转、缩放、对称变换; 18 | 9. 绘制图形和图形变换时,显示中间过程的“橡皮筋”效果; 19 | 10. 文件内容加载和持久化存储(bmp位图); 20 | 11. 其他:工具栏按钮、清空画布; 21 | 22 | 23 | ## 已知BUG 24 | 25 | 1. 只记录填充位置,窗口大小改变时会导致填充错位,移动图形位置,也会导致填充错位; 26 | 2. 贝塞尔曲线绘制的中间过程不会被擦除; 27 | 3. 贝塞尔曲线只能使用控制边进行选择; 28 | 4. 文件持久化存储不能对象化,只能保存画布上的图像,也就是说加载操作无法还原完整的信息; 29 | 30 | 31 | ## 演示图片(选取几张,所有图片在`show`目录下,这些图片不一定是最新版本的效果!) 32 | 33 | ![绘制点](./show/draw_point.gif) 34 | 35 | ![绘制直线](./show/draw_line.gif) 36 | 37 | ![绘制椭圆](./show/draw_circle_oval.gif) 38 | 39 | ![绘制多边形](./show/draw_polygon.gif) 40 | 41 | ![填充](./show/fill.gif) 42 | 43 | ![选择图形](./show/select.gif) 44 | 45 | ![平移](./show/transform_translate.gif) 46 | 47 | ![旋转](./show/transform_rotate.gif) 48 | 49 | ![缩放](./show/transform_scale.gif) 50 | 51 | ![对称](./show/transform_symmetry.gif) 52 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Ultronxr 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /MFCOpenGL01.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25420.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MFCOpenGL01", "MFCOpenGL01\MFCOpenGL01.vcxproj", "{1DF6C547-2FD1-482F-9D0B-0D498E03D6DE}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {1DF6C547-2FD1-482F-9D0B-0D498E03D6DE}.Debug|x64.ActiveCfg = Debug|x64 17 | {1DF6C547-2FD1-482F-9D0B-0D498E03D6DE}.Debug|x64.Build.0 = Debug|x64 18 | {1DF6C547-2FD1-482F-9D0B-0D498E03D6DE}.Debug|x86.ActiveCfg = Debug|Win32 19 | {1DF6C547-2FD1-482F-9D0B-0D498E03D6DE}.Debug|x86.Build.0 = Debug|Win32 20 | {1DF6C547-2FD1-482F-9D0B-0D498E03D6DE}.Release|x64.ActiveCfg = Release|x64 21 | {1DF6C547-2FD1-482F-9D0B-0D498E03D6DE}.Release|x64.Build.0 = Release|x64 22 | {1DF6C547-2FD1-482F-9D0B-0D498E03D6DE}.Release|x86.ActiveCfg = Release|Win32 23 | {1DF6C547-2FD1-482F-9D0B-0D498E03D6DE}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | EndGlobal 29 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /MFCOpenGL01/ReadMe.txt: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | 项目自动生成的ReadMe文件 3 | ================================================================================ 4 | 5 | ================================================================================ 6 | MICROSOFT 基础类库 : MFCOpenGL01 项目概述 7 | =============================================================================== 8 | 9 | 应用程序向导已为您创建了此 MFCOpenGL01 应用程序。此应用程序不仅演示 Microsoft 基础类的基本使用方法,还可作为您编写应用程序的起点。 10 | 11 | 本文件概要介绍组成 MFCOpenGL01 应用程序的每个文件的内容。 12 | 13 | MFCOpenGL01.vcxproj 14 | 这是使用应用程序向导生成的 VC++ 项目的主项目文件,其中包含生成该文件的 Visual C++ 的版本信息,以及有关使用应用程序向导选择的平台、配置和项目功能的信息。 15 | 16 | MFCOpenGL01.vcxproj.filters 17 | 这是使用“应用程序向导”生成的 VC++ 项目筛选器文件。它包含有关项目文件与筛选器之间的关联信息。在 IDE 中,通过这种关联,在特定节点下以分组形式显示具有相似扩展名的文件。例如,“.cpp”文件与“源文件”筛选器关联。 18 | 19 | MFCOpenGL01.h 20 | 这是应用程序的主头文件。 21 | 其中包括其他项目特定的标头(包括 Resource.h),并声明 CMFCOpenGL01App 应用程序类。 22 | 23 | MFCOpenGL01.cpp 24 | 这是包含应用程序类 CMFCOpenGL01App 的主应用程序源文件。 25 | 26 | MFCOpenGL01.rc 27 | 这是程序使用的所有 Microsoft Windows 资源的列表。它包括 RES 子目录中存储的图标、位图和光标。此文件可以直接在 Microsoft Visual C++ 中进行编辑。项目资源包含在 2052 中。 28 | 29 | res\MFCOpenGL01.ico 30 | 这是用作应用程序图标的图标文件。此图标包括在主资源文件 MFCOpenGL01.rc 中。 31 | 32 | res\MFCOpenGL01.rc2 33 | 此文件包含不在 Microsoft Visual C++ 中进行编辑的资源。您应该将不可由资源编辑器编辑的所有资源放在此文件中。 34 | 35 | ///////////////////////////////////////////////////////////////////////////// 36 | 37 | 对于主框架窗口: 38 | 该项目包含一个标准的 MFC 接口。 39 | 40 | MainFrm.h, MainFrm.cpp 41 | 这些文件中包含框架类 CMainFrame,该类派生自 42 | CFrameWnd 并控制所有 SDI 框架功能。 43 | 44 | res\Toolbar.bmp 45 | 此位图文件用于为工具栏创建平铺图像。 46 | 初始工具栏和状态栏在 CMainFrame 类中构造。使用资源编辑器编辑此工具栏位图,并更新 MFCOpenGL01.rc 中的 IDR_MAINFRAME TOOLBAR 数组以添加工具栏按钮。 47 | ///////////////////////////////////////////////////////////////////////////// 48 | 49 | 应用程序向导创建一种文档类型和一个视图: 50 | 51 | MFCOpenGL01Doc.h、MFCOpenGL01Doc.cpp - 文档 52 | 这些文件包含 CMFCOpenGL01Doc 类。编辑这些文件以添加特殊文档数据并实现文件保存和加载(通过 CMFCOpenGL01Doc::Serialize)。 53 | 54 | MFCOpenGL01View.h、MFCOpenGL01View.cpp - 文档视图 55 | 这些文件包含 CMFCOpenGL01View 类。 56 | CMFCOpenGL01View 对象用于查看 CMFCOpenGL01Doc 对象。 57 | 58 | 59 | 60 | 61 | ///////////////////////////////////////////////////////////////////////////// 62 | 63 | 其他功能: 64 | 65 | ActiveX 控件 66 | 该应用程序包含对使用 ActiveX 控件的支持。 67 | 68 | 打印和打印预览支持 69 | 应用程序向导通过从 MFC 库调用 CView 类中的成员函数生成代码,来处理打印、打印设置和打印预览命令。 70 | 71 | ///////////////////////////////////////////////////////////////////////////// 72 | 73 | 其他标准文件: 74 | 75 | StdAfx.h, StdAfx.cpp 76 | 这些文件用于生成名为 MFCOpenGL01.pch 的预编译头 (PCH) 文件和名为 StdAfx.obj 的预编译类型文件。 77 | 78 | Resource.h 79 | 这是标准头文件,可用于定义新的资源 ID。Microsoft Visual C++ 将读取并更新此文件。 80 | 81 | MFCOpenGL01.manifest 82 | Windows XP 使用应用程序清单文件来描述特定版本的并行程序集的应用程序依赖项。加载程序使用这些信息来从程序集缓存中加载相应的程序集,并保护其不被应用程序访问。应用程序清单可能会包含在内,以作为与应用程序可执行文件安装在同一文件夹中的外部 .manifest 文件进行重新分发,它还可能以资源的形式包含在可执行文件中。 83 | ///////////////////////////////////////////////////////////////////////////// 84 | 85 | 其他注释: 86 | 87 | 应用程序向导使用“TODO:”来指示应添加或自定义的源代码部分。 88 | 89 | 如果应用程序使用共享 DLL 中的 MFC,您将需要重新分发 MFC DLL。如果应用程序所使用的语言与操作系统的区域设置不同,则还需要重新分发相应的本地化资源 mfc110XXX.DLL。 90 | 有关上述话题的更多信息,请参见 MSDN 文档中有关重新分发 Visual C++ 应用程序的部分。 91 | 92 | ///////////////////////////////////////////////////////////////////////////// 93 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | [Xx]64/ 19 | [Xx]86/ 20 | [Bb]uild/ 21 | bld/ 22 | [Bb]in/ 23 | [Oo]bj/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | # Uncomment if you have tasks that create the project's static files in wwwroot 28 | #wwwroot/ 29 | 30 | # MSTest test Results 31 | [Tt]est[Rr]esult*/ 32 | [Bb]uild[Ll]og.* 33 | 34 | # NUNIT 35 | *.VisualState.xml 36 | TestResult.xml 37 | 38 | # Build Results of an ATL Project 39 | [Dd]ebugPS/ 40 | [Rr]eleasePS/ 41 | dlldata.c 42 | 43 | # DNX 44 | project.lock.json 45 | artifacts/ 46 | 47 | *_i.c 48 | *_p.c 49 | *_i.h 50 | *.ilk 51 | *.meta 52 | *.obj 53 | *.pch 54 | *.pdb 55 | *.pgc 56 | *.pgd 57 | *.rsp 58 | *.sbr 59 | *.tlb 60 | *.tli 61 | *.tlh 62 | *.tmp 63 | *.tmp_proj 64 | *.log 65 | *.vspscc 66 | *.vssscc 67 | .builds 68 | *.pidb 69 | *.svclog 70 | *.scc 71 | 72 | # Chutzpah Test files 73 | _Chutzpah* 74 | 75 | # Visual C++ cache files 76 | ipch/ 77 | *.aps 78 | *.ncb 79 | *.opendb 80 | *.opensdf 81 | *.sdf 82 | *.cachefile 83 | *.VC.db 84 | 85 | # Visual Studio profiler 86 | *.psess 87 | *.vsp 88 | *.vspx 89 | *.sap 90 | 91 | # TFS 2012 Local Workspace 92 | $tf/ 93 | 94 | # Guidance Automation Toolkit 95 | *.gpState 96 | 97 | # ReSharper is a .NET coding add-in 98 | _ReSharper*/ 99 | *.[Rr]e[Ss]harper 100 | *.DotSettings.user 101 | 102 | # JustCode is a .NET coding add-in 103 | .JustCode 104 | 105 | # TeamCity is a build add-in 106 | _TeamCity* 107 | 108 | # DotCover is a Code Coverage Tool 109 | *.dotCover 110 | 111 | # NCrunch 112 | _NCrunch_* 113 | .*crunch*.local.xml 114 | nCrunchTemp_* 115 | 116 | # MightyMoose 117 | *.mm.* 118 | AutoTest.Net/ 119 | 120 | # Web workbench (sass) 121 | .sass-cache/ 122 | 123 | # Installshield output folder 124 | [Ee]xpress/ 125 | 126 | # DocProject is a documentation generator add-in 127 | DocProject/buildhelp/ 128 | DocProject/Help/*.HxT 129 | DocProject/Help/*.HxC 130 | DocProject/Help/*.hhc 131 | DocProject/Help/*.hhk 132 | DocProject/Help/*.hhp 133 | DocProject/Help/Html2 134 | DocProject/Help/html 135 | 136 | # Click-Once directory 137 | publish/ 138 | 139 | # Publish Web Output 140 | *.[Pp]ublish.xml 141 | *.azurePubxml 142 | 143 | # TODO: Un-comment the next line if you do not want to checkin 144 | # your web deploy settings because they may include unencrypted 145 | # passwords 146 | #*.pubxml 147 | *.publishproj 148 | 149 | # NuGet Packages 150 | *.nupkg 151 | # The packages folder can be ignored because of Package Restore 152 | **/packages/* 153 | # except build/, which is used as an MSBuild target. 154 | !**/packages/build/ 155 | # Uncomment if necessary however generally it will be regenerated when needed 156 | #!**/packages/repositories.config 157 | # NuGet v3's project.json files produces more ignoreable files 158 | *.nuget.props 159 | *.nuget.targets 160 | 161 | # Microsoft Azure Build Output 162 | csx/ 163 | *.build.csdef 164 | 165 | # Microsoft Azure Emulator 166 | ecf/ 167 | rcf/ 168 | 169 | # Windows Store app package directory 170 | AppPackages/ 171 | BundleArtifacts/ 172 | 173 | # Visual Studio cache files 174 | # files ending in .cache can be ignored 175 | *.[Cc]ache 176 | # but keep track of directories ending in .cache 177 | !*.[Cc]ache/ 178 | 179 | # Others 180 | ClientBin/ 181 | [Ss]tyle[Cc]op.* 182 | ~$* 183 | *~ 184 | *.dbmdl 185 | *.dbproj.schemaview 186 | *.pfx 187 | *.publishsettings 188 | node_modules/ 189 | orleans.codegen.cs 190 | 191 | # RIA/Silverlight projects 192 | Generated_Code/ 193 | 194 | # Backup & report files from converting an old project file 195 | # to a newer Visual Studio version. Backup files are not needed, 196 | # because we have git ;-) 197 | _UpgradeReport_Files/ 198 | Backup*/ 199 | UpgradeLog*.XML 200 | UpgradeLog*.htm 201 | 202 | # SQL Server files 203 | *.mdf 204 | *.ldf 205 | 206 | # Business Intelligence projects 207 | *.rdl.data 208 | *.bim.layout 209 | *.bim_*.settings 210 | 211 | # Microsoft Fakes 212 | FakesAssemblies/ 213 | 214 | # GhostDoc plugin setting file 215 | *.GhostDoc.xml 216 | 217 | # Node.js Tools for Visual Studio 218 | .ntvs_analysis.dat 219 | 220 | # Visual Studio 6 build log 221 | *.plg 222 | 223 | # Visual Studio 6 workspace options file 224 | *.opt 225 | 226 | # Visual Studio LightSwitch build output 227 | **/*.HTMLClient/GeneratedArtifacts 228 | **/*.DesktopClient/GeneratedArtifacts 229 | **/*.DesktopClient/ModelManifest.xml 230 | **/*.Server/GeneratedArtifacts 231 | **/*.Server/ModelManifest.xml 232 | _Pvt_Extensions 233 | 234 | # LightSwitch generated files 235 | GeneratedArtifacts/ 236 | ModelManifest.xml 237 | 238 | # Paket dependency manager 239 | .paket/paket.exe 240 | 241 | # FAKE - F# Make 242 | .fake/ 243 | -------------------------------------------------------------------------------- /MFCOpenGL01/MFCOpenGL01.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | {f1dd4aee-b787-40ae-bee2-615d75b5d6c9} 18 | 19 | 20 | 21 | 22 | 头文件 23 | 24 | 25 | 头文件 26 | 27 | 28 | 头文件 29 | 30 | 31 | 头文件 32 | 33 | 34 | 头文件 35 | 36 | 37 | 头文件 38 | 39 | 40 | 头文件 41 | 42 | 43 | 头文件 44 | 45 | 46 | 头文件 47 | 48 | 49 | 头文件 50 | 51 | 52 | 头文件 53 | 54 | 55 | 头文件 56 | 57 | 58 | 头文件 59 | 60 | 61 | 头文件 62 | 63 | 64 | 头文件 65 | 66 | 67 | 头文件 68 | 69 | 70 | 头文件 71 | 72 | 73 | 74 | 75 | 源文件 76 | 77 | 78 | 源文件 79 | 80 | 81 | 源文件 82 | 83 | 84 | 源文件 85 | 86 | 87 | 源文件 88 | 89 | 90 | 源文件 91 | 92 | 93 | 源文件 94 | 95 | 96 | 源文件 97 | 98 | 99 | 源文件 100 | 101 | 102 | 源文件 103 | 104 | 105 | 源文件 106 | 107 | 108 | 源文件 109 | 110 | 111 | 源文件 112 | 113 | 114 | 源文件 115 | 116 | 117 | 源文件 118 | 119 | 120 | 121 | 122 | 资源文件 123 | 124 | 125 | 126 | 127 | 资源文件 128 | 129 | 130 | 资源文件 131 | 132 | 133 | 资源文件 134 | 135 | 136 | 资源文件 137 | 138 | 139 | 资源文件 140 | 141 | 142 | 资源文件 143 | 144 | 145 | 资源文件 146 | 147 | 148 | 资源文件 149 | 150 | 151 | 资源文件 152 | 153 | 154 | 资源文件 155 | 156 | 157 | 资源文件 158 | 159 | 160 | 资源文件 161 | 162 | 163 | 资源文件 164 | 165 | 166 | 资源文件 167 | 168 | 169 | 资源文件 170 | 171 | 172 | 资源文件 173 | 174 | 175 | 资源文件 176 | 177 | 178 | 资源文件 179 | 180 | 181 | 资源文件 182 | 183 | 184 | 资源文件 185 | 186 | 187 | 资源文件 188 | 189 | 190 | 资源文件 191 | 192 | 193 | 资源文件 194 | 195 | 196 | 资源文件 197 | 198 | 199 | 资源文件 200 | 201 | 202 | 资源文件 203 | 204 | 205 | 资源文件 206 | 207 | 208 | 资源文件 209 | 210 | 211 | 资源文件 212 | 213 | 214 | 资源文件 215 | 216 | 217 | show 218 | 219 | 220 | show 221 | 222 | 223 | show 224 | 225 | 226 | show 227 | 228 | 229 | show 230 | 231 | 232 | show 233 | 234 | 235 | show 236 | 237 | 238 | show 239 | 240 | 241 | show 242 | 243 | 244 | show 245 | 246 | 247 | show 248 | 249 | 250 | 资源文件 251 | 252 | 253 | 资源文件 254 | 255 | 256 | 257 | 258 | 资源文件 259 | 260 | 261 | 262 | 263 | 资源文件 264 | 265 | 266 | 资源文件 267 | 268 | 269 | 270 | 271 | 272 | -------------------------------------------------------------------------------- /MFCOpenGL01/MFCOpenGL01.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | {1DF6C547-2FD1-482F-9D0B-0D498E03D6DE} 23 | MFCOpenGL01 24 | 8.1 25 | MFCProj 26 | 27 | 28 | 29 | Application 30 | true 31 | v140 32 | Unicode 33 | Dynamic 34 | 35 | 36 | Application 37 | false 38 | v140 39 | true 40 | Unicode 41 | Dynamic 42 | 43 | 44 | Application 45 | true 46 | v140 47 | Unicode 48 | Dynamic 49 | 50 | 51 | Application 52 | false 53 | v140 54 | true 55 | Unicode 56 | Dynamic 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | true 78 | 79 | 80 | true 81 | 82 | 83 | false 84 | 85 | 86 | false 87 | 88 | 89 | 90 | Use 91 | Level3 92 | Disabled 93 | WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions) 94 | 95 | 96 | Windows 97 | 98 | 99 | false 100 | true 101 | _DEBUG;%(PreprocessorDefinitions) 102 | 103 | 104 | 0x0804 105 | _DEBUG;%(PreprocessorDefinitions) 106 | $(IntDir);%(AdditionalIncludeDirectories) 107 | 108 | 109 | 110 | 111 | Use 112 | Level3 113 | Disabled 114 | _WINDOWS;_DEBUG;%(PreprocessorDefinitions) 115 | 116 | 117 | Windows 118 | 119 | 120 | false 121 | true 122 | _DEBUG;%(PreprocessorDefinitions) 123 | 124 | 125 | 0x0804 126 | _DEBUG;%(PreprocessorDefinitions) 127 | $(IntDir);%(AdditionalIncludeDirectories) 128 | 129 | 130 | 131 | 132 | Level3 133 | Use 134 | MaxSpeed 135 | true 136 | true 137 | WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions) 138 | 139 | 140 | Windows 141 | true 142 | true 143 | 144 | 145 | false 146 | true 147 | NDEBUG;%(PreprocessorDefinitions) 148 | 149 | 150 | 0x0804 151 | NDEBUG;%(PreprocessorDefinitions) 152 | $(IntDir);%(AdditionalIncludeDirectories) 153 | 154 | 155 | 156 | 157 | Level3 158 | Use 159 | MaxSpeed 160 | true 161 | true 162 | _WINDOWS;NDEBUG;%(PreprocessorDefinitions) 163 | 164 | 165 | Windows 166 | true 167 | true 168 | 169 | 170 | false 171 | true 172 | NDEBUG;%(PreprocessorDefinitions) 173 | 174 | 175 | 0x0804 176 | NDEBUG;%(PreprocessorDefinitions) 177 | $(IntDir);%(AdditionalIncludeDirectories) 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | Create 215 | Create 216 | Create 217 | Create 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。 292 | 293 | 294 | 295 | 296 | -------------------------------------------------------------------------------- /MFCOpenGL01/MFCOpenGL01Doc.cpp: -------------------------------------------------------------------------------- 1 | 2 | // MFCOpenGL01Doc.cpp : CMFCOpenGL01Doc 类的实现 3 | // 4 | 5 | #include "stdafx.h" 6 | // SHARED_HANDLERS 可以在实现预览、缩略图和搜索筛选器句柄的 7 | // ATL 项目中进行定义,并允许与该项目共享文档代码。 8 | #ifndef SHARED_HANDLERS 9 | #include "MFCOpenGL01.h" 10 | #endif 11 | 12 | #include "MFCOpenGL01Doc.h" 13 | 14 | #include 15 | 16 | #ifdef _DEBUG 17 | #define new DEBUG_NEW 18 | #endif 19 | 20 | // CMFCOpenGL01Doc 21 | 22 | IMPLEMENT_DYNCREATE(CMFCOpenGL01Doc, CDocument) 23 | 24 | BEGIN_MESSAGE_MAP(CMFCOpenGL01Doc, CDocument) 25 | END_MESSAGE_MAP() 26 | 27 | 28 | // CMFCOpenGL01Doc 构造/析构 29 | 30 | CMFCOpenGL01Doc::CMFCOpenGL01Doc() 31 | { 32 | //调试输出信息用的控制台 33 | /*::AllocConsole(); 34 | FILE *fp; 35 | freopen_s(&fp, "CONOUT$", "w+t", stdout);*/ 36 | 37 | // TODO: 在此添加一次性构造代码 38 | m_operation = 0; 39 | m_color = RGB(0, 0, 0); 40 | m_size = 1; 41 | //计算杨辉三角 42 | std::memset(yanghui, 0, sizeof(yanghui)); 43 | for (int i = 0; i <= 50; i++) { 44 | for (int j = 0; j <= i; j++) { 45 | if (j == 0 || i == j) yanghui[i][j] = 1; 46 | else yanghui[i][j] = yanghui[i - 1][j - 1] + yanghui[i - 1][j]; 47 | } 48 | } 49 | } 50 | 51 | CMFCOpenGL01Doc::~CMFCOpenGL01Doc() 52 | { 53 | //释放调试控制台 54 | //FreeConsole(); 55 | } 56 | 57 | BOOL CMFCOpenGL01Doc::OnNewDocument() 58 | { 59 | if (!CDocument::OnNewDocument()) 60 | return FALSE; 61 | 62 | // TODO: 在此添加重新初始化代码 63 | // (SDI 文档将重用该文档) 64 | 65 | return TRUE; 66 | } 67 | 68 | 69 | 70 | 71 | // CMFCOpenGL01Doc 序列化 72 | 73 | void CMFCOpenGL01Doc::Serialize(CArchive& ar) 74 | { 75 | if (ar.IsStoring()) 76 | { 77 | // TODO: 在此添加存储代码 78 | } 79 | else 80 | { 81 | // TODO: 在此添加加载代码 82 | } 83 | } 84 | 85 | #ifdef SHARED_HANDLERS 86 | 87 | // 缩略图的支持 88 | void CMFCOpenGL01Doc::OnDrawThumbnail(CDC& dc, LPRECT lprcBounds) 89 | { 90 | // 修改此代码以绘制文档数据 91 | dc.FillSolidRect(lprcBounds, RGB(255, 255, 255)); 92 | 93 | CString strText = _T("TODO: implement thumbnail drawing here"); 94 | LOGFONT lf; 95 | 96 | CFont* pDefaultGUIFont = CFont::FromHandle((HFONT) GetStockObject(DEFAULT_GUI_FONT)); 97 | pDefaultGUIFont->GetLogFont(&lf); 98 | lf.lfHeight = 36; 99 | 100 | CFont fontDraw; 101 | fontDraw.CreateFontIndirect(&lf); 102 | 103 | CFont* pOldFont = dc.SelectObject(&fontDraw); 104 | dc.DrawText(strText, lprcBounds, DT_CENTER | DT_WORDBREAK); 105 | dc.SelectObject(pOldFont); 106 | 107 | } 108 | 109 | // 搜索处理程序的支持 110 | void CMFCOpenGL01Doc::InitializeSearchContent() 111 | { 112 | CString strSearchContent; 113 | // 从文档数据设置搜索内容。 114 | // 内容部分应由“;”分隔 115 | 116 | // 例如: strSearchContent = _T("point;rectangle;circle;ole object;"); 117 | SetSearchContent(strSearchContent); 118 | 119 | 120 | } 121 | 122 | void CMFCOpenGL01Doc::SetSearchContent(const CString& value) 123 | { 124 | if (value.IsEmpty()) 125 | { 126 | RemoveChunk(PKEY_Search_Contents.fmtid, PKEY_Search_Contents.pid); 127 | } 128 | else 129 | { 130 | CMFCFilterChunkValueImpl *pChunk = NULL; 131 | ATLTRY(pChunk = new CMFCFilterChunkValueImpl); 132 | if (pChunk != NULL) 133 | { 134 | pChunk->SetTextValue(PKEY_Search_Contents, value, CHUNK_TEXT); 135 | SetChunkValue(pChunk); 136 | } 137 | } 138 | } 139 | 140 | #endif // SHARED_HANDLERS 141 | 142 | // CMFCOpenGL01Doc 诊断 143 | 144 | #ifdef _DEBUG 145 | void CMFCOpenGL01Doc::AssertValid() const 146 | { 147 | CDocument::AssertValid(); 148 | } 149 | 150 | void CMFCOpenGL01Doc::Dump(CDumpContext& dc) const 151 | { 152 | CDocument::Dump(dc); 153 | } 154 | #endif //_DEBUG 155 | 156 | 157 | // CMFCOpenGL01Doc 命令 158 | 159 | 160 | 161 | 162 | ///寻找鼠标是否选中图形 163 | //一次只能选中一个图形(不论何种类型的图形) 优先级:点>线>正圆>椭圆>多边形 164 | void CMFCOpenGL01Doc::select_all(CDC * pDC, CPoint point){ 165 | 166 | //选择图形 167 | int sp = select_point(point); 168 | int sl = select_line(point); 169 | int spc = select_perfect_circle(point); 170 | int soc = select_oval_circle(point); 171 | int spo = select_polygon(point); 172 | int sb = select_bezier(point); 173 | 174 | COLORREF co = RGB(255, 0, 128); 175 | 176 | //处理点 177 | if (sp != -1) { //当前选中 178 | if (v_point[sp].type == 0) point_circle(pDC, co, v_point[sp].p.x, v_point[sp].p.y, v_point[sp].size); 179 | else if (v_point[sp].type == 1) point_cross(pDC, co, v_point[sp].p.x, v_point[sp].p.y, v_point[sp].size); 180 | else if (v_point[sp].type == 2) point_rhombus(pDC, co, v_point[sp].p.x, v_point[sp].p.y, v_point[sp].size); 181 | 182 | sl = spc = soc = spo = -1; 183 | } 184 | if (selected_point != -1 && selected_point != sp) { //上次选中的 185 | int msp = selected_point; 186 | if (v_point[msp].type == 0) point_circle(pDC, v_point[msp].color, v_point[msp].p.x, v_point[msp].p.y, v_point[msp].size); 187 | else if (v_point[msp].type == 1) point_cross(pDC, v_point[msp].color, v_point[msp].p.x, v_point[msp].p.y, v_point[msp].size); 188 | else if (v_point[msp].type == 2) point_rhombus(pDC, v_point[msp].color, v_point[msp].p.x, v_point[msp].p.y, v_point[msp].size); 189 | } 190 | 191 | //处理线 192 | if (sl != -1) { 193 | line_cpen(pDC, co, v_line[sl].p1, v_line[sl].p2, v_line[sl].size); 194 | spc = soc = spo = -1; 195 | } 196 | if (selected_line != -1 && selected_line != sl) { 197 | int msl = selected_line; 198 | line_cpen(pDC, v_line[msl].color, v_line[msl].p1, v_line[msl].p2, v_line[msl].size); 199 | } 200 | 201 | //处理正圆 202 | if (spc != -1) { 203 | circle_perfect_cpen(pDC, co, v_perf_circle[spc].p0, v_perf_circle[spc].radius, v_perf_circle[spc].size); 204 | soc = spo = -1; 205 | } 206 | if (selected_perfect_circle != -1 && selected_perfect_circle != spc) { 207 | int mspc = selected_perfect_circle; 208 | circle_perfect_cpen(pDC, v_perf_circle[mspc].color, v_perf_circle[mspc].p0, v_perf_circle[mspc].radius, v_perf_circle[mspc].size); 209 | } 210 | 211 | //处理椭圆 212 | if (soc != -1) { 213 | circle_oval_angle_cpen(pDC, co, v_oval_circle[soc].p0.x, v_oval_circle[soc].p0.y, v_oval_circle[soc].a, v_oval_circle[soc].b, v_oval_circle[soc].angle, v_oval_circle[soc].size); 214 | spo = -1; 215 | } 216 | if (selected_oval_circle != -1 && selected_oval_circle != soc) { 217 | circle_oval_angle_cpen(pDC, v_oval_circle[selected_oval_circle].color, v_oval_circle[selected_oval_circle].p0.x, v_oval_circle[selected_oval_circle].p0.y, v_oval_circle[selected_oval_circle].a, v_oval_circle[selected_oval_circle].b, v_oval_circle[selected_oval_circle].angle, v_oval_circle[selected_oval_circle].size); 218 | } 219 | 220 | //处理多边形 221 | if (spo != -1) { 222 | draw_polygon_cpen(pDC, v_polygon[spo], co, v_polygon[spo].size); 223 | } 224 | if (selected_polygon != -1 && selected_polygon != spo) { 225 | draw_polygon_cpen(pDC, v_polygon[selected_polygon], v_polygon[selected_polygon].color, v_polygon[selected_polygon].size); 226 | } 227 | 228 | //处理贝塞尔曲线 229 | if (sb != -1) { 230 | bezier_cpen(pDC, v_bezier[sb], co, v_bezier[sb].size); 231 | } 232 | if (selected_bezier != -1 && selected_bezier != sb) { 233 | bezier_cpen(pDC, v_bezier[selected_bezier], v_bezier[selected_bezier].color, v_bezier[selected_bezier].size); 234 | } 235 | 236 | selected_point = sp; 237 | selected_line = sl; 238 | selected_perfect_circle = spc; 239 | selected_oval_circle = soc; 240 | selected_polygon = spo; 241 | selected_bezier = sb; 242 | } 243 | 244 | int CMFCOpenGL01Doc::select_point(CPoint pos){ 245 | double dis = 0.0; 246 | for (int i = 0; i < v_point.size(); i++) { 247 | dis = sqrt((v_point[i].p.x - pos.x)*(v_point[i].p.x - pos.x) + (v_point[i].p.y - pos.y)*(v_point[i].p.y - pos.y)); 248 | if (dis < (v_point[i].size / 2.0 + 5.0)) return i; 249 | } 250 | return -1; 251 | } 252 | 253 | int CMFCOpenGL01Doc::select_line(CPoint pos){ 254 | double am = 0.0, bm = 0.0, ab = 0.0; 255 | for (int i = 0; i < v_line.size(); i++) { 256 | am = sqrt((v_line[i].p1.x - pos.x)*(v_line[i].p1.x - pos.x) + (v_line[i].p1.y - pos.y)*(v_line[i].p1.y - pos.y)); 257 | bm = sqrt((v_line[i].p2.x - pos.x)*(v_line[i].p2.x - pos.x) + (v_line[i].p2.y - pos.y)*(v_line[i].p2.y - pos.y)); 258 | ab = sqrt((v_line[i].p1.x - v_line[i].p2.x)*(v_line[i].p1.x - v_line[i].p2.x) + (v_line[i].p1.y - v_line[i].p2.y)*(v_line[i].p1.y - v_line[i].p2.y)); 259 | if (abs(am + bm - ab) < 5.0) return i; 260 | } 261 | return -1; 262 | } 263 | 264 | int CMFCOpenGL01Doc::select_perfect_circle(CPoint pos){ 265 | double dis = 0.0; 266 | for (int i = 0; i < v_perf_circle.size(); i++) { 267 | dis = sqrt((v_perf_circle[i].p0.x - pos.x)*(v_perf_circle[i].p0.x - pos.x) + (v_perf_circle[i].p0.y - pos.y)*(v_perf_circle[i].p0.y - pos.y)); 268 | if (abs(dis - v_perf_circle[i].radius) < (v_perf_circle[i].size / 2.0 + 5.0)) return i; 269 | } 270 | return -1; 271 | } 272 | 273 | int CMFCOpenGL01Doc::select_oval_circle(CPoint pos){ 274 | CPoint poss; 275 | double check = 0.0, t1 = 0.0, t2 = 0.0; 276 | for (int i = 0; i < v_oval_circle.size(); i++) { 277 | poss = get_rotated_point(pos, v_oval_circle[i].p0, v_oval_circle[i].angle); 278 | t1 = poss.x - v_oval_circle[i].p0.x; 279 | t2 = poss.y - v_oval_circle[i].p0.y; 280 | check = ((double)(t1*t1) / (double)(v_oval_circle[i].a*v_oval_circle[i].a)) + ((double)(t2*t2) / (double)(v_oval_circle[i].b*v_oval_circle[i].b)); 281 | 282 | //_cprintf("a=%d b=%d pos(%d,%d) poss(%d,%d) check=%lf\n", v_oval_circle[i].a, v_oval_circle[i].b, pos.x, pos.y, poss.x, poss.y, check); 283 | if (check >= 0.8 && check <= 1.2) return i; 284 | } 285 | return -1; 286 | } 287 | 288 | int CMFCOpenGL01Doc::select_polygon(CPoint pos){ 289 | double am = 0.0, bm = 0.0, ab = 0.0; 290 | for (int i = 0; i < v_polygon.size(); i++) { 291 | for (int j = 0; j < v_polygon[i].ps.size()-1; j++) { 292 | am = sqrt((v_polygon[i].ps[j].x - pos.x)*(v_polygon[i].ps[j].x - pos.x) + (v_polygon[i].ps[j].y - pos.y)*(v_polygon[i].ps[j].y - pos.y)); 293 | bm = sqrt((v_polygon[i].ps[j + 1].x - pos.x)*(v_polygon[i].ps[j + 1].x - pos.x) + (v_polygon[i].ps[j + 1].y - pos.y)*(v_polygon[i].ps[j + 1].y - pos.y)); 294 | ab = sqrt((v_polygon[i].ps[j].x - v_polygon[i].ps[j + 1].x)*(v_polygon[i].ps[j].x - v_polygon[i].ps[j + 1].x) + (v_polygon[i].ps[j].y - v_polygon[i].ps[j + 1].y)*(v_polygon[i].ps[j].y - v_polygon[i].ps[j + 1].y)); 295 | if (abs(am + bm - ab) < 5.0) return i; 296 | } 297 | am = sqrt((v_polygon[i].ps[0].x - pos.x)*(v_polygon[i].ps[0].x - pos.x) + (v_polygon[i].ps[0].y - pos.y)*(v_polygon[i].ps[0].y - pos.y)); 298 | bm = sqrt((v_polygon[i].ps[v_polygon[i].ps.size() - 1].x - pos.x)*(v_polygon[i].ps[v_polygon[i].ps.size() - 1].x - pos.x) + (v_polygon[i].ps[v_polygon[i].ps.size() - 1].y - pos.y)*(v_polygon[i].ps[v_polygon[i].ps.size() - 1].y - pos.y)); 299 | ab = sqrt((v_polygon[i].ps[v_polygon[i].ps.size() - 1].x - v_polygon[i].ps[0].x)*(v_polygon[i].ps[v_polygon[i].ps.size() - 1].x - v_polygon[i].ps[0].x) + (v_polygon[i].ps[v_polygon[i].ps.size() - 1].y - v_polygon[i].ps[0].y)*(v_polygon[i].ps[v_polygon[i].ps.size() - 1].y - v_polygon[i].ps[0].y)); 300 | if (abs(am + bm - ab) < 5.0) return i; 301 | } 302 | return -1; 303 | } 304 | 305 | int CMFCOpenGL01Doc::select_bezier(CPoint pos) { 306 | double am = 0.0, bm = 0.0, ab = 0.0; 307 | for (int i = 0; i < v_bezier.size(); i++) { 308 | for (int j = 0; j < v_bezier[i].ps.size()-1; j++) { 309 | am = sqrt((v_bezier[i].ps[j].x - pos.x)*(v_bezier[i].ps[j].x - pos.x) + (v_bezier[i].ps[j].y - pos.y)*(v_bezier[i].ps[j].y - pos.y)); 310 | bm = sqrt((v_bezier[i].ps[j + 1].x - pos.x)*(v_bezier[i].ps[j + 1].x - pos.x) + (v_bezier[i].ps[j + 1].y - pos.y)*(v_bezier[i].ps[j + 1].y - pos.y)); 311 | ab = sqrt((v_bezier[i].ps[j].x - v_bezier[i].ps[j + 1].x)*(v_bezier[i].ps[j].x - v_bezier[i].ps[j + 1].x) + (v_bezier[i].ps[j].y - v_bezier[i].ps[j + 1].y)*(v_bezier[i].ps[j].y - v_bezier[i].ps[j + 1].y)); 312 | if (abs(am + bm - ab) < 5.0) return i; 313 | } 314 | } 315 | return -1; 316 | } 317 | 318 | 319 | 320 | //刷新所有绘制的图像 321 | void CMFCOpenGL01Doc::flush_all_drawing(CDC * pDC){ 322 | 323 | for (int i = 0; i < v_point.size(); i++) { 324 | if (v_point[i].type == 0) point_circle(pDC, v_point[i].color, v_point[i].p.x, v_point[i].p.y, v_point[i].size); 325 | else if(v_point[i].type == 1) point_cross(pDC, v_point[i].color, v_point[i].p.x, v_point[i].p.y, v_point[i].size); 326 | else if(v_point[i].type == 2) point_rhombus(pDC, v_point[i].color, v_point[i].p.x, v_point[i].p.y, v_point[i].size); 327 | } 328 | 329 | for (int i = 0; i < v_line.size(); i++) 330 | line_cpen(pDC, v_line[i].color, v_line[i].p1, v_line[i].p2, v_line[i].size); 331 | 332 | for (int i = 0; i < v_perf_circle.size(); i++) 333 | circle_perfect_cpen(pDC, v_perf_circle[i].color, v_perf_circle[i].p0, v_perf_circle[i].radius, v_perf_circle[i].size); 334 | 335 | for (int i = 0; i < v_oval_circle.size(); i++) 336 | circle_oval_angle_cpen(pDC, v_oval_circle[i].color, v_oval_circle[i].p0.x, v_oval_circle[i].p0.y, v_oval_circle[i].a, v_oval_circle[i].b, v_oval_circle[i].angle, v_oval_circle[i].size); 337 | 338 | for (int i = 0; i < v_polygon.size(); i++) 339 | draw_polygon_cpen(pDC, v_polygon[i], v_polygon[i].color, v_polygon[i].size); 340 | 341 | for (int i = 0; i < v_bezier.size(); i++) 342 | bezier_cpen(pDC, v_bezier[i], v_bezier[i].color, v_bezier[i].size); 343 | 344 | for (int i = 0; i < v_fill.size(); i++) 345 | flood_fill_cbrush(pDC, v_fill[i].color, pDC->GetPixel(v_fill[i].p.x, v_fill[i].p.y), v_fill[i].p); 346 | 347 | } 348 | 349 | //绘制多边形 350 | void CMFCOpenGL01Doc::draw_polygon_cpen(CDC * pDC, d_polygon p, COLORREF color, int size){ 351 | 352 | if (p.ps.size() == 0) return; 353 | CPen cpen; 354 | cpen.CreatePen(PS_SOLID, size, color); 355 | CPen* pOldPen = (CPen*)pDC->SelectObject(&cpen); 356 | 357 | pDC->MoveTo(p.ps[0]); 358 | for (int i = 0; i < p.ps.size(); i++) pDC->LineTo(p.ps[i]); 359 | pDC->LineTo(p.ps[0]); 360 | 361 | pDC->SelectObject(pOldPen); 362 | cpen.DeleteObject(); 363 | } 364 | 365 | //绘制带控制边的贝塞尔曲线 366 | void CMFCOpenGL01Doc::bezier_cpen(CDC * pDC, d_bezier b, COLORREF color, int size){ 367 | 368 | if (b.ps.size() == 0) return; 369 | 370 | CPen cpen1; 371 | cpen1.CreatePen(PS_DASHDOT, 1, color); 372 | CPen* pOldPen1 = (CPen*)pDC->SelectObject(&cpen1); 373 | for (int i = 0; i < b.ps.size() - 1; i++) { 374 | pDC->MoveTo(b.ps[i]); 375 | pDC->LineTo(b.ps[i + 1]); 376 | } 377 | pDC->SelectObject(pOldPen1); 378 | cpen1.DeleteObject(); 379 | 380 | CPen cpen2; 381 | cpen2.CreatePen(PS_SOLID, size, color); 382 | CPen* pOldPen2 = (CPen*)pDC->SelectObject(&cpen2); 383 | if (b.order == 0) {} 384 | else if (b.order == 1) { 385 | pDC->MoveTo(b.ps[0].x, b.ps[0].y); 386 | pDC->LineTo(b.ps[1].x, b.ps[1].y); 387 | } 388 | else { 389 | for (double t = 0.0; t <= 1.0; t += (0.08/b.ps.size())) { 390 | double tx = 0.0, ty = 0.0; 391 | for (int i = 0; i <= b.order; i++) { 392 | tx += (1.0 * yanghui[b.order][i] * pow(t, 1.0*i) * pow(1.0 - t, 1.0*(b.order - i)) * b.ps[i].x); 393 | ty += (1.0 * yanghui[b.order][i] * pow(t, 1.0*i) * pow(1.0 - t, 1.0*(b.order - i)) * b.ps[i].y); 394 | } 395 | if (t == 0.0) pDC->MoveTo(tx, ty); 396 | pDC->LineTo(tx, ty); 397 | } 398 | } 399 | pDC->SelectObject(pOldPen2); 400 | cpen2.DeleteObject(); 401 | } 402 | 403 | 404 | 405 | 406 | 407 | ///画点 开始 408 | 409 | //绘制圆形的点 410 | void CMFCOpenGL01Doc::point_circle(CDC *pDC, COLORREF color, int x, int y, int size) { 411 | CPen cpen; 412 | cpen.CreatePen(PS_SOLID, size, color); 413 | CPen* pOldPen = (CPen*)pDC->SelectObject(&cpen); 414 | pDC->MoveTo(x, y); 415 | pDC->LineTo(x, y); 416 | pDC->SelectObject(pOldPen); 417 | cpen.DeleteObject(); 418 | return; 419 | } 420 | 421 | //绘制十字的点 422 | void CMFCOpenGL01Doc::point_cross(CDC *pDC, COLORREF color, int x, int y, int size) { 423 | 424 | if (size == 1) { 425 | line_midpoint(pDC, color, x - 4, y, x + 3, y); 426 | line_midpoint(pDC, color, x, y - 4, x, y + 3); 427 | return; 428 | } 429 | 430 | int t = size / 2 + 3 * size; 431 | CRect rec1(x - t, y - size / 2, x + t, y + size / 2); 432 | CRect rec2(x - size / 2, y - t, x + size / 2, y + t); 433 | 434 | CBrush cbrush; 435 | cbrush.CreateSolidBrush(color); 436 | CBrush* pOldBrush = (CBrush*)pDC->SelectObject(&cbrush); 437 | 438 | pDC->FillRect(rec1, &cbrush); 439 | pDC->FillRect(rec2, &cbrush); 440 | 441 | pDC->SelectObject(pOldBrush); 442 | cbrush.DeleteObject(); 443 | 444 | return; 445 | } 446 | 447 | //绘制菱形的点 448 | void CMFCOpenGL01Doc::point_rhombus(CDC *pDC, COLORREF color, int x, int y, int size) { 449 | 450 | int t = size + size / 5; 451 | line_midpoint(pDC, color, x - size, y, x, y - t); 452 | line_midpoint(pDC, color, x, y - t, x + size, y); 453 | line_midpoint(pDC, color, x + size, y, x, y + t); 454 | line_midpoint(pDC, color, x, y + t, x - size, y); 455 | 456 | CBrush cbrush; 457 | cbrush.CreateSolidBrush(color); 458 | CBrush* pOldBrush = (CBrush*)pDC->SelectObject(&cbrush); 459 | 460 | pDC->FloodFill(x, y, color); //从起点开始,用brush的颜色填充“最小”的那块封闭区域,相当于油漆桶 461 | //COLORREF color_banned = pDC->GetPixel(CPoint(x, y)); 462 | //pDC->ExtFloodFill(x, y, color_banned, FLOODFILLSURFACE); //从起点开始,用brush的颜色向外填充,直到遇到某种颜色为止 463 | 464 | pDC->SelectObject(pOldBrush); 465 | cbrush.DeleteObject(); 466 | 467 | return; 468 | } 469 | 470 | 471 | 472 | 473 | 474 | 475 | ///画线算法 开始 476 | 477 | //DDA数值微分法法画线,斜率任意; 参数:pDC,颜色,起点x坐标,起点y坐标,终点x坐标,终点y坐标 478 | void CMFCOpenGL01Doc::line_dda(CDC *pDC, COLORREF color, int x0, int y0, int x1, int y1) { 479 | 480 | double delta_x = 0.0, delta_y = 0.0, x = 0.0, y = 0.0; 481 | int dx = 0, dy = 0, steps = 0; 482 | dx = x1 - x0; 483 | dy = y1 - y0; 484 | if (abs(dx)>abs(dy)) steps = abs(dx); 485 | else steps = abs(dy); 486 | delta_x = (double)dx / (double)steps; 487 | delta_y = (double)dy / (double)steps; 488 | x = x0, y = y0; 489 | pDC->SetPixel(x, y, color); 490 | for (int i = 1; i <= steps; i++) { 491 | x += delta_x; 492 | y += delta_y; 493 | pDC->SetPixel(x, y, color); 494 | } 495 | 496 | return; 497 | } 498 | 499 | //中点法画线,斜率任意; 参数:pDC,颜色,起点x坐标,起点y坐标,终点x坐标,终点y坐标 500 | void CMFCOpenGL01Doc::line_midpoint(CDC *pDC, COLORREF color, int x0, int y0, int x1, int y1) { 501 | 502 | int x = x0, y = y0; 503 | int a = y0 - y1; 504 | int b = x1 - x0; 505 | int cx = (b >= 0 ? 1 : (b = -b, -1)); 506 | int cy = (a <= 0 ? 1 : (a = -a, -1)); 507 | int d, d1, d2; 508 | if (-a <= b) { // 斜率绝对值 <= 1 509 | d = a + a + b; 510 | d1 = a + a; 511 | d2 = a + a + b + b; 512 | while (x != x1) { 513 | if (d < 0) { 514 | y += cy; 515 | d += d2; 516 | } 517 | else { 518 | d += d1; 519 | } 520 | x += cx; 521 | pDC->SetPixel(x, y, color); 522 | } 523 | } 524 | else { // 斜率绝对值 > 1 525 | d = a + b + b; 526 | d1 = b + b; 527 | d2 = a + a + b + b; 528 | while (y != y1) { 529 | if (d < 0) { 530 | d += d1; 531 | } 532 | else { 533 | x += cx; 534 | d += d2; 535 | } 536 | y += cy; 537 | pDC->SetPixel(x, y, color); 538 | } 539 | } 540 | return; 541 | } 542 | 543 | //中点法画线,斜率绝对值[0,1],指定线宽,垂直线刷子; 参数:pDC,颜色,起点x坐标,起点y坐标,终点x坐标,终点y坐标,线宽 544 | void CMFCOpenGL01Doc::line_midpoint_vertical_linebrush(CDC *pDC, COLORREF color, int x0, int y0, int x1, int y1, int width) { 545 | 546 | int x = x0, y = y0; 547 | int a = y0 - y1; 548 | int b = x1 - x0; 549 | int cx = (b >= 0 ? 1 : (b = -b, -1)); 550 | int cy = (a <= 0 ? 1 : (a = -a, -1)); 551 | int d, d1, d2; 552 | if (-a <= b) { // 斜率绝对值 <= 1 553 | d = a + a + b; 554 | d1 = a + a; 555 | d2 = a + a + b + b; 556 | while (x != x1) { 557 | if (d < 0) { 558 | y += cy; 559 | d += d2; 560 | } 561 | else { 562 | d += d1; 563 | } 564 | x += cx; 565 | for (int i = -width / 2; i <= width / 2; i++) 566 | pDC->SetPixel(x, y + i, color); 567 | } 568 | } 569 | else { // 斜率绝对值 > 1 570 | d = a + b + b; 571 | d1 = b + b; 572 | d2 = a + a + b + b; 573 | while (y != y1) { 574 | if (d < 0) { 575 | d += d1; 576 | } 577 | else { 578 | x += cx; 579 | d += d2; 580 | } 581 | y += cy; 582 | for (int i = -width / 2; i <= width / 2; i++) 583 | pDC->SetPixel(x, y + i, color); 584 | } 585 | } 586 | return; 587 | } 588 | 589 | //中点法画线,斜率绝对值(1,+oo),指定线宽,水平线刷子; 参数:pDC,颜色,起点x坐标,起点y坐标,终点x坐标,终点y坐标,线宽 590 | void CMFCOpenGL01Doc::line_midpoint_horizontal_linebrush(CDC *pDC, COLORREF color, int x0, int y0, int x1, int y1, int width) { 591 | 592 | int x = x0, y = y0; 593 | int a = y0 - y1; 594 | int b = x1 - x0; 595 | int cx = (b >= 0 ? 1 : (b = -b, -1)); 596 | int cy = (a <= 0 ? 1 : (a = -a, -1)); 597 | int d, d1, d2; 598 | if (-a <= b) { // 斜率绝对值 <= 1 599 | d = a + a + b; 600 | d1 = a + a; 601 | d2 = a + a + b + b; 602 | while (x != x1) { 603 | if (d < 0) { 604 | y += cy; 605 | d += d2; 606 | } 607 | else { 608 | d += d1; 609 | } 610 | x += cx; 611 | for (int i = -width / 2; i <= width / 2; i++) 612 | pDC->SetPixel(x + i, y, color); 613 | } 614 | } 615 | else { // 斜率绝对值 > 1 616 | d = a + b + b; 617 | d1 = b + b; 618 | d2 = a + a + b + b; 619 | while (y != y1) { 620 | if (d < 0) { 621 | d += d1; 622 | } 623 | else { 624 | x += cx; 625 | d += d2; 626 | } 627 | y += cy; 628 | for (int i = -width / 2; i <= width / 2; i++) 629 | pDC->SetPixel(x + i, y, color); 630 | } 631 | } 632 | return; 633 | } 634 | 635 | //中点法画线,斜率任意,指定线宽,方形线刷子; 参数:pDC,颜色,起点x坐标,起点y坐标,终点x坐标,终点y坐标,线宽 636 | void CMFCOpenGL01Doc::line_midpoint_square_linebrush(CDC *pDC, COLORREF color, int x0, int y0, int x1, int y1, int width) { 637 | 638 | int x = x0, y = y0; 639 | int a = y0 - y1; 640 | int b = x1 - x0; 641 | int cx = (b >= 0 ? 1 : (b = -b, -1)); 642 | int cy = (a <= 0 ? 1 : (a = -a, -1)); 643 | int d, d1, d2; 644 | if (-a <= b) { // 斜率绝对值 <= 1 645 | d = a + a + b; 646 | d1 = a + a; 647 | d2 = a + a + b + b; 648 | while (x != x1) { 649 | if (d < 0) { 650 | y += cy; 651 | d += d2; 652 | } 653 | else { 654 | d += d1; 655 | } 656 | x += cx; 657 | for (int i = -width / 2; i <= width / 2; i++) { 658 | for (int j = -width / 2; j <= width / 2; j++) { 659 | pDC->SetPixel(x + i, y + j, color); 660 | } 661 | } 662 | } 663 | } 664 | else { // 斜率绝对值 > 1 665 | d = a + b + b; 666 | d1 = b + b; 667 | d2 = a + a + b + b; 668 | while (y != y1) { 669 | if (d < 0) { 670 | d += d1; 671 | } 672 | else { 673 | x += cx; 674 | d += d2; 675 | } 676 | y += cy; 677 | for (int i = -width / 2; i <= width / 2; i++) { 678 | for (int j = -width / 2; j <= width / 2; j++) { 679 | pDC->SetPixel(x + i, y + j, color); 680 | } 681 | } 682 | } 683 | } 684 | return; 685 | } 686 | 687 | //bresenham法画线,斜率任意; 参数:pDC,颜色,起点x坐标,起点y坐标,终点x坐标,终点y坐标 688 | void CMFCOpenGL01Doc::line_bresenham(CDC *pDC, COLORREF color, int x0, int y0, int x1, int y1) { 689 | 690 | int dx = x1 - x0; 691 | int dy = y1 - y0; 692 | int ux = ((dx > 0) << 1) - 1; 693 | int uy = ((dy > 0) << 1) - 1; 694 | int x = x0, y = y0, eps; 695 | 696 | eps = 0; dx = abs(dx); dy = abs(dy); 697 | if (dx > dy) { 698 | for (x = x0; x != x1; x += ux) { 699 | pDC->SetPixel(x, y, color); 700 | eps += dy; 701 | if ((eps << 1) >= dx) { 702 | y += uy; eps -= dx; 703 | } 704 | } 705 | } 706 | else { 707 | for (y = y0; y != y1; y += uy) { 708 | pDC->SetPixel(x, y, color); 709 | eps += dx; 710 | if ((eps << 1) >= dy) { 711 | x += ux; eps -= dy; 712 | } 713 | } 714 | } 715 | 716 | return; 717 | } 718 | 719 | 720 | //Cpen函数 721 | 722 | void CMFCOpenGL01Doc::line_cpen(CDC* pDC, COLORREF color, CPoint p1, CPoint p2, int size) { 723 | CPen cpen; 724 | cpen.CreatePen(PS_SOLID, size, color); 725 | CPen* pOldPen = (CPen*)pDC->SelectObject(&cpen); 726 | 727 | pDC->MoveTo(p1); 728 | pDC->LineTo(p2); 729 | 730 | pDC->SelectObject(pOldPen); 731 | cpen.DeleteObject(); 732 | } 733 | 734 | 735 | 736 | 737 | 738 | 739 | 740 | ///画圆算法 开始 741 | 742 | //bresenham法画正圆; 参数:pDC,颜色,圆心x坐标,圆心y坐标,半径 743 | void CMFCOpenGL01Doc::circle_perfect_bresenham(CDC *pDC, COLORREF color, int x0, int y0, int radius) { 744 | 745 | double x = 0.0, y = 0.0, d = 0.0; 746 | d = 1.25 - radius; 747 | x = 0; y = radius; 748 | for (x = 0; x <= y; x++) { 749 | set_points_on_circle(pDC, color, x0, y0, x, y); 750 | if (d < 0) d += 2 * x + 3; 751 | else { 752 | d += 2 * (x - y) + 5; 753 | y--; 754 | } 755 | } 756 | 757 | return; 758 | } 759 | 760 | //bresenham法画正圆-gl版; 参数:整型颜色R,整型颜色G,整型颜色B,圆心x坐标,圆心y坐标,半径 761 | void CMFCOpenGL01Doc::circle_perfect_bresenham_gl(int colord1, int colord2, int colord3, int x0, int y0, int radius) { 762 | 763 | glBegin(GL_POINTS); 764 | double x = 0.0, y = 0.0, d = 0.0; 765 | d = 1.25 - radius; 766 | x = 0; y = radius; 767 | for (x = 0; x < y; x++) { 768 | glVertex2d((x0 + x), (y0 + y)); 769 | glVertex2d((x0 - x), (y0 + y)); 770 | glVertex2d((x0 + x), (y0 - y)); 771 | glVertex2d((x0 - x), (y0 - y)); 772 | 773 | glVertex2d((x0 + y), (y0 + x)); 774 | glVertex2d((x0 - y), (y0 + x)); 775 | glVertex2d((x0 + y), (y0 - x)); 776 | glVertex2d((x0 - y), (y0 - x)); 777 | if (d < 0) d += 2 * x + 3; 778 | else { 779 | d += 2 * (x - y) + 5; 780 | y--; 781 | } 782 | } 783 | glEnd(); 784 | return; 785 | } 786 | 787 | //中点法画正圆; 参数:pDC,颜色,圆心x坐标,圆心y坐标,半径 788 | void CMFCOpenGL01Doc::circle_perfect_midpoint(CDC *pDC, COLORREF color, int x0, int y0, int radius) { 789 | 790 | int x = 0, y = 0, h = 0; 791 | x = 0, y = radius; 792 | h = 1 - radius; 793 | set_points_on_circle(pDC, color, x0, y0, x, y); 794 | while (x < y) { 795 | if (h < 0) h += 2 * x + 2; 796 | else { 797 | h += 2 * (x - y) + 5; 798 | y--; 799 | } 800 | x++; 801 | set_points_on_circle(pDC, color, x0, y0, x, y); 802 | } 803 | 804 | return; 805 | } 806 | 807 | //对称地画圆上的点; 参数:pDC,颜色,圆心x坐标,圆心y坐标,目标点的x坐标,目标点的y坐标 808 | void CMFCOpenGL01Doc::set_points_on_circle(CDC *pDC, COLORREF color, int x0, int y0, int x, int y) { 809 | 810 | pDC->SetPixel((x0 + x), (y0 + y), color); 811 | pDC->SetPixel((x0 - x), (y0 + y), color); 812 | pDC->SetPixel((x0 + x), (y0 - y), color); 813 | pDC->SetPixel((x0 - x), (y0 - y), color); 814 | 815 | pDC->SetPixel((x0 + y), (y0 + x), color); 816 | pDC->SetPixel((x0 - y), (y0 + x), color); 817 | pDC->SetPixel((x0 + y), (y0 - x), color); 818 | pDC->SetPixel((x0 - y), (y0 - x), color); 819 | 820 | return; 821 | } 822 | 823 | 824 | //bresenham法画椭圆; 参数:pDC,颜色,圆心x坐标,圆心y坐标,长轴的长度,短轴的长度 825 | void CMFCOpenGL01Doc::circle_oval_bresenham(CDC *pDC, COLORREF color, int x0, int y0, int a, int b) { 826 | 827 | int sqa = a * a, sqb = b * b; 828 | int x = 0, y = b; 829 | int d = 2 * sqb - 2 * b * sqa + sqa; 830 | set_points_on_oval(pDC, color, x0, y0, x, y); 831 | int P_x = round((double)sqa / sqrt((double)(sqa + sqb))); 832 | while (x <= P_x) { 833 | if (d < 0) 834 | d += 2 * sqb * (2 * x + 3); 835 | else { 836 | d += 2 * sqb * (2 * x + 3) - 4 * sqa * (y - 1); 837 | y--; 838 | } 839 | x++; 840 | set_points_on_oval(pDC, color, x0, y0, x, y); 841 | } 842 | 843 | d = sqb * (x * x + x) + sqa * (y * y - y) - sqa * sqb; 844 | while (y >= 0) { 845 | set_points_on_oval(pDC, color, x0, y0, x, y); 846 | y--; 847 | if (d < 0) { 848 | x++; 849 | d = d - 2 * sqa * y - sqa + 2 * sqb * x + 2 * sqb; 850 | } 851 | else 852 | d = d - 2 * sqa * y - sqa; 853 | } 854 | 855 | return; 856 | } 857 | 858 | //中点法画椭圆; 参数:pDC,颜色,圆心x坐标,圆心y坐标,长轴的长度,短轴的长度 859 | void CMFCOpenGL01Doc::circle_oval_midpoint(CDC *pDC, COLORREF color, int x0, int y0, int a, int b) { 860 | 861 | double sqa = a * a; 862 | double sqb = b * b; 863 | double d = sqb + sqa * (-b + 0.25); 864 | int x = 0; 865 | int y = b; 866 | set_points_on_oval(pDC, color, x0, y0, x, y); 867 | while (sqb * (x + 1) < sqa * (y - 0.5)) { 868 | if (d < 0) d += sqb * (2 * x + 3); 869 | else { 870 | d += (sqb * (2 * x + 3) + sqa * (-2 * y + 2)); 871 | y--; 872 | } 873 | x++; 874 | set_points_on_oval(pDC, color, x0, y0, x, y); 875 | } 876 | d = (b * (x + 0.5)) * 2 + (a * (y - 1)) * 2 - (a * b) * 2; 877 | while (y > 0) { 878 | if (d < 0) { 879 | d += sqb * (2 * x + 2) + sqa * (-2 * y + 3); 880 | x++; 881 | } 882 | else d += sqa * (-2 * y + 3); 883 | y--; 884 | set_points_on_oval(pDC, color, x0, y0, x, y); 885 | } 886 | 887 | return; 888 | } 889 | 890 | //对称地画椭圆上的点; 参数:pDC,颜色,圆心x坐标,圆心y坐标,目标点的x坐标,目标点的y坐标 891 | void CMFCOpenGL01Doc::set_points_on_oval(CDC *pDC, COLORREF color, int x0, int y0, int x, int y) { 892 | 893 | pDC->SetPixel((x0 + x), (y0 + y), color); 894 | pDC->SetPixel((x0 - x), (y0 + y), color); 895 | pDC->SetPixel((x0 + x), (y0 - y), color); 896 | pDC->SetPixel((x0 - x), (y0 - y), color); 897 | 898 | return; 899 | } 900 | 901 | 902 | 903 | //CPen函数 904 | 905 | void CMFCOpenGL01Doc::circle_perfect_cpen(CDC *pDC, COLORREF color, CPoint p0, int radius, int size) { 906 | CPen cpen; 907 | cpen.CreatePen(PS_SOLID, size, color); 908 | CPen* pOldPen = (CPen*)pDC->SelectObject(&cpen); 909 | pDC->Arc(CRect(p0.x-radius, p0.y-radius, p0.x+radius, p0.y+radius), CPoint(0, 0), CPoint(0, 0)); 910 | pDC->SelectObject(pOldPen); 911 | cpen.DeleteObject(); 912 | } 913 | 914 | 915 | 916 | //带有旋转角度的椭圆,顺时针旋转 参数:pDC,颜色,圆心x,圆心y,长轴a,短轴b,旋转角度(角度制),线宽 917 | void CMFCOpenGL01Doc::circle_oval_angle_cpen(CDC *pDC, COLORREF color, float x0, float y0, float a, float b, double angle, int size){ 918 | CPen cpen; 919 | cpen.CreatePen(PS_SOLID, size, color); 920 | CPen* pOldPen = (CPen*)pDC->SelectObject(&cpen); 921 | 922 | int i; 923 | float x, y; 924 | double dx, dy, di, aa, bb, sinA, cosA; 925 | double arc = pi / 180.0*angle; //转弧度制 926 | cosA = cos(arc); 927 | sinA = sin(arc); 928 | aa = a*a; 929 | bb = b*b; 930 | float flX[4], flY[4]; 931 | x = 0; 932 | y = b; 933 | dx = 0; 934 | dy = 2 * aa*y; 935 | di = bb - aa*b + aa / 4; 936 | flX[0] = x0 + x*cosA - y*sinA; 937 | flX[1] = x0 + x*cosA + y*sinA; 938 | flX[2] = x0 - x*cosA - y*sinA; 939 | flX[3] = x0 - x*cosA + y*sinA; 940 | flY[0] = y0 + y*cosA + x*sinA; 941 | flY[1] = y0 - y*cosA + x*sinA; 942 | flY[2] = y0 + y*cosA - x*sinA; 943 | flY[3] = y0 - y*cosA - x*sinA; 944 | i = 0; 945 | while (dxMoveTo(flX[0], flY[0]); 951 | pDC->LineTo(x0 + x*cosA - y*sinA, y0 + y*cosA + x*sinA); 952 | pDC->MoveTo(flX[1], flY[1]); 953 | pDC->LineTo(x0 + x*cosA + y*sinA, y0 - y*cosA + x*sinA); 954 | pDC->MoveTo(flX[2], flY[2]); 955 | pDC->LineTo(x0 - x*cosA - y*sinA, y0 + y*cosA - x*sinA); 956 | pDC->MoveTo(flX[3], flY[3]); 957 | pDC->LineTo(x0 - x*cosA + y*sinA, y0 - y*cosA - x*sinA); 958 | flX[0] = x0 + x*cosA - y*sinA; 959 | flX[1] = x0 + x*cosA + y*sinA; 960 | flX[2] = x0 - x*cosA - y*sinA; 961 | flX[3] = x0 - x*cosA + y*sinA; 962 | flY[0] = y0 + y*cosA + x*sinA; 963 | flY[1] = y0 - y*cosA + x*sinA; 964 | flY[2] = y0 + y*cosA - x*sinA; 965 | flY[3] = y0 - y*cosA - x*sinA; 966 | i = 0; 967 | } 968 | x++; 969 | dx += 2 * bb; 970 | di += dx + bb; 971 | if (di >= 0) 972 | { 973 | dy -= 2 * aa; 974 | di -= dy; 975 | y--; 976 | } 977 | } 978 | pDC->MoveTo(flX[0], flY[0]); 979 | pDC->LineTo(x0 + x*cosA - y*sinA, y0 + y*cosA + x*sinA); 980 | pDC->MoveTo(flX[1], flY[1]); 981 | pDC->LineTo(x0 + x*cosA + y*sinA, y0 - y*cosA + x*sinA); 982 | pDC->MoveTo(flX[2], flY[2]); 983 | pDC->LineTo(x0 - x*cosA - y*sinA, y0 + y*cosA - x*sinA); 984 | pDC->MoveTo(flX[3], flY[3]); 985 | pDC->LineTo(x0 - x*cosA + y*sinA, y0 - y*cosA - x*sinA); 986 | 987 | di += int((3 * (aa - bb) - 2 * (dx - dy)) / 4 + 0.5); 988 | flX[0] = x0 + x*cosA - y*sinA; 989 | flX[1] = x0 + x*cosA + y*sinA; 990 | flX[2] = x0 - x*cosA - y*sinA; 991 | flX[3] = x0 - x*cosA + y*sinA; 992 | flY[0] = y0 + y*cosA + x*sinA; 993 | flY[1] = y0 - y*cosA + x*sinA; 994 | flY[2] = y0 + y*cosA - x*sinA; 995 | flY[3] = y0 - y*cosA - x*sinA; 996 | i = 0; 997 | while (y>=0) 998 | { 999 | i++; 1000 | if (i == 5) 1001 | { 1002 | pDC->MoveTo(flX[0], flY[0]); 1003 | pDC->LineTo(x0 + x*cosA - y*sinA, y0 + y*cosA + x*sinA); 1004 | pDC->MoveTo(flX[1], flY[1]); 1005 | pDC->LineTo(x0 + x*cosA + y*sinA, y0 - y*cosA + x*sinA); 1006 | pDC->MoveTo(flX[2], flY[2]); 1007 | pDC->LineTo(x0 - x*cosA - y*sinA, y0 + y*cosA - x*sinA); 1008 | pDC->MoveTo(flX[3], flY[3]); 1009 | pDC->LineTo(x0 - x*cosA + y*sinA, y0 - y*cosA - x*sinA); 1010 | flX[0] = x0 + x*cosA - y*sinA; 1011 | flX[1] = x0 + x*cosA + y*sinA; 1012 | flX[2] = x0 - x*cosA - y*sinA; 1013 | flX[3] = x0 - x*cosA + y*sinA; 1014 | flY[0] = y0 + y*cosA + x*sinA; 1015 | flY[1] = y0 - y*cosA + x*sinA; 1016 | flY[2] = y0 + y*cosA - x*sinA; 1017 | flY[3] = y0 - y*cosA - x*sinA; 1018 | i = 0; 1019 | } 1020 | y--; 1021 | dy -= 2 * aa; 1022 | di += aa - dy; 1023 | if (di<0) 1024 | { 1025 | dx += 2 * bb; 1026 | di += dx; 1027 | x++; 1028 | } 1029 | } 1030 | pDC->MoveTo(flX[0], flY[0]); 1031 | pDC->LineTo(x0 + x*cosA - y*sinA, y0 + y*cosA + x*sinA); 1032 | pDC->MoveTo(flX[1], flY[1]); 1033 | pDC->LineTo(x0 + x*cosA + y*sinA, y0 - y*cosA + x*sinA); 1034 | pDC->MoveTo(flX[2], flY[2]); 1035 | pDC->LineTo(x0 - x*cosA - y*sinA, y0 + y*cosA - x*sinA); 1036 | pDC->MoveTo(flX[3], flY[3]); 1037 | pDC->LineTo(x0 - x*cosA + y*sinA, y0 - y*cosA - x*sinA); 1038 | 1039 | 1040 | //float th = acos(-1.0) / 180; 1041 | //float x, y, tx, ty; 1042 | //for (float i = -180; i <= 180; i = i + 0.01) { 1043 | // x = a*cos(i*th); 1044 | // y = b*sin(i*th); 1045 | // tx = x; 1046 | // ty = y; 1047 | // x = tx*cos(angle*th) - ty*sin(angle*th) + x0; 1048 | // y = y0 - (ty*cos(angle*th) + tx*sin(angle*th)); 1049 | // /*pDC->MoveTo(x, y); 1050 | // pDC->LineTo(x, y);*/ 1051 | // pDC->SetPixel(x, y, RGB(255, 0, 0)); 1052 | //} 1053 | 1054 | pDC->SelectObject(pOldPen); 1055 | cpen.DeleteObject(); 1056 | return; 1057 | } 1058 | 1059 | 1060 | 1061 | 1062 | 1063 | ///区域填充算法 开始 1064 | 1065 | void CMFCOpenGL01Doc::flood_fill_cbrush(CDC *pDC, COLORREF color, COLORREF color_banned, CPoint pt) { 1066 | 1067 | CBrush cbrush; 1068 | cbrush.CreateSolidBrush(color); 1069 | CBrush* pOldBrush = (CBrush*)pDC->SelectObject(&cbrush); 1070 | 1071 | pDC->ExtFloodFill(pt.x, pt.y, color_banned, FLOODFILLSURFACE); 1072 | 1073 | pDC->SelectObject(pOldBrush); 1074 | cbrush.DeleteObject(); 1075 | 1076 | return; 1077 | } 1078 | 1079 | 1080 | 1081 | 1082 | 1083 | 1084 | ///二维图形裁剪算法 开始 1085 | 1086 | 1087 | //Cohen-Sutherland+中点分割(区域编码+中点分割)法线段裁剪 参数:pDC,颜色,裁剪窗口范围的左上方点坐标,裁剪窗口范围的右下方点坐标,几条线,待裁剪的直线 1088 | void CMFCOpenGL01Doc::line_cut_Sutherland_midpoint(CDC *pDC, COLORREF color, vertex window_vertex_left_top, vertex window_vertex_right_bottom, int num, line lines[]) { 1089 | 1090 | for (int i = 0; i < num; i++) { 1091 | set_vertex_code(window_vertex_left_top, window_vertex_right_bottom, &lines[i].vertex_coded_begin); 1092 | set_vertex_code(window_vertex_left_top, window_vertex_right_bottom, &lines[i].vertex_coded_end); 1093 | } 1094 | 1095 | for (int i = 0; i < num; i++) { 1096 | vertex_coded vb = lines[i].vertex_coded_begin; 1097 | vertex_coded ve = lines[i].vertex_coded_end; 1098 | if (vb.code == 0 && ve.code == 0) { //全部在裁剪范围内,直接整条画出来 1099 | line_midpoint(pDC, color, vb.x, vb.y, ve.x, ve.y); 1100 | continue; 1101 | } 1102 | if ((vb.code & ve.code) != 0) { //全部不在裁剪范围内,直接删除 1103 | //line_midpoint(pDC, RGB(0,255,0), vb.x, vb.y, ve.x, ve.y); 1104 | continue; 1105 | } 1106 | if ((vb.code & ve.code) == 0) { 1107 | if ((vb.code == 0) || (ve.code == 0)) { //有一点在外,另一点在内 1108 | vertex_coded vd = line_cut_midpoint(window_vertex_left_top, window_vertex_right_bottom, lines[i]); 1109 | if (vb.code == 0) 1110 | line_midpoint(pDC, color, vb.x, vb.y, vd.x, vd.y); 1111 | else 1112 | line_midpoint(pDC, color, ve.x, ve.y, vd.x, vd.y); 1113 | } 1114 | else { //两点全在外面(线段贯穿裁剪框),需要把线段分割成两部分分别处理 1115 | vertex_coded vmid; 1116 | //左上->右下的对角线与待裁剪线段存在交点,用此交点进行分割成两部分 1117 | if (judge_line_pos(window_vertex_left_top, window_vertex_right_bottom, lines[i].vertex_coded_begin, lines[i].vertex_coded_end)) { 1118 | vmid = get_mid_point(window_vertex_left_top, window_vertex_right_bottom, vb, ve); 1119 | set_vertex_code(window_vertex_left_top, window_vertex_right_bottom, &vmid); 1120 | } 1121 | else { //右上->左下的对角线与待裁剪线段存在交点,用此交点进行分割成两部分 1122 | vmid = get_mid_point(vertex(window_vertex_right_bottom.x, window_vertex_left_top.y), vertex(window_vertex_left_top.x, window_vertex_right_bottom.y), vb, ve); 1123 | set_vertex_code(window_vertex_left_top, window_vertex_right_bottom, &vmid); 1124 | } 1125 | vertex_coded vd1 = line_cut_midpoint(window_vertex_left_top, window_vertex_right_bottom, line(vb, vmid)); 1126 | vertex_coded vd2 = line_cut_midpoint(window_vertex_left_top, window_vertex_right_bottom, line(vmid, ve)); 1127 | line_midpoint(pDC, color, vmid.x, vmid.y, vd1.x, vd1.y); 1128 | line_midpoint(pDC, color, vmid.x, vmid.y, vd2.x, vd2.y); 1129 | } 1130 | 1131 | } 1132 | } 1133 | 1134 | return; 1135 | } 1136 | 1137 | //中点分割法递归二分确定线段与裁剪边框相交于哪一点 参数:裁剪窗口范围的左上方点坐标,裁剪窗口范围的右下方点坐标,待裁剪的直线 1138 | CMFCOpenGL01Doc::vertex_coded CMFCOpenGL01Doc::line_cut_midpoint(vertex window_vertex_left_top, vertex window_vertex_right_bottom, line single_line) { 1139 | 1140 | vertex_coded vin = single_line.vertex_coded_begin.code == 0 ? single_line.vertex_coded_begin : single_line.vertex_coded_end; 1141 | vertex_coded vout = single_line.vertex_coded_begin.code != 0 ? single_line.vertex_coded_begin : single_line.vertex_coded_end; 1142 | vertex_coded vmid = vertex_coded((vin.x + vout.x) / 2, (vin.y + vout.y) / 2); 1143 | set_vertex_code(window_vertex_left_top, window_vertex_right_bottom, &vmid); 1144 | 1145 | if (abs(vmid.x - vin.x) <= 1 || abs(vmid.y - vin.y) <= 1) return vmid; //取极限 1146 | 1147 | if (vmid.code == 0) vin = vmid; //中点在裁剪框内,把内部的端点移向中点 1148 | else vout = vmid; //中点在裁剪框外,把外部的点移向中点 1149 | 1150 | return line_cut_midpoint(window_vertex_left_top, window_vertex_right_bottom, line(vin, vout)); 1151 | } 1152 | 1153 | //确定线段的端点落在那个区域,获取其对应的编码 参数:裁剪窗口范围的左上方点坐标,裁剪窗口范围的右下方点坐标,端点指针 1154 | void CMFCOpenGL01Doc::set_vertex_code(vertex window_vertex_left_top, vertex window_vertex_right_bottom, vertex_coded *v) { 1155 | 1156 | if (v->y >= window_vertex_left_top.y) v->code |= 8; //1000 上 1157 | if (v->y <= window_vertex_right_bottom.y) v->code |= 4; //0100 下 1158 | if (v->x >= window_vertex_right_bottom.x) v->code |= 2; //0010 右 1159 | if (v->x <= window_vertex_left_top.x) v->code |= 1; //0001 左 1160 | 1161 | return; 1162 | } 1163 | 1164 | //判断裁剪框对角线和待裁剪线段的位置关系 参数:裁剪线框的对角线的起点,裁剪线框对角线的终点,待裁剪线段的起点,待裁剪线段的终点 1165 | bool CMFCOpenGL01Doc::judge_line_pos(vertex window_vertex_a, vertex window_vertex_b, vertex_coded va, vertex_coded vb) { 1166 | long long int d1, d2, d3, d4; 1167 | d1 = (window_vertex_b.x - window_vertex_a.x)*(va.y - window_vertex_a.y) - (window_vertex_b.y - window_vertex_a.y)*(va.x - window_vertex_a.x); 1168 | d2 = (window_vertex_b.x - window_vertex_a.x)*(vb.y - window_vertex_a.y) - (window_vertex_b.y - window_vertex_a.y)*(vb.x - window_vertex_a.x); 1169 | d3 = (vb.x - va.x)*(window_vertex_a.y - va.y) - (vb.y - va.y)*(window_vertex_a.x - va.x); 1170 | d4 = (vb.x - va.x)*(window_vertex_b.y - va.y) - (vb.y - va.y)*(window_vertex_b.x - va.x); 1171 | if (d1*d2 <= 0 && d3*d4 <= 0) 1172 | return true; //相交及重合 1173 | else 1174 | return false; //不相交 1175 | } 1176 | 1177 | //得到线段与对角线的交点 参数:裁剪框对角线的起点,裁剪框对角线的终点,待裁剪线的起点,待裁剪线的终点 1178 | CMFCOpenGL01Doc::vertex_coded CMFCOpenGL01Doc::get_mid_point(vertex diagonal_vertex_a, vertex diagonal_vertex_b, vertex_coded va, vertex_coded vb) { 1179 | int a = vb.x - va.x; 1180 | int b = diagonal_vertex_a.x - diagonal_vertex_b.x; 1181 | int c = vb.y - va.y; 1182 | int d = diagonal_vertex_a.y - diagonal_vertex_b.y; 1183 | int g = diagonal_vertex_a.x - va.x; 1184 | int h = diagonal_vertex_a.y - va.y; 1185 | int f = a*d - b*c; 1186 | double t = double((d*g - b*h)) / double(f); 1187 | vertex_coded m; 1188 | m.x = va.x + t*(vb.x - va.x); 1189 | m.y = va.y + t*(vb.y - va.y); 1190 | return m; 1191 | } 1192 | 1193 | 1194 | 1195 | 1196 | 1197 | //Sutherland-Hodgman(逐边裁剪)法多边形裁剪(返回裁剪完成的新多边形) 参数:裁剪窗口范围的左上方点坐标,裁剪窗口范围的右下方点坐标,待裁剪的多边形 1198 | CMFCOpenGL01Doc::polygon CMFCOpenGL01Doc::polygon_cut_Sutherland_Hodgman(vertex window_vertex_left_top, vertex window_vertex_right_bottom, polygon src_polygon) { 1199 | 1200 | polygon p1, p2, p3, p4; 1201 | vertex vs, vp; //s->p 1202 | //左边框裁剪 1203 | for (int i = 0; i < src_polygon.vertex_num; i++) { 1204 | vs = src_polygon.vertexes[i]; 1205 | if (i == src_polygon.vertex_num - 1) vp = src_polygon.vertexes[0]; 1206 | else vp = src_polygon.vertexes[i + 1]; 1207 | 1208 | if (vs.x >= window_vertex_left_top.x && vp.x >= window_vertex_left_top.x) { //情况一:s、p都在内侧,输出p 1209 | p1.vertexes.push_back(vp); 1210 | p1.vertex_num++; 1211 | } 1212 | if (vs.x < window_vertex_left_top.x && vp.x < window_vertex_left_top.x) { //情况二:s、p都在外侧,无输出 1213 | continue; 1214 | } 1215 | if (vs.x >= window_vertex_left_top.x && vp.x < window_vertex_left_top.x) { //情况三:s在内侧,p在外侧,输出交点i 1216 | vertex vi(window_vertex_left_top.x, get_intersection_point(vs, vp, window_vertex_left_top.x, true)); 1217 | p1.vertexes.push_back(vi); 1218 | p1.vertex_num++; 1219 | } 1220 | if (vs.x < window_vertex_left_top.x && vp.x >= window_vertex_left_top.x) { //情况四:s在外侧,p在内侧,输出i和p 1221 | vertex vi(window_vertex_left_top.x, get_intersection_point(vs, vp, window_vertex_left_top.x, true)); 1222 | p1.vertexes.push_back(vi); 1223 | p1.vertexes.push_back(vp); 1224 | p1.vertex_num += 2; 1225 | } 1226 | } 1227 | 1228 | //上边框裁剪 1229 | for (int i = 0; i < p1.vertex_num; i++) { 1230 | vs = p1.vertexes[i]; 1231 | if (i == p1.vertex_num - 1) vp = p1.vertexes[0]; 1232 | else vp = p1.vertexes[i + 1]; 1233 | 1234 | if (vs.y <= window_vertex_left_top.y && vp.y <= window_vertex_left_top.y) { //情况一:s、p都在内侧,输出p 1235 | p2.vertexes.push_back(vp); 1236 | p2.vertex_num++; 1237 | } 1238 | if (vs.y > window_vertex_left_top.y && vp.y > window_vertex_left_top.y) { //情况二:s、p都在外侧,无输出 1239 | continue; 1240 | } 1241 | if (vs.y <= window_vertex_left_top.y && vp.y > window_vertex_left_top.y) { //情况三:s在内侧,p在外侧,输出交点i 1242 | vertex vi(get_intersection_point(vs, vp, window_vertex_left_top.y, false), window_vertex_left_top.y); 1243 | p2.vertexes.push_back(vi); 1244 | p2.vertex_num++; 1245 | } 1246 | if (vs.y > window_vertex_left_top.y && vp.y <= window_vertex_left_top.y) { //情况四:s在外侧,p在内侧,输出i和p 1247 | vertex vi(get_intersection_point(vs, vp, window_vertex_left_top.y, false), window_vertex_left_top.y); 1248 | p2.vertexes.push_back(vi); 1249 | p2.vertexes.push_back(vp); 1250 | p2.vertex_num += 2; 1251 | } 1252 | } 1253 | 1254 | //右边框裁剪 1255 | for (int i = 0; i < p2.vertex_num; i++) { 1256 | vs = p2.vertexes[i]; 1257 | if (i == p2.vertex_num - 1) vp = p2.vertexes[0]; 1258 | else vp = p2.vertexes[i + 1]; 1259 | 1260 | if (vs.x <= window_vertex_right_bottom.x && vp.x <= window_vertex_right_bottom.x) { //情况一:s、p都在内侧,输出p 1261 | p3.vertexes.push_back(vp); 1262 | p3.vertex_num++; 1263 | } 1264 | if (vs.x > window_vertex_right_bottom.x && vp.x > window_vertex_right_bottom.x) { //情况二:s、p都在外侧,无输出 1265 | continue; 1266 | } 1267 | if (vs.x <= window_vertex_right_bottom.x && vp.x > window_vertex_right_bottom.x) { //情况三:s在内侧,p在外侧,输出交点i 1268 | vertex vi(window_vertex_right_bottom.x, get_intersection_point(vs, vp, window_vertex_right_bottom.x, true)); 1269 | p3.vertexes.push_back(vi); 1270 | p3.vertex_num++; 1271 | } 1272 | if (vs.x > window_vertex_right_bottom.x && vp.x <= window_vertex_right_bottom.x) { //情况四:s在外侧,p在内侧,输出i和p 1273 | vertex vi(window_vertex_right_bottom.x, get_intersection_point(vs, vp, window_vertex_right_bottom.x, true)); 1274 | p3.vertexes.push_back(vi); 1275 | p3.vertexes.push_back(vp); 1276 | p3.vertex_num += 2; 1277 | } 1278 | } 1279 | 1280 | //下边框裁剪 1281 | for (int i = 0; i < p3.vertex_num; i++) { 1282 | vs = p3.vertexes[i]; 1283 | if (i == p3.vertex_num - 1) vp = p3.vertexes[0]; 1284 | else vp = p3.vertexes[i + 1]; 1285 | 1286 | if (vs.y >= window_vertex_right_bottom.y && vp.y >= window_vertex_right_bottom.y) { //情况一:s、p都在内侧,输出p 1287 | p4.vertexes.push_back(vp); 1288 | p4.vertex_num++; 1289 | } 1290 | if (vs.y < window_vertex_right_bottom.y && vp.y < window_vertex_right_bottom.y) { //情况二:s、p都在外侧,无输出 1291 | continue; 1292 | } 1293 | if (vs.y >= window_vertex_right_bottom.y && vp.y < window_vertex_right_bottom.y) { //情况三:s在内侧,p在外侧,输出交点i 1294 | vertex vi(get_intersection_point(vs, vp, window_vertex_right_bottom.y, false), window_vertex_right_bottom.y); 1295 | p4.vertexes.push_back(vi); 1296 | p4.vertex_num++; 1297 | } 1298 | if (vs.y < window_vertex_right_bottom.y && vp.y >= window_vertex_right_bottom.y) { //情况四:s在外侧,p在内侧,输出i和p 1299 | vertex vi(get_intersection_point(vs, vp, window_vertex_right_bottom.y, false), window_vertex_right_bottom.y); 1300 | p4.vertexes.push_back(vi); 1301 | p4.vertexes.push_back(vp); 1302 | p4.vertex_num += 2; 1303 | } 1304 | } 1305 | 1306 | return p4; 1307 | } 1308 | 1309 | //求出直线和裁剪框的交点(返回交点处的数值) 参数:待裁剪的线的起始点,待裁剪的线的结束点,裁剪线框的某一条线x=value或y=value的value值,是x=还是y=(true为x,false为y) 1310 | int CMFCOpenGL01Doc::get_intersection_point(vertex vb, vertex ve, int value, bool flag) { 1311 | 1312 | int result = 0; 1313 | 1314 | if (flag) { //与直线x=value相交,返回y 1315 | if (vb.y == ve.y) { //k=0 1316 | result = vb.y; 1317 | } 1318 | else { 1319 | double k = 1.0*(ve.y - vb.y) / (ve.x - vb.x); 1320 | double b = ve.y - (k * ve.x); 1321 | result = k*value + b; 1322 | } 1323 | } 1324 | else { //与直线y=value相交,返回x 1325 | if (vb.x == ve.x) { //k不存在 1326 | result = vb.x; 1327 | } 1328 | else { 1329 | double k = 1.0*(ve.y - vb.y) / (ve.x - vb.x); 1330 | double b = ve.y - (k * ve.x); 1331 | result = (value - b) / k; 1332 | } 1333 | } 1334 | 1335 | return result; 1336 | } 1337 | 1338 | //绘制多边形 参数:PDC,颜色,顶点个数,多边形 1339 | void CMFCOpenGL01Doc::draw_polygon(CDC *pDC, COLORREF color, polygon p) { 1340 | for (int i = 0; i < p.vertex_num - 1; i++) 1341 | line_midpoint(pDC, color, p.vertexes[i].x, p.vertexes[i].y, p.vertexes[i + 1].x, p.vertexes[i + 1].y); 1342 | 1343 | line_midpoint(pDC, color, p.vertexes[p.vertex_num - 1].x, p.vertexes[p.vertex_num - 1].y, p.vertexes[0].x, p.vertexes[0].y); 1344 | 1345 | return; 1346 | } 1347 | 1348 | 1349 | 1350 | 1351 | 1352 | 1353 | ///二维图形变换算法 开始 1354 | 1355 | //平移(以图形的重心点作为基准平移) 参数:图形集,待平移图形的下标,平移到哪个位置 1356 | void CMFCOpenGL01Doc::transform_translate_point(std::vector &v_point, int index, CPoint point){ 1357 | v_point[index].p.x = point.x; 1358 | v_point[index].p.y = point.y; 1359 | return; 1360 | } 1361 | 1362 | void CMFCOpenGL01Doc::transform_translate_line(std::vector &v_line, int index, CPoint point){ 1363 | int xm = (v_line[index].p1.x + v_line[index].p2.x) / 2, 1364 | ym = (v_line[index].p1.y + v_line[index].p2.y) / 2; 1365 | int delta_x = point.x - xm, 1366 | delta_y = point.y - ym; 1367 | v_line[index].p1.x += delta_x; 1368 | v_line[index].p1.y += delta_y; 1369 | v_line[index].p2.x += delta_x; 1370 | v_line[index].p2.y += delta_y; 1371 | return; 1372 | } 1373 | 1374 | void CMFCOpenGL01Doc::transform_translate_perfect_circle(std::vector& v_perf_circle, int index, CPoint point){ 1375 | v_perf_circle[index].p0.x = point.x; 1376 | v_perf_circle[index].p0.y = point.y; 1377 | return; 1378 | } 1379 | 1380 | void CMFCOpenGL01Doc::transform_translate_oval_circle(std::vector& v_oval_circle, int index, CPoint point){ 1381 | v_oval_circle[index].p0.x = point.x; 1382 | v_oval_circle[index].p0.y = point.y; 1383 | return; 1384 | } 1385 | 1386 | void CMFCOpenGL01Doc::transform_translate_polygon(std::vector& v_polygon, int index, CPoint point){ 1387 | int mid_x = 0, mid_y = 0; 1388 | for (int i = 0; i < v_polygon[index].ps.size(); i++) { 1389 | mid_x += v_polygon[index].ps[i].x; 1390 | mid_y += v_polygon[index].ps[i].y; 1391 | } 1392 | mid_x /= v_polygon[index].ps.size(); 1393 | mid_y /= v_polygon[index].ps.size(); 1394 | int delta_x = point.x - mid_x, 1395 | delta_y = point.y - mid_y; 1396 | for (int i = 0; i < v_polygon[index].ps.size(); i++) { 1397 | v_polygon[index].ps[i].x += delta_x; 1398 | v_polygon[index].ps[i].y += delta_y; 1399 | } 1400 | return; 1401 | } 1402 | 1403 | void CMFCOpenGL01Doc::transform_translate_bezier(std::vector& v_bezier, int index, CPoint point){ 1404 | int mid_x = 0, mid_y = 0; 1405 | for (int i = 0; i < v_bezier[index].ps.size(); i++) { 1406 | mid_x += v_bezier[index].ps[i].x; 1407 | mid_y += v_bezier[index].ps[i].y; 1408 | } 1409 | mid_x /= v_bezier[index].ps.size(); 1410 | mid_y /= v_bezier[index].ps.size(); 1411 | int delta_x = point.x - mid_x; 1412 | int delta_y = point.y - mid_y; 1413 | for (int i = 0; i < v_bezier[index].ps.size(); i++) { 1414 | v_bezier[index].ps[i].x += delta_x; 1415 | v_bezier[index].ps[i].y += delta_y; 1416 | } 1417 | return; 1418 | } 1419 | 1420 | 1421 | //获取点p围绕p0旋转后的点,angle为角度制,逆时针为正 1422 | CPoint CMFCOpenGL01Doc::get_rotated_point(CPoint p, CPoint p0, int angle) { 1423 | double arc = pi / 180.0*angle; 1424 | double pxx = p0.x + (p.x - p0.x)*std::cos(arc) - (p.y - p0.y)*std::sin(arc); 1425 | double pyy = p0.y + (p.x - p0.x)*std::sin(arc) + (p.y - p0.y)*std::cos(arc); 1426 | return CPoint(pxx, pyy); 1427 | } 1428 | 1429 | //旋转 参数:图形集,待旋转图形的下标,旋转前鼠标位置,旋转后鼠标位置(以图形重心为基准) 1430 | //旋转角度(角度制,顺时针 < 0,逆时针 >= 0) 1431 | void CMFCOpenGL01Doc::transform_rotate_line(std::vector& v_line, int index, CPoint oldPoint, CPoint point){ 1432 | int xm = (v_line[index].p1.x + v_line[index].p2.x) / 2, 1433 | ym = (v_line[index].p1.y + v_line[index].p2.y) / 2; 1434 | double a = sqrt((xm - point.x)*(xm - point.x) + (ym - point.y)*(ym - point.y)), 1435 | b = sqrt((oldPoint.x - point.x)*(oldPoint.x - point.x) + (oldPoint.y - point.y)*(oldPoint.y - point.y)), 1436 | c = sqrt((xm - oldPoint.x)*(xm - oldPoint.x) + (ym - oldPoint.y)*(ym - oldPoint.y)); 1437 | double angle = (acos((a*a + c*c - b*b) / (2 * a*c)) / pi * 180.0); 1438 | double angle_judge = (oldPoint.x - xm)*(point.y - ym) - (point.x - xm)*(oldPoint.y - ym); //<0顺时针,>=0逆时针 1439 | angle = (angle_judge >= 0.0 ? angle : -angle); 1440 | v_line[index].p1 = get_rotated_point(v_line[index].p1, CPoint(xm, ym), angle); 1441 | v_line[index].p2 = get_rotated_point(v_line[index].p2, CPoint(xm, ym), angle); 1442 | return; 1443 | } 1444 | 1445 | void CMFCOpenGL01Doc::transform_rotate_oval_circle(std::vector& v_oval_circle, int index, CPoint oldPoint, CPoint point){ 1446 | int xm = v_oval_circle[index].p0.x, 1447 | ym = v_oval_circle[index].p0.y; 1448 | double a = sqrt((xm - point.x)*(xm - point.x) + (ym - point.y)*(ym - point.y)), 1449 | b = sqrt((oldPoint.x - point.x)*(oldPoint.x - point.x) + (oldPoint.y - point.y)*(oldPoint.y - point.y)), 1450 | c = sqrt((xm - oldPoint.x)*(xm - oldPoint.x) + (ym - oldPoint.y)*(ym - oldPoint.y)); 1451 | double angle = (acos((a*a + c*c - b*b) / (2 * a*c)) / pi * 180.0); 1452 | double angle_judge = (oldPoint.x - xm)*(point.y - ym) - (point.x - xm)*(oldPoint.y - ym); //<0顺时针,>=0逆时针 1453 | angle = (angle_judge >= 0.0 ? angle : -angle); 1454 | v_oval_circle[index].angle += angle; 1455 | return; 1456 | } 1457 | 1458 | void CMFCOpenGL01Doc::transform_rotate_polygon(std::vector& v_polygon, int index, CPoint oldPoint, CPoint point){ 1459 | int mid_x = 0, mid_y = 0; 1460 | for (int i = 0; i < v_polygon[index].ps.size(); i++) { 1461 | mid_x += v_polygon[index].ps[i].x; 1462 | mid_y += v_polygon[index].ps[i].y; 1463 | } 1464 | mid_x /= v_polygon[index].ps.size(); 1465 | mid_y /= v_polygon[index].ps.size(); 1466 | 1467 | double a = sqrt((mid_x - point.x)*(mid_x - point.x) + (mid_y - point.y)*(mid_y - point.y)), 1468 | b = sqrt((oldPoint.x - point.x)*(oldPoint.x - point.x) + (oldPoint.y - point.y)*(oldPoint.y - point.y)), 1469 | c = sqrt((mid_x - oldPoint.x)*(mid_x - oldPoint.x) + (mid_y - oldPoint.y)*(mid_y - oldPoint.y)); 1470 | double angle = (acos((a*a + c*c - b*b) / (2 * a*c)) / pi * 180.0); 1471 | double angle_judge = (oldPoint.x - mid_x)*(point.y - mid_y) - (point.x - mid_x)*(oldPoint.y - mid_y); //<0顺时针,>=0逆时针 1472 | angle = (angle_judge >= 0.0 ? angle : -angle); 1473 | for (int i = 0; i < v_polygon[index].ps.size(); i++) 1474 | v_polygon[index].ps[i] = get_rotated_point(v_polygon[index].ps[i], CPoint(mid_x, mid_y), angle); 1475 | return; 1476 | } 1477 | 1478 | void CMFCOpenGL01Doc::transform_rotate_bezier(std::vector& v_bezier, int index, CPoint oldPoint, CPoint point){ 1479 | int mid_x = 0, mid_y = 0; 1480 | for (int i = 0; i < v_bezier[index].ps.size(); i++) { 1481 | mid_x += v_bezier[index].ps[i].x; 1482 | mid_y += v_bezier[index].ps[i].y; 1483 | } 1484 | mid_x /= v_bezier[index].ps.size(); 1485 | mid_y /= v_bezier[index].ps.size(); 1486 | 1487 | double a = sqrt((mid_x - point.x)*(mid_x - point.x) + (mid_y - point.y)*(mid_y - point.y)), 1488 | b = sqrt((oldPoint.x - point.x)*(oldPoint.x - point.x) + (oldPoint.y - point.y)*(oldPoint.y - point.y)), 1489 | c = sqrt((mid_x - oldPoint.x)*(mid_x - oldPoint.x) + (mid_y - oldPoint.y)*(mid_y - oldPoint.y)); 1490 | double angle = (acos((a*a + c*c - b*b) / (2 * a*c)) / pi * 180.0); 1491 | double angle_judge = (oldPoint.x - mid_x)*(point.y - mid_y) - (point.x - mid_x)*(oldPoint.y - mid_y); //<0顺时针,>=0逆时针 1492 | angle = (angle_judge >= 0.0 ? angle : -angle); 1493 | for (int i = 0; i < v_bezier[index].ps.size(); i++) 1494 | v_bezier[index].ps[i] = get_rotated_point(v_bezier[index].ps[i], CPoint(mid_x, mid_y), angle); 1495 | } 1496 | 1497 | 1498 | //缩放 参数:图形集,待缩放图形的下标,缩放前鼠标位置,缩放后鼠标位置(以图形重心为基准) 1499 | void CMFCOpenGL01Doc::transform_scale_line(std::vector& v_line, int index, CPoint oldPoint, CPoint point){ 1500 | int xm = (v_line[index].p1.x + v_line[index].p2.x) / 2, 1501 | ym = (v_line[index].p1.y + v_line[index].p2.y) / 2; 1502 | double dis1 = sqrt((oldPoint.x - xm)*(oldPoint.x - xm) + (oldPoint.y - ym)*(oldPoint.y - ym)), 1503 | dis2 = sqrt((point.x - xm)*(point.x - xm) + (point.y - ym)*(point.y - ym)); 1504 | double rate = dis2 / dis1; 1505 | v_line[index].p1.x = (v_line[index].p1.x - xm)*rate + xm; 1506 | v_line[index].p1.y = (v_line[index].p1.y - ym)*rate + ym; 1507 | v_line[index].p2.x = (v_line[index].p2.x - xm)*rate + xm; 1508 | v_line[index].p2.y = (v_line[index].p2.y - ym)*rate + ym; 1509 | return; 1510 | } 1511 | 1512 | void CMFCOpenGL01Doc::transform_scale_perfect_circle(std::vector& v_perf_circle, int index, CPoint oldPoint, CPoint point){ 1513 | int xm = v_perf_circle[index].p0.x, 1514 | ym = v_perf_circle[index].p0.y; 1515 | double dis1 = sqrt((oldPoint.x - xm)*(oldPoint.x - xm) + (oldPoint.y - ym)*(oldPoint.y - ym)), 1516 | dis2 = sqrt((point.x - xm)*(point.x - xm) + (point.y - ym)*(point.y - ym)); 1517 | double rate = dis2 / dis1; 1518 | v_perf_circle[index].radius *= rate; 1519 | return; 1520 | } 1521 | 1522 | void CMFCOpenGL01Doc::transform_scale_oval_circle(std::vector& v_oval_circle, int index, CPoint oldPoint, CPoint point){ 1523 | int xm = v_oval_circle[index].p0.x, 1524 | ym = v_oval_circle[index].p0.y; 1525 | double dis1 = sqrt((oldPoint.x - xm)*(oldPoint.x - xm) + (oldPoint.y - ym)*(oldPoint.y - ym)), 1526 | dis2 = sqrt((point.x - xm)*(point.x - xm) + (point.y - ym)*(point.y - ym)); 1527 | double rate = dis2 / dis1; 1528 | v_oval_circle[index].a *= rate; 1529 | v_oval_circle[index].b *= rate; 1530 | return; 1531 | } 1532 | 1533 | void CMFCOpenGL01Doc::transform_scale_polygon(std::vector& v_polygon, int index, CPoint oldPoint, CPoint point){ 1534 | int mid_x = 0, mid_y = 0; 1535 | for (int i = 0; i < v_polygon[index].ps.size(); i++) { 1536 | mid_x += v_polygon[index].ps[i].x; 1537 | mid_y += v_polygon[index].ps[i].y; 1538 | } 1539 | mid_x /= v_polygon[index].ps.size(); 1540 | mid_y /= v_polygon[index].ps.size(); 1541 | double dis1 = sqrt((oldPoint.x - mid_x)*(oldPoint.x - mid_x) + (oldPoint.y - mid_y)*(oldPoint.y - mid_y)), 1542 | dis2 = sqrt((point.x - mid_x)*(point.x - mid_x) + (point.y - mid_y)*(point.y - mid_y)); 1543 | double rate = dis2 / dis1; 1544 | for (int i = 0; i < v_polygon[index].ps.size(); i++) { 1545 | v_polygon[index].ps[i].x = (v_polygon[index].ps[i].x - mid_x)*rate + mid_x; 1546 | v_polygon[index].ps[i].y = (v_polygon[index].ps[i].y - mid_y)*rate + mid_y; 1547 | } 1548 | return; 1549 | } 1550 | 1551 | void CMFCOpenGL01Doc::transform_scale_bezier(std::vector& v_bezier, int index, CPoint oldPoint, CPoint point){ 1552 | int mid_x = 0, mid_y = 0; 1553 | for (int i = 0; i < v_bezier[index].ps.size(); i++) { 1554 | mid_x += v_bezier[index].ps[i].x; 1555 | mid_y += v_bezier[index].ps[i].y; 1556 | } 1557 | mid_x /= v_bezier[index].ps.size(); 1558 | mid_y /= v_bezier[index].ps.size(); 1559 | double dis1 = sqrt((oldPoint.x - mid_x)*(oldPoint.x - mid_x) + (oldPoint.y - mid_y)*(oldPoint.y - mid_y)), 1560 | dis2 = sqrt((point.x - mid_x)*(point.x - mid_x) + (point.y - mid_y)*(point.y - mid_y)); 1561 | double rate = dis2 / dis1; 1562 | for (int i = 0; i < v_bezier[index].ps.size(); i++) { 1563 | v_bezier[index].ps[i].x = (v_bezier[index].ps[i].x - mid_x)*rate + mid_x; 1564 | v_bezier[index].ps[i].y = (v_bezier[index].ps[i].y - mid_y)*rate + mid_y; 1565 | } 1566 | } 1567 | 1568 | 1569 | //对称 参数:图形集,待对称的图形的下标,对称标志(0为上下,1为左右) 1570 | void CMFCOpenGL01Doc::transform_symmetry_line(std::vector& v_line, int index, int flag){ 1571 | int xm = (v_line[index].p1.x + v_line[index].p2.x) / 2, 1572 | ym = (v_line[index].p1.y + v_line[index].p2.y) / 2; 1573 | if (!flag) { 1574 | v_line[index].p1.y = ym * 2 - v_line[index].p1.y; 1575 | v_line[index].p2.y = ym * 2 - v_line[index].p2.y; 1576 | } 1577 | else { 1578 | v_line[index].p1.x = xm * 2 - v_line[index].p1.x; 1579 | v_line[index].p2.x = xm * 2 - v_line[index].p2.x; 1580 | } 1581 | return; 1582 | } 1583 | 1584 | void CMFCOpenGL01Doc::transform_symmetry_oval_circle(std::vector& v_oval_circle, int index, int flag){ 1585 | v_oval_circle[index].angle = 180.0 - v_oval_circle[index].angle; //椭圆两种对称结果形状相同 1586 | return; 1587 | } 1588 | 1589 | void CMFCOpenGL01Doc::transform_symmetry_polygon(std::vector& v_line, int index, int flag){ 1590 | int mid_x = 0, mid_y = 0; 1591 | for (int i = 0; i < v_polygon[index].ps.size(); i++) { 1592 | mid_x += v_polygon[index].ps[i].x; 1593 | mid_y += v_polygon[index].ps[i].y; 1594 | } 1595 | mid_x /= v_polygon[index].ps.size(); 1596 | mid_y /= v_polygon[index].ps.size(); 1597 | if (!flag) { 1598 | for (int i = 0; i < v_polygon[index].ps.size(); i++) 1599 | v_polygon[index].ps[i].y = mid_y * 2 - v_polygon[index].ps[i].y; 1600 | } 1601 | else { 1602 | for (int i = 0; i < v_polygon[index].ps.size(); i++) 1603 | v_polygon[index].ps[i].x = mid_x * 2 - v_polygon[index].ps[i].x; 1604 | } 1605 | } 1606 | 1607 | void CMFCOpenGL01Doc::transform_symmetry_bezier(std::vector& v_bezier, int index, int flag){ 1608 | int mid_x = 0, mid_y = 0; 1609 | for (int i = 0; i < v_bezier[index].ps.size(); i++) { 1610 | mid_x += v_bezier[index].ps[i].x; 1611 | mid_y += v_bezier[index].ps[i].y; 1612 | } 1613 | mid_x /= v_bezier[index].ps.size(); 1614 | mid_y /= v_bezier[index].ps.size(); 1615 | if (!flag) { 1616 | for (int i = 0; i < v_bezier[index].ps.size(); i++) 1617 | v_bezier[index].ps[i].y = mid_y * 2 - v_bezier[index].ps[i].y; 1618 | } 1619 | else { 1620 | for (int i = 0; i < v_bezier[index].ps.size(); i++) 1621 | v_bezier[index].ps[i].x = mid_x * 2 - v_bezier[index].ps[i].x; 1622 | } 1623 | } 1624 | 1625 | 1626 | 1627 | 1628 | 1629 | 1630 | 1631 | 1632 | 1633 | ///二维图形矩阵变换函数 1634 | 1635 | //计算1*3矩阵 乘 3*3矩阵的结果,返回一个1*3的矩阵 1636 | double* CMFCOpenGL01Doc::matrix_1_3_times_3_3(double matrix_1_3[3], double matrix_3_3[3][3]) { 1637 | double res[3]; 1638 | res[0] = (matrix_1_3[0] * matrix_3_3[0][0] + matrix_1_3[1] * matrix_3_3[1][0] + matrix_1_3[2] * matrix_3_3[2][0]); 1639 | res[1] = (matrix_1_3[0] * matrix_3_3[0][1] + matrix_1_3[1] * matrix_3_3[1][1] + matrix_1_3[2] * matrix_3_3[2][1]); 1640 | res[2] = (matrix_1_3[0] * matrix_3_3[0][2] + matrix_1_3[1] * matrix_3_3[1][2] + matrix_1_3[2] * matrix_3_3[2][2]); 1641 | return res; 1642 | } 1643 | 1644 | //矩阵计算一个点经过平移后的点,返回变换后的点 1645 | CPoint CMFCOpenGL01Doc::transform_translate_matrix(CPoint p, double delta_x, double delta_y){ 1646 | double matrix_1_3[3] = { 1.0*p.x, 1.0*p.y, 1.0 }; 1647 | double matrix_3_3[3][3] = { 1648 | 1.0, 0, 0, 1649 | 0, 1.0, 0, 1650 | delta_x, delta_y, 1.0 1651 | }; 1652 | double* matrix_res = matrix_1_3_times_3_3(matrix_1_3, matrix_3_3); 1653 | return CPoint(matrix_res[0], matrix_res[1]); 1654 | } 1655 | 1656 | //矩阵计算一个点p绕p0旋转angle度后的点(angle为角度制,逆时针为正),返回变换后的点 1657 | CPoint CMFCOpenGL01Doc::transform_rotate_matrix(CPoint p, CPoint p0, double angle){ 1658 | double arc = pi / 180.0*angle; 1659 | double matrix_1_3[3] = { 1.0*(p.x - p0.x), 1.0*(p.y - p0.y), 1.0 }; 1660 | double matrix_3_3[3][3] = { 1661 | cos(arc), sin(arc), 0, 1662 | -sin(arc), cos(arc), 0, 1663 | 0, 0, 1.0 1664 | }; 1665 | double* matrix_res = matrix_1_3_times_3_3(matrix_1_3, matrix_3_3); 1666 | return CPoint(matrix_res[0] + p0.x, matrix_res[1] + p0.y); 1667 | } 1668 | 1669 | //矩阵计算一个点p以p0为中心缩放s倍后的点(x,y缩放倍率相同),返回变换后的点 1670 | CPoint CMFCOpenGL01Doc::transform_scale_matrix(CPoint p, CPoint p0, double s){ 1671 | double matrix_1_3[3] = { 1.0*(p.x - p0.x), 1.0*(p.y - p0.y), 1.0 }; 1672 | double matrix_3_3[3][3] = { 1673 | s, 0, 0, 1674 | 0, s, 0, 1675 | 0, 0, 1.0 1676 | }; 1677 | double* matrix_res = matrix_1_3_times_3_3(matrix_1_3, matrix_3_3); 1678 | return CPoint(matrix_res[0] + p0.x, matrix_res[1] + p0.y); 1679 | } 1680 | 1681 | //矩阵计算一个点p经过p0所在对称轴对称后的点(flag为0上下对称,1为左右对称),返回变换后的点 1682 | CPoint CMFCOpenGL01Doc::transform_symmetry_matrix(CPoint p, CPoint p0, int flag){ 1683 | double matrix_1_3[3] = { 1.0*(p.x - p0.x), 1.0*(p.y - p0.y), 1.0 }; 1684 | double matrix_3_3_x[3][3] = { 1685 | 1.0, 0, 0, 1686 | 0, -1.0, 0, 1687 | 0, 0, 1.0 1688 | }, 1689 | matrix_3_3_y[3][3] = { 1690 | -1.0, 0, 0, 1691 | 0, 1.0, 0, 1692 | 0, 0, 1.0 1693 | }; 1694 | double* matrix_res = !flag ? matrix_1_3_times_3_3(matrix_1_3, matrix_3_3_x) : matrix_1_3_times_3_3(matrix_1_3, matrix_3_3_y); 1695 | return CPoint(matrix_res[0] + p0.x, matrix_res[1] + p0.y); 1696 | } 1697 | 1698 | 1699 | 1700 | --------------------------------------------------------------------------------