Run the example
1. Realize drawing the coordinate axis and rectangle
Create a new project named Translation and
first define some variables and classes that need to be used
They are point class, line class, color class,
line class contains point class and color class
TranslationView.h contains line class
There is also CLine, I forgot to take a screenshot
Then directly write the header files and source files of the three classes, just copy and paste the code in
RGB.h
RGB.cpp
first delete the default constructor and destructor and then copy them in. Then go
to P2.h
P2.cpp You need to add the header file
math.h
and then delete the two default
constructors and copy and paste all the code into it
Then go to Line.h
Line.h needs to include P2.h and RGB.h
and then go to Line.cpp
Line.cpp needs to include math.h and rounding macro definitions
Delete the default construction and destructor copy code
Next go to TranslationView.h
to declare some variables and functions
and include the line class
Then go to TranslationView.cpp
to add macro definitions and math.h
and modify the OnDraw function
and the four functions just declared.
There is a mistake here. Two functions forgot to write parameters into it.
Finally, add a special function, use this function to call the function of reading the point table.
If you don’t add it, you will only draw the coordinate axis, but not the rectangle.
Then you can compile and run
(if you want to Let the window open with maximized)
modify the following code
2. Realize graphic transformation
First add the graphics transformation class
and then write the menu function
Transform.h
Transform.cpp
and then modify the content of TranslationView.h
and then TranslationView.cpp
first modify the content of a function
and then start to write the menu function,
a total of eight,
up and down, left and right translation, clockwise
and counterclockwise rotation,
zoom in and out proportionally,
there is nothing to pay attention to after
the copy and paste The code compiles and runs just fine