1 /* $Id: nurbscrv.c,v 1.2 2003/08/22 20:11:43 brianp Exp $ */
4 * Mesa 3-D graphics library
6 * Copyright (C) 1995-2000 Brian Paul
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the Free
20 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 * NURBS implementation written by Bogdan Sikorski (bogdan@cira.it)
26 * See README2 for more info.
41 /* main NURBS curve procedure */
43 do_nurbs_curve(GLUnurbsObj
* nobj
)
45 GLint geom_order
, color_order
= 0, normal_order
= 0, texture_order
= 0;
48 GLfloat
*new_geom_ctrl
, *new_color_ctrl
, *new_normal_ctrl
,
50 GLfloat
*geom_ctrl
= 0, *color_ctrl
= 0, *normal_ctrl
= 0, *texture_ctrl
= 0;
53 GLint geom_dim
, color_dim
= 0, normal_dim
= 0, texture_dim
= 0;
55 /* test the user supplied data */
56 if (test_nurbs_curves(nobj
) != GLU_NO_ERROR
)
59 if (convert_curves(nobj
, &new_geom_ctrl
, &n_ctrl
, &new_color_ctrl
,
60 &new_normal_ctrl
, &new_texture_ctrl
) != GLU_NO_ERROR
)
63 geom_order
= nobj
->curve
.geom
.order
;
64 geom_type
= nobj
->curve
.geom
.type
;
65 geom_dim
= nobj
->curve
.geom
.dim
;
67 if (glu_do_sampling_crv(nobj
, new_geom_ctrl
, n_ctrl
, geom_order
, geom_dim
,
68 &factors
) != GLU_NO_ERROR
) {
73 free(new_normal_ctrl
);
75 free(new_texture_ctrl
);
80 glEnable(nobj
->curve
.color
.type
);
81 color_dim
= nobj
->curve
.color
.dim
;
82 color_ctrl
= new_color_ctrl
;
83 color_order
= nobj
->curve
.color
.order
;
85 if (new_normal_ctrl
) {
86 glEnable(nobj
->curve
.normal
.type
);
87 normal_dim
= nobj
->curve
.normal
.dim
;
88 normal_ctrl
= new_normal_ctrl
;
89 normal_order
= nobj
->curve
.normal
.order
;
91 if (new_texture_ctrl
) {
92 glEnable(nobj
->curve
.texture
.type
);
93 texture_dim
= nobj
->curve
.texture
.dim
;
94 texture_ctrl
= new_texture_ctrl
;
95 texture_order
= nobj
->curve
.texture
.order
;
97 for (i
= 0, j
= 0, geom_ctrl
= new_geom_ctrl
;
98 i
< n_ctrl
; i
+= geom_order
, j
++, geom_ctrl
+= geom_order
* geom_dim
) {
99 if (fine_culling_test_2D
100 (nobj
, geom_ctrl
, geom_order
, geom_dim
, geom_dim
)) {
101 color_ctrl
+= color_order
* color_dim
;
102 normal_ctrl
+= normal_order
* normal_dim
;
103 texture_ctrl
+= texture_order
* texture_dim
;
106 glMap1f(geom_type
, 0.0, 1.0, geom_dim
, geom_order
, geom_ctrl
);
107 if (new_color_ctrl
) {
108 glMap1f(nobj
->curve
.color
.type
, 0.0, 1.0, color_dim
,
109 color_order
, color_ctrl
);
110 color_ctrl
+= color_order
* color_dim
;
112 if (new_normal_ctrl
) {
113 glMap1f(nobj
->curve
.normal
.type
, 0.0, 1.0, normal_dim
,
114 normal_order
, normal_ctrl
);
115 normal_ctrl
+= normal_order
* normal_dim
;
117 if (new_texture_ctrl
) {
118 glMap1f(nobj
->curve
.texture
.type
, 0.0, 1.0, texture_dim
,
119 texture_order
, texture_ctrl
);
120 texture_ctrl
+= texture_order
* texture_dim
;
122 glMapGrid1f(factors
[j
], 0.0, 1.0);
123 glEvalMesh1(GL_LINE
, 0, factors
[j
]);
128 free(new_color_ctrl
);
130 free(new_normal_ctrl
);
131 if (new_texture_ctrl
)
132 free(new_texture_ctrl
);