Professional Documents
Culture Documents
POLYGON MESHES
list of vertices - polygon; list of edges - polygon
list of polygons -- objects
Plane equation from 3 vertices:
Ax+By+Cz+D=0
Copyright @ 2002 by
1 n
C ( yi yi 1 )( xi 1 xi
2 i 1
Ax By Cz D
A2 B 2 C 2
Copyright @ 2002 by
QUADRIC SURFACES
Quadric Surfaces
The implicit surface equation of the form
defines the family of quadric surfaces:
ax2 +by2 +cz2 +2(dxy+eyz+fxz+gx,+hy+jz)+k=0
Sphere
x2+y2+z2=R2 ;orinparametricform
x=rcoscos,y=rcossin,z=rsin
Ellipsoid
2
Torus
[r((x/a)2 +(y/b)2 )1/2 ]2 +(z/c)2=1;or
x=a(r+coscos,y=b(r+cossin,z=csin
Copyright @ 2002 by
Superquadrics
supperellipse: x=acoss,y=bsin s
supperellipsoid
x=rcosscost,y=rcoss sint,z=rsins
Blobby Objects
Some objects do not maintain a fixed shape, but
change their surface characteristics in certain
motions or when in proximaity to other objects.
One way to model: combinations of Gaussian
density functions, or bumps:
bk e ak X k yk zk T
2
whereTisathreshold
andaandbaretoadjusttheamountof
blobbiness
Copyright @ 2002 by
G
(
t
)
4
Hermite Surfaces
Curve:
x(u ) u 3
u 1 Mh
P1 (t )
P (t )
x ( s, t ) S M h 4 ,
R1 (t )
R4 (t ) x
Surface:
Since:
u2
P1 (t )
P1
P
4
R1
R4
and
x
1
2 2 1
3 3 2 1
Mh
0
0
1
0
1
0
0
0
x(0,0)
x(0,1)
P1x (t ) T M h
(0,0)
t
x(0,1)
T
P4 (t ) R1 (t ) R4 (t ) x T M h GHx
we have:
Copyright @ 2002 by
x ( s, t ) S M h
P1 (t )
P (t )
4
R1 (t )
S M h GHx M hT T T
R4 (t )
Where
x(0,1)
x(1,0)
x(1,1)
s x(0,0)
x(1,0)
s
x(0,1)
s
x(1,1)
s
x(0,0)
GHx
x(0,0)
t
x(1,0)
t
2
x(0,0)
st
2
x(1,0)
st
x(0,1)
t
x(1,1)
t
x(0,1)
st
2
x(1,1)
st
Copyright @ 2002 by
Bezier Surfaces
The Bezier bicubic formulation can be derived in exactly the same way
as above. The results are:
x( s, t ) S M b GBx M bT T T
B-Spline Surfaces
The B-Spline bicubic formulation can be derived in exactly the same
way also. The results are: x ( s, t ) S M G M T T T
Bs
BSx
Bs
Normals to Surfaces
The cross product between the s and t tangent vectors of the surface
Q(s, t) results in the normal at given s and t:
Q ( s, t ) Q ( s, t )
s
t
Copyright @ 2002 by
1
0
Bin (u )
and
Click Me
C (u ) Bin (u ) Pi
i 0
Copyright @ 2002 by
1
1
voidmyinit(void){
glClearColor(0.0,0.0,0.0,1.0);
glMap1f(GL_MAP1_VERTEX_3,0.0,1.0,3,
4,&ctrlpoints[0][0]);
glEnable(GL_MAP1_VERTEX_3);
glShadeModel(GL_FLAT);
}
GL_MAP1_VERTEX_3: Three-dimensional vertices are
produced
0--Low value of parameter u
1--High value of parameter u
3--The number of floating-point values to advance in the
data between one control point and the next
4--The order of the spline, which is the degree+1;
&ctrlpoints[0][0]--Pointer to the first control points data
Copyright @ 2002 by
1
2
voiddisplay(void){
inti;
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glColor3f(1.0,1.0,1.0);
glBegin(GL_LINE_STRIP);
for(i=0;i<=30;i++)
glEvalCoord1f((GLfloat)i/30.0);
glEnd();
/*Thefollowingcodedisplaysthecontrolpointsasdo
glPointSize(5.0);
glColor3f(1.0,1.0,0.0);
glBegin(GL_POINTS);
Click Me
for(i=0;i<4;i++)
glVertex3fv(&ctrlpoints[i][0]);
glEnd();
glFlush();
}
Copyright @ 2002 by
1
3
Two-Dimensional Evaluators
Mathematically, the definition of a Bzier
surface patch is given by
n
Copyright @ 2002 by
1
4
glEnable(GL_MAP2_VERTEX_3);
glEnable(GL_DEPTH_TEST);
glShadeModel(GL_FLAT);
}
CLICK ME
voiddisplay(void){
inti,j;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3f(1.0,1.0,1.0);
glPushMatrix();
glRotatef(85.0,1.0,1.0,1.0);
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();
glBegin(GL_LINE_STRIP);
for(i=0;i<=30;i++)
glEvalCoord2f((GLfloat)j/8.0, (GLfloat)i/30.0);
glEnd();
}
glPopMatrix();glFlush();
}
Copyright @ 2002 by
1
5
Copyright @ 2002 by
1
6
voiddisplay(void){
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glRotatef(85.0,1.0,1.0,1.0);
glEvalMesh2(GL_FILL,0,8,0,8);
glPopMatrix();
glFlush();
}
voidmyinit(void){
glClearColor(0.0,0.0,0.0,1.0);
glEnable(GL_DEPTH_TEST);
glMap2f(GL_MAP2_VERTEX_3,0,1,3,4,0,1,12,4,&ctr
glEnable(GL_MAP2_VERTEX_3);
glEnable(GL_AUTO_NORMAL);
glMapGrid2f(8,0.0,1.0,8,0.0,1.0);
initlights();
}
CLICK ME
Copyright @ 2002 by
1
7
Example115DrawingaNURBSSurface:surface.c
include<GL/glu.h>
#include <stdlib.h>
#include <stdio.h>
GLfloatctlpoints[4][4][3];
GLUnurbsObj*theNurb;
Copyright @ 2002 by
1
8
voidinit_surface(void)
{
intu,v;
for(u=0;u<4;u++){
for(v=0;v<4;v++){
ctlpoints[u][v][0]=2.0*((GLfloat)u1.5);
ctlpoints[u][v][1]=2.0*((GLfloat)v1.5);
Click
ClickHere
Here
if((u==1||u==2)&&(v==1||v==2))
ctlpoints[u][v][2]=3.0;
else
ctlpoints[u][v][2]=3.0;
}
}
}
voidmyinit(void)
{
GLfloatmat_diffuse[]={0.7,0.7,0.7,1.0};
GLfloatmat_specular[]={1.0,1.0,1.0,1.0};
GLfloatmat_shininess[]={100.0};
glClearColor(0.0,0.0,0.0,1.0);
Copyright @ 2002 by
1
9
glMaterialfv(GL_FRONT,GL_DIFFUSE,mat_diffuse);
glMaterialfv(GL_FRONT,GL_SPECULAR,mat_specular);
glMaterialfv(GL_FRONT,GL_SHININESS,mat_shininess);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glDepthFunc(GL_LEQUAL);
glEnable(GL_DEPTH_TEST);
glEnable(GL_AUTO_NORMAL);
glEnable(GL_NORMALIZE);
init_surface();
Click
ClickHere
Here
theNurb=gluNewNurbsRenderer();
gluNurbsProperty(theNurb,GLU_SAMPLING_TOLERANCE,25.0)
gluNurbsProperty(theNurb,GLU_DISPLAY_MODE,GLU_FILL);
}
Copyright @ 2002 by
2
0
voiddisplay(void)
{
GLfloatknots[8]={0.0,0.0,0.0,0.0,1.0,1.0,1.0,
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glRotatef(330.0,1.,0.,0.);
glScalef(0.5,0.5,0.5); Click Here
Click Here
gluBeginSurface(theNurb);
gluNurbsSurface(theNurb,
8,knots,
8,knots,
4*3,
3,
&ctlpoints[0][0][0],
4,4,
GL_MAP2_VERTEX_3);
gluEndSurface(theNurb);
glPopMatrix();
glFlush();
}
Copyright @ 2002 by
2
1