Computer Graphics Modeling. Modeling is simply the process of creating 3D objects –Many different...

73
Computer Graphics Modeling

Transcript of Computer Graphics Modeling. Modeling is simply the process of creating 3D objects –Many different...

Page 1: Computer Graphics Modeling. Modeling is simply the process of creating 3D objects –Many different processes to create models –Many different representations.

Computer Graphics

Modeling

Page 2: Computer Graphics Modeling. Modeling is simply the process of creating 3D objects –Many different processes to create models –Many different representations.

Modeling

• Modeling is simply the process of creating 3D objects– Many different processes to create models– Many different representations of model data

• Once the models are obtained, one can transform them to the correct locations in space, place a virtual camera in space, and render a 2D image of the scene

Page 3: Computer Graphics Modeling. Modeling is simply the process of creating 3D objects –Many different processes to create models –Many different representations.

Model Representations

• Polygonal

• CSG (constructive solid geometry)

• Spatial subdivision techniques

• Implicit representation

• Parametric patches

Page 4: Computer Graphics Modeling. Modeling is simply the process of creating 3D objects –Many different processes to create models –Many different representations.

Polygonal

• Complex objects arebroken down intomany simple polygons

• Polygons form the “skin” of the object– Objects are hollow– Polygons have a front face and a back face

Page 5: Computer Graphics Modeling. Modeling is simply the process of creating 3D objects –Many different processes to create models –Many different representations.

Triangles

• Triangles are the #1 choice of polygons– They are always planar– Graphics hardware is often optimized for

triangles• Nvidia TNT2 8M triangles per second• Nvidia Geforce2 31M triangles per second• Nvidia Geforce4 136M vertices per second

– Note: Don’t read too much into these numbers. They are similar to processor speed numbers in that they don’t tell the whole story of how fast the computer actually is.

Page 6: Computer Graphics Modeling. Modeling is simply the process of creating 3D objects –Many different processes to create models –Many different representations.

Triangulation

• How are triangles obtained?– Triangulating a set of surface points

• Several different triangulation approaches – Delaunay triangulations attempt to equalize

triangle angles (reduces long skinny triangles)

Page 7: Computer Graphics Modeling. Modeling is simply the process of creating 3D objects –Many different processes to create models –Many different representations.

How Many Triangles?

• More triangles are needed in surface areas that require more geometric detail– Higher curvature more triangles necessary

Page 8: Computer Graphics Modeling. Modeling is simply the process of creating 3D objects –Many different processes to create models –Many different representations.

Level Of Detail (LOD)

• It can be very costly to always display an entire object at the greatest level of detail

• Less detail is necessary the farther away you are from on object– Also depends on the viewing angle and screen size

• Solution: create several models of the object at different levels of detail– Display the correct one for the viewing distance

Page 9: Computer Graphics Modeling. Modeling is simply the process of creating 3D objects –Many different processes to create models –Many different representations.

LOD

50 Vertices 500 Vertices 2000 Vertices

Page 10: Computer Graphics Modeling. Modeling is simply the process of creating 3D objects –Many different processes to create models –Many different representations.

LOD

Page 11: Computer Graphics Modeling. Modeling is simply the process of creating 3D objects –Many different processes to create models –Many different representations.

LOD

• How to create the same model in multiple levels of detail?– Ex: start with most detailed, resample with less

vertices, and then re-triangulate

• When to switch models when rendering?– Based on distance and screen size

– Ex: 640x480 screen 307,200 pixels Object takes up half of screen 150K

pixels Any more than 300K triangles (half are

facing away from the camera) is overkill at this distance and screen size

– Visual artifacts can occur at switching point

Page 12: Computer Graphics Modeling. Modeling is simply the process of creating 3D objects –Many different processes to create models –Many different representations.

Creating the Surface Points

• Triangulation works on a set of points– One needs to create this surface point set

• Many different approaches:– Manual placement– Mathematical (geometrical) generation– Scanning real objects

