04 |transformation

20
04 |Transformation Eriq Muhammad Adams J | [email protected]

Upload: roxy

Post on 25-Jan-2016

41 views

Category:

Documents


3 download

DESCRIPTION

04 |Transformation. Eriq Muhammad Adams J | [email protected]. Transformation. Modeling transformation. Menggerakkan objek dari local coordinates ke world coordinates. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: 04 |Transformation

04 |TransformationEriq Muhammad Adams J | [email protected]

Page 2: 04 |Transformation

Transformation

• Modeling transformation. Menggerakkan objek dari local coordinates ke world coordinates.

• Viewing transformation. Memposisikan dan mengarahkan camera, dan menggerakkan objek dari world coordinates ke eye or camera coordinates.

• Projection transformation. Mendefinisikan viewing volume and clipping planes dan memetakan objek dari eye coordinates ke clip coordinates.

• Viewport transformation. Memetakan clip coordinates ke 2D viewport, atau window, atau layar.

Page 3: 04 |Transformation

Vertex Transformation Pipeline

Vertex Data(x, y, z, w)

Vertex Data(x, y, z, w)

Model Transformation

Matrix

Model Transformation

Matrix

View Transformation

Matrix

View Transformation

Matrix

Projection Transformation

Matrix

Projection Transformation

Matrix

Perspective Division

Perspective Division

Viewport Transformation

Viewport Transformation

ModelView Matrix

World Coordinates

EyeCoordinates

ClipCoordinates

NormalizedDevice

Coordinates

WindowCoordinates

(x,y)

Page 4: 04 |Transformation

Urutan penulisan transformasi

• Urutan penulisan transformasi dalam program (terbalik dari urutan vertex transformation pipeline) :1. Viewport Transformation2. Viewing Transformation3. Projection Transformation4. Modelling Transformation

Page 5: 04 |Transformation

Modelling TransformationTranslation

Rotation

Scaling

glTranslate{fd}(TYPE x, TYPE y, TYPE z)

glRotate{fd}(TYPE angle, TYPE x, TYPE y, TYPE z)

glScale{fd}(TYPE x, TYPE y, TYPE z)

Page 6: 04 |Transformation

Modelling Transformation (cont.)

• Urutan transformasi mempengaruhi hasil.

Page 7: 04 |Transformation

Modelling Transformation (cont.)

• How to code :1.Aktifasi ModelView Matrix :

glMatrixMode(GL_ModelView);

2.Me-reset ModelView Matrix :glLoadIdentity()

3.Melakukan Transformation4.Me-Render Objek

Page 8: 04 |Transformation

Matrix Stack

• Stack untuk menyimpan matrix utk modelling & projection transformation dan color.

• Ada 4 tipe matrix stack :1. Modelview matrix stack2. Projection matrix stack3. Color matrix stack4. Texture matrix stack

Page 9: 04 |Transformation

Matrix Stack (cont.)

Page 10: 04 |Transformation

Matrix Stack (cont.)

• Menyimpan current matrix dalam stack menggunakan glPushMatrix(), dan menghapus matrix teratas menggunakan glPopMatrix().

Page 11: 04 |Transformation

Viewing Transformation

• Camera secara default akan mengarah ke sumbu z negatif.

Page 12: 04 |Transformation

Viewing Transformation (cont.)

• Menggunakan gluLookAt() :void gluLookAt(GLdouble eyex, GLdouble eyey, GLdouble eyez, GLdouble centerx, GLdouble centery, GLdouble centerz, GLdouble upx, GLdouble upy, GLdouble upz);

Page 13: 04 |Transformation

Projection Transformation

• 2 tipe projection transformation : 1. Perspective projection :

Menampilkan 3D world secara perspektif (ada unsur depth), objek yang jauh ditampilkan lebih kecil daripada objek yang dekat.

2. Orthographic projection :Menampilkan semua objek dalam ukuran yang sebenarnya (tidak ada unsur depth, biasa digunakan untuk CAD program, 2D games, dsb)

Page 14: 04 |Transformation

Projection Transformation (cont.)

• Orthographic projection menggunakan glOrtho() atau gluOrtho2D(). – glOrtho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble

top, GLdouble near, GLdouble far);– gluOrtho2D(GLdouble left, GLdouble right, GLdouble bottom,

GLdouble top);

Page 15: 04 |Transformation

Projection Transformation (cont.)

• Perspective projection menggunakan glFustrum() dan gluPerspective(). – void glFrustum(GLdouble left, GLdouble right, GLdouble bottom,

GLdouble top, GLdouble near, GLdouble far);

Page 16: 04 |Transformation

Projection Transformation (cont.)

• void gluPerspective(GLdouble fov, GLdouble aspect, GLdouble near, GLdouble far);

Page 17: 04 |Transformation

Projection Transformation (cont.)

• How to code :1.Aktifasi Projection Matrix :

glMatrixMode(GL_Projection);

2.Mereset Projection Matrix :glLoadIdentity()

3.Melakukan Transformation4.Me-render Objek

Page 18: 04 |Transformation

Viewport Transformation

• Setting viewport menggunakan glViewport(). void glViewport(GLint x, GLint y, GLsizei width, GLsizei height);

Viewport Height

Width

(x,y)

Page 19: 04 |Transformation

Hello Transformation!

Page 20: 04 |Transformation

Tugas ke-1

• Membuat model 3D bergerak yang tersusun dari kubus (seperti model LEGO misal helicopter, mobil, dsb). Dikumpulkan dan dibahas minggu depan (laporan + kode program + executable).

• Program menggunakan vertex arrays / VBO dan transformation.• Format laporan harus berisi :

– Judul– Anggota Kelompok– Pembagian Tugas – Kode Program– Flow-chart Program– Penjelasan kode program– Screenshot Program