Digital Media Technology Computer Graphics VC++ Experiment 4: Realize the translation, scaling and rotation transformation of two-dimensional graphics

Run the example
insert image description here

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

insert image description here
insert image description here
insert image description here
insert image description here
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
insert image description here
RGB.cpp
first delete the default constructor and destructor and then copy them in. Then go
insert image description here
to P2.h
insert image description here
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
insert image description here

Then go to Line.h
Line.h needs to include P2.h and RGB.h
insert image description here
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
insert image description here
Next go to TranslationView.h
to declare some variables and functions
and include the line class
insert image description here

insert image description here
insert image description here
Then go to TranslationView.cpp
to add macro definitions and math.h
and modify the OnDraw function
and the four functions just declared.
insert image description here
There is a mistake here. Two functions forgot to write parameters into it.

insert image description here

insert image description here
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.
insert image description here
insert image description here
Then you can compile and run
(if you want to Let the window open with maximized)
modify the following code
insert image description here

insert image description here

2. Realize graphic transformation

First add the graphics transformation class
and then write the menu function

insert image description here
Transform.h
insert image description here

Transform.cpp
insert image description here
and then modify the content of TranslationView.h
insert image description here
insert image description here
and then TranslationView.cpp
first modify the content of a function
insert image description here
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
insert image description here

Guess you like

Origin blog.csdn.net/m0_62316271/article/details/130622458