110 likes | 207 Views
Computer Graphic And Vision. Computer Science Department 2014-2015. Curves and Surfaces. Curves and Surfaces in OpenGL. OpenGL supports Bézier curves and surfaces though mechanisms called Evaluators . These are used to compute values for the Bernstein polynomials of any order.
E N D
Computer Graphic And Vision Computer Science Department 2014-2015 Curves and Surfaces
Curves and Surfaces in OpenGL • OpenGL supports Bézier curves and surfaces though mechanisms called Evaluators. • These are used to compute values for the Bernstein polynomials of any order. • The OpenGL evaluator functions allow you to use a polynomial mapping to produce Vertices, Normals, Texture Coordinates, and Colors.
OpenGL Bezier-Spline Curve Function • To specify parameters and activate Bezier-curve: publicvoid glMap1{fd}(Glenum target , TYPE u1, TYPE u2, GLint stride, GLint order, const TYPE *points); • glEnable(Glenum target); • glDisable(Glenum target); target : GL_MAP1_VERTEX_3 target-type of objects to be evaluated using Bezier polynomials: GL_MAP1_VERTEX_3 u1,u2- u_min, u_max -Range of parameter values [0 – 1] stride - is the number of single- or doubleprecision values (as appropriate) in each block of storage. Thus, it’s an offset value between the beginning ofone control point and the beginning of the next. order- The orderis the degree plus 1, and it should agree with the number of control points. *points – Control Points float[] ctrlpoints = {…} double[] ctrlpoints = {…}
Evaluator - Curve • To calculate the coordinate position along the curve path: • void glEvalCoord1{fd}(TYPE u); • void glEvalCoord1{fd}v(const TYPE *u); • A Bézier curve is a vector-valued function of one variable • C(u) = [X(u) Y(u) Z(u)] • where u varies in some domain [0, 1]
Bezier Curve Example BezierCurve.java
Defining Evenly Spaced Coordinate Values in One Dimension • the following commands can be used to produce a set of uniformly spaced parameter values: • glMapGrid1{fd}(n, u1, u2); • glEvalMesh(mode, n1, n2); n: Equal subdivisions from u1 to u2 n1 and n2: an integer range corresponding tou1 and u2 mode: either GL_POINT, GL_LINE • Example: in the previous example we can replace the block containing the for loop with: • glColor3f(1.0, 1.0, 1.0); • glMapGrid1f(100, 0.0, 1.0); • glEvalMesh1(GL_LINE, 0, 100); GridBezierCurve.java
OpenGL Bezier-Spline Surface Function • To specify parameters and activate Surface: publicvoid glMap2f{fd}(Glenum target , TYPE u1, TYPE u2, GLintustride, GLintuorder, TYPE v1, TYPE v2, GLintvstride, GLintvorder, const TYPE *points); • glEnable(Glenum target); • glDisable(Glenum target); target : GL_MAP2_VERTEX_3
Evaluator - Surface • To calculate the coordinate position along the curve path: • void glEvalCoord2{fd}(TYPE u , TYPE v); • void glEvalCoord2{fd}v(const TYPE *values); • A Bézier surface patch is a vectorvalued 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 [0, 1]
Bezier Surface Example BezierSurface.java
Defining Evenly Spaced Coordinate Values in Two Dimensions • Instead of using the glEvalCoord2() command, we can generate evenly spaced parameter values over the surface with • glMapGrid2{fd}(nu, u1, u2, nv, v1, v2); • glEvalMesh2(mode, nu1, nu2, nv1, nv2); nu: equaly spaced intervals between u1 and u2 nv: equaly spaced intervals between v1 and v2 nu1 and nu2: the corresponding integer for u nv1 and nv2: the corresponding integer for v mode: GL_POINT, GL_LINE, or GL_FILL • Example: in the previous example we can replace the block containing the two for loops with: • glMapGrid2{fd}(8, 0.0, 1.0, 8, 0.0, 1.0); • glEvalMesh2(GL_LINE, 0, 8, 0, 8) GridBezierSurface.java