100 likes | 298 Views
Curves and Surfaces in OpenGL. Manually Generating Line Coordinates. We can define almost any curve using a formula such as Q (U) = A0 + A1*U + A2*U 2 + A3*U 3 where: Q is the calculation for x, y, or z coordinate. U varies over the range of the curve segment
E N D
Manually Generating Line Coordinates We can define almost any curve using a formula such as Q (U) = A0 + A1*U + A2*U2 + A3*U3 where: Q is the calculation for x, y, or z coordinate. U varies over the range of the curve segment see spreadsheet 1 at course web site
Point 1,1 Point 1,2 etc 1st point 2nd point Nth point Lines v. Curves So, U varies from 1 to N and V varies from 1 to M And, for each point N,M we need to create an X,Y,Z So, U varies from 1 to N
Manually Generating Curved Surface Coordinates Parametric surfaces can be defined using both a U and a V. So, Q(U,V) = A00 + A10U + A01V + A11UV + A20U2 + . . . The problem is keeping up with all these coefficients. We need a separate A00 A10 etc for X and Y and Z. see really bad spreadsheet on course web site
Automated Curved Lines in OpenGL • We can define a curve using just a few control points. • For example • {-4.0, -4.0, 0.0} • {-2.0, 4.0, 0.0} • { 2.0, -4.0, 0.0} • { 4.0, 4.0, 0.0} • see bezcurve.c for source code
Function Details glmap1f ( target, float Ustart, float Uend, int stride, int order, float *points) target GL_MAP1_VERTEX_3, GL_MAP1_VERTEX_4 GL_MAP1_NORMAL, GL_COLOR_4, etc Ustart, Uend almost always 0 and 1 stride distance between points in data (3->3D, 4->4D) order order + 1 , so 4 = cubic curve points array of control points
Shortcuts • If this was too much code glBegin(GL_LINE_STRIP); for (i =3D 0; i <=3D 30; i++) glEvalCoord1f((GLfloat) i/30.0); glEnd(); • Try this equivalent glMapGrid1f (30, 0.0, 1.0); glEvalMesh1 (GL_LINE, 30);
Automated Curved Surfaces in OpenGL glMap2f ( target, uStart, uEnd, uStride, uOrder, vStart, vEnd, vStride, vOrder, points) glEvalCoord2f ( u, v ) glMapGrid2f ( uNumber, uStart, uEnd, vNumber, vStart, vEnd) glEvalMesh2 (drawing_mode, i1, i2, j1, j2) drawing mode GL_LINE creates a mesh GL_POINT GL_FILL creates a filled surface i and j range of curve along x and y