Page 13: Computer Graphics Modeling. Modeling is simply the process of creating 3D objects –Many different processes to create models –Many different representations.

Mathematical Generation

• Solids of Revolution– Rotation of a cross-section around an axis

• Spheres• Cones• Cylinders• Bundt cakes?

Page 14: Computer Graphics Modeling. Modeling is simply the process of creating 3D objects –Many different processes to create models –Many different representations.

Mathematical Generation

• Extrusion– Extrude a cross-section along a profile curve– Scale may vary along the profile

• Many metal and plastic parts• Cones• Cylinders• Bottles

Page 15: Computer Graphics Modeling. Modeling is simply the process of creating 3D objects –Many different processes to create models –Many different representations.

Scanning Real Objects

• Laser scanning

• Tomographic methods– Medical scanning (Xray, CT, MRI)– Radar

                                                         

                                                       

                                                      

Recovered 3D model

Hand-held laser

scanner

Slice of brain from CT scan

Recovered 3D model of lungs

Page 16: Computer Graphics Modeling. Modeling is simply the process of creating 3D objects –Many different processes to create models –Many different representations.

Scanning Real Objects

• Computer vision

Actual photograph of Hoover

Tower

Recovered 3D model

Model rendered from novel view

and texture mapped

Page 17: Computer Graphics Modeling. Modeling is simply the process of creating 3D objects –Many different processes to create models –Many different representations.

Triangle Representations

• Graphics cards do most of the triangle work– Need an efficient way to send triangles to the card

• Some typical primitive triangle representations:– Lists– Fans– Strips

1.6 vertices per triangle

1.5 vertices per triangle

3.0 vertices per triangle

Page 18: Computer Graphics Modeling. Modeling is simply the process of creating 3D objects –Many different processes to create models –Many different representations.

Triangle Representations

• Adding a level of indirection with indexed triangle representations– Store the vertices (in a vertex buffer)

independently of the rendering order (which is stored in a index buffer)

– Enables one to reuse a vertex multiple times without sending 3 coordinates each time

• Conventional wisdom is that indexed triangle strips are the most efficient triangle representation

Page 19: Computer Graphics Modeling. Modeling is simply the process of creating 3D objects –Many different processes to create models –Many different representations.

Surface Normal

• Each triangle has a single surface normal– Easy way to defines the orientation of the

surface– Again, the normal is just a vector (no position)

Page 20: Computer Graphics Modeling. Modeling is simply the process of creating 3D objects –Many different processes to create models –Many different representations.

Computing the Surface Normal

1. Let V1 be the vector from point A to point B

2. Let V2 be the vector from point A to point C

3. N = V1 x V2

4. N is often normalized

• Note that order of vertices becomes important– Triangle ABC has an outward facing normal– Triangle ACB has an inward facing normal

Page 21: Computer Graphics Modeling. Modeling is simply the process of creating 3D objects –Many different processes to create models –Many different representations.

Modeling Approaches

• Polygonal

• CSG (constructive solid geometry)

• Spatial subdivision techniques

• Implicit representation

• Parametric patches

Page 22: Computer Graphics Modeling. Modeling is simply the process of creating 3D objects –Many different processes to create models –Many different representations.

Constructive Solid Geometry

• Unlike polygonal approaches, CSG models are “solids”– Polygonal models are “skins”

• Solid approaches are often better suited for medical applications because– Cutting slices through objects– Representing internal functional data

• Temperature• Blood flow

Page 23: Computer Graphics Modeling. Modeling is simply the process of creating 3D objects –Many different processes to create models –Many different representations.

CSG Trees

• CSG models are stored in trees– Leaves are primitive shapes

• Spheres, Cubes, Cones, etc.

– Nodes are Boolean operations• Union, Difference, Intersection

Page 24: Computer Graphics Modeling. Modeling is simply the process of creating 3D objects –Many different processes to create models –Many different representations.

CSG Operations

• Primitives:

• Union:

• Intersection:

• Difference:

Page 25: Computer Graphics Modeling. Modeling is simply the process of creating 3D objects –Many different processes to create models –Many different representations.

