Opengl Notes 8
Transcript of Opengl Notes 8
-
8/8/2019 Opengl Notes 8
1/26
OpenGL Notes a
Stu Pomerantz
http://www.psc.edu/~smp
December 8, 2004
aMost material is adapted from: OpenGL ARB, et. al, The OpenGL Pro-gramming Guide, Third Ed., Reading: Addison-Wesley, 1999
1
-
8/8/2019 Opengl Notes 8
2/26
2D Parametric Curves
In two dimensions a parametric curve is defined by:
x = x(u)y = y(u)
Where u is the parameter that is free to vary. For example:
x = cos()
y = sin()
x and y will trace out a circle as 0 2 .
222
-
8/8/2019 Opengl Notes 8
3/26
2D Parametric Curves
Drawing of the parametric circle:
223
-
8/8/2019 Opengl Notes 8
4/26
2D Parametric Curves
Code for the parametric circle:
glBegin(GL_LINES) ;du = PI/32 ;
f o r ( u = 0 ; u < 8 * P I ; u + = d u ) {
x = cos(u) ; y = sin(u) ; z = 0 ;
glVertex3f(x,y,z) ;
x = cos(u+du) ; y = sin(u+du) ; z = 0 ;
glVertex3f(x,y,z) ;
}
glEnd() ;
224
-
8/8/2019 Opengl Notes 8
5/26
3D Parametric Curves
In two dimensions a parametric curve is defined by:
x = x(u)y = y(u)
z = z(u)
Where u is the parameter that is free to vary. For example:
x = cos()
y = sin()
z =
x, y and z will trace out a circlular helix as 0 2 .
225
-
8/8/2019 Opengl Notes 8
6/26
3D Parametric Curves
Drawing of the parametric helix:
226
-
8/8/2019 Opengl Notes 8
7/26
3D Parametric Curves
Code for the parametric helix:
glBegin(GL_LINES) ;du = PI/32 ;
f o r ( u = 0 ; u < 8 * P I ; u + = d u ) {
x = cos(u) ; y = sin(u) ; z = u ;
glVertex3f(x,y,z) ;
x = cos(u+du) ; y = sin(u+du) ; z = u+du ;
glVertex3f(x,y,z) ;
}
glEnd() ;
227
-
8/8/2019 Opengl Notes 8
8/26
3D Parametric Surfaces
In three dimensions a parametric surface is defined by:
x = x(u, v)y = y(u, v)
z = z(u, v)
Where u and v are the parameters that are free to vary. Forexample:
x = cos() sin()
y = sin() sin()z = cos()
x, y and z will trace out a sphere as 0 2 and 0 2 .
228
-
8/8/2019 Opengl Notes 8
9/26
3D Parametric Surfaces
Drawing of the parametric sphere:
229
-
8/8/2019 Opengl Notes 8
10/26
Polynomial Parametric Curves
p(u) =n
k=0
ukc k
where
c k =
cxk
cyk
czk
230
-
8/8/2019 Opengl Notes 8
11/26
Polynomial Parametric Curves
For example if n = 3,
p(u) =3
k=0
ukc k
expands to:
p(u) = u3
cx3
cy3
cz3
+ u2
cx2
cy2
cz2
+ u
cx1
cy1
cz1
+
cx0
cy0
cz0
231
-
8/8/2019 Opengl Notes 8
12/26
Polynomial Parametric Curves
Continuing,
p(u) = u3
cx3
cy3
cz3
+ u2
cx2
cy2
cz2
+ u
cx1
cy1
cz1
+
cx0
cy0
cz0
expands to
p(
u) =
x(u) = cx3u3 + cx2u
2 + cx1u + cx0
y(u) = cy3u3
+ cy2u2
+ cy1u + cy0z(u) = cz3u
3 + cz2u2 + cz1u + cz0
Notice that 4 coefficient vectors which must be specified.
232
-
8/8/2019 Opengl Notes 8
13/26
-
8/8/2019 Opengl Notes 8
14/26
Interpolation Revisited
Two points, p0 and p1, can be linearly interpolated like this:
p = a p0 + (1 a) p1
where a [0, 1]
In this context, interpolation is also called blending. The points aremixed together by the a and 1 a which are weights.
The points p0 and p1 can be thought of as control points since they
influence (constrain) the final interpolated value.
This is similar, but not identical to, OpenGLs blending functions.
And, in this case the purpose is not to produce transparent
surfaces but rather to produce a new interpolated point.
234
-
8/8/2019 Opengl Notes 8
15/26
Interpolation using Cubic Polynomials
Recall the cubic polynomial
p(u) =3
k=0
ukc k
Requires 4 vectors of coefficients in order for it to be completely
determined.
Rewrite this equation...
235
-
8/8/2019 Opengl Notes 8
16/26
Interpolation using Cubic Polynomials
..using a matrix representation of the coefficient vectors.
p(u) = [x(u) y(u) z(u)] =
u3 u2 u 1
m11 m12 m13 m14
m21 m22 m23 m24
m31 m32 m33 m34
m41 m42 m43 m44
g1x g1y g1z
g2x g2y g2z
g3x g3y g3z
g4x g4y g4z
Or more briefly,
p(u) = U M G
Call M the basis matrix. Call G the Geometry matrix.
236
-
8/8/2019 Opengl Notes 8
17/26
Interpolation using Cubic Polynomials
For example,
x(u) = (u3
m11 + u2
m21 + um31 + m41)g1x+(u3m12 + u
2m22 + um32 + m42)g2x+
(u3m13 + u2m23 + um33 + m43)g3x+
(u3
m14 + u2
m24 + um34 + m44)g4x+
This form emphasizes that the curve is a weighted sum of the
elements of G (geometry) matrix.
237
-
8/8/2019 Opengl Notes 8
18/26
Interpolation using Cubic Polynomials
The geometry matrix, G, contains 4 points. They are called
control points.
Analogous to the 2 control points in the previous linear
interpolation example.
The meaning of these 4 points is dependant on the basis matrix
M.
The basis matrix M affects
The continuity of the curve.
Which and whether control points are interpolated.
238
-
8/8/2019 Opengl Notes 8
19/26
The Hermite Basis
The Hermite basis is named after the Mathematician. The
construction the Hermite basis matrix is as follows:
Given 4 control points: p1, p2, p3, p4
Constrain the curve so that it interpolates p1 at u = 0 and p4
at u = 1
Let p2 and p3 be the tangent vectors for p1 and p4 respectively.
239
-
8/8/2019 Opengl Notes 8
20/26
The Hermite Basis
Recall,
U = u3 u2 u 1
so,
U =
3u2 2u 1 0
There are 4 equations and 4 unknowns:
p1 = [0 0 0 1] (u = 0)
p4 = [1 1 1 1] (u = 1)
p2 = [0 0 1 0] (u = 0)
p3 = [3 2 1 0] (u = 1)
240
-
8/8/2019 Opengl Notes 8
21/26
The Hermite Basis
Rewriting the 4 equations above as a matrix:
p1
p4
p2
p3
=
0 0 0 1
1 1 1 1
0 0 1 0
3 2 1 0
For these equations to be satisfied M, the Hermitian basis matrix
must be the inverse of this matrix.
241
-
8/8/2019 Opengl Notes 8
22/26
The Hermite Basis
The Hermitian basis matrix:
M =
2 2 1 1
3 3 2 1
0 0 1 0
1 0 0 0
So,
p(u) =(2u3 3u2 + 1)p1 + (2u3 + 3u2)p4 +
(u3 2u2 + u)p3 + (u3 u2)p4
242
-
8/8/2019 Opengl Notes 8
23/26
The Hermite Basis
A picture of the Hermitian basis functions:
243
-
8/8/2019 Opengl Notes 8
24/26
Example Hermite Curves
244
-
8/8/2019 Opengl Notes 8
25/26
Comparison of Curve Types
Curves differ by basis matrix.
Hermite Bezier Non-Uniform B-Spline Catmull-RomA Y Y N Y
B Y N N Y
CC0 C0 C2 C1
A = Interpolates some control points
B = Interpolates all control points
C = Inherent Continuity
If the direction and magnitude of the nth derivative are equal at
the joint point, the curve is called Cn continuous.
245
-
8/8/2019 Opengl Notes 8
26/26
Example NURBS Surface
246