/** * $Id:$ * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** * * The contents of this file may be used under the terms of either the GNU * General Public License Version 2 or later (the "GPL", see * http://www.gnu.org/licenses/gpl.html ), or the Blender License 1.0 or * later (the "BL", see http://www.blender.org/BL/ ) which has to be * bought from the Blender Foundation to become active, in which case the * above mentioned GPL option does not apply. * * The Original Code is Copyright (C) 1997 by Ton Roosendaal, Frank van Beek and Joeri Kassenaar. * All rights reserved. * * The Original Code is: all of this file. * * Contributor(s): none yet. * * ***** END GPL/BL DUAL LICENSE BLOCK ***** */ #include #include #include #include #include #include #include float tex[]= { AMBIENT, .1, .1, .1, DIFFUSE, .8, .9, 1.0, SPECULAR, 0.0, 0.0, 0.0, SHININESS, 0.0, LMNULL, }; float lm[]= { AMBIENT, .1, .1, .1, LOCALVIEWER, 1, LMNULL, }; float lt[]= { LCOLOR, 0.99, 0.99, 0.99, POSITION, -1.2, -1.0, 1.0, 0.0, LMNULL, }; float blue_light[] = {LCOLOR, 0.3,0.3,0.9, /* blue light */ POSITION, 0.2,0.1,0.0,0.0, /* Y axis at infinity */ LMNULL}; void deflighting() { lmdef(DEFMATERIAL, 1, 0, tex); lmdef(DEFLIGHT, 1, 10, lt); lmdef(DEFLIGHT, 2, 10, blue_light); lmdef(DEFLMODEL, 1, 0, lm); } void bindlighting() { lmbind(MATERIAL, 1); lmbind(LIGHT0, 1); lmbind(LIGHT1, 2); lmbind(LMODEL, 1); } #define SEGS 30 #define PTS 18 int num[SEGS]; int extralight= SEGS; Matrix matone = { /* identity matrix */ 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0 }; float v[8][3] = { {-100.2, -100.2, -100.0}, {-100.0, -100.0, 100.0}, {-100.0, 100.0, 100.0}, {-100.2, 100.2, -100.0}, { 100.2, -100.2, -100.0}, { 100.0, -100.0, 100.0}, { 100.0, 100.0, 100.0}, { 100.2, 100.2, -100.0}, }; void drawgourcube() { float vec[3]; float n[3]; n[0]=0; n[1]=0; n[2]=0; bgnpolygon(); n[0]= -1.0; n3f(n); v3f(v[0]); v3f(v[1]); v3f(v[2]); v3f(v[3]); n[0]=0; endpolygon(); bgnpolygon(); n[1]= -1.0; n3f(n); v3f(v[0]); v3f(v[4]); v3f(v[5]); v3f(v[1]); n[1]=0; endpolygon(); bgnpolygon(); n[0]= 1.0; n3f(n); v3f(v[4]); v3f(v[7]); v3f(v[6]); v3f(v[5]); n[0]=0; endpolygon(); bgnpolygon(); n[1]= 1.0; n3f(n); v3f(v[7]); v3f(v[3]); v3f(v[2]); v3f(v[6]); n[1]=0; endpolygon(); bgnpolygon(); n[2]= 1.0; n3f(n); v3f(v[1]); v3f(v[5]); v3f(v[6]); v3f(v[2]); n[2]=0; endpolygon(); bgnpolygon(); n[2]= -1.0; n3f(n); v3f(v[7]); v3f(v[4]); v3f(v[0]); v3f(v[3]); endpolygon(); } void drawcube() { bgnline(); v3f(v[0]); v3f(v[1]);v3f(v[2]); v3f(v[3]); v3f(v[0]); v3f(v[4]);v3f(v[5]); v3f(v[6]); v3f(v[7]); v3f(v[4]); endline(); bgnline(); v3f(v[1]); v3f(v[5]); endline(); bgnline(); v3f(v[2]); v3f(v[6]); endline(); bgnline(); v3f(v[3]); v3f(v[7]); endline(); } float tube[SEGS][PTS][3]; float norms[SEGS][PTS][3]; float Normalise(n) float *n; { register float d; d= n[0]*n[0]+n[1]*n[1]+n[2]*n[2]; if(d>0.0) { d= fsqrt(d); n[0]/=d; n[1]/=d; n[2]/=d; } else { n[0]=n[1]=n[2]= 0.0; } return d; } float CalcNormFloat(v1,v2,v3,n) float *v1,*v2,*v3; float *n; { float n1[3],n2[3]; n1[0]= v1[0]-v2[0]; n2[0]= v2[0]-v3[0]; n1[1]= v1[1]-v2[1]; n2[1]= v2[1]-v3[1]; n1[2]= v1[2]-v2[2]; n2[2]= v2[2]-v3[2]; n[0]= n1[1]*n2[2]-n1[2]*n2[1]; n[1]= n1[2]*n2[0]-n1[0]*n2[2]; n[2]= n1[0]*n2[1]-n1[1]*n2[0]; return Normalise(n); } void getmouse(adr) short *adr; { /* map muiscoordinaat invers naar geprojecteerde coordinaat */ static Device mdev[2]= {MOUSEX, MOUSEY}; long x, y; getdev(2, mdev, adr); /* coordinaat binnen window */ getorigin(&x, &y); adr[0]-=x; adr[1]-=y; } void extrude(int seg) { float nor[3], dvec[3], fac, *v1, *v2, *v3, *v4, *n1, *n2, *n3, *n4; int i, segmin1; short mval[2]; segmin1= seg-1; if(segmin1 < 0) segmin1= SEGS-1; /* normaal berekenen */ CalcNormFloat(tube[segmin1][0], tube[segmin1][1], tube[segmin1][2], nor); /* perturben */ dvec[0]= rand(); dvec[1]= rand(); dvec[2]= rand(); Normalise(dvec); getmouse(mval); fac= ((float) mval[0])/800.0; /*fac= 0.0;*/ nor[0]+= dvec[0]/2.0; nor[1]+= dvec[1]/2.0; nor[2]+= dvec[2]/(1.1+fac); Normalise(nor); nor[0]*= 750.0; nor[1]*= 750.0; nor[2]*= 750.0; for(i=0; i2) { seg--; seg1= num[seg]; seg2= num[seg-1]; v2= tube[seg1][PTS-1]; v1= tube[seg1][0]; v4= tube[seg2][PTS-1]; v3= tube[seg2][0]; n2= norms[seg1][PTS-1]; n1= norms[seg1][0]; n4= norms[seg2][PTS-1]; n3= norms[seg2][0]; randcol(v1[0], v1[1], v1[2], seg); for(i=0; i= SEGS) num[i]= 0; } }