CSG Rendering

• CSG models can be rendered by:– Computing surface points and triangulating

• Rendering can then be performed by standard hardware

– Use of special CSG rendering routines• Not hardware optimized

Page 26: Computer Graphics Modeling. Modeling is simply the process of creating 3D objects –Many different processes to create models –Many different representations.

Modeling Approaches

• Polygonal

• CSG (constructive solid geometry)

• Spatial subdivision techniques

• Implicit representation

• Parametric patches

Page 27: Computer Graphics Modeling. Modeling is simply the process of creating 3D objects –Many different processes to create models –Many different representations.

Spatial subdivision techniques

• The idea is to divide up space into pieces that are the object are pieces that are not the object– A “solid” approach to modeling

• Usually pieces are cubes

• Amount of detail that can be represented is controlled by how small the cubes are

Page 28: Computer Graphics Modeling. Modeling is simply the process of creating 3D objects –Many different processes to create models –Many different representations.

2D Images

• B/W images– Image is evenly divided up into pixels– Pixels size controls the level of detail– Pixels are on/off to represent

presence/absence of object– Representation designed for ease of blitting

onto screen, not for efficient data representation

Page 29: Computer Graphics Modeling. Modeling is simply the process of creating 3D objects –Many different processes to create models –Many different representations.

2D Quad Trees

• Quad trees adaptively subdivide the image– Subdivision can continue until the required

level of detail is reached– Significantly more efficient than using a 2D

block of uniform small squares

Page 30: Computer Graphics Modeling. Modeling is simply the process of creating 3D objects –Many different processes to create models –Many different representations.

3D Space Subdivision

• Voxels are the 3D extension of pixels

• Again, the brute-force approach is to fill 3D space with uniform small voxels and mark the space as occupied or empty

Page 31: Computer Graphics Modeling. Modeling is simply the process of creating 3D objects –Many different processes to create models –Many different representations.

Octrees

• Octrees are the 3D extension of quad trees and use adaptive subdivision

Page 32: Computer Graphics Modeling. Modeling is simply the process of creating 3D objects –Many different processes to create models –Many different representations.

Modeling Approaches

• Polygonal

• CSG (constructive solid geometry)

• Spatial subdivision techniques

• Implicit representation

• Parametric patches

Page 33: Computer Graphics Modeling. Modeling is simply the process of creating 3D objects –Many different processes to create models –Many different representations.

Implicit Representation

• An implicit definition of a sphere:x2 + y2 + z2 = r2

• Defines a type of “isosurface”– A set of 3D points that satisfy the equation

• However, they are difficult to work with– Quickly tell me all the points that satisfy the

above equation given a particular value of r

Page 34: Computer Graphics Modeling. Modeling is simply the process of creating 3D objects –Many different processes to create models –Many different representations.

Metaballs

• Metaballs (a.k.a. blobby objects) are an implicit modeling technique

Page 35: Computer Graphics Modeling. Modeling is simply the process of creating 3D objects –Many different processes to create models –Many different representations.

Metaballs in Action

• Implicit representations find most of the use in shape changing animations

Page 36: Computer Graphics Modeling. Modeling is simply the process of creating 3D objects –Many different processes to create models –Many different representations.

Modeling Approaches

• Polygonal

• CSG (constructive solid geometry)

• Spatial subdivision techniques

• Implicit representation

• Parametric patches

Page 37: Computer Graphics Modeling. Modeling is simply the process of creating 3D objects –Many different processes to create models –Many different representations.

Parametric Patches

• Parametric patches are used to model smooth curved surfaces and to allow dynamic control over the shape of the surface

• Parametric patches are uses heavily in CAD application and animation

• Currently real-time applications are dominated by triangle meshes– Patches hold many advantages over triangle meshes

and if hardware support for them becomes widespread there could be a major shift to them

Page 38: Computer Graphics Modeling. Modeling is simply the process of creating 3D objects –Many different processes to create models –Many different representations.

Parametric Patches

