Learning Objectives 3D Object Representations Polyhedron Quadrics, SuperQuadrics Spline, Bezier Blobby Constructive Solid Geometry
3D Object Representations Graphics scenes melibatkan berbagai jenis objek dan material surfaces Trees, flowers, clouds, rocks, water, bricks, wood paneling, rubber, paper, marble, steel, glass, plastic, etc. Bagaimana merepresentasikan objek 3D pada openGL?
3D Object Representations Untuk merepresentasikan objek 3D, ada beberapa teknik Menggunakan polygon dan quadric untuk membuat objek seperti polyhedrons ataupun ellipsoids Untuk membuat permukaan berkurva seperti pada sayap pesawat, gears, bodi mesin, etc, digunakan Spline surfaces Constructive solid geometry untuk menyusun bentuk geometri dasar menjadi objek komplek Untuk memodelkan pegunungan, awan, tumbuhan, atau air terjun digunakan procedural methods seperti fractals dan particle system
Predefined Objects OpenGL sudah menyediakan fungsi menggambar beberapa objek dasar yang tinggal dipakai. Tak perlu membuat dari awal. Objek-objek dari OpenGL ini dapat disusun untuk membuat bentuk yang kita inginkan Beberapa yang sudah disediakan OpenGL antara lain: Polyhedra Polyhedron functions Quadric Surfaces Superquadrics
Object with Superquadrics
A. Polyhedron A polyhedron is a connected mesh of simple planar polygons that encloses a finite amount of space. Polyhedron adalah rangkaian jala polygon (polygon mesh) dengan kriteria sbb Setiap edge dipakai oleh 2 faces Sedikitnya 3 edge bertemu pada setiap vertex. Faces tidak saling menembus, tetapi berhenti pada suatu edge. Euler’s formula : If F, E, V represent the number of faces, vertices and edges of a polyhedron, then V + F E = 2.
3D Object Representation The data for polygonal meshes can be represented in two ways. Method 1: Vertex List Normal List Face List (Polygon List) Method 2: Edge List
Surface Normal n
Vertices and Faces - E.g. Cube 2 5 5 4 3 1 1 1 5 6 6 7 7 2 2 3 3 4 Vertex Index Face Index
Data representation using vertex, face and normal lists: xyz axis
Data representation using vertex, face and edge lists:
Normal Vectors (OpenGL)
Regular Polyhedra (Platonic Solids) Jika semua face pada polyhedron adalah identik dan berupa regular polygon, maka polyhedron tsb disebut platonic solid. Hanya ada 5 jenis platonic solid
The Platonic Solids Regular tetrahedron (or triangular pyramid) has 4 faces Regular hexahedron (or cube) with 6 faces Regular octahedron with 8 faces Regular dodecahedron with 12 faces Regular icosahedron with 20 faces
Menggambar polyhedron Ada 2 cara Method1 : Fitting the surface with a polygon mesh. Membungkus permukaan objek polyhedron dengan susunan jala polygon. Proses ini disebut juga dengan surface tesselation Method 2 : Memakai fungsi yang disediakan library GLUT
Method-1 Polygon Mesh In fitting polygons to a surface, we are not limited to using GL_POLYGON We can also use GL_TRIANGLES GL_TRIANGLE_STRIP GL_TRIANGLE_FAN GL_QUADS GL_QUAD_STRIP
Polygon Mesh Polygon mesh ini juga bisa dipakai untuk memodelkan permukaan objek lainnya
Method 2- OpenGL Polyhedron Functions 5 functions produce wire frames which can be easily used Ex: glutWireX(), where X is one of the names Cube, Tetrahedron, Octahedron, Dodecahedron, or Icosahedron (with the first letter capitalized). 5 functions produce polyhedra facets as shaded fill areas - the characteristics of these are determined by material and lighting properties. Ex: glutSolidX(), where X is as above.
GLUT Library of Polyhedron Functions Example: prog8OGLGLUTPolyhedra.cpp
glutWireTetrahedron() and glutWireCube(1.0) 4 faces 6 faces
glutWireOctahedron() and glutWireDodecahedron() 8 faces 12 faces
And, glutWireIcosahedron() 20 faces
B.Quadrics Objek yang didefinisikan sebagai persamaan quadratics Sphere Ellipsoid Torus General form
Quadric surfaces Double cones Ellipsoids Hyperboloids of one sheet Hyperboloids of two sheets
Quadric surfaces Elliptic paraboloids Hyperbolic paraboloids
Superquadrics the squaring operations are replaced by arbitrary powers. Superellipses
Superquadrics Superellipsoids
GLUT Quadric Functions – for Solids, Substitute Solid for Wire glutWireSphere(radius, slices, stacks); glutWireCone(base, height, slices, stacks); glutWireTorus(innerRadius, outerRadius, nsides, rings); and the following is provided also! glutWireTeapot(size);
GLUT Quadric Functions QuadricSurfs.cpp
GLU Quadric-Surface Functions void gluSphere (GLUquadricObj *qobj, GLdouble radius,GLint slices, GLint stacks); void gluCylinder (GLUquadricObj *qobj, GLdouble baseRadius,GLdouble topRadius, GLdouble height,GLint slices, GLint stacks); void gluDisk (GLUquadricObj *qobj, GLdouble innerRadius,GLdouble outerRadius, GLint slices, GLint rings);
GLU Quadric-Surface Functions void gluPartialDisk (GLUquadricObj *qobj, GLdouble innerRadius,GLdouble outerRadius, GLint slices, GLint rings,GLdouble startAngle, GLdouble sweepAngle);
GLU Quadric-Surface Functions Quadric.c
WHY IS THE TEAPOT POPULAR? Pada zaman dahulu belum ada library packages untuk 3D modelling. Pemodelan objek 3D dilakukan dengan tangan, menggambar kurva dan titik2nya dicatat secara manual. Computer graphics researcher Martin Newell, ketika hendak mencari barang untuk dibuat model matematika tak sengaja menemukan teapot Teapot adalah model yang ideal untuk eksperimen 3D modelling, karena Mudah dikenal Topologi yang komplek Mempunyai proyeksi bayangan pada dirinya sendiri Melibatkan topik hidden surface Memiliki permukaan cekung dan cembung, juga saddle points (curved up and down) Doesn't take much storage space
The Utah Teapot The real teapot--- The teapot was donated to the Boston Computer Museum but now resides in the Ephemera collection of the Computer History Museum where it's catalogued as "Teapot used for Computer Graphics rendering" catalogue number X00398.1984.
Many Versions of Teapots From Steve Baker’s History of the Teapot site: http://www.sjbaker.org/teapot/index.html
%^$@ Teapot! From Steve Baker’s History of the Teapot site: http://www.sjbaker.org/teapot/index.html.
wireframe
Lighting & shading
Texture mapped
Multiple Teapots of Various Materials teapots.c
C. Spline Representations Splines are used to design curves and surfaces based on a set of user-defined points Control points Himpunan titik koordinat yang mengontrol bentuk kurva Interpolation Semua control points tersambung satu sama lain pada garis kurva Approximate Semua atau beberapa control points terletak di luar garis kurva
Spline Representations Interpolated Approximate
Bezier Spline Curves Developed by French engineer Pierre Bézier for use in the design of Renault automobile bodies Easy to implement Widely used in CAD systems, graphics, drawing and painting packages
Bezier Curve Equations Diketahui sejumlah n +1 control points, nilai k antara 0 sampai n Persamaan garis Bezier akan membentuk titik-titik garis kurva sesuai control point yang didefinisikan
Bezier Curve Equations Degree 1 – Linear Curve Degree 2 Degree 3 Degree n
Bezier Spline Curves A common use for Bezier curves is in font definition
Bezier Spline Curves If we specify the first and the last control point as the same point, we can generate a closed Bezier curve
Bezier Surfaces Two sets of Bezier curves can be used to design an object surface with pj,k specifying the location of (m+1) by (n+1) control points
Bezier Surfaces u and v parameters
Bezier Surfaces An example Bezier surface
OpenGL Approximation Spline Functions Bezier splines and B-splines can be displayed using OpenGL functions The core library contains Bezier functions, and GLU has B-spline functions Bezier functions are often hardware implemented
OpenGL Bezier-Spline Curve Functions We specify parameters and activate the routines for Bezier-curve display with glMap1*(GL_MAP1_VERTEX_3, uMin, uMax, stride, nPts, *ctrlPts); glEnable(GL_MAP1_VERTEX_3); and deactivate with glDisable(GL_MAP1_VERTEX_3); uMin and uMax are typically 0 and 1.0 stride=3 for 3D nPts is the number of control points ctrlPts is the array of control points
OpenGL Bezier-Spline Curve Functions After setting parameters, we need to evaluate positions along the spline path and display the resulting curve. To calculate coordinate positions we use glEvalCoord1*(uValue); where uValue is assigned some value in the interval from uMin to uMax
Example OpenGL Code prog8OGLBezierCurve.cpp GLfloat ctrlPts [4][3] = { {-40.0, 40.0, 0.0}, {-10.0, 200.0, 0.0}, {10.0, -200.0, 0.0}, {40.0, 40.0, 0.0} }; glMap1f (GL_MAP1_VERTEX_3, 0.0, 1.0, 3, 4, *ctrlPts); glEnable (GL_MAP1_VERTEX_3); GLint k; glColor3f (0.0, 0.0, 1.0); // Set line color to blue. glBegin (GL_LINE_STRIP); // Generate Bezier "curve". for (k = 0; k <= 50; k++) glEvalCoord1f (GLfloat (k) / 50.0); glEnd ( ); glColor3f (1.0, 0.0, 0.0); // Set point color to red. glPointSize (5.0); // Set point size to 5.0. glBegin (GL_POINTS); // Plot control points. for (k = 0; k < 4; k++) glVertex3fv (&ctrlPts [k][0]); prog8OGLBezierCurve.cpp
Example OpenGL Code prog8OGLBezierCurve.cpp
OpenGL Bezier-Spline Surface Functions We specify parameters and activate the routines for Bezier surface display with glMap2*(GL_MAP2_VERTEX_3, uMin, uMax, uStride, nuPts, vMin, vMax, vStride, nvPts, *ctrlPts); glEnable(GL_MAP2_VERTEX_3); and deactivate with glDisable(GL_MAP2_VERTEX_3); uMin, uMax, vMin and vMax are typically 0 and 1.0 stride=3 for 3D nuPts and nvPts are the size of the array ctrlPts is the double subscripted array of control points
Example OpenGL Code bezsurf.c GLfloat ctrlpoints[4][4][3] = { {{-1.5, -1.5, 4.0}, {-0.5, -1.5, 2.0}, {0.5, -1.5, -1.0}, {1.5, -1.5, 2.0}}, {{-1.5, -0.5, 1.0}, {-0.5, -0.5, 3.0}, {0.5, -0.5, 0.0}, {1.5, -0.5, -1.0}}, {{-1.5, 0.5, 4.0}, {-0.5, 0.5, 0.0}, {0.5, 0.5, 3.0}, {1.5, 0.5, 4.0}}, {{-1.5, 1.5, -2.0}, {-0.5, 1.5, -2.0}, {0.5, 1.5, 0.0}, {1.5, 1.5, -1.0}} }; glMap2f(GL_MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4, &ctrlpoints[0][0][0]); glEnable(GL_MAP2_VERTEX_3); for (j = 0; j <= 8; j++) { glBegin(GL_LINE_STRIP); for (i = 0; i <= 30; i++) glEvalCoord2f((GLfloat)i/30.0, (GLfloat)j/8.0); glEnd(); glEvalCoord2f((GLfloat)j/8.0, (GLfloat)i/30.0); } bezsurf.c
Example OpenGL Code bezsurf.c
Bézier Surfaces: Example Utah Teapot modeled by 32 Bézier Patches
D. Blobby Objects Memodelkan objek yang dapat berubah bentuk tapi volumenya tetap Contoh Water drops Molecules Force fields
Blobby Objects A collection of density functions Equi-density surfaces
Metaballs (Blinn Blobbies)
E.Constructive Solid Geometry Primitives Transformed Combined Bermula dari objek geometri primitive, ditransformasikan dan dikombinasikan membentuk objek yang kompleks