1 / 15

Transformasi

Learn about various transformations in computer graphics, from setting up the camera to modeling objects and viewing perspectives. Explore transformations like Projections, Viewing, and Modeling in OpenGL programming.

wperry
Download Presentation

Transformasi

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Transformasi

  2. Transformasi • GrafikaKomputeradalahprosestransformasidari model 3D obyekmenjadicitra 2D, inisamadengananalogikamera. • Sebelummemotret, apa yang dilakukan? • melakukanpengesetankameradalambentuk setting lensakamera (zoom in/out) • mengarahkankamerakeobyek (ex: mengaturletak tripod) • mengaturletakobyek (ex: mengubah-ubahletakobjek) • mengaturskaladan layout darifoto (ex : fotodenganorangdisisipinggir)

  3. Transformasi • Analogidiatasmerupakanpenjelasandarijenis-jenistransformasisbb: • melakukanpengesetankameradalambentuk setting lensakamera (TransformasiProyeksi), • mengarahkamerakeobyek (Transformasi Viewing), • mengaturletakobyek (Transformasi Modeling), • mengaturskaladan layout darifoto (Transformasi Viewport) -> denganglViewPortpadacontohsebelumnya

  4. TransformasiProyeksi • Digunakanuntukmenentukan viewing volume. • Duamacam Transf. proyeksiyaituPerspektifdan Orthogonal • Perspektif : objek yang jauhterlihatlebihkecil • Orthogonal : maps objects directly onto the screen without affecting their relative size

  5. TransformasiProyeksiterdiridari a. Transformasi Orthogonal/Paralel (gambaratas) b. TransformasiPerspektif (mengerucutkesatutitikproyeksi, gambarbawah)

  6. Transformasi Viewing • Untukmenghasilkangambar, kameraperludiletakkanpadaposisi yang tepatdidepanpemandangan yang diinginkan. • Secara default, dalam OpenGL kemeraakanberadapadaposisi (0,0,0) denganmenghadapkearahz = -1 dengansumbuymengarahkeataskamera. • Hal inidapatdilakukandenganmenggunakanperintahgluLookAt() dengandidahuluiprosesmerubah status OpenGL kemodelviewdenganperintahglMatrixMode(GL_MODELVIEW).

  7. #include <GL/gl.h> • #include <GL/glu.h> • #include <GL/glut.h> • void init(void) • { • glClearColor (0.0, 0.0, 0.0, 0.0); • glShadeModel (GL_FLAT); • } • void display(void) • { • glClear (GL_COLOR_BUFFER_BIT); • glColor3f (1.0, 1.0, 1.0); • glLoadIdentity (); /* clear the matrix */ • /* viewing transformation */ • gluLookAt (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); • glScalef (1.0, 2.0, 1.0); /* modeling transformation */ • glutWireCube (1.0); • glFlush (); • } • void reshape (int w, int h) • { • glViewport (0, 0, (GLsizei) w, (GLsizei) h); • glMatrixMode (GL_PROJECTION); • glLoadIdentity (); • glFrustum (-1.0, 1.0, -1.0, 1.0, 1.5, 20.0); • glMatrixMode (GL_MODELVIEW); • } • int main(intargc, char** argv) • { • glutInit(&argc, argv); • glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); • glutInitWindowSize (500, 500); • glutInitWindowPosition (100, 100); • glutCreateWindow (argv[0]); • init (); • glutDisplayFunc(display); • glutReshapeFunc(reshape); • glutMainLoop(); • return 0; • }

  8. Viewing Transformation - gluLookAt() • After the matrix is initialized, the viewing transformation is specified with gluLookAt(). • The arguments for this command indicate where the camera (or eye position) is placed, where it is aimed, and which way is up. • The arguments used here place the camera at (0, 0, 5), aim the camera lens towards (0, 0, 0), and specify the up-vector as (0, 1, 0). The up-vector defines a unique orientation for the camera. • IfgluLookAt() was not called, the camera has a default position and orientation. By default, the camera is situated at the origin, points down the negative z-axis, and has an up-vector of (0, 1, 0). 

  9. Try This • Change the gluLookAt() call in code to the modeling transformation glTranslatef() with parameters (0.0, 0.0, -5.0). The result should look exactly the same as when you used gluLookAt(). Why are the effects of these two commands similar?

  10. GLU Quadrics • gluQuadricTexture(GLUquadricObj *obj, Glboolean mode) • OpenGL generates texture coordinates • GL_FALSE: no texture coordinates (default) • gluSphere(GLUquadricObj *obj, Gldouble radius, Glint slices, Glint • stacks) • creates a Sphere in the origin with the given radius • gluCylinder(GLUquadricObj *obj, Gldouble base, Gldoubletop,Gldouble height, Gldouble slices, Gldouble stacks) • A centered cylinder with specified base and top radii • glutWireSphere(Gldouble radius, Glint slices, Glint stacks) • glutSolidSphere(Gldouble radius, Glint slices, Glint stacks) • glutWire[Solid]Cone(Gldouble base, Gldouble height, Glint slices, • Glint stacks) • glutWire[Solid]Teapot (Gldouble size)

  11. Modelling Transformation • You use the modeling transformation to position and orient the model. For example, you can rotate, translate, or scale the model - or perform some combination of these operations. • Example 3-1,glScalef() is the modeling transformation that is used. The arguments for this command specify how scaling should occur along the three axes. If all the arguments are 1.0, this command has no effect. In Example 3-1, the cube is drawn twice as large in the y direction. Thus, if one corner of the cube had originally been at (3.0, 3.0, 3.0), that corner would wind up being drawn at (3.0, 6.0, 3.0). The effect of this modeling transformation is to transform the cube so that it isn't a cube but a rectangular box.

  12. Try This • Change the gluLookAt() call in Example 3-1 to the modeling transformation glTranslatef() with parameters (0.0, 0.0, -5.0). The result should look exactly the same as when you usedgluLookAt(). Why are the effects of these two commands similar?

  13. Viewport Transformation • Together, the projection transformation and the viewport transformation determine how a scene gets mapped onto the computer screen. 

  14. Tambahkananimasirotasipadaobjekkubusdaninputan keyboard untuktranslasipadasumbu z. Contoh coding padapertemuan 2

More Related