reshuffling of dlls
[reactos.git] / reactos / dll / win32 / glu32 / libnurbs / interface / incurveeval.cc
1 /*
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:
9 **
10 ** http://oss.sgi.com/projects/FreeB
11 **
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.
17 **
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.
23 **
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.
33 **
34 ** $Date$ $Revision: 1.1 $
35 */
36 /*
37 ** $Header: /cygdrive/c/RCVS/CVS/ReactOS/reactos/lib/glu32/libnurbs/interface/incurveeval.cc,v 1.1 2004/02/02 16:39:08 navaraf Exp $
38 */
39
40 #include <stdlib.h>
41 #include <stdio.h>
42
43 #include "glcurveval.h"
44
45
46 /*
47 *compute the Bezier polynomials C[n,j](v) for all j at v with
48 *return values stored in coeff[], where
49 * C[n,j](v) = (n,j) * v^j * (1-v)^(n-j),
50 * j=0,1,2,...,n.
51 *order : n+1
52 *vprime: v
53 *coeff : coeff[j]=C[n,j](v), this array store the returned values.
54 *The algorithm is a recursive scheme:
55 * C[0,0]=1;
56 * C[n,j](v) = (1-v)*C[n-1,j](v) + v*C[n-1,j-1](v), n>=1
57 *This code is copied from opengl/soft/so_eval.c:PreEvaluate
58 */
59 void OpenGLCurveEvaluator::inPreEvaluate(int order, REAL vprime, REAL *coeff)
60 {
61 int i, j;
62 REAL oldval, temp;
63 REAL oneMinusvprime;
64
65 /*
66 * Minor optimization
67 * Compute orders 1 and 2 outright, and set coeff[0], coeff[1] to
68 * their i==1 loop values to avoid the initialization and the i==1 loop.
69 */
70 if (order == 1) {
71 coeff[0] = 1.0;
72 return;
73 }
74
75 oneMinusvprime = 1-vprime;
76 coeff[0] = oneMinusvprime;
77 coeff[1] = vprime;
78 if (order == 2) return;
79
80 for (i = 2; i < order; i++) {
81 oldval = coeff[0] * vprime;
82 coeff[0] = oneMinusvprime * coeff[0];
83 for (j = 1; j < i; j++) {
84 temp = oldval;
85 oldval = coeff[j] * vprime;
86 coeff[j] = temp + oneMinusvprime * coeff[j];
87 }
88 coeff[j] = oldval;
89 }
90 }
91
92 void OpenGLCurveEvaluator::inMap1f(int which, //0: vert, 1: norm, 2: color, 3: tex
93 int k, //dimension
94 REAL ulower,
95 REAL uupper,
96 int ustride,
97 int uorder,
98 REAL *ctlpoints)
99 {
100 int i,x;
101 curveEvalMachine *temp_em;
102 switch(which){
103 case 0: //vertex
104 vertex_flag = 1;
105 temp_em = &em_vertex;
106 break;
107 case 1: //normal
108 normal_flag = 1;
109 temp_em = &em_normal;
110 break;
111 case 2: //color
112 color_flag = 1;
113 temp_em = &em_color;
114 break;
115 default:
116 texcoord_flag = 1;
117 temp_em = &em_texcoord;
118 break;
119 }
120
121 REAL *data = temp_em->ctlpoints;
122 temp_em->uprime = -1; //initialized
123 temp_em->k = k;
124 temp_em->u1 = ulower;
125 temp_em->u2 = uupper;
126 temp_em->ustride = ustride;
127 temp_em->uorder = uorder;
128 /*copy the control points*/
129 for(i=0; i<uorder; i++){
130 for(x=0; x<k; x++){
131 data[x] = ctlpoints[x];
132 }
133 ctlpoints += ustride;
134 data += k;
135 }
136 }
137
138 void OpenGLCurveEvaluator::inDoDomain1(curveEvalMachine *em, REAL u, REAL *retPoint)
139 {
140 int j, row;
141 REAL the_uprime;
142 REAL *data;
143
144 if(em->u2 == em->u1)
145 return;
146 the_uprime = (u-em->u1) / (em->u2-em->u1);
147 /*use already cached values if possible*/
148 if(em->uprime != the_uprime){
149 inPreEvaluate(em->uorder, the_uprime, em->ucoeff);
150 em->uprime = the_uprime;
151 }
152
153 for(j=0; j<em->k; j++){
154 data = em->ctlpoints+j;
155 retPoint[j] = 0.0;
156 for(row=0; row<em->uorder; row++)
157 {
158 retPoint[j] += em->ucoeff[row] * (*data);
159 data += em->k;
160 }
161 }
162 }
163
164 void OpenGLCurveEvaluator::inDoEvalCoord1(REAL u)
165 {
166 REAL temp_vertex[4];
167 REAL temp_normal[3];
168 REAL temp_color[4];
169 REAL temp_texcoord[4];
170 if(texcoord_flag) //there is a texture map
171 {
172 inDoDomain1(&em_texcoord, u, temp_texcoord);
173 texcoordCallBack(temp_texcoord, userData);
174 }
175 #ifdef DEBUG
176 printf("color_flag = %i\n", color_flag);
177 #endif
178 if(color_flag) //there is a color map
179 {
180 inDoDomain1(&em_color, u, temp_color);
181 colorCallBack(temp_color, userData);
182 }
183 if(normal_flag) //there is a normal map
184 {
185 inDoDomain1(&em_normal, u, temp_normal);
186 normalCallBack(temp_normal, userData);
187 }
188 if(vertex_flag)
189 {
190 inDoDomain1(&em_vertex, u, temp_vertex);
191 vertexCallBack(temp_vertex, userData);
192 }
193 }
194
195 void OpenGLCurveEvaluator::inMapMesh1f(int umin, int umax)
196 {
197 REAL du, u;
198 int i;
199 if(global_grid_nu == 0)
200 return; //no points to output
201 du = (global_grid_u1 - global_grid_u0) / (REAL) global_grid_nu;
202 bgnline();
203 for(i=umin; i<= umax; i++){
204 u = (i==global_grid_nu)? global_grid_u1: global_grid_u0 + i*du;
205 inDoEvalCoord1(u);
206 }
207 endline();
208 }