Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > DoxygenbezierPatch.cc
Go to the documentation of this file.
00001 /* 00002 ** License Applicability. Except to the extent portions of this file are 00003 ** made subject to an alternative license as permitted in the SGI Free 00004 ** Software License B, Version 1.1 (the "License"), the contents of this 00005 ** file are subject only to the provisions of the License. You may not use 00006 ** this file except in compliance with the License. You may obtain a copy 00007 ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 00008 ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: 00009 ** 00010 ** http://oss.sgi.com/projects/FreeB 00011 ** 00012 ** Note that, as provided in the License, the Software is distributed on an 00013 ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS 00014 ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND 00015 ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A 00016 ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. 00017 ** 00018 ** Original Code. The Original Code is: OpenGL Sample Implementation, 00019 ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, 00020 ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. 00021 ** Copyright in any portions created by third parties is as indicated 00022 ** elsewhere herein. All Rights Reserved. 00023 ** 00024 ** Additional Notice Provisions: The application programming interfaces 00025 ** established by SGI in conjunction with the Original Code are The 00026 ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released 00027 ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version 00028 ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X 00029 ** Window System(R) (Version 1.3), released October 19, 1998. This software 00030 ** was created using the OpenGL(R) version 1.2.1 Sample Implementation 00031 ** published by SGI, but has not been independently verified as being 00032 ** compliant with the OpenGL(R) version 1.2.1 Specification. 00033 ** 00034 ** $Date: 2008-11-21 15:01:01 +0000 (Fri, 21 Nov 2008) $ $Revision: 1.1 $ 00035 */ 00036 /* 00037 ** $Header: /cygdrive/c/RCVS/CVS/ReactOS/reactos/lib/glu32/libnurbs/interface/bezierPatch.cc,v 1.1 2004/02/02 16:39:08 navaraf Exp $ 00038 */ 00039 00040 #include "gluos.h" 00041 #include <stdlib.h> 00042 #include <stdio.h> 00043 #include <assert.h> 00044 #include <GL/glu.h> /*for drawing bzier patch*/ 00045 #include "bezierPatch.h" 00046 #include "bezierEval.h" 00047 00048 /* 00049 *allocate an instance of bezierPatch. The control points are unknown. But 00050 *the space of this array is allocated with size of 00051 * uorder*vorder*dimension 00052 * 00053 */ 00054 bezierPatch* bezierPatchMake(float umin, float vmin, float umax, float vmax, int uorder, int vorder, int dimension) 00055 { 00056 bezierPatch* ret = (bezierPatch*) malloc(sizeof(bezierPatch)); 00057 assert(ret); 00058 ret->umin = umin; 00059 ret->vmin = vmin; 00060 ret->umax = umax; 00061 ret->vmax = vmax; 00062 ret->uorder = uorder; 00063 ret->vorder = vorder; 00064 ret->dimension = dimension; 00065 ret->ctlpoints = (float*) malloc(sizeof(float) * dimension * uorder * vorder); 00066 assert(ret->ctlpoints); 00067 00068 ret->next = NULL; 00069 00070 return ret; 00071 } 00072 00073 bezierPatch* bezierPatchMake2(float umin, float vmin, float umax, float vmax, int uorder, int vorder, int dimension, int ustride, int vstride, float* ctlpoints) 00074 { 00075 bezierPatch* ret = (bezierPatch*) malloc(sizeof(bezierPatch)); 00076 assert(ret); 00077 ret->umin = umin; 00078 ret->vmin = vmin; 00079 ret->umax = umax; 00080 ret->vmax = vmax; 00081 ret->uorder = uorder; 00082 ret->vorder = vorder; 00083 ret->dimension = dimension; 00084 ret->ctlpoints = (float*) malloc(sizeof(float) * dimension * uorder * vorder); 00085 assert(ret->ctlpoints); 00086 00087 /*copy the control points there*/ 00088 int the_ustride = vorder * dimension; 00089 int the_vstride = dimension; 00090 for(int i=0; i<uorder; i++) 00091 for(int j=0; j<vorder; j++) 00092 for(int k=0; k<dimension; k++) 00093 ret->ctlpoints[i * the_ustride + j*the_vstride+k] = ctlpoints[i*ustride+j*vstride+k]; 00094 00095 ret->next = NULL; 00096 00097 return ret; 00098 } 00099 00100 /* 00101 *deallocate the space as allocated by Make 00102 */ 00103 void bezierPatchDelete(bezierPatch *b) 00104 { 00105 free(b->ctlpoints); 00106 free(b); 00107 } 00108 00109 /*delete the whole linked list 00110 */ 00111 void bezierPatchDeleteList(bezierPatch *b) 00112 { 00113 bezierPatch *temp; 00114 00115 while(b != NULL) 00116 { 00117 temp = b->next; 00118 bezierPatchDelete(b); 00119 b = temp; 00120 } 00121 } 00122 00123 bezierPatch* bezierPatchInsert(bezierPatch *list, bezierPatch *b) 00124 { 00125 b->next = list; 00126 return b; 00127 } 00128 00129 /*print the data stored in this patch*/ 00130 void bezierPatchPrint(bezierPatch *b) 00131 { 00132 printf("bezierPatch:\n"); 00133 printf("umin,umax=(%f,%f), (vmin, vmax)=(%f,%f)\n", b->umin, b->umax, b->vmin, b->vmax); 00134 printf("uorder=%i, vorder=%i\n", b->uorder, b->vorder); 00135 printf("idmension = %i\n", b->dimension); 00136 } 00137 00138 /*print the whole list*/ 00139 void bezierPatchPrintList(bezierPatch *list) 00140 { 00141 bezierPatch* temp; 00142 for(temp=list; temp != NULL; temp = temp->next) 00143 bezierPatchPrint(temp); 00144 } 00145 00146 void bezierPatchEval(bezierPatch *b, float u, float v, float ret[]) 00147 { 00148 if( u >= b->umin && u<= b->umax 00149 && v >= b->vmin && v<= b->vmax) 00150 { 00151 00152 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); 00153 00154 } 00155 else if(b->next != NULL) 00156 bezierPatchEval(b->next, u,v, ret); 00157 else 00158 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); 00159 } 00160 00161 /*the returned normal is normlized 00162 */ 00163 void bezierPatchEvalNormal(bezierPatch *b, float u, float v, float ret[]) 00164 { 00165 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); 00166 00167 if( u >= b->umin && u<= b->umax 00168 && v >= b->vmin && v<= b->vmax) 00169 { 00170 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); 00171 } 00172 else if(b->next != NULL) 00173 bezierPatchEvalNormal(b->next, u,v, ret); 00174 else 00175 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); 00176 00177 } 00178 00179 void bezierPatchDraw(bezierPatch *bpatch, int u_reso, int v_reso) 00180 { 00181 if(bpatch->dimension == 3) 00182 glMap2f(GL_MAP2_VERTEX_3, bpatch->umin, bpatch->umax, 3*bpatch->vorder, bpatch->uorder, bpatch->vmin, bpatch->vmax,3, bpatch->vorder, (GLfloat*) bpatch->ctlpoints); 00183 else 00184 glMap2f(GL_MAP2_VERTEX_4, bpatch->umin, bpatch->umax, 4*bpatch->vorder, bpatch->uorder, bpatch->vmin, bpatch->vmax,3, bpatch->vorder, (GLfloat*) bpatch->ctlpoints); 00185 00186 glMapGrid2f(u_reso, bpatch->umin, bpatch->umax, 00187 v_reso, bpatch->vmin, bpatch->vmax); 00188 glEvalMesh2(GL_LINE, 0, u_reso, 0, v_reso); 00189 } 00190 00191 void bezierPatchListDraw(bezierPatch *list, int u_reso, int v_reso) 00192 { 00193 bezierPatch *temp; 00194 glEnable(GL_LIGHTING); 00195 glEnable(GL_LIGHT0); 00196 glEnable(GL_MAP2_VERTEX_3); 00197 glEnable(GL_AUTO_NORMAL); 00198 glEnable(GL_NORMALIZE); 00199 glColor3f(1,0,0); 00200 #ifdef DEBUG 00201 printf("mapmap\n"); 00202 #endif 00203 00204 00205 for(temp = list; temp != NULL; temp = temp->next) 00206 bezierPatchDraw(temp, u_reso, v_reso); 00207 } 00208 00209 00210 Generated on Fri May 25 2012 04:21:45 for ReactOS by
1.7.6.1
|