• One of the first uses of parametric patches is the “Utah Teapot”– The actual teapot is on the left

Page 39: Computer Graphics Modeling. Modeling is simply the process of creating 3D objects –Many different processes to create models –Many different representations.

Parametric Patches

• We will start be examining curves– Bézier curves– B-Spline curves

• Then we will expand to surface patches– Bézier patches– B-Spline patches

Page 40: Computer Graphics Modeling. Modeling is simply the process of creating 3D objects –Many different processes to create models –Many different representations.

Bézier Curves

• Pierre Bézier, a French designer, first used them in the 1970’s in the design of Renault car bodies

• Since, they have been heavily used by Adobe in their fonts as well as in graphic applications

• A Bézier curve is a parametric curve– The function C(u) defines the curve points (x,

y, z) as the parameter u varies through [0..1]

Page 41: Computer Graphics Modeling. Modeling is simply the process of creating 3D objects –Many different processes to create models –Many different representations.

Bézier Curves

• The space curve C(u) is defined by:C(u) = i0..N Pi Bi (u)

where the Pi are the control points

and the Bi(u) are the blending functions

Page 42: Computer Graphics Modeling. Modeling is simply the process of creating 3D objects –Many different processes to create models –Many different representations.

Bézier Curves

• The control points are simply 3D points• The blending functions are defined as:

Bi(u) = N ui (1 – u)N-i

i

• Most of the time, the cubic version is used (n=3)– This implies 4 control points are needed and 4 blending

functions:

B0(u) = (1 – u)3

B1(u) = 3u (1 – u)2

B2(u) = 3u2 (1 – u)

B3(u) = u3

Page 43: Computer Graphics Modeling. Modeling is simply the process of creating 3D objects –Many different processes to create models –Many different representations.

Bézier Curves

• The blending functions make much more sense graphically– Note that t in the graph below is our u

Page 44: Computer Graphics Modeling. Modeling is simply the process of creating 3D objects –Many different processes to create models –Many different representations.

Bézier Curves

• Due to the setup of the blending functions:– The curve goes through the end points

• control points P0 and P3

– The curve doesn’t go through the interior control points

• The interior control influence the curve– The curve is pulled in the direction of the

control point– Moving a control point changes the shape of

the entire curve (called global control)

Page 45: Computer Graphics Modeling. Modeling is simply the process of creating 3D objects –Many different processes to create models –Many different representations.

Bézier Curves

• A Bézier Curve can only “curve” as much as its degree allows– Degree 1 (linear) is a line

– Degree 2 (quadratic) can curve once

– Degree 3 (cubic) can curve twice

• Recall that the number of control points is always 1 larger than the degree

Page 46: Computer Graphics Modeling. Modeling is simply the process of creating 3D objects –Many different processes to create models –Many different representations.

Bézier Curves

• So what if you want a really “curvy” curve?– You could increase the degree of the curve

• The downfall of this approach is that each control point has global control over the curve shape

– That is, changing a single control point will modify the shape of the entire curve (not great for modeling)

– High degree curves are “unstable”

• It is computationally expensive

– You could join multiple cubic curves together• Each control point only has influence over its piece of the

curve (local control w.r.t. the entire joined curve)• Hardware can be optimized for cubic curves• But, we must maintain continuity across the joins!

Page 47: Computer Graphics Modeling. Modeling is simply the process of creating 3D objects –Many different processes to create models –Many different representations.

Bézier Curves

• So how are we going to maintain continuity?• Notice that the line between the first 2 control

points specify the tangent of the curve at u=0• And the line between the last 2 control points

specify the tangent of the curve at u=1

Page 48: Computer Graphics Modeling. Modeling is simply the process of creating 3D objects –Many different processes to create models –Many different representations.

Bézier Curves

• So if we line up P2P3 with Q0Q1, then we have the same tangent at end u=1 point of curve P and u=0 point of curve Q

Page 49: Computer Graphics Modeling. Modeling is simply the process of creating 3D objects –Many different processes to create models –Many different representations.

