Video Processing Lab 臺灣師範大學數位媒體中心視訊處理研究室
3D object representations
Chen Jing-Fung (2006/12/5) Assistant Research Fellow,
Digital Media Center, National Taiwan Normal University
Ch8: Computer Graphics with OpenGL 3th, Hearn Baker Ch6: Interactive Computer Graphics 3th, Addison Wesley
Video Processing Lab
臺灣師範大學數位媒體中心視訊處理研究室
2
3D objects
• Regular Polyhedrons
– Solid
– Mesh surface
Video Processing Lab
臺灣師範大學數位媒體中心視訊處理研究室
3
Graphics scenes
• Contain many different kinds of objects and material surfaces – Trees, flowers, clouds, rocks, water, bricks …
• Polygon and quadric surfaces provide precise descriptions for simple Euclidean objects – Polyhedrons & ellipsoids – Quadric surfaces (Ex: spline surfaces…)
• Mathematical method modify those objects
Video Processing Lab
臺灣師範大學數位媒體中心視訊處理研究室
4
Useful design
• The constructive solid-geometry techniques are useful design – Aircraft wings, gear and other
engineering structures
Air France 747-200(Boeing)
landing gear wing loading
The F-15 Eagle has a large relatively lightly loaded wing (large and low..)
Video Processing Lab
臺灣師範大學數位媒體中心視訊處理研究室
5
Polyhedrons
• The most commonly used boundary to show 3D graphics object – A set of surface polygons to enclose the object
interior
• Simply & speed up the surface rendering and display of object – Graphics systems store all object descriptions
• Standard graphics objects
Video Processing Lab
臺灣師範大學數位媒體中心視訊處理研究室
6
OpenGL polyhedron functions
• Polygon Fill-Area functions – OpenGL primitive constants
• GL_POLYGON, GL_TRIANGLES, GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN, GL_QUADS and GL_QUAD_STRIP
– All faces compose by a group of parallelograms, all faces compose by triangular surfaces or other polygon from..
Video Processing Lab
臺灣師範大學數位媒體中心視訊處理研究室
7
GLUT regular Polyhedron functions (1)
• Five regular polyhedrons are pre-defined by routines in GLUT library – These polyhedrons are also called Platonic
solids • All the faces are same regular polygons
– All edges are equal, All edge angles are equal and All face angles are equal
– Polyhedron are named according to numberface • Ex: regular tetrahedron (4 faces), regular
hexahedron ( or cube, 6 faces) ….
Video Processing Lab
臺灣師範大學數位媒體中心視訊處理研究室
8
GLUT regular Polyhedron functions (2)
– Each regular polyhedron is described in modeling coordinates
• Each object’s center at world-coordinaate origin
– Wire-frame object functions • glutWire*()
– Tetrahedron, Octahedron, Dodecahedron and Icosahedron
– Fill areas polyhedron functions • glutSolid*()
– Tetrahedron, Octahedron, Dodecahedron and Icosahedron
glutWireCube (edgeLength) glutSolidCube (edgeLength)
edgeLength must be pre-defined
Video Processing Lab
臺灣師範大學數位媒體中心視訊處理研究室
9
Design notices
• Display function – Set viewing transformation
• gluLookAt()
• Reshape function – glMatrixMode(GL_PROJECTION)
• 3D projection – glFrustum() or glOrtho() ….
demo
Video Processing Lab
臺灣師範大學數位媒體中心視訊處理研究室
10
Regular 3D object’s mesh
• What is 3D object’s mesh? – Like the object’s skin
• How to construct it? – Curved surfaces coordinate
– What polygon can be used?
Video Processing Lab
臺灣師範大學數位媒體中心視訊處理研究室
11
Curved surfaces
• General coordinates – Cartesian coordinate
• Quadric surfaces – Spherical surface – Ellipsoid’s surface – Torus’s surface
y
x
z
Video Processing Lab
臺灣師範大學數位媒體中心視訊處理研究室
12
Spherical Surface
• In cartesian coordinates, a spherical surface – radius r, any point (x,y,z)
• x2+y2+z2=r2
– Describe the spherical surface •
y
x
z (x,y,z)
θ
φ
sin
sincos
coscos
rz
ry
rx
/ 2 / 2
Video Processing Lab
臺灣師範大學數位媒體中心視訊處理研究室
13
Think!!
• We change the angle φ of the point’s axis – the angle range will be
re-computed
– Want to re-range two angles in 0~1 • substituting
y
x
z (x,y,z)
θ
φ
sin
sincos
coscos
rz
ry
rx
0
0 2
Why?
, 2u v
Video Processing Lab
臺灣師範大學數位媒體中心視訊處理研究室
14
Draw a sphere wire • Plot longitude and latitude to
approximates the spherical surface as a quadrilateral mesh – Divide to three parts
• Top, floor – The primary element is triangle
• Side
– Construct it with rectangles – A surface
Top & floor means covered the surface
Video Processing Lab
臺灣師範大學數位媒體中心視訊處理研究室
15
Top (+z) & floor (-z)
glBegin(GL_TRIANGLE_FAN); glVertex3d(x,y,z); c=3.14159/180.0; //interval Δφ, φ=80.0*c z=sin(c*80.0); // z=+..top, z=-.. floor for(thet=-180.0; thet<=180.0;thet+=20.0){ x=cos(c*80.0)*cos(c*thet); y=cos(c*80.0)*sin(c*thet); glVertex3d(x,y,z); } glEnd();
Δθ
sin
sincos
coscos
rz
ry
rx
Video Processing Lab
臺灣師範大學數位媒體中心視訊處理研究室
16
Side
for(phi=-80.0; phi<=80.0; phi+=20.0){ glBegin(GL_QUAD_STRIP); for(thet=-180.0; thet<=180.0;thet+=20.0) { x=cos(c*phi)*cos(c*thet); y=cos(c*phi)*sin(c*thet); z=sin(c*phi); glVertex3d(x,y,z); x=cos(c*(phi+20.0))*cos(c*thet); y=cos(c*(phi+20.0))*sin(c*thet); z=sin(c*(phi+20.0)); glVertex3d(x,y,z); } glEnd(); }
Δθ
glBegin(GL_QUAD_STRIP); glVertex3d(p1)…. glVertex3d(p8) glEnd();
p1
p2 p3
p4
p6
p5
p7
p8
x2+y2+z2=r2
sin
sincos
coscos
rz
ry
rx
Video Processing Lab
臺灣師範大學數位媒體中心視訊處理研究室
17
Advantage of this design
• Put each design component to list function in initial function – Ex: top, floor or side
• In display function call our design to let them move
• Next page will show how to design
Video Processing Lab
臺灣師範大學數位媒體中心視訊處理研究室
18
Display architecture
Host
Simple graphics architecture
Immediate mode
Host
Display processor
(DPU)
Display file (display list)
Display-processor architecture
Retained mode Ex : progressive
Ex : interlace
server server
Video Processing Lab
臺灣師範大學數位媒體中心視訊處理研究室
19
Definition & execution of display lists
• Display lists have much in common with ordinary files. – Define (create)
• What contents of display list
– Manipulate (place information in) • What functions of display lists
– Such as: flexible enough….
Video Processing Lab
臺灣師範大學數位媒體中心視訊處理研究室
20
OpenGL display lists
• Display lists in OpenGL are defined similarly to geometric primitive
glNewList(BOX, flag);
glBegin(GL_POLYGON)
…
glEnd();
glEndList();
Object’s name in the list
GL_COMPILE: send list to server, not to display
GL_COMPILE_AND_EXECUTE: immediate display
Display function:
*Each time that we wish to draw: (Ex: do transformation or set up time control…)
glCallList(BOX);
Matrix and attribute stacks:
glPushAttrib(GL_ALL_ATTRIB_BITS);
glPushMatrix();
Display list function:
glPopAttrib();
glPopMatrix();
Video Processing Lab
臺灣師範大學數位媒體中心視訊處理研究室
21
OpenGL GLUT Quadric-Surface sphere functions
• GLUT sphere functions – Approximate the spherical surface as a
quadrilateral mesh – glutWireSphere (r,nLongitudes, nLatitudes);
glutSolidSphere (…) • r (sphere radius): double or float point • nLongitudes & nLatitudes: the integer number about
longitude lines & latitude lines
– The sphere is defined in modeling coordinates, centered at the originworld-coordinate with its polar axis along the z-axis
Video Processing Lab
臺灣師範大學數位媒體中心視訊處理研究室
22
GLUT Cone functions
• GLUT cone is obtained with – glutWireCone(rBase,height,nLongitudes,nLatitudes);
glutSolidCone(…);
• rbase & height: float or double
• nLongitudes & nLatitudes: integer Ex: 5, 6 – Each latitude line is parallel with theirseves
• the quadrilateral mesh approximation
height
rBase
Video Processing Lab
臺灣師範大學數位媒體中心視訊處理研究室
23
Ellipsoid’s surface
• Describe it an extension of a spherical surface – Three radii
– In Cartesian coordinates
– Representation by two angle (φ&θ)
y
x
z
rz
rx ry
cos cos
cos sin
sin
x
y
z
x r
y r
z r
/ 2 / 2
22 2
1x y z
x y z
r r r
This mesh is similar the spherical mesh
Video Processing Lab
臺灣師範大學數位媒體中心視訊處理研究室
24
• What is Torus? – a doughnut-shaped object or called ring
– Describe the surface • rotating a circle or an ellipse about a co-
planar axis line
φ r
0
(0,y,z)
y axis
z axis
raxial
Side view
0
θ
(x,y,z) y axis
x axis
Top view
Torus’s surface (1) raxial
Video Processing Lab
臺灣師範大學數位媒體中心視訊處理研究室
25
Torus’s surface (2)
• In Cartesian equation
• Using a circular cross section
raxial
2 2 2 2 2( )axialx y r z r
( cos )cos
( cos )sin
sin
axial
axial
x r r
y r r
z r
Video Processing Lab
臺灣師範大學數位媒體中心視訊處理研究室
26
• If generate a torus by rotating an ellipse & round circle about the z axis – In Cartesian equation
– The torus with an elliptical cross section
2 22 2
1axial
y z
x y r z
r r
( cos )cos
( cos )sin
sin
axial y
axial y
z
x r r
y r r
z r
Video Processing Lab
臺灣師範大學數位媒體中心視訊處理研究室
27
GLUT torus functions
• Wire-frame or surface-shaded displays of a torus with a circular cross section – glutWireTorus(rCrossSection, rAxial,
nConcentrics,nRadialSlices); glutSolidTorus(…);
• rcrossSection (=inner Radius)& rAxial (=outer Radius) – float or double
• nConcentrics(sides) & nRadialSlices(rings) – Integer
– sides is parallel together(nCon..: the number of sides), nRadial..: the number of rings
rin
rout
Video Processing Lab
臺灣師範大學數位媒體中心視訊處理研究室
28
GLU Quadric-Surface functions
• Quadric surface can used GLU functions to design – Assign a name to the quadric
– Activate the GLU quadric render
– Designate values for surface parameters
• Set other parameter values to control the appearance of a GLU quadric surface.
Video Processing Lab
臺灣師範大學數位媒體中心視訊處理研究室
29
Some GLU functions
• Sphere: – gluSphere(name,r,nLongitudes,nLatitudes);
• Cylinder: – gluCylinder(name,rBase,rTop,height,
nLongitudes,nLatitudes);
• A section of ring: – gluPartialDisk(name, rin,rout,nRadii,nRings, Anglestart,
Anglesweep);
Video Processing Lab
臺灣師範大學數位媒體中心視訊處理研究室
30
How to use? • Example: to draw the sphere
• Display mode: – GLU_LINE, GLU_POINT, GLU_FULL
• Normal vector direction – GLU_OUTSIDE or GLU_INSIDE (inside: back-face,
outside:fact-face) • General mode
– default=GLU_NONE, flat surface=GLU_FLAT(object of constant color)
GLUquadricObj *sphere1;
sphere1 = gluNewQuadric (); gluQuadricDrawStyle(sphere1, display mode);
gluSphere(sphere1,…);
gluQuadricOrientation(sphere1, normalvectordirection);//signal face surface
gluQuadricNormal(sphere1, generationMode);//total object
pluDeleteQuadric (sphere1);//delete the object
Video Processing Lab
臺灣師範大學數位媒體中心視訊處理研究室
31
Approximation of a sphere by recursive subdivision
• Recursive subdivision is a powerful technique for generating approximations to curves and surfaces to any desired level of accuracy – Start from four equilateral triangles (a
tetrahedron) • Four vertices (points) in unit sphere: (0,0,1),(0,2 2 /3, 1/3),( 6 /3, 2 /3, 1/3),( 6 /3, 2 /3, 1/3)
Video Processing Lab
臺灣師範大學數位媒體中心視訊處理研究室
32
Triangle -> tetrahedron
void triangle( point a, point b, point c)// display one triangle using a line loop for wire frame { glBegin(GL_LINE_LOOP); glVertex3fv(a); glVertex3fv(b); glVertex3fv(c); glEnd(); }
void tetrahedron() { triangle(v[0],v[1],v[2]); triangle(v[3],v[2],v[1]); triangle(v[0],v[3],v[1]); triangle(v[0],v[2],v[3]); }
v0
v1 v2 v3
Video Processing Lab
臺灣師範大學數位媒體中心視訊處理研究室
33
void normal(point p){ /* normalize a vector */ double sqrt(); float d =0.0; int i; for(i=0; i<3; i++) d+=p[i]*p[i]; d=sqrt(d); if(d>0.0) for(i=0; i<3; i++) p[i]/=d;}
)det(pVnor
p
void tetrahedron( int m){ /* Apply triangle subdivision to faces of tetrahedron */ divide_triangle(v[0], v[1], v[2], m); divide_triangle(v[3], v[2], v[1], m); divide_triangle(v[0], v[3], v[1], m); divide_triangle(v[0], v[2], v[3], m);}
void divide_triangle(point a, point b, point c, int m){ /* triangle subdivision using vertex numbers righthand rule applied to create outward pointing faces */ point v1, v2, v3; int j; if(m>0) { for(j=0; j<3; j++) v1[j]=a[j]+b[j]; normal(v1); for(j=0; j<3; j++) v2[j]=a[j]+c[j]; normal(v2); for(j=0; j<3; j++) v3[j]=b[j]+c[j]; normal(v3); divide_triangle(a, v1, v2, m-1); divide_triangle(c, v2, v3, m-1); divide_triangle(b, v3, v1, m-1); divide_triangle(v1, v3, v2, m-1); } else(triangle(a,b,c)); /* draw triangle at end of recursion */}
v0
v1 v2 v3
Video Processing Lab
臺灣師範大學數位媒體中心視訊處理研究室
34
Approximate object
• Recursive subdivision – We could design a object’s surface
numbers.
– Recursive from coarse to fine
• Mesh object related its surface – Direction: Longitude and latitude
Video Processing Lab
臺灣師範大學數位媒體中心視訊處理研究室
35
How to plot 3D object
• Take apart of object to several polygon facets – First, list the vertices to show one surface
• primitive: – GL_POLYGON, GL_QUADS or GL_TRIANGLES… – Function: glVertex3* (pointcoordinate)
» Key point: triangle: 3 points or triangle+quadrangle
– Second, list its surface direction • Find function about the approximate point
– Ex: approximate sphere glNormal3* (normcoordinate)
• Surface function construct from those vertices
Video Processing Lab
臺灣師範大學數位媒體中心視訊處理研究室
36
Homework 1
• Draw two object’s mesh (wire & solid) name Implicit function (F=0) Parametric form v range u range
Hyperboloid
Elliptic cone
Hyperbolic
superellipsoid
superhyperboloid
x2+y2-z2-1
x2+y2-z2
-x2+y2-z
( / 2, / 2)
( , )
( cos( ), sin( ), )v u v u v
0,( , )v 2( tan( ), sec( ), )v u v u v
any real nums,( , )
1112
22 /2//2/2
sssss zyx
(sec( )cos( ),sec( )sin( ),
tan( ))
v u v u
v
1 2 1 2
1
(cos ( )cos ( ),cos ( )sin ( ),
sin ( ))
s s s s
s
v u v u
v 1 2
( / 2, / 2),( , )
, : 0.5 ~ 3.0(#6)s s
2 12 2 1
/2 / 2 / 2 / 1
s ss s sx y z
1 2 1 2
1
(sec ( )sec ( ),sec ( )tan ( ),
tan ( ))
s s s s
s
v u v u
v
#1: ( / 2, / 2)sheet
#2: ( / 2,3 /2)sheet Superellipse demo
: ( / 2, / 2)
: sheet#1 or sheet#2
v
u
Video Processing Lab
臺灣師範大學數位媒體中心視訊處理研究室
37
Homework 2
• Practice “Recursive subdivision” – Draw a magic box
• Hint: Some things jump out the cube or this box’s sub-part can be rotated
Video Processing Lab
臺灣師範大學數位媒體中心視訊處理研究室
38
Appendix
name Implicit function (F=0) Parametric form v, u range
Ellipsoid
Hyperboloid of one sheet
Hyperboloid of two sheet
x2+y2+z2-1 (cos( )cos( ),cos( )sin( ),
sin( ))
v u v u
v
: ( / 2, / 2)
: ( , )
v
u
x2+y2-z2-1 (sec( )cos( ),sec( )sin( ),
tan( ))
v u v u
v
x2-y2-z2-1
: ( / 2, / 2)
: ( , )
v
u
(sec( )cos( ),sec( )tan( ),
tan( ))
v u v u
v
: ( / 2, / 2) v
sheet# 1: : ( , )2 2
3sheet# 2 : : ( , )
2 2
u
u
Ellipsoid Hyperboloid of one sheet Hyperboloid of two sheet
Ch9: Computer Graphics, Hill
Video Processing Lab
臺灣師範大學數位媒體中心視訊處理研究室
39
name Implicit function (F=0) Parametric form v, u range
Elliptic cone
Elliptic paraboloid
Hyperboloid paraboloid
x2+y2-z2
x2+y2-z
-x2+y2-z
( cos( ), sin( ), )v u v u v
0
: ( , )
v
u
: any real
: ( , )
v
u
2( cos( ), sin( ), )v u v u v
2( tan( ), sec( ), )v u v u v0
: ( , )
v
u
Elliptic cone Elliptic paraboloid
Hyperboloid paraboloid
Video Processing Lab
臺灣師範大學數位媒體中心視訊處理研究室
40
superellipsoid
Superhyperboloid of one sheet
1112
22 /2//2/2
sssss zyx1 2 1 2
1
(cos ( )cos ( ),cos ( )sin ( ),
sin ( ))
s s s s
s
v u v u
v
: ( / 2, / 2)
: ( , )
v
u
2 12 2 1
/2 / 2 / 2 / 1
s ss s sx y z
1 2 1 2
1
(sec ( )cos ( ),sec ( )sin ( ),
tan ( ))
s s s s
s
v u v u
v
1 2, : 0.5 ~ 2.5(#5)s s
: ( / 2, / 2)
: ( , )
v
u
superellipsoid
Superhyperboloid of one sheet
Video Processing Lab
臺灣師範大學數位媒體中心視訊處理研究室
41
superhyperboloid
Supertorus 2
2 2 1
1
/ 22 / 2 / 2 /
2 /
( )
1
ss s s
s
x y d
z
1 2
1 2
1
(( cos ( ))cos ( ),
( cos ( ))sin ( ),
sin ( ))
s s
s s
s
d v u
d v u
v
1 2, : 0.5 ~ 2.5(#5)s s
: ( , )
: ( , )
v
u
superhyperboloid
Supertorus
2 12 2 1
/2 / 2 / 2 / 1
s ss s sx y z
1 2 1 2
1
(sec ( )sec ( ),sec ( )tan ( ),
tan ( ))
s s s s
s
v u v u
v
: sheet #1: ( / 2, / 2) u
: sheet #2 : ( / 2,3 /2) u
: ( / 2, / 2)
: sheet#1 or sheet#2
v
u