Solution Tut 4
Câu 1
Gọi
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
D
là ma trận của phép biến đối xứng qua trục Oy
T(0,1)R
z
(45
0
)DR
z
(-45
0
)T(0,-1)
2 2 2 2
0 0 0 0
1 0 0 0 1 0 0 0 1 0 0 0
2 2 2 2
0 1 0 1 0 1 0 0 0 1 0 1
Câu 2
Tịnh tiến ABCD sao cho điểm A tiến về gốc toạ độ O
1
1 0 0 6
0 1 0 5
()
0 0 1 0
0 0 0 1
M T A
Biến đổi kích thước hình chữ nhật từ 6x3 về hình chữ nhật kích thước 3x4
2
1
Tịnh tiến hình bình hành sao cho đỉnh A từ O tiến về vị trí đỉnh A‘ như kết quả
4
1 0 0 0
0 1 0 1
(0, 1,0)
0 0 1 0
0 0 0 1
MT
Kết quả như sau:
4 3 2 1
* * *
1
glBegin(GL_TRIANGLE_STRIP);
glVertex3f(0.1f, 0.1f, 0.1f);
glVertex3f(0.1f, 0.1f, -0.1f);
glVertex3f(-0.1f, 0.1f, 0.1f);
glVertex3f(-0.1f, 0.1f, -0.1f);
glEnd();
glBegin(GL_TRIANGLE_STRIP);
glVertex3f(0.1f, -0.1f, 0.1f);
glVertex3f(0.1f, -0.1f, -0.1f);
glVertex3f(-0.1f, -0.1f, 0.1f);
glVertex3f(-0.1f, -0.1f, -0.1f);
glEnd();
}
void OnDisplay_cau3a(){
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
//glDisable(GL_COLOR_LOGIC_OP);
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-4, 4, -4, 4, -100, 100);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glRotatef(angle2, 1.0, 0.0, 0.0);
glRotatef(angle, 0.0, 1.0, 0.0);
glPopMatrix();
}
glutSwapBuffers();
}
void OnDisplay_cau3b(){
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
//glDisable(GL_COLOR_LOGIC_OP);
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-4, 4, -4, 4, -100, 100);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glRotatef(angle2, 1.0, 0.0, 0.0);
glRotatef(angle, 0.0, 1.0, 0.0);
float fScale = 1.0f;
float fRotate = 0.0f;
glColor3f(0.0f, 0.0f, 0.0f);
drawCube();
for(int i = 1; i<10; i++)
{
fScale *= 0.9f;
fRotate += 22.5f;
glColor3f(0.0f, 0.0f, 1.0f);
glPushMatrix();
glTranslatef(0.0f, 0.0f, -SPACE*i);
glRotatef(fRotate, 0.0f, 0.0f, 1.0f);
glScalef(fScale, fScale, fScale);
drawCube();
glPopMatrix();
glPushMatrix();
glTranslatef(0.0f, 0.0f, SPACE*i);
glRotatef(fRotate, 0.0f, 0.0f, 1.0f);
glScalef(fScale, fScale, fScale);
drawCube();
glPopMatrix();
glPopMatrix();
}
glutSwapBuffers();
}
void OnMouseMove(int x, int y)
{
if (moving) {
angle = angle + (x - startx)*0.1;
angle2 = angle2 + (y - starty)*0.1;
startx = x;
starty = y;
glutPostRedisplay();
}
6. glRotatef(60f, 0f, 0f, 1f);
7. glScalef(2.5f, 1f, 1.5f);
8. glRotatef(90f, 0f, 0f, 1f);
R
z
(90
0
)S(2.5, 1, 1.5)R
z
(60
0
)T(3,2,1)
3
1
00
1 0 0 3 2.5 0 0 0 0 1 0 0
22
0 1 0 2 0 1 0 0 1 0 0 0
3
1
00
* * *
22
0 0 1 1 0 0 1.5 0 0 0 1 0
0 0 1 0
0 0 0 1 0 0 0 1 0 0 0 1
0 0 0 1
3
1.25 0 3
2
Câu 5
#include <Windows.h>
#include <gl/GL.h>
#include <gl/glut.h>
#include <math.h>
int iWnd;
float sqrt2 = sqrt(2.0);
struct SPOSITION {
float x, y;
SPOSITION(float x, float y):x(x), y(y) {}
};
struct SCOLOR {
float r, g, b;
SCOLOR(int r, int g, int b): r(r/255.0f), g(g/255.0f), b(b/255.0f) {}
};
void drawSquare(float r, float g, float b) {
glColor3f(r, g, b);
glBegin(GL_POLYGON);
glVertex2f( 5f, .5f);
glVertex2f( 5f, 5f);
glVertex2f(.5f, 5f);
glVertex2f(.5f, .5f);
glEnd();
}
void drawSquareAt(SPOSITION origin, SCOLOR color, float edge) {
drawSquareAt(SPOSITION(x, y), VIOLET, sqrt2);
//PINK
if (x%4 == 0 && y %2 == 1 && y!=1 && y!= row*2-1)
drawSquareAt(SPOSITION(x, y), PINK, sqrt2);
//YELLOW
if (x%4 == 3 && y %4 == 0 && x!= col*2-1)
drawSquareAt(SPOSITION(x, y), YELLOW, sqrt2);
//BROWN
if (x%4 == 1 && y %4 == 0 && x!=1)
drawSquareAt(SPOSITION(x, y), BROWN, sqrt2);
}
}
void drawGrid() {
for (int i=0; i< 50; i++) {
glBegin(GL_QUAD_STRIP);
for (int j=0; j< 50; j++) {
glVertex2i(i, j);
glVertex2i(i+1, j);
}
glEnd();
}
}
void OnDisplay(){
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-5, 20, -5, 20, 0, 1);