Bézier Curves

• Continuity put into more formal terms:– C0 continuity means the curve points vary smoothly

• That is, the curve is a set of connected points• For our joined example, it means the two joined segments

share the same endpoints– P3 is the same point as Q0

– C1 continuity means the curve’s first derivatives vary smoothly (plus C0 continuity)

• For our joined example, it means the tangents at the end endpoints must be the same (P2, P3, Q0, Q1 must form a line)

– And P0, P1 must form a line with the curve before it and Q2, Q3 must form a line with the curve after it all 4 control points are constrained to some extent

Page 50: Computer Graphics Modeling. Modeling is simply the process of creating 3D objects –Many different processes to create models –Many different representations.

Bézier Curves

– C2 continuity means the curve’s second derivatives vary smoothly (plus C1 continuity)

• Second derivative corresponds to curvature• For our joined example, it implies constrains on

P1, P2, P3, Q0, Q1, and Q2– Plus P0, P1, and P2 are constrained from the curve

before it and Q1, Q2, and Q3 are constrained from the curve after it

– Thus, although it can be achieved, there are so many constrains on the positions of the control points that joined cubic Bézier curves are almost never C2 continuous

Page 51: Computer Graphics Modeling. Modeling is simply the process of creating 3D objects –Many different processes to create models –Many different representations.

Bézier Curves

• Do we care about C2 continuity?– Probably not for simple modeling– But if the curve is being used to specify the

path/orientation of a camera:• Not C0 means the camera position jumps• Not C1 means the camera’s orientation jumps• Not C2 means the change in the camera’s

orientation has sudden jumps

– Think in terms of a car: position, velocity, acceleration

Page 52: Computer Graphics Modeling. Modeling is simply the process of creating 3D objects –Many different processes to create models –Many different representations.

B-Spline Curves

• B-Splines fix two major problems of Béziers:– Global control of control points– Relationship between degree of the curve and the

number of control points

• This is achieved by letting the user specify any number of control points and automatically constructing a set of cubic curves that are C2– This is similar to a set of joined cubic Bézier curves

• Joined cubic Bézier curves can have any number of control points and are still cubic, and each control point only influences its local cubic curve

– But B-Splines are C2 and have no constraints on control point locations as joined cubic Bézier curves

Page 53: Computer Graphics Modeling. Modeling is simply the process of creating 3D objects –Many different processes to create models –Many different representations.

B-Spline Curves• The definition of cubic B-Spline curve is:

C(u) = i0..M Pi Bi (u)

• So just like with Bézier curves, we have control points (Pi) and blending functions (Bi(u))

• However, a full B-Spline curve of M+1 control points is really made up of M-2 curve segments, each being controlled by 4 of the control points

• Also, the blending functions are defined differently than with Bézier curves, with the two most popular variations being:– Uniform– Non-Uniform

Page 54: Computer Graphics Modeling. Modeling is simply the process of creating 3D objects –Many different processes to create models –Many different representations.

Uniform B-Spline Curves

• Uniform blending functions get their name from the fact that all the blending functions are uniform

Page 55: Computer Graphics Modeling. Modeling is simply the process of creating 3D objects –Many different processes to create models –Many different representations.

Uniform B-Spline Curves

• Recall that each curve segment composing the full B-Spline needs 4 control points modified by 4 blending functions

• This implies that only the section in yellow on the previous slide can be used to define the curve– At either end there are not enough blending functions

• This also implies that the curve will not go through any of the control points, including the first and last (as was the case with Bézier)– There are multiple non-zero blending functions at u=0

and u=1

Page 56: Computer Graphics Modeling. Modeling is simply the process of creating 3D objects –Many different processes to create models –Many different representations.

Uniform B-Spline Curves

• Here is an example of a Uniform B-spline curve– M=8 9 control points, 6 curve segments

Page 57: Computer Graphics Modeling. Modeling is simply the process of creating 3D objects –Many different processes to create models –Many different representations.

Non-Uniform B-Spline Curves

