Docsity

Evaluators, Curves, Surfaces - Computer Graphics - Lecture Slides, Slides of Computer Graphics

Partial preview of the text

Download Evaluators, Curves, Surfaces - Computer Graphics - Lecture Slides and more Slides Computer Graphics in PDF only on Docsity!

Computer

Graphics

Lecture 44Docsity.com

Evaluators, curves

and Surfaces

A Bezier curve is a vector valued function of one variable C(u) = [X(u) Y(u) Z(u)] where u varies in some domain (say [0,1]). A Bezier surface patch is a vector valued function of two variables:

S(u,v) = [X(u,v) Y(u,v) Z(u,v)]

where u and v can both vary in some domain. The range isn't necessarily three-dimensional as shown here.

This way, the curve or surface vertices can be used like any other vertices to form points or lines. In addition, other commands automatic- ally generate series of vertices that produce a regular mesh uniformly spaced in u (or in u and v).

One and two-dimensional evaluators are similar, but the description is somewhat simpler in one dimension, so that case is discussed first.

This section presents an example of using one- dimensional evaluators to draw a curve. It then describes the commands and equations that control evaluators.

One-Dimensional Example:

A Simple Bezier Curve

The program shown in Example 1 draws a cubic Bezier curve using four control points, as shown in Figure 1.

Bezier Curve with Four Control Points:

#include <GL/gl.h>

#include <GL/glu.h>

#include <stdlib.h>

#include <GL/glut.h>

GLfloat ctrlpoints[4][3] = {

{-4.0, -4.0, 0.0}, { -2.0, 4.0, 0.0 } ,{2.0, -4.0, 0.0}, {4.0, 4.0, 0.0}};

void init(void)

{

glClearColor(0.0, 0.0, 0.0, 0.0); glShadeModel(GL_FLAT);

void display(void)

{

int i; glClear(GL_COLOR_ 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();

/*The following code displays the control points as dots. */

void reshape(int w, int h)

{

glViewport(0, 0, (GLsizei) w, (GLsizei) h); glMatrixMode( GL_PROJECTION); glLoadIdentity(); if (w <= h)

glOrtho(-5.0, 5.0, -5.0* (GLfloat)h/(GLfloat)w, 5.0*(GLfloat)h/(GLfloat)w, -5.0 ,5.0);

else

glOrtho(-5.0(GLfloat)w/ (GLfloat)h, 5.0(GLfloat)w/ (GLfloat)h,-5.0,5.0, -5.0,5.0);