/
Week01.tex
178 lines (145 loc) · 4.04 KB
/
Week01.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
\chapter{Week 1 - Primitives and attributes}
\section{Part 1}
The purpose of the lines that have been commented out in the appendix 1 is to
setup the projection of the camera. This defines a mapping between world space
and view space. By default - when these lines are commented out - this mapping
is defined by an identity matrix, which means that the viewer sees object located
within the $[0,1][0,1]$ intervals with respect to x an y coordinates.
gluOrtho2d as used below defines a scale and a translation so that the viewer sees object
located within $[-10,10][-10,10]$
glMatrixMode is a primitive that selects the current matrix, so that OpenGL matrix
operations carried after are operated on the one selected (projection or modelview)
\begin{verbatim}
//glMatrixMode (GL_PROJECTION);
//glLoadIdentity ();
//gluOrtho2D (-10., 10., -10., 10.);
//glMatrixMode (GL_MODELVIEW);
\end{verbatim}
\section{Part 2}
Here are the lines modified as requested in the assignment
\begin{lstlisting}[caption=Snapshot from Part2.cpp]
glLoadIdentity ();
glTranslated(1.5,0,0);
glRotated(45, 0, 0, 1);
glTranslated(-1.5,0,0);
glColor3f(1.0,1.0,0.0);
glBegin (GL_POLYGON);
glVertex2fv (V[0]);
glVertex2fv (V[1]);
glVertex2fv (V[2]);
glVertex2fv (V[3]);
glEnd ();
glLoadIdentity();
glTranslated(6,7,0);
glBegin(GL_TRIANGLES);
glColor3f (1.0, 0.0, 0.0);
glVertex2f(2.0, 2.0);
glColor3f (0.0, 1.0, 0.0);
glVertex2f(5.0, 2.0);
glColor3f (0.0, 0.0, 1.0);
glVertex2f(3.5,5);
glEnd();
\end{lstlisting}
This gives the following result:
\image{Week01/Part2.png}{Output image of Part 2.}{0.5}{img:p2}
%\section{Part 3}
%\section{Part 4}
\section{Part 5}
\image{Week01/Part05.png}{Output image of Part 5.}{0.5}{img:p5}
\section{Part 6}
Given a viewport defined by the coordinates $[x_{w1},x_{w2},y_{w1},y_{w2}]$ and $[x_{v1},x_{v2},y_{v1},y_{v2}]$,
the matrix mapping a point $(x_{w},y_{w})$ to the point $(x_{v},y_{v})$
is:
$$
\begin{pmatrix}
A& 0& 0& tx \\
0& B& 0& ty \\
0& 0& 0& 0 \\
0& 0& 0& 1 \\
\end{pmatrix}
$$
With the scaling components\\
\begin{align*}
A &= \frac{1}{sx} = \frac{1}{(x_{min}-x_{u2})/(x_{v1}-x_{v2})} \\
B &= \frac{1}{sy} = \frac{1}{(y_{min}-y_{u2})/(y_{v1}-y_{v2})}
\end{align*}
And the translation components\\
\begin{align*}
t_x &= x_{v1}-x_{u2} \\
t_y &= y_{v1}-y_{u2}
\end{align*}
\section{Part 7}
The required transformations have been implemented in the function display below:
\begin{lstlisting}[caption=Snapshot from Part7.cpp]
void display (void) {
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3f (1.,1.,1.);
// tansformation
glTranslated(0,3,0);
glRotated(30,0,1,0);
glScaled(2,2,2);
// draw the cube
glutWireCube (1.);
// draw the axis
glLoadIdentity();
axis();
glFlush ();
}
\end{lstlisting}
A translation matrix can is expressed as follows:
$$
\begin{pmatrix}
1& 0& 0& tx\\
0& 1& 0& ty\\
0& 0& 1& tz\\
0& 0& 0& 1
\end{pmatrix}
$$
A rotation around y is:
$$
\begin{pmatrix}
cos(\theta)& 0& sin(\theta)& 0\\
0& 1& 0& 0\\
-sin(\theta)& 0& cos(\theta)& 0\\
0& 0& 0& 1\\
\end{pmatrix}
$$
And a scale is written as:
$$
\begin{pmatrix}
sx 0 0 0
0 sy 0 0
0 0 sz 0
0 0 0 1
\end{pmatrix}
$$
witz sx, sy and sz the scaling factors along x, y and z.\\
~\\
Therefor, the matrix form of the transformations we used are expressed as follows:
glTranslated(0,3,0);
$$
\begin{pmatrix}
1& 0& 0& 0\\
0& 1& 0& 3\\
0& 0& 1& 0\\
0& 0& 0& 1
\end{pmatrix}$$
glRotated(30,0,1,0);
$$\begin{pmatrix}
cos(30)& 0& sin(30)& 0\\
0& 1& 0& 0\\
-sin(30)& 0& cos(30)& 0\\
0& 0& 0& 1\\
\end{pmatrix}$$
glScaled(2,2,2);
$$\begin{pmatrix}
2& 0& 0& 0\\
0& 2& 0& 0\\
0& 0& 2& 0\\
0& 0& 0& 1\\
\end{pmatrix}$$
the final modelview matrix is the multiplication of the three previous matrices.
\image{Week01/Part7.png}{Output image of Part 7.}{0.5}{img:p5}
\section{Part 8}
\image{Week01/Part8a.png}{Front perspective view.}{0.5}{img:p5}
\image{Week01/Part8.png}{X perspective view.}{0.5}{img:p5}