• The main difference between Uniform and Non-Uniform B-Splines is that all the blending functions are not the same

• There are several variations on the blending functions, all controlled by “knot values”– We won’t get into the details of knot values

• In particular, the blending function can be specified in such a way as force the curve to go through the endpoints (like Bézier)– P.97 from 3D games book has a good example

Page 58: Computer Graphics Modeling. Modeling is simply the process of creating 3D objects –Many different processes to create models –Many different representations.

Rational Curves

• A rational curve is a curve defined in 4D space that is then projected into 3D space

• The main point of using rational curves is that it allows you to define weights on the control points– Giving a control point a higher weight causes the

curve to be pulled more towards that control point– P.105 in 3D games book for an example

• One can have Rational Bézier curves or Rational B-Spline curves– Or other types of curves not covered (Hermite, etc.)

Page 59: Computer Graphics Modeling. Modeling is simply the process of creating 3D objects –Many different processes to create models –Many different representations.

NURBS

• NURBS stands for Non-Uniform Rational B-Splines

• It is one of the most popular curve representations used in CAD and graphics work because it allows:– Local control of the curve when moving the

control points (B-Spline)– Ability to adjust the blending functions by

moving the “knot values” (Non-Uniform)– Ability to weight the control points (Rational)

Page 60: Computer Graphics Modeling. Modeling is simply the process of creating 3D objects –Many different processes to create models –Many different representations.

Bézier Patches

• These patches are based on Bézier curves• The equation for a cubic patch is:

C(u, v) = i0..3 j0..3 Pij Bi (u) Bj (v)

• That is, it is a lattice of Bézier curves– Specifically, 4 horizontal curves (u direction) and 4

vertical curves (v direction)

• These 8 curves share control points such that there are a total of 16 control points in the lattice

Page 61: Computer Graphics Modeling. Modeling is simply the process of creating 3D objects –Many different processes to create models –Many different representations.

Bézier Patches

• The following is an example of the control point lattice:

Page 62: Computer Graphics Modeling. Modeling is simply the process of creating 3D objects –Many different processes to create models –Many different representations.

• The surface that is created is based on the control points:

Bézier Patches

Page 63: Computer Graphics Modeling. Modeling is simply the process of creating 3D objects –Many different processes to create models –Many different representations.

Bézier Patches

• The surface is based on Bézier curves• Thus, the surface only matches the control

points at the 4 corners

Page 64: Computer Graphics Modeling. Modeling is simply the process of creating 3D objects –Many different processes to create models –Many different representations.

Bézier Patches

• Adjusting the control points changes the shape of the surface:

• See the applet on:– http://www.nbb.cornell.edu/neurobio/land/OldStudentProjects/cs490-96to97/anson/BezierPatchApplet/

• All the same issue occur with patches as with curves– Control points have global control– Increasing the number of control points

will increase the degree of the patch

Page 65: Computer Graphics Modeling. Modeling is simply the process of creating 3D objects –Many different processes to create models –Many different representations.

Bézier Patches

• Thus, we handle large curvy surfaces the same was as with curves: join patches together

• See the applet on:– http://www1.ics.uci.edu/~frost/unex/JavaGraphics/course/Bezpatch.html

• Recall the continuity constrains:– C0 continuity: edges must match– C1 continuity: colinear control points

• More difficult near joins of 4 patches

Page 66: Computer Graphics Modeling. Modeling is simply the process of creating 3D objects –Many different processes to create models –Many different representations.

B-Spline Patches

• B-Spline patches are similar to Bézier patches except that they are based on B-Spline curves

• This implies that:– You can have any number of control points in

either the u or v direction (4x4, 8x12, etc.) and still maintain piecewise C2 cubic patches

– With Uniform patches, the patch is will no go through the control points

• See P.116 in Games book

Page 67: Computer Graphics Modeling. Modeling is simply the process of creating 3D objects –Many different processes to create models –Many different representations.

Rendering Patches

• There are two types of ways we can render patches:– Render them directly from the parametric

