Path: utzoo!attcan!uunet!seismo!sundc!pitstop!sun!decwrl!ucbvax!pasteur!ames!mailrus!tut.cis.ohio-state.edu!osu-cis!att!ihlts!ihnp4!twitch!homxb!dean From: dean@homxb.UUCP (D.JONES) Newsgroups: comp.graphics Subject: Re: teapot database Summary: C source/SunCore translation Message-ID: <2069@homxb.UUCP> Date: 26 Aug 88 15:42:08 GMT References: <810@csed-pyramid.trwrb.UUCP> <7684@cit-vax.Caltech.Edu> <20706@tut.cis.ohio-state.edu> Distribution: na Organization: AT&T Bell Laboratories, Holmdel Lines: 562 This is a translation from pascal to c of the teapot database/program that was recently posted by: "Stephen Spencer, Advanced Computing Center for the Arts and Design (ACCAD)" and written by: "Charles W. Grant, Lawrence Livermore National Laboratory" I have hacked it to use SunCore Graphics. I don't know if it of any use to anyone, but since I just started mucking about with Graphics recently, It's really pretty nifty to me ... :-) If anyone could munge this thing to use polygons so that I could shade them, Please E-mail it back to be. I'm just getting to hidden line removal in the Foley/Van-Dam book, but the rest is still beyond me. compile with: "cc -O -f68881 tea.c patches.c ducks.c -o tea -lcore -lsunwindow -lpixrect -lm" Dean S Jones AT&T Bell Labs HO 1K-426 (201) 949-4256 {AT&T Gateways}!homxb!dean #! /bin/sh # This is a shell archive. Remove anything before this line, then unpack # it by saving it into a file and typing "sh file". To overwrite existing # files, type "sh file -c". You can also feed this as standard input via # unshar, or by typing "sh ducks.c <<'END_OF_ducks.c' X#include "tea.h" X Xdt ducks[DUCK_COUNT] = { X{1.4,0.0,2.4}, X{1.4,-0.784,2.4}, X{0.784,-1.4,2.4}, X{0.0,-1.4,2.4}, X{1.3375,0.0,2.53125}, X{1.3375,-0.749,2.53125}, X{0.749,-1.3375,2.53125}, X{0.0,-1.3375,2.53125}, X{1.4375,0.0,2.53125}, X{1.4375,-0.805,2.53125}, X{0.805,-1.4375,2.53125}, X{0.0,-1.4375,2.53125}, X{1.5,0.0,2.4}, X{1.5,-0.84,2.4}, X{0.84,-1.5,2.4}, X{0.0,-1.5,2.4}, X{-0.784,-1.4,2.4}, X{-1.4,-0.784,2.4}, X{-1.4,0.0,2.4}, X{-0.749,-1.3375,2.53125}, X{-1.3375,-0.749,2.53125}, X{-1.3375,0.0,2.53125}, X{-0.805,-1.4375,2.53125}, X{-1.4375,-0.805,2.53125}, X{-1.4375,0.0,2.53125}, X{-0.84,-1.5,2.4}, X{-1.5,-0.84,2.4}, X{-1.5,0.0,2.4}, X{-1.4,0.784,2.4}, X{-0.784,1.4,2.4}, X{0.0,1.4,2.4}, X{-1.3375,0.749,2.53125}, X{-0.749,1.3375,2.53125}, X{0.0,1.3375,2.53125}, X{-1.4375,0.805,2.53125}, X{-0.805,1.4375,2.53125}, X{0.0,1.4375,2.53125}, X{-1.5,0.84,2.4}, X{-0.84,1.5,2.4}, X{0.0,1.5,2.4}, X{0.784,1.4,2.4}, X{1.4,0.784,2.4}, X{0.749,1.3375,2.53125}, X{1.3375,0.749,2.53125}, X{0.805,1.4375,2.53125}, X{1.4375,0.805,2.53125}, X{0.84,1.5,2.4}, X{1.5,0.84,2.4}, X{1.75,0.0,1.875}, X{1.75,-0.98,1.875}, X{0.98,-1.75,1.875}, X{0.0,-1.75,1.875}, X{2.0,0.0,1.35}, X{2.0,-1.12,1.35}, X{1.12,-2.0,1.35}, X{0.0,-2.0,1.35}, X{2.0,0.0,0.9}, X{2.0,-1.12,0.9}, X{1.12,-2.0,0.9}, X{0.0,-2.0,0.9}, X{-0.98,-1.75,1.875}, X{-1.75,-0.98,1.875}, X{-1.75,0.0,1.875}, X{-1.12,-2.0,1.35}, X{-2.0,-1.12,1.35}, X{-2.0,0.0,1.35}, X{-1.12,-2.0,0.9}, X{-2.0,-1.12,0.9}, X{-2.0,0.0,0.9}, X{-1.75,0.98,1.875}, X{-0.98,1.75,1.875}, X{0.0,1.75,1.875}, X{-2.0,1.12,1.35}, X{-1.12,2.0,1.35}, X{0.0,2.0,1.35}, X{-2.0,1.12,0.9}, X{-1.12,2.0,0.9}, X{0.0,2.0,0.9}, X{0.98,1.75,1.875}, X{1.75,0.98,1.875}, X{1.12,2.0,1.35}, X{2.0,1.12,1.35}, X{1.12,2.0,0.9}, X{2.0,1.12,0.9}, X{2.0,0.0,0.45}, X{2.0,-1.12,0.45}, X{1.12,-2.0,0.45}, X{0.0,-2.0,0.45}, X{1.5,0.0,0.225}, X{1.5,-0.84,0.225}, X{0.84,-1.5,0.225}, X{0.0,-1.5,0.225}, X{1.5,0.0,0.15}, X{1.5,-0.84,0.15}, X{0.84,-1.5,0.15}, X{0.0,-1.5,0.15}, X{-1.12,-2.0,0.45}, X{-2.0,-1.12,0.45}, X{-2.0,0.0,0.45}, X{-0.84,-1.5,0.225}, X{-1.5,-0.84,0.225}, X{-1.5,0.0,0.225}, X{-0.84,-1.5,0.15}, X{-1.5,-0.84,0.15}, X{-1.5,0.0,0.15}, X{-2.0,1.12,0.45}, X{-1.12,2.0,0.45}, X{0.0,2.0,0.45}, X{-1.5,0.84,0.225}, X{-0.84,1.5,0.225}, X{0.0,1.5,0.225}, X{-1.5,0.84,0.15}, X{-0.84,1.5,0.15}, X{0.0,1.5,0.15}, X{1.12,2.0,0.45}, X{2.0,1.12,0.45}, X{0.84,1.5,0.225}, X{1.5,0.84,0.225}, X{0.84,1.5,0.15}, X{1.5,0.84,0.15}, X{-1.6,0.0,2.025}, X{-1.6,-0.3,2.025}, X{-1.5,-0.3,2.25}, X{-1.5,0.0,2.25}, X{-2.3,0.0,2.025}, X{-2.3,-0.3,2.025}, X{-2.5,-0.3,2.25}, X{-2.5,0.0,2.25}, X{-2.7,0.0,2.025}, X{-2.7,-0.3,2.025}, X{-3.0,-0.3,2.25}, X{-3.0,0.0,2.25}, X{-2.7,0.0,1.8}, X{-2.7,-0.3,1.8}, X{-3.0,-0.3,1.8}, X{-3.0,0.0,1.8}, X{-1.5,0.3,2.25}, X{-1.6,0.3,2.025}, X{-2.5,0.3,2.25}, X{-2.3,0.3,2.025}, X{-3.0,0.3,2.25}, X{-2.7,0.3,2.025}, X{-3.0,0.3,1.8}, X{-2.7,0.3,1.8}, X{-2.7,0.0,1.575}, X{-2.7,-0.3,1.575}, X{-3.0,-0.3,1.35}, X{-3.0,0.0,1.35}, X{-2.5,0.0,1.125}, X{-2.5,-0.3,1.125}, X{-2.65,-0.3,0.9375}, X{-2.65,0.0,0.9375}, X{-2.0,-0.3,0.9}, X{-1.9,-0.3,0.6}, X{-1.9,0.0,0.6}, X{-3.0,0.3,1.35}, X{-2.7,0.3,1.575}, X{-2.65,0.3,0.9375}, X{-2.5,0.3,1.125}, X{-1.9,0.3,0.6}, X{-2.0,0.3,0.9}, X{1.7,0.0,1.425}, X{1.7,-0.66,1.425}, X{1.7,-0.66,0.6}, X{1.7,0.0,0.6}, X{2.6,0.0,1.425}, X{2.6,-0.66,1.425}, X{3.1,-0.66,0.825}, X{3.1,0.0,0.825}, X{2.3,0.0,2.1}, X{2.3,-0.25,2.1}, X{2.4,-0.25,2.025}, X{2.4,0.0,2.025}, X{2.7,0.0,2.4}, X{2.7,-0.25,2.4}, X{3.3,-0.25,2.4}, X{3.3,0.0,2.4}, X{1.7,0.66,0.6}, X{1.7,0.66,1.425}, X{3.1,0.66,0.825}, X{2.6,0.66,1.425}, X{2.4,0.25,2.025}, X{2.3,0.25,2.1}, X{3.3,0.25,2.4}, X{2.7,0.25,2.4}, X{2.8,0.0,2.475}, X{2.8,-0.25,2.475}, X{3.525,-0.25,2.49375}, X{3.525,0.0,2.49375}, X{2.9,0.0,2.475}, X{2.9,-0.15,2.475}, X{3.45,-0.15,2.5125}, X{3.45,0.0,2.5125}, X{2.8,0.0,2.4}, X{2.8,-0.15,2.4}, X{3.2,-0.15,2.4}, X{3.2,0.0,2.4}, X{3.525,0.25,2.49375}, X{2.8,0.25,2.475}, X{3.45,0.15,2.5125}, X{2.9,0.15,2.475}, X{3.2,0.15,2.4}, X{2.8,0.15,2.4}, X{0.0,0.0,3.15}, X{0.0,-0.002,3.15}, X{0.002,0.0,3.15}, X{0.8,0.0,3.15}, X{0.8,-0.45,3.15}, X{0.45,-0.8,3.15}, X{0.0,-0.8,3.15}, X{0.0,0.0,2.85}, X{0.2,0.0,2.7}, X{0.2,-0.112,2.7}, X{0.112,-0.2,2.7}, X{0.0,-0.2,2.7}, X{-0.002,0.0,3.15}, X{-0.45,-0.8,3.15}, X{-0.8,-0.45,3.15}, X{-0.8,0.0,3.15}, X{-0.112,-0.2,2.7}, X{-0.2,-0.112,2.7}, X{-0.2,0.0,2.7}, X{0.0,0.002,3.15}, X{-0.8,0.45,3.15}, X{-0.45,0.8,3.15}, X{0.0,0.8,3.15}, X{-0.2,0.112,2.7}, X{-0.112,0.2,2.7}, X{0.0,0.2,2.7}, X{0.45,0.8,3.15}, X{0.8,0.45,3.15}, X{0.112,0.2,2.7}, X{0.2,0.112,2.7}, X{0.4,0.0,2.55}, X{0.4,-0.224,2.55}, X{0.224,-0.4,2.55}, X{0.0,-0.4,2.55}, X{1.3,0.0,2.55}, X{1.3,-0.728,2.55}, X{0.728,-1.3,2.55}, X{0.0,-1.3,2.55}, X{1.3,0.0,2.4}, X{1.3,-0.728,2.4}, X{0.728,-1.3,2.4}, X{0.0,-1.3,2.4}, X{-0.224,-0.4,2.55}, X{-0.4,-0.224,2.55}, X{-0.4,0.0,2.55}, X{-0.728,-1.3,2.55}, X{-1.3,-0.728,2.55}, X{-1.3,0.0,2.55}, X{-0.728,-1.3,2.4}, X{-1.3,-0.728,2.4}, X{-1.3,0.0,2.4}, X{-0.4,0.224,2.55}, X{-0.224,0.4,2.55}, X{0.0,0.4,2.55}, X{-1.3,0.728,2.55}, X{-0.728,1.3,2.55}, X{0.0,1.3,2.55}, X{-1.3,0.728,2.4}, X{-0.728,1.3,2.4}, X{0.0,1.3,2.4}, X{0.224,0.4,2.55}, X{0.4,0.224,2.55}, X{0.728,1.3,2.55}, X{1.3,0.728,2.55}, X{0.728,1.3,2.4}, X{1.3,0.728,2.4}, X{0.0,0.0,0.0}, X{1.5,0.0,0.15}, X{1.5,0.84,0.15}, X{0.84,1.5,0.15}, X{0.0,1.5,0.15}, X{1.5,0.0,0.075}, X{1.5,0.84,0.075}, X{0.84,1.5,0.075}, X{0.0,1.5,0.075}, X{1.425,0.0,0.0}, X{1.425,0.798,0.0}, X{0.798,1.425,0.0}, X{0.0,1.425,0.0}, X{-0.84,1.5,0.15}, X{-1.5,0.84,0.15}, X{-1.5,0.0,0.15}, X{-0.84,1.5,0.075}, X{-1.5,0.84,0.075}, X{-1.5,0.0,0.075}, X{-0.798,1.425,0.0}, X{-1.425,0.798,0.0}, X{-1.425,0.0,0.0}, X{-1.5,-0.84,0.15}, X{-0.84,-1.5,0.15}, X{0.0,-1.5,0.15}, X{-1.5,-0.84,0.075}, X{-0.84,-1.5,0.075}, X{0.0,-1.5,0.075}, X{-1.425,-0.798,0.0}, X{-0.798,-1.425,0.0}, X{0.0,-1.425,0.0}, X{0.84,-1.5,0.15}, X{1.5,-0.84,0.15}, X{0.84,-1.5,0.075}, X{1.5,-0.84,0.075}, X{0.798,-1.425,0.0}, X{1.425,-0.798,0.0}, X}; END_OF_ducks.c if test 5617 -ne `wc -c patches.c <<'END_OF_patches.c' X#include "tea.h" X Xpt patches[PATCH_COUNT] = { X{{1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,16}}, X{{4,17,18,19},{8,20,21,22},{12,23,24,25},{16,26,27,28}}, X{{19,29,30,31},{22,32,33,34},{25,35,36,37},{28,38,39,40}}, X{{31,41,42,1},{34,43,44,5},{37,45,46,9},{40,47,48,13}}, X{{13,14,15,16},{49,50,51,52},{53,54,55,56},{57,58,59,60}}, X{{16,26,27,28},{52,61,62,63},{56,64,65,66},{60,67,68,69}}, X{{28,38,39,40},{63,70,71,72},{66,73,74,75},{69,76,77,78}}, X{{40,47,48,13},{72,79,80,49},{75,81,82,53},{78,83,84,57}}, X{{57,58,59,60},{85,86,87,88},{89,90,91,92},{93,94,95,96}}, X{{60,67,68,69},{88,97,98,99},{92,100,101,102},{96,103,104,105}}, X{{69,76,77,78},{99,106,107,108},{102,109,110,111},{105,112,113,114}}, X{{78,83,84,57},{108,115,116,85},{111,117,118,89},{114,119,120,93}}, X{{121,122,123,124},{125,126,127,128},{129,130,131,132},{133,134,135,136}}, X{{124,137,138,121},{128,139,140,125},{132,141,142,129},{136,143,144,133}}, X{{133,134,135,136},{145,146,147,148},{149,150,151,152},{69,153,154,155}}, X{{136,143,144,133},{148,156,157,145},{152,158,159,149},{155,160,161,69}}, X{{162,163,164,165},{166,167,168,169},{170,171,172,173},{174,175,176,177}}, X{{165,178,179,162},{169,180,181,166},{173,182,183,170},{177,184,185,174}}, X{{174,175,176,177},{186,187,188,189},{190,191,192,193},{194,195,196,197}}, X{{177,184,185,174},{189,198,199,186},{193,200,201,190},{197,202,203,194}}, X{{204,204,204,204},{207,208,209,210},{211,211,211,211},{212,213,214,215}}, X{{204,204,204,204},{210,217,218,219},{211,211,211,211},{215,220,221,222}}, X{{204,204,204,204},{219,224,225,226},{211,211,211,211},{222,227,228,229}}, X{{204,204,204,204},{226,230,231,207},{211,211,211,211},{229,232,233,212}}, X{{212,213,214,215},{234,235,236,237},{238,239,240,241},{242,243,244,245}}, X{{215,220,221,222},{237,246,247,248},{241,249,250,251},{245,252,253,254}}, X{{222,227,228,229},{248,255,256,257},{251,258,259,260},{254,261,262,263}}, X{{229,232,233,212},{257,264,265,234},{260,266,267,238},{263,268,269,242}}, X{{270,270,270,270},{279,280,281,282},{275,276,277,278},{271,272,273,274}}, X{{270,270,270,270},{282,289,290,291},{278,286,287,288},{274,283,284,285}}, X{{270,270,270,270},{291,298,299,300},{288,295,296,297},{285,292,293,294}}, X{{270,270,270,270},{300,305,306,279},{297,303,304,275},{294,301,302,271}} X}; END_OF_patches.c if test 2266 -ne `wc -c tea.c <<'END_OF_tea.c' X#include "tea.h" X#include X Xextern dt ducks[DUCK_COUNT]; Xextern pt patches[PATCH_COUNT]; X Xint pixwindd(); X Xstruct vwsurf vwsurf = DEFAULT_VWSURF(pixwindd); X X#define RPD(i) ((float)i * 0.017453292519) X Xmain(argc, argv) int argc; char *argv[]; X{ X int i = 6; X X if(argc > 1){ X i = atoi(argv[1]); X i = (i > 0) ? i : 6; X } X X initialize_core(DYNAMICC, NOINPUT, THREED); X initialize_view_surface(&vwsurf, FALSE); X select_view_surface(&vwsurf); X set_viewport_3(0.0, 1.0, 0.0, 0.75, 0.0, 1.0); X set_window(-5.0, 5.0, -5.0, 5.0); X X set_image_transformation_type(XFORM3); X X create_retained_segment(1024); X display_patches(i); X close_retained_segment(1024); X sleep(5); X X set_segment_image_transformation_3(1024, 1.0,1.0,0.15, RPD(90),0.0,0.0, 0.0,0.2,0.0); X sleep(2); X set_segment_image_transformation_3(1024, 1.0,1.0,0.15, RPD(90),RPD(90),0.0, 0.0,0.2,0.0); X sleep(2); X set_segment_image_transformation_3(1024, 1.0,1.0,0.15, RPD(45),0.0,0.0, 0.0,0.0,0.0); X sleep(2); X set_segment_image_transformation_3(1024, 1.0,1.0,0.15, RPD(45),RPD(45),0.0, 0.0,0.0,0.0); X sleep(2); X X deselect_view_surface(&vwsurf); X terminate_core(); X} X Xvoid blend_vector(d0, d1, d2, d3, t, r) Xdt d0, d1, d2, d3; Xfloat t; Xdt *r; X{ X r->x = d0.x*(1-t)*(1-t)*(1-t) + d1.x*3*t*(1-t)*(1-t) + X d2.x*3*t*t*(1-t) + d3.x*t*t*t; X X r->y = d0.y*(1-t)*(1-t)*(1-t) + d1.y*3*t*(1-t)*(1-t) + X d2.y*3*t*t*(1-t) + d3.y*t*t*t; X X r->z = d0.z*(1-t)*(1-t)*(1-t) + d1.z*3*t*(1-t)*(1-t) + X d2.z*3*t*t*(1-t) + d3.z*t*t*t; X} X Xvoid display_curve (d0, d1, d2, d3, steps) Xdt d0, d1, d2, d3; Xint steps; X{ X dt tmp; X float t, step; X X t = step = (1.0 / (float)steps); X X move_abs_3(d0.x, d0.y, d0.z); X while(t < (1.0 + step / 2.0)){ X blend_vector(d0, d1, d2, d3, t, &tmp); X line_abs_3(tmp.x, tmp.y, tmp.z); X t += step; X } X} X Xvoid display_patch(patch, steps) Xpt patch; Xint steps; X{ X float t, step; X dt d0, d1, d2, d3; X X t = 0; X step = (1.0 / (float)steps); X while(t < (1.0 + step / 2.0)) { X blend_vector(ducks[patch[0][0]-1],ducks[patch[0][1]-1], X ducks[patch[0][2]-1],ducks[patch[0][3]-1], t, &d0); X X blend_vector(ducks[patch[1][0]-1],ducks[patch[1][1]-1], X ducks[patch[1][2]-1],ducks[patch[1][3]-1], t, &d1); X X blend_vector(ducks[patch[2][0]-1],ducks[patch[2][1]-1], X ducks[patch[2][2]-1],ducks[patch[2][3]-1], t, &d2); X X blend_vector(ducks[patch[3][0]-1],ducks[patch[3][1]-1], X ducks[patch[3][2]-1],ducks[patch[3][3]-1], t, &d3); X X display_curve(d0, d1, d2, d3, steps); X X blend_vector(ducks[patch[0][0]-1],ducks[patch[1][0]-1], X ducks[patch[2][0]-1],ducks[patch[3][0]-1], t, &d0); X X blend_vector(ducks[patch[0][1]-1],ducks[patch[1][1]-1], X ducks[patch[2][1]-1],ducks[patch[3][1]-1], t, &d1); X X blend_vector(ducks[patch[0][2]-1],ducks[patch[1][2]-1], X ducks[patch[2][2]-1],ducks[patch[3][2]-1], t, &d2); X X blend_vector(ducks[patch[0][3]-1],ducks[patch[1][3]-1], X ducks[patch[2][3]-1],ducks[patch[3][3]-1], t, &d3); X X display_curve(d0, d1, d2, d3, steps); X t += step; X } X} X Xdisplay_patches(s) int s; X{ X int i; X X for(i=0;itea.h <<'END_OF_tea.h' X#define DEGREE 4 X#define DUCK_COUNT 306 X#define PATCH_COUNT 32 X Xtypedef struct { X float x, y, z; X} dt; X Xtypedef int pt[DEGREE][DEGREE]; END_OF_tea.h if test 137 -ne `wc -c