2 ** License Applicability. Except to the extent portions of this file are
3 ** made subject to an alternative license as permitted in the SGI Free
4 ** Software License B, Version 1.1 (the "License"), the contents of this
5 ** file are subject only to the provisions of the License. You may not use
6 ** this file except in compliance with the License. You may obtain a copy
7 ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
8 ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
10 ** http://oss.sgi.com/projects/FreeB
12 ** Note that, as provided in the License, the Software is distributed on an
13 ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
14 ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
15 ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
16 ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
18 ** Original Code. The Original Code is: OpenGL Sample Implementation,
19 ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
20 ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
21 ** Copyright in any portions created by third parties is as indicated
22 ** elsewhere herein. All Rights Reserved.
24 ** Additional Notice Provisions: The application programming interfaces
25 ** established by SGI in conjunction with the Original Code are The
26 ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
27 ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
28 ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
29 ** Window System(R) (Version 1.3), released October 19, 1998. This software
30 ** was created using the OpenGL(R) version 1.2.1 Sample Implementation
31 ** published by SGI, but has not been independently verified as being
32 ** compliant with the OpenGL(R) version 1.2.1 Specification.
41 #include "glcurveval.h"
45 *compute the Bezier polynomials C[n,j](v) for all j at v with
46 *return values stored in coeff[], where
47 * C[n,j](v) = (n,j) * v^j * (1-v)^(n-j),
51 *coeff : coeff[j]=C[n,j](v), this array store the returned values.
52 *The algorithm is a recursive scheme:
54 * C[n,j](v) = (1-v)*C[n-1,j](v) + v*C[n-1,j-1](v), n>=1
55 *This code is copied from opengl/soft/so_eval.c:PreEvaluate
57 void OpenGLCurveEvaluator::inPreEvaluate(int order, REAL vprime, REAL *coeff)
65 * Compute orders 1 and 2 outright, and set coeff[0], coeff[1] to
66 * their i==1 loop values to avoid the initialization and the i==1 loop.
73 oneMinusvprime = 1-vprime;
74 coeff[0] = oneMinusvprime;
76 if (order == 2) return;
78 for (i = 2; i < order; i++) {
79 oldval = coeff[0] * vprime;
80 coeff[0] = oneMinusvprime * coeff[0];
81 for (j = 1; j < i; j++) {
83 oldval = coeff[j] * vprime;
84 coeff[j] = temp + oneMinusvprime * coeff[j];
90 void OpenGLCurveEvaluator::inMap1f(int which, //0: vert, 1: norm, 2: color, 3: tex
99 curveEvalMachine *temp_em;
103 temp_em = &em_vertex;
107 temp_em = &em_normal;
115 temp_em = &em_texcoord;
119 REAL *data = temp_em->ctlpoints;
120 temp_em->uprime = -1; //initialized
122 temp_em->u1 = ulower;
123 temp_em->u2 = uupper;
124 temp_em->ustride = ustride;
125 temp_em->uorder = uorder;
126 /*copy the control points*/
127 for(i=0; i<uorder; i++){
129 data[x] = ctlpoints[x];
131 ctlpoints += ustride;
136 void OpenGLCurveEvaluator::inDoDomain1(curveEvalMachine *em, REAL u, REAL *retPoint)
144 the_uprime = (u-em->u1) / (em->u2-em->u1);
145 /*use already cached values if possible*/
146 if(em->uprime != the_uprime){
147 inPreEvaluate(em->uorder, the_uprime, em->ucoeff);
148 em->uprime = the_uprime;
151 for(j=0; j<em->k; j++){
152 data = em->ctlpoints+j;
154 for(row=0; row<em->uorder; row++)
156 retPoint[j] += em->ucoeff[row] * (*data);
162 void OpenGLCurveEvaluator::inDoEvalCoord1(REAL u)
167 REAL temp_texcoord[4];
168 if(texcoord_flag) //there is a texture map
170 inDoDomain1(&em_texcoord, u, temp_texcoord);
171 texcoordCallBack(temp_texcoord, userData);
174 printf("color_flag = %i\n", color_flag);
176 if(color_flag) //there is a color map
178 inDoDomain1(&em_color, u, temp_color);
179 colorCallBack(temp_color, userData);
181 if(normal_flag) //there is a normal map
183 inDoDomain1(&em_normal, u, temp_normal);
184 normalCallBack(temp_normal, userData);
188 inDoDomain1(&em_vertex, u, temp_vertex);
189 vertexCallBack(temp_vertex, userData);
193 void OpenGLCurveEvaluator::inMapMesh1f(int umin, int umax)
197 if(global_grid_nu == 0)
198 return; //no points to output
199 du = (global_grid_u1 - global_grid_u0) / (REAL) global_grid_nu;
201 for(i=umin; i<= umax; i++){
202 u = (i==global_grid_nu)? global_grid_u1: global_grid_u0 + i*du;