descriptions in hardware• Must have hardware support

– Approximate the patch with a triangle mesh and render this mesh

• Usually done in software• Standard pipeline can be used

Page 68: Computer Graphics Modeling. Modeling is simply the process of creating 3D objects –Many different processes to create models –Many different representations.

Rendering Patches• To approximate the patch with triangles,

we can use a uniform subdivision– Evaluate the surface at fixed (u,v)

intervals and connect the points withtriangle strips

– Nehe Tutorial 28 (left/right/up/down/space)– OpenGL has support for this which Nehe28

doesn’t use

Page 69: Computer Graphics Modeling. Modeling is simply the process of creating 3D objects –Many different processes to create models –Many different representations.

Rendering Patches

• Or we can use an adaptive subdivision• Divide surface in quarters• If approximation patch is “flat enough” relative to the actual surface

patch, then draw it• Otherwise, repeat the sub-division on that quarter

– Pros:• More triangles are generated where the curvature is high,

less triangles where curvature is low

– Cons:• Problems with cracks

– Neighbors not subdividedto the same level

– Can be fixed by addingmore edges

Page 70: Computer Graphics Modeling. Modeling is simply the process of creating 3D objects –Many different processes to create models –Many different representations.

Rendering Patches

• To have proper lighting we also need normals for the triangles– We can simply use the triangles normal– Or, if we want to be more accurate, we can

use the actual normal to the parametric surface

• Partial derivative in the u direction is 1st tangent• Partial derivative in the v direction is 2nd tangent• Take their cross product and normalize to produce

the normal vector

Page 71: Computer Graphics Modeling. Modeling is simply the process of creating 3D objects –Many different processes to create models –Many different representations.

OpenGL Bézier Curve Support• To setup a Bézier curve:

– glMap1f(GL_MAP1_VERTEX_3, 0.0, 1.0, 3, 4, &controlPts[0][0]);

• Params are: map type, u start, u end, stride, order (degree + 1), array of control points

– glEnable(GL_MAP1_VERTEX_3);

• To setup a grid for subdivision– glMapGrid1f(100, 0.0, 10.0)

• 100 subdivision between starting with 0 and ending with 10• Grid 0 gets mapped to u=0, grid 10 get mapped to u=1

• To draw the curve– glEvalMesh1(GL_LINE, 0, 10)

• Draw lines to approximate the curve from grid range 0 to 10

Page 72: Computer Graphics Modeling. Modeling is simply the process of creating 3D objects –Many different processes to create models –Many different representations.

OpenGL Bézier Patch Support

– glMap2f(GL_MAP2_VERTEX_3, 0.0, 1.0, 3, 4, 0.0, 1.0, 12, 4, &controlPts[0][0][0]);

– glEnable(GL_MAP2_VERTEX_3);– glMapGrid2f(100, 0.0f, 10.0f, 100, 0.0f, 10.0f);– glEvalMesh2(GL_LINE, 0, 10, 0, 10);

• Or GL_FILL which produces lit, shaded surface if lighting is turned on and we have normals for our surface

– glEnable(GL_AUTO_NORMAL);

• Texture mapping can also be done by using similar mapping to automatically generate texture coordinates

Page 73: Computer Graphics Modeling. Modeling is simply the process of creating 3D objects –Many different processes to create models –Many different representations.

OpenGL NURBS Support

• To setup the NURBS:– GLUnurbsObj *myNurb = gluNewNurbsRenderer();– gluNurbsProperty(myNurb, GLU_SAMPLING_TOLERANCE,

maxUnitLength);– gluNurbsProperty(myNurb, GLU_DISPLAY_MODE, GLU_FILL);

• To display the NURBS:– gluBeginSurface(myNurb);– gluNurbsSurface(myNurb,

uKnotCount, uKnotArray, vKnotCount, vKnotArray, uStride, vStride, controlPtsArray, uOrder, vOrder, GL_MAP2_VERTEX_3);

– gluEndSurface(myNurb);

• Tons more parameters and control available