04 |transformation

Post on 25-Jan-2016

43 Views

Category:

Documents

3 Downloads

Preview:

Click to see full reader

DESCRIPTION

04 |Transformation. Eriq Muhammad Adams J | eriq.adams@ub.ac.id. Transformation. Modeling transformation. Menggerakkan objek dari local coordinates ke world coordinates. - PowerPoint PPT Presentation

TRANSCRIPT

04 |TransformationEriq Muhammad Adams J | eriq.adams@ub.ac.id

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.

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)

Urutan penulisan transformasi

• Urutan penulisan transformasi dalam program (terbalik dari urutan vertex transformation pipeline) :1. Viewport Transformation2. Viewing Transformation3. Projection Transformation4. Modelling 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)

Modelling Transformation (cont.)

• Urutan transformasi mempengaruhi hasil.

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

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

Matrix Stack (cont.)

Matrix Stack (cont.)

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

Viewing Transformation

• Camera secara default akan mengarah ke sumbu z negatif.

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);

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)

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);

Projection Transformation (cont.)

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

GLdouble top, GLdouble near, GLdouble far);

Projection Transformation (cont.)

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

Projection Transformation (cont.)

• How to code :1.Aktifasi Projection Matrix :

glMatrixMode(GL_Projection);

2.Mereset Projection Matrix :glLoadIdentity()

3.Melakukan Transformation4.Me-render Objek

Viewport Transformation

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

Viewport Height

Width

(x,y)

Hello 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

top related