43 #include <libnurbs2.h>
44 #include "bezierPatch.h"
45 #include "bezierEval.h"
53 bezierPatch* bezierPatchMake(
float umin,
float vmin,
float umax,
float vmax,
int uorder,
int vorder,
int dimension)
63 ret->dimension = dimension;
64 ret->ctlpoints = (
float*) malloc(
sizeof(
float) * dimension * uorder * vorder);
65 assert(ret->ctlpoints);
72 bezierPatch* bezierPatchMake2(
float umin,
float vmin,
float umax,
float vmax,
int uorder,
int vorder,
int dimension,
int ustride,
int vstride,
float* ctlpoints)
82 ret->dimension = dimension;
83 ret->ctlpoints = (
float*) malloc(
sizeof(
float) * dimension * uorder * vorder);
84 assert(ret->ctlpoints);
87 int the_ustride = vorder * dimension;
88 int the_vstride = dimension;
89 for(
int i=0; i<uorder; i++)
90 for(
int j=0; j<vorder; j++)
91 for(
int k=0; k<dimension; k++)
92 ret->ctlpoints[i * the_ustride + j*the_vstride+k] = ctlpoints[i*ustride+j*vstride+k];
116 bezierPatchDelete(temp);
129 printf(
"bezierPatch:\n");
130 printf(
"umin,umax=(%f,%f), (vmin, vmax)=(%f,%f)\n", b->umin, b->umax, b->vmin, b->vmax);
131 printf(
"uorder=%i, vorder=%i\n", b->uorder, b->vorder);
132 printf(
"idmension = %i\n", b->dimension);
139 for(temp=list; temp != NULL; temp = temp->next)
140 bezierPatchPrint(temp);
143 void bezierPatchEval(
bezierPatch *b,
float u,
float v,
float ret[])
145 if( u >= b->umin && u<= b->umax
146 && v >= b->vmin && v<= b->vmax)
149 bezierSurfEval(b->umin, b->umax, b->uorder, b->vmin, b->vmax, b->vorder, b->dimension, b->ctlpoints, b->dimension * b->vorder, b->dimension, u, v, ret);
152 else if(b->next != NULL)
153 bezierPatchEval(b->next, u,v, ret);
155 bezierSurfEval(b->umin, b->umax, b->uorder, b->vmin, b->vmax, b->vorder, b->dimension, b->ctlpoints, b->dimension * b->vorder, b->dimension, u, v, ret);
160 void bezierPatchEvalNormal(
bezierPatch *b,
float u,
float v,
float ret[])
162 bezierSurfEvalNormal(b->umin, b->umax, b->uorder, b->vmin, b->vmax, b->vorder, b->dimension, b->ctlpoints, b->dimension * b->vorder, b->dimension, u, v, ret);
164 if( u >= b->umin && u<= b->umax
165 && v >= b->vmin && v<= b->vmax)
167 bezierSurfEvalNormal(b->umin, b->umax, b->uorder, b->vmin, b->vmax, b->vorder, b->dimension, b->ctlpoints, b->dimension * b->vorder, b->dimension, u, v, ret);
169 else if(b->next != NULL)
170 bezierPatchEvalNormal(b->next, u,v, ret);
172 bezierSurfEvalNormal(b->umin, b->umax, b->uorder, b->vmin, b->vmax, b->vorder, b->dimension, b->ctlpoints, b->dimension * b->vorder, b->dimension, u, v, ret);
176 void bezierPatchDraw(
bezierPatch *bpatch,
int u_reso,
int v_reso)
178 if(bpatch->dimension == 3)
179 glMap2f(GL_MAP2_VERTEX_3, bpatch->umin, bpatch->umax, 3*bpatch->vorder, bpatch->uorder, bpatch->vmin, bpatch->vmax,3, bpatch->vorder, (GLfloat*) bpatch->ctlpoints);
181 glMap2f(GL_MAP2_VERTEX_4, bpatch->umin, bpatch->umax, 4*bpatch->vorder, bpatch->uorder, bpatch->vmin, bpatch->vmax,3, bpatch->vorder, (GLfloat*) bpatch->ctlpoints);
183 glMapGrid2f(u_reso, bpatch->umin, bpatch->umax,
184 v_reso, bpatch->vmin, bpatch->vmax);
185 glEvalMesh2(GL_LINE, 0, u_reso, 0, v_reso);
188 void bezierPatchListDraw(
bezierPatch *list,
int u_reso,
int v_reso)
191 glEnable(GL_LIGHTING);
193 glEnable(GL_MAP2_VERTEX_3);
194 glEnable(GL_AUTO_NORMAL);
195 glEnable(GL_NORMALIZE);
202 for(temp = list; temp != NULL; temp = temp->next)
203 bezierPatchDraw(temp, u_reso, v_reso);