[comp.sources.amiga] v90i065: Surf r2 - bezier surfaces of revolution, Part03/04

Amiga-Request@cs.odu.edu (Amiga Sources/Binaries Moderator) (02/11/90)

Submitted-by: <edavies@sanjuan.uvic.ca>
Posting-number: Volume 90, Issue 065
Archive-name: applications/surf-r2/part03

#!/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 <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of archive 3 (of 4)."
# Contents:  functions.h mergergb.c poly.c readilbm.c scrnops.c tov3d.c
# Wrapped by tadguy@xanth on Sat Feb 10 15:47:42 1990
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'functions.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'functions.h'\"
else
echo shar: Extracting \"'functions.h'\" \(9629 characters\)
sed "s/^X//" >'functions.h' <<'END_OF_FILE'
Xtypedef	long	cList;
X
Xlong					AbleICR();
Xvoid					AbortIO();
Xlong					ActivateGadget();
Xvoid					ActivateWindow();
Xvoid					AddAnimOb();
Xvoid					AddBob();
Xvoid					AddConfigDev();
Xvoid					AddDevice();
Xlong					AddDosNode();
Xvoid					AddFont();
Xlong					AddFreeList();
Xshort					AddGadget();
Xunsigned short			AddGList();
Xvoid					AddHead();
Xstruct Interrupt *		AddICRVector();
Xvoid					AddIntServer();
Xvoid					AddLibrary();
Xlong					AddMemList();
Xvoid					AddPort();
Xvoid					AddResource();
Xvoid					AddSemaphore();
Xvoid					AddTail();
Xvoid					AddTask();
Xvoid					AddTime();
Xvoid					AddVSprite();
Xlong					Alert();
Xvoid *					AllocAbs();
Xlong					AllocBoardMem();
XcList					AllocCList();
Xstruct ConfigDev *		AllocConfigDev();
Xstruct MemList *		AllocEntry();
Xlong					AllocExpansionMem();
Xvoid *					AllocMem();
Xlong					AllocPotBits();
Xvoid *					AllocRaster();
Xchar *					AllocRemember();
Xlong					AllocSignal();
Xlong					AllocTrap();
Xstruct WBObject *		AllocWBObject();
Xvoid *					Allocate();
Xvoid					AlohaWorkbench();
Xvoid					AndRectRegion();
Xlong					AndRegionRegion();
Xvoid					Animate();
Xshort					AreaDraw();
Xlong					AreaEllipse();
Xvoid					AreaEnd();
Xshort					AreaMove();
Xvoid					AskFont();
Xlong					AskSoftStyle();
Xlong					AttemptLockLayerRom();
Xlong					AttemptSemaphore();
Xshort					AutoRequest();
Xlong					AvailFonts();
Xlong					AvailMem();
Xvoid					BeginIO();
Xvoid					BeginRefresh();
Xvoid					BeginUpdate();
Xvoid					BeginLayer();
Xlong					BltBitMap();
Xlong					BltBitMapRastPort();
Xvoid					BltClear();
Xvoid					BltMaskBitMapRastPort();
Xvoid					BltPattern();
Xvoid					BltTemplate();
Xstruct Window *			BuildSysRequest();
Xchar *					BumpRevision();
Xvoid					Cause();
Xvoid					CBump();
Xvoid					CDInputHandler();
Xvoid					ChangeSprite();
Xstruct IORequest *		CheckIO();
Xshort					ClearDMRequest();
Xvoid					ClearEOL();
Xvoid					ClearMenuStrip();
Xvoid					ClearPointer();
Xvoid					ClearRegion();
Xlong					ClearRectRegion();
Xvoid					ClearScreen();
Xvoid					ClipBit();
Xvoid					Close();
Xvoid					CloseDevice();
Xvoid					CloseFont();
Xvoid					CloseLibrary();
Xvoid					CloseScreen();
Xvoid					CloseWindow();
Xshort					CloseWorkBench();
Xvoid					CMove();
Xshort					CmpTime();
Xlong					ConcatCList();
Xlong					ConfigBoard();
Xlong					ConfigChain();
Xlong					ConsoleDevice();
Xlong					CopperListInit();
XcList					CopyCList();
Xvoid					CopyMem();
Xvoid					CopyMemQuick();
Xvoid					CopySBitMap();
Xvoid					CreateBehindLayer();
Xstruct Lock *			CreateDir();
Xstruct MsgPort *		CreatePort();
Xstruct Process *		CreateProc();
Xstruct IOStdReq *		CreateStdIO();
Xstruct Task *			CreateTask();
Xvoid					CreateUpfrontLayer();
Xstruct Lock *			CurrentDir();
Xvoid					CurrentTime();
Xvoid					CWait();
Xlong *					DateStamp();
Xvoid					Deallocate();
Xvoid					Debug();
Xvoid					Delay();
Xshort					DeleteFile();
Xvoid					DeleteLayer();
Xvoid					DeletePort();
Xvoid					DeleteStdIO();
Xvoid					DeleteTask();
Xstruct Process *		DeviceProc();
Xvoid					Disable();
Xvoid					DisownBlitter();
Xshort					DisplayAlert();
Xvoid					DisplayBeep();
Xvoid					DisposeRegion();
Xvoid					DoCollision();
Xlong					DoIO();
Xshort					DoubleClick();
Xvoid					Draw();
Xvoid					DrawBorder();
Xvoid					DrawEllipse();
Xvoid					DrawGList();
Xvoid					DrawImage();
Xstruct Lock *			DupLock();
Xvoid					Enable();
Xvoid					EndRefresh();
Xvoid					EndRequest();
Xvoid					EndUpdate();
Xvoid					Enqueue();
Xshort					ExNext();
Xshort					Examine();
Xshort					Execute();
Xvoid					Exit();
Xstruct ConfigDev *		FindConfigDev();
Xstruct Node *			FindName();
Xstruct MsgPort *		FindPort();
Xlong					FindResident();
Xstruct SignalSemaphore *FindSemaphore();
Xstruct Task *			FindTask();
Xchar *					FindToolType();
Xvoid					Flood();
Xvoid					FlushCList();
Xvoid					Forbid();
Xvoid					FreeBoardMem();
Xvoid					FreeCList();
Xvoid					FreeColorMap();
Xvoid					FreeConfigDev();
Xvoid					FreeCopList();
Xvoid					FreeCprList();
Xvoid					FreeDiskObject();
Xvoid					FreeEntry();
Xvoid					FreeExpansionMem();
Xvoid					FreeFreeList();
Xvoid					FreeGBuffers();
Xvoid					FreeMem();
Xvoid					FreePotBits();
Xvoid					FreeRaster();
Xvoid					FreeRemember();
Xvoid					FreeSignal();
Xvoid					FreeSprite();
Xvoid					FreeSysRequest();
Xvoid					FreeTrap();
Xvoid					FreeVPortCopLists();
Xvoid					FreeWBObject();
Xlong					GetCC();
Xlong					GetCLBuf();
Xshort					GetCLChar();
Xshort					GetCLWord();
Xstruct ColorMap *		GetColorMap();
Xlong					GetCurrentBinding();
Xstruct Preferences *	GetDefPrefs();
Xstruct DiskObject *		GetDiskObject();
Xvoid					GetGBuffers();
Xlong					GetIcon();
Xstruct Message *		GetMsg();
Xstruct Preferences *	GetPrefs();
Xshort					GetRGB4();
Xlong					GetScreenData();
Xshort					GetSprite();
Xstruct WBObject *		GetWBObject();
Xlong					IncrCLMark();
Xshort					Info();
Xvoid					InitArea();
Xvoid					InitBitMap();
Xlong					InitCLPool();
Xvoid					InitCode();
Xvoid					InitGMasks();
Xvoid					InitGels();
Xvoid					InitMasks();
Xvoid					InitRastPort();
Xvoid					InitRequester();
Xvoid					InitResident();
Xvoid					InitSemaphore();
Xvoid					InitStruct();
Xvoid					InitTmpRas();
Xvoid					InitVPort();
Xvoid					InitView();
Xstruct FileHandle *		Input();
Xvoid					Insert();
Xstruct Region *			InstallClipRegion();
Xlong					IntuiTextLength();
Xstruct InputEvent *		Intuition();
Xlong					IoErr();
Xshort					IsInteractive();
Xstruct MenuItem *		ItemAddress();
Xvoid					LoadRGB4();
Xstruct Segment *		LoadSeg();
Xvoid					LoadView();
Xstruct Lock *			Lock();
Xvoid					LockLayer();
Xvoid					LockLayerInfo();
Xvoid					LockLayerRom();
Xvoid					LockLayers();
Xstruct DeviceNode *		MakeDosNode();
Xlong					MakeFunctions();
Xstruct Library *		MakeLibrary();
Xvoid					MakeScreen();
Xvoid					MakeVPort();
Xlong					MarkCList();
Xlong					MatchToolValue();
Xvoid					ModifyIDCMP();
Xvoid					ModifyProp();
Xvoid					Move();
Xvoid					MoveLayer();
Xvoid					MoveScreen();
Xvoid					MoveSprite();
Xvoid					MoveWindow();
Xvoid					MrgCop();
Xvoid					NewList();
Xvoid					NewModifyProp();
Xstruct Region *			NewRegion();
Xvoid					ObtainConfigBinding();
Xvoid					ObtainSemaphore();
Xvoid					ObtainSemaphoreList();
Xvoid					OffGadget();
Xvoid					OffMenu();
Xvoid					OnGadget();
Xvoid					OnMenu();
Xstruct FileHandle *		Open();
Xlong					OpenDevice();
Xstruct Font *			OpenDiskFont();
Xstruct Font *			OpenFont();
Xvoid					OpenIntuition();
Xstruct Library *		OpenLibrary();
Xstruct MiscResource *	OpenResource();
Xstruct Screen *			OpenScreen();
Xstruct Window *			OpenWindow();
Xshort					OpenWorkBench();
Xvoid					OrRectRegion();
Xlong					OrRegionRegion();
Xstruct FileHandle *		Output();
Xvoid					OwnBlitter();
Xstruct Lock *			ParentDir();
Xshort					PeekCLMark();
Xvoid					Permit();
Xvoid					PolyDraw();
Xvoid					PrintIText();
Xlong					PutCLBuf();
Xlong					PutCLChar();
Xlong					PutCLWord();
Xshort					PutDiskObject();
Xlong					PutIcon();
Xvoid					PutMsg();
Xlong					PutWBObject();
Xvoid					QBSBlit();
Xvoid					QBlit();
Xshort					RawKeyConvert();
Xlong					Read();
Xchar					ReadExpansionByte();
Xlong					ReadExpansionRom();
Xshort					ReadPixel();
Xvoid					RectFill();
Xvoid					RefreshGadgets();
Xvoid					RefreshGList();
Xvoid					RefreshWindowFrame();
Xvoid					ReleaseConfigBinding();
Xvoid					ReleaseSemaphore();
Xvoid					ReleaseSemaphoreList();
Xvoid					RemConfigDev();
Xvoid					RemDevice();
Xvoid					RemFont();
Xstruct Node *			RemHead();
Xvoid					RemIBob();
Xvoid					RemICRVector();
Xvoid					RemIntServer();
Xlong					RemLibrary();
Xunsigned short			RemoveGList();
Xvoid					RemPort();
Xvoid					RemResource();
Xvoid					RemSemaphore();
Xstruct Node *			RemTail();
Xvoid					RemTask();
Xvoid					RemVSprite();
Xvoid					RemakeDisplay();
Xvoid					Remove();
Xunsigned short			RemoveGadget();
Xshort					Rename();
Xvoid					ReplyMsg();
Xvoid					ReportMouse();
Xshort					Request();
Xvoid					RethinkDisplay();
Xvoid					ScreenToBack();
Xvoid					ScreenToFront();
Xvoid					ScrollLayer();
Xvoid					ScrollRaster();
Xvoid					ScrollVPort();
Xlong					Seek();
Xvoid					SendIO();
Xvoid					SetAPen();
Xvoid					SetBPen();
Xvoid					SetCollision();
Xshort					SetComment();
Xvoid					SetCurrentBinding();
Xshort					SetDMRequest();
Xvoid					SetDRMd();
Xlong					SetExcept();
Xlong					SetFont();
Xlong					SetFunction();
Xlong					SetICR();
Xstruct Interrupt *		SetIntVector();
Xvoid					SetMenuStrip();
Xvoid					SetPointer();
Xvoid					SetPrefs();
Xshort					SetProtection();
Xvoid					SetRast();
Xvoid					SetRGB4();
Xvoid					SetRGB4CM();
Xlong					SetSR();
Xlong					SetSignal();
Xlong					SetSoftStyle();
Xshort					SetTaskPri();
Xvoid					SetWindowTitles();
Xvoid					ShowTitle();
Xvoid					Signal();
Xlong					SizeCList();
Xvoid					SizeLayer();
Xvoid					SizeWindow();
Xvoid					SortGList();
XcList					SplitCList();
XcList					SubCList();
Xvoid					SubTime();
Xvoid					SubLibrary();
Xvoid					SumKickData();
Xlong					SuperState();
Xvoid					SwapBitsRastPortClipRect();
Xvoid					SyncSBitMap();
Xlong					Text();
Xlong					TextLength();
Xlong					Translate();
Xlong					UnGetCLChar();
Xlong					UnGetCLWord();
Xvoid					UnLoadSeg();
Xvoid					UnLock();
Xshort					UnPutCLChar();
Xshort					UnPutCLWord();
Xvoid					UnlockLayer();
Xvoid					UnlockLayerInfo();
Xvoid					UnlockLayerRom();
Xvoid					UnlockLayers();
Xvoid					UpfrontLayer();
Xvoid					UserState();
Xshort					VBeamPos();
Xstruct View *			ViewAddress();
Xstruct ViewPort *		ViewPortAddress();
Xshort					WBenchToBack();
Xshort					WBenchToFront();
Xlong					Wait();
Xvoid					WaitBOVP();
Xvoid					WaitBlit();
Xshort					WaitForChar();
Xlong					WaitIO();
Xstruct Message *		WaitPort();
Xvoid					WaitTOF();
Xstruct Layer *			WhichLayer();
Xshort					WindowLimits();
Xvoid					WindowToBack();
Xvoid					WindowToFront();
Xlong					Write();
Xlong					WriteExpansionByte();
Xvoid					WritePixel();
Xvoid					WritePotgo();
Xvoid					XorRectRegion();
Xlong					XorRegionRegion();
X
END_OF_FILE
if test 9629 -ne `wc -c <'functions.h'`; then
    echo shar: \"'functions.h'\" unpacked with wrong size!
fi
# end of 'functions.h'
fi
if test -f 'mergergb.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'mergergb.c'\"
else
echo shar: Extracting \"'mergergb.c'\" \(7542 characters\)
sed "s/^X//" >'mergergb.c' <<'END_OF_FILE'
X/*
X * This program, when called with arg "smith", tries to read smith.r, smith.g
X * and smith.b, and write a combined raw data file acceptable to RAY2, called
X * smith.tmp
X */
X#include <stdio.h>
X#include "mytypes.h"
X
X#define RED 0
X#define GRN 1
X#define BLU 2
X#define NumPrims 3 /* number of primary colors */
X
X#define MakeID(a,b,c,d) ( ((a)<<24) | ((b)<<16) | ((c)<<8) | (d) )
X
X#define ID_FORM MakeID('F','O','R','M')
X#define ID_ILBM MakeID('I','L','B','M')
X#define ID_BMHD MakeID('B','M','H','D')
X#define ID_CMAP MakeID('C','M','A','P')
X#define ID_CAMG MakeID('C','A','M','G')
X#define ID_BODY MakeID('B','O','D','Y')
X
X#define ROUNDUP(x) ( ((x)+1) & (~1L) )
X
Xstruct CHUNK {
X    unsigned long Id, Size;
X} Chunk;
X
Xstruct BMHD {
X    short w,h,x,y;
X    char npl,mask,compress,pad1;
X    short transparentColor;
X    char xAspect,yAspect;
X    short pageWidth,pageHeight;
X};
X
X/*
X * compare width and height of two bit maps
X * return false if equal
X */
Xbool CmpBMHD(a, b)
X    struct BMHD *a, *b;
X{
X    return( a->w != b->w ||
X            a->h != b->h ||
X          a->npl != b->npl
X          );
X}
X
X
Xstruct BMHD bmhd[NumPrims];
Xstatic FILE *ftrip[NumPrims], *fout;
Xchar *nametrip[NumPrims];
Xchar *oname;
Xbool FileError;
Xshort depth;
X
Xunsigned char colmap[NumPrims][32][3];
X
X
X/*
X * read len bytes from selected file
X */
Xvoid FRead(buffer, len, filenum)
X    char *buffer;
X    int len, filenum;
X{
X    if( fread(buffer, len, 1, ftrip[filenum]) == 0 ) {
X        fprintf(stderr, "read error in %s\n", nametrip[filenum] );
X        exit(-1);
X    }
X}
X
X
X
X#define ABORT(str) { fprintf(stderr,str); exit(-1); }
X
X#define ReadChunk()  FRead(&Chunk, sizeof(Chunk), filenum)
X
Xvoid ReadIffHeaders(filenum)
X    int filenum;
X{
X    long    ILBMid;
X    bool cmapFlag = false,
X         bmhdFlag = false;
X    short i;
X
X
X    ReadChunk ();
X    if (Chunk.Id != ID_FORM)
X        ABORT ("Not an IFF File");
X
X    FRead (&ILBMid, 4, filenum);
X    if (ILBMid != ID_ILBM)
X        ABORT ("Not an ILBM File");
X
X    while (1) {
X        long camgdata;
X
X        ReadChunk ();
X
X        if (Chunk.Id == ID_BODY) {
X            if (!cmapFlag) {
X                printf("no cmap before body in %s\n", nametrip[filenum]);
X                FileError = true;
X            }
X            if (!bmhdFlag) {
X                printf("no bmhd before the body in %s\n", nametrip[filenum]);
X                FileError = true;
X            }
X            return;
X        }
X
X        if( feof( ftrip[filenum] ) ) {
X            printf("reached end of file without seeing body in %s\n", nametrip[filenum]);
X            FileError = true;
X            return;
X        }
X
X        switch (Chunk.Id) {
X            case ID_CMAP:
X                FRead (colmap[filenum], Chunk.Size, filenum);
X                for (i = 0; i < 32; i++) {
X                    colmap[filenum][i][filenum] >>= 4;
X                }
X                cmapFlag = true;
X                break;
X            case ID_BMHD:
X                FRead(&bmhd[filenum], Chunk.Size, filenum);
X                bmhdFlag = true;
X                break;
X            case ID_CAMG:
X                FRead( &camgdata, sizeof(camgdata),filenum );
X                break;
X            default:            /* unknown identifier */
X                fseek( ftrip[filenum], Chunk.Size, 1);
X                break;
X        }
X    }
X}
X
X
X/*
X * leftmost pixel of byte is in most significant bit of byte
X */
Xstatic char GetIlbmVal( rastlist, h)
X    char *rastlist[6];
X    int h;
X{
X    int i;
X    char value = 0;
X    short mask, bytep;
X
X    mask = 0x80 >> ( h & 7);
X    bytep = h >> 3;
X
X    for( i = depth-1; i >= 0; i-- ) {
X        value <<= 1;
X        value |= (*(rastlist[i]+bytep) & mask) ? 1: 0;
X    }
X    return( value );
X}
X
X/*
X * decompress a runlength row of bytes
X */
Xstatic void ReadDecomLine(linebytes, rp, filenum)
X    int linebytes, filenum;
X    char *rp;
X{
X    int runlen;
X    char pixel;
X
X    while (linebytes) {
X        runlen = getc (ftrip[filenum]);
X        if (runlen > 127)
X            runlen -= 256;
X        if (runlen >= 0) {
X            runlen++;
X            FRead (rp, runlen, filenum);
X            rp += runlen;
X            linebytes -= runlen;
X        }
X        else {
X            runlen = -runlen + 1;
X            linebytes -= runlen;
X            pixel = getc (ftrip[filenum]);
X            do
X                *(rp++) = pixel;
X            while (--runlen);
X        }
X    }
X}
X/*
X * read raster line from one of the color files
X */
Xvoid LoadRaster(raster, ByteWidth, filenum)
X    char *raster[6];
X    int ByteWidth, filenum;
X{
X    if(bmhd[filenum].compress = 0) {
X        FRead (raster, ByteWidth * depth, filenum);
X    }
X    else {
X        short i;
X        for( i = 0; i < depth; i++) {
X            ReadDecomLine( ByteWidth, raster[i], filenum);
X        }
X    }
X}
X
X/*
X * write intensity values for a given gun
X * note: I've made dirty assumption about byte ordering in a short word
X * if you run this on an ibm (ha ha ha) you'll have to change it
X */
X#define ChipSize 4
Xvoid SaveRaster( raster, width, prim)
X    char *raster[];
X    int width, prim;
X{
X    short i, j;
X    unsigned short val;
X
X    for( i = 0; i < width; i += ChipSize ) {
X        val = colmap[prim][GetIlbmVal(raster, i+3)][prim] << ChipSize;
X        val |= colmap[prim][GetIlbmVal(raster, i+2)][prim];
X        fputc( val&0xff, fout);
X        val = colmap[prim][GetIlbmVal(raster, i+1)][prim] << ChipSize;
X        val |= colmap[prim][GetIlbmVal(raster, i+0)][prim];
X        fputc( val&0xff, fout);
X    }
X}
X
X/*
X * translate body of file to format RAY2 likes
X */
Xvoid TranslateRay2Body()
X{
X    int BytesWidth;
X    int row, height, width, plane, prim;
X    char *raster[6];
X
X    depth = bmhd[0].npl;
X    width = bmhd[0].w;
X    height = bmhd[0].h;
X    BytesWidth = (width + 7)/8 ;
X
X    for( plane = 0; plane < bmhd[0].npl; plane++ ) {
X        raster[plane] = (char *)malloc(BytesWidth);
X    }
X
X    for( row = 0; !FileError && row < height; row++ ) {
X        fputc((unsigned char)(row>>8),fout);      /* write line number */
X        fputc((unsigned char)(row&0xff),fout);
X
X        for( prim = RED; prim <= BLU; prim++ ) {
X            LoadRaster( raster, BytesWidth, prim);
X            SaveRaster( raster, width, prim);
X        }
X    }
X}
X
X
X
Xmain(argc, argv)
X    int argc;
X    char *argv[];
X{
X    char buff[4][80];
X    char *extensions = "rgb";
X    int i;
X
X    if( argc == 1 || *argv[1] == '?' ) {
X        fprintf(stderr,"usage:  merge filename\n");
X        exit(-1);
X    }
X    FileError = false;
X
X    for( i = 0; i < NumPrims; i++ ) {
X        sprintf(buff[i], "%s.%c", argv[1], extensions[i]);
X        nametrip[i] = buff[i];
X        ftrip[i] = fopen(nametrip[i],"r");
X        if(!ftrip[i]) {
X            fprintf(stderr,"unable to read %s\n", nametrip[i]);
X            FileError = true;
X        }
X    }
X
X    sprintf(buff[3], "%s.tmp", argv[1]);
X    oname = (argc>2)? argv[2]: buff[3];
X    fout = fopen( oname,"w");
X    if(!fout) {
X        fprintf(stderr,"unable to write to %s\n", oname);
X        FileError = true;
X    }
X
X    if( FileError ) goto ErrorExit;
X
X    for( i = 0; i < NumPrims; i++ ) {
X        printf("reading header %d\n", i);
X        ReadIffHeaders(i);
X    }
X
X    for( i = 1; i < NumPrims; i++ ) {
X        if( CmpBMHD(&bmhd[0], &bmhd[i])) {
X            fprintf(stderr,"image sizes differ(r != %d)\n", i);
X            FileError = true;
X        }
X    }
X
X    if( FileError ) goto ErrorExit;
X    printf("about to translate body\n");
X    TranslateRay2Body();
X
X    ErrorExit:
X        for( i = 0; i < NumPrims; i++) {
X            if(ftrip[i]) fclose( ftrip[i] );
X        }
X        if(fout) fclose(fout);
X}
X
X
END_OF_FILE
if test 7542 -ne `wc -c <'mergergb.c'`; then
    echo shar: \"'mergergb.c'\" unpacked with wrong size!
fi
# end of 'mergergb.c'
fi
if test -f 'poly.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'poly.c'\"
else
echo shar: Extracting \"'poly.c'\" \(8961 characters\)
sed "s/^X//" >'poly.c' <<'END_OF_FILE'
X#include <math.h>
X#include "mytypes.h"
X#include "scrnio.h"
X#include "bezpt.h"
X#include "revolve.h"
X#include "control.h"
X#include "poly.h"
X#include "readilbm.h"
X#include "menuexp.h"
X
Xbool  SpecOn = false; /* specular lighting enable - default off */
X
Xfloat Ambience = DefAmbience;
Xfloat PtIntensity = (float)DefIntensity;
Xfloat Kd = DefKd,
X      Ks = DefKs;
X
XPt3 LightSrc = {
X        DefLightSrcX,
X        DefLightSrcY,
X        DefLightSrcZ
X        };
X
Xstatic
XRhomboid *polylist = null,
X         *nextpoly;
X
XMapRhomboid *mpolylist = null,
X        *mnextpoly;
X
Xstatic
Xint polyspace = 0;
X
X
Xstatic bool shadeflag;
X
Xlong CalcMaxPolyNum() {
X    return( GetNumSegs() * BezMesh * RevMesh );
X}
X
Xstatic
Xbool PrepPoly()
X{
X        if( polylist ) free( (char *)polylist );
X        polylist = (Rhomboid *)malloc( CalcMaxPolyNum() * sizeof(Rhomboid));
X        if( !polylist ) {
X            OutErr("PrepPoly: not enough memory");
X            return( true );
X        }
X        nextpoly = polylist;
X        return(false); /* success = 0 */
X}
X
X
Xstatic bool
XPrepMPoly()
X{
X        if( mpolylist ) free( (char *)mpolylist );
X        mpolylist = (MapRhomboid *)
X                    malloc( CalcMaxPolyNum() * sizeof(MapRhomboid));
X        if( !mpolylist ) {
X            OutErr("PrepPoly: not enough memory");
X            return( true );
X        }
X        mnextpoly = mpolylist;
X        return(false); /* success = 0 */
X}
X
X
X/*
X * Multiply a vector by scalar quantity
X */
Xvoid ScaleVec( fact, src, dst )
X        float fact;
X        Pt3 *src, *dst;
X{
X        dst->x = src->x * fact;
X        dst->y = src->y * fact;
X        dst->z = src->z * fact;
X}
X/*
X * convert a vector to a unitized vector
X * if possible
X */
Xvoid Unitize( vec )
X        Pt3 *vec;
X{
X        float len;
X
X        len = vec->x*vec->x + vec->y*vec->y + vec->z*vec->z;
X        len = sqrt( len );
X        if( len != 0.0 ) {
X                vec->x /= len;
X                vec->y /= len;
X                vec->z /= len;
X        }
X}
X
X/*
X * calculate a vector from two points
X */
Xvoid CalcVector( src1, src2, dest )
XPt3 *src1, *src2, *dest ;
X{
X        dest->x = src1->x - src2->x;
X        dest->y = src1->y - src2->y;
X        dest->z = src1->z - src2->z;
X}
X
X
X
X
X/*
X * calculate a normal from a list of polygons. This routine does the
X * logical trick of trying to exclude each point in turn if the
X * normal can not be calculated, or something of the sort.
X * a value of true is returned if a normal with a nonzero z component
X * could not be calculated
X */
X
Xbool CalcNormal( vxlist, normal)
X        PtGen *vxlist[];
X        register Pt3 *normal;
X{
X        int i, k, m;
X        Pt3 *j[3];
X        Pt3 v1, v2;
X
X        for( i = 0; i < RhomVxNum; i++ ) {
X                for( k = 0, m = 3; m--; k++ ) {
X                        if( k == i ) {
X                                k++;
X                        }
X                        j[m] = &vxlist[k]->d3;
X                }
X                CalcVector( j[1], j[0], &v1 );
X                CalcVector( j[2], j[1], &v2 );
X
X                normal->z = v1.x*v2.y - v1.y*v2.x;
X                if( normal->z == 0 ) {
X                        continue;
X                }
X                normal->x = v1.y*v2.z - v1.z*v2.y;
X                normal->y = v1.z*v2.x - v1.x*v2.z;
X                if( normal->z < 0 ) {
X                        normal->x = -normal->x;
X                        normal->y = -normal->y;
X                        normal->z = -normal->z;
X                }
X                Unitize(normal);
X                return( false );
X        }
X        return(true);
X}
X
X
X/*
X * Euclidean dot product.
X * I wonder what the minkowski dot product would look like
X */
Xfloat DotProd( v1, v2 )
X        Pt3 *v1, *v2;
X{
X        return( v1->x*v2->x + v1->y*v2->y + v1->z*v2->z );
X}
X
X
X
X
X
X/*
X * define a polygon as a set of four points
X * returns true if polygon created
X */
Xstatic bool CreatePoly(curpoly, p0, p1, p2, p3)
X    register Rhomboid *curpoly;
X    PtGen *p0, *p1, *p2, *p3;
X{
X
X    Pt3 normal;
X    PtGen *list[RhomVxNum];
X
X    list[0] = p0; list[1] = p1; list[2] = p2; list[3] = p3;
X    /*
X     * compute stuff needed only if producing shaded image
X     */
X    if( shadeflag ) {
X            Pt3 lvec;
X            Pt3 center;
X            float ptintens;
X            float ldotn; /* light vector dot normal */
X            /*
X            * if cant compute normal, then junk polygon
X            */
X            if( CalcNormal( list, &normal )) {
X                return(false);
X            }
X
X            curpoly->intensity = Ambience;
X            center.x = ( list[0]->d3.x
X                    + list[1]->d3.x
X                    + list[2]->d3.x
X                    + list[3]->d3.x)/4.0;
X            center.y = ( list[0]->d3.y
X                    + list[1]->d3.y
X                    + list[2]->d3.y
X                    + list[3]->d3.y)/4.0;
X            center.z = ( list[0]->d3.z
X                    + list[1]->d3.z
X                    + list[2]->d3.z
X                    + list[3]->d3.z)/4.0;
X
X            curpoly->depth = center.z;
X
X            CalcVector( &center, &LightSrc, &lvec );
X            Unitize( &lvec );
X            ldotn = DotProd( &lvec, &normal );
X            if( ldotn < 0 ) {
X                ptintens = PtIntensity * Kd * -ldotn;
X                curpoly->intensity += ptintens;
X            }
X            /*
X             * calculate specular component
X             */
X            if( SpecOn && ldotn < 0 ) {
X                float Kspec, Is;
X                Pt3 rvec; /* lvec reflected through poly */
X
X                ScaleVec( 2*ldotn, &normal, &rvec );
X                CalcVector(&lvec, &rvec, &rvec );
X                Unitize( &center );
X                Kspec = DotProd( &rvec, &center);
X
X                if( Kspec <= 0.0 ) {
X                    Is = Ks * Kspec * Kspec* PtIntensity;
X                    curpoly->intensity += Is;
X                }
X            }
X
X            if( curpoly->intensity > 1.0 ) {
X                curpoly->intensity = 1.0;
X            }
X    }
X    else {
X        /*
X         * calculate depth of polygon
X         * for now, try an average of the vertex depths
X         */
X        curpoly->depth =( list[0]->d3.z
X                + list[1]->d3.z
X                + list[2]->d3.z
X                + list[3]->d3.z)/4.0;
X    }
X    /*
X     * store index to screen coordinates
X     */
X    curpoly->pt[0] = p0->d2;
X    curpoly->pt[1] = p1->d2;
X    curpoly->pt[2] = p2->d2;
X    curpoly->pt[3] = p3->d2;
X
X    return(true);
X}
X/*
X * passable procedure for creating polygons without mapping
X */
Xstatic
Xvoid AcceptPoly(p0, p1, p2, p3)
X    PtGen *p0, *p1, *p2, *p3;
X{
X    if( CreatePoly(nextpoly, p0, p1, p2,p3)) {
X        nextpoly++;
X    }
X}
X
Xstatic
Xvoid AcceptMPoly( p0, p1, p2, p3)
X    PtGen *p0, *p1, *p2, *p3;
X{
X    if( CreatePoly(&mnextpoly->rhom, p0, p1, p2,p3)) {
X        mnextpoly->bezindex = RevImageB;
X        mnextpoly->revindex = RevImageR;
X        mnextpoly++;
X    }
X}
X
X
X
X
X
X/*
X * compare the depth of two polygons for SortPoly
X */
Xstatic int CmpDepth( a, b )
X        Rhomboid *a, *b;
X{
X        if( a->depth < b->depth ) return(-1);
X        else if( a->depth > b->depth ) return(1);
X        else return(0);
X}
X
Xstatic int CmpMDepth( a, b )
X        MapRhomboid *a, *b;
X{
X        if( a->rhom.depth < b->rhom.depth ) return(-1);
X        else if( a->rhom.depth > b->rhom.depth ) return(1);
X        else return(0);
X}
X
X
X
X
X
Xvoid RevNoShade() {
X        Rhomboid *i;
X        if( GetNumSegs() < 1 ) {
X                return;
X        }
X
X        ClrAbort();
X        shadeflag = false;
X        if( PrepPoly() ) return;
X        if( Revolve(AcceptPoly) ) return;
X        CurMode = NOTACTIVE;
X
X        qsort( (char *)polylist, nextpoly - polylist,
X                sizeof(Rhomboid), CmpDepth);
X
X        ClrWindow(false);
X
X        for( i = polylist; i< nextpoly; i++ ) {
X            if( AbortDraw ) return;
X                DrawRhomFrame( i->pt );
X        }
X}
X
X
X
X
Xvoid RevShade() {
X        register Rhomboid *i;
X
X        if( !AllocDither()) return; /* not enough memory */
X        if( GetNumSegs() < 1 ) {
X                return;
X        }
X        CurMode = NOTACTIVE;
X        ClrAbort();
X        shadeflag = true;
X        if( PrepPoly() || Revolve(AcceptPoly) ) {
X            return;
X        }
X        qsort( (char *)polylist, nextpoly-polylist,
X                sizeof(Rhomboid), CmpDepth);
X
X        ClrWindow(false);
X
X        for( i = polylist; i< nextpoly; i++ ) {
X                if( AbortDraw ) return;
X                DrawRhomShade( i );
X        }
X}
X
X
X
Xvoid RevMap() {
X    register MapRhomboid *i;
X
X    ClrAbort();
X    if( GetNumSegs() < 1 ) {
X            return;
X    }
X    if( InitMapping() ) {
X        return;
X    }
X    CurMode = NOTACTIVE;
X    shadeflag = true;
X
X
X    if( PrepMPoly() || Revolve(AcceptMPoly) ) {
X        return;
X    }
X    qsort( (char *)mpolylist, mnextpoly-mpolylist,
X        sizeof(MapRhomboid), CmpMDepth);
X    ClrWindow(false);
X
X    for( i = mpolylist; i< mnextpoly; i++ ) {
X            if( AbortDraw ) return;
X            DrawRhomMap(i);
X    }
X}
END_OF_FILE
if test 8961 -ne `wc -c <'poly.c'`; then
    echo shar: \"'poly.c'\" unpacked with wrong size!
fi
# end of 'poly.c'
fi
if test -f 'readilbm.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'readilbm.c'\"
else
echo shar: Extracting \"'readilbm.c'\" \(8906 characters\)
sed "s/^X//" >'readilbm.c' <<'END_OF_FILE'
X#include <stdio.h>
X#include <ctype.h>
X#include "readilbm.h"
X
X#define FALSE 0
X#define TRUE 1
X
X#define RED 0
X#define GRN 1
X#define BLU 2
X
X /* color to grey conversion methods */
X
X#define AVERAGE 0
X#define LUMIN    1
X#define DIST     2
X#define REDONLY  3
X#define GREENONLY 4
X#define BLUEONLY 5
X
X#define MakeID(a,b,c,d) ( ((a)<<24) | ((b)<<16) | ((c)<<8) | (d) )
X
X#define ID_FORM MakeID('F','O','R','M')
X#define ID_ILBM MakeID('I','L','B','M')
X#define ID_BMHD MakeID('B','M','H','D')
X#define ID_CMAP MakeID('C','M','A','P')
X#define ID_CAMG MakeID('C','A','M','G')
X#define ID_BODY MakeID('B','O','D','Y')
X
X#define ROUNDUP(x) ( ((x)+1) & (~1L) )
X
X
X
Xstatic struct CHUNK {
X    unsigned long Id, Size;
X} Chunk;
X
Xstatic unsigned char   cmap[32][3];
X
Xstruct BMHD {
X    short w,h,x,y;
X    char npl,mask,compress,pad1;
X    short transparentColor;
X    char xAspect,yAspect;
X    short pageWidth,pageHeight;
X};
X
X
Xstatic short    Color[32],              /* output colors        */
X                Method = AVERAGE;       /* color conversion     */
Xstatic short     numcolors;
X
Xstatic
XFILE            *fin;                   /* input file           */
X
Xextern char     *malloc();
X
Xstatic void FRead();
Xstatic void ReadBMHD();
Xstatic void ReadChunk();
Xstatic void RastOut();
Xstatic void HamOut();
Xstatic char GetIlbmVal();
Xstatic void InitColorMappings();
Xstatic short Convert();
Xstatic void ReadDecomLine();
Xstatic void ProcessRows();
X
X#define ABORT(str) { OutErr(str); goto ErrorExit; }
X
X
Xvoid SetGreyModel( model )
X    int model;
X{
X    Method = model;
X}
X
X /*
X  * main routine for reading in an iff file
X  */
X
Xvoid ReadIlbm(filename)
X    char *filename;
X{
X    struct BMHD bmhd;
X    long    ILBMid;
X    unsigned char cmapFlag = FALSE,
X                  bmhdFlag = FALSE;
X
X
X    if ((fin = fopen (filename, "r")) == NULL) {
X        OutErr ("ERROR: cannot open input file");
X        return;
X    }
X    /* read in iff file */
X
X    ReadChunk ();
X    if (Chunk.Id != ID_FORM)
X        ABORT ("Not an IFF File");
X
X    FRead (&ILBMid, 4);
X    if (ILBMid != ID_ILBM)
X        ABORT ("Not an ILBM File");
X
X    while (1) {
X        long camgdata;
X
X        ReadChunk ();
X
X        if (Chunk.Id == ID_BODY)
X            break;
X
X        if( feof( fin ) ) {
X            ABORT("reached end of file without seeing body\n");
X        }
X
X        switch (Chunk.Id) {
X            case ID_CMAP:
X                FRead (cmap, Chunk.Size);
X                numcolors = Chunk.Size/3;
X                cmapFlag = TRUE;
X                break;
X            case ID_BMHD:
X                ReadBMHD (&bmhd);
X                bmhdFlag = TRUE;
X                break;
X            case ID_CAMG:
X                FRead( &camgdata, sizeof(camgdata) );
X                break;
X            default:            /* unknown identifier */
X                fseek( fin, Chunk.Size, 1);
X                break;
X        }
X    }
X    if (!cmapFlag) {
X        ABORT("IFF file does not contain a CMAP chunk before the BODY\n");
X    }
X
X    if (!bmhdFlag) {
X        ABORT("IFF file does not contain a BMHD chunk before the BODY\n");
X    }
X
X    InitColorMappings();
X    if( OpenImgPix( bmhd.w, bmhd.h, Convert(0xf, 0xf, 0xf)) ) {
X        ProcessRows(&bmhd);
X    }
X
X    ErrorExit:
X        fclose( fin);
X}
X
Xstatic void ProcessRows(bmhd)
X    struct BMHD *bmhd;
X{
X    char *rastlist[6];
X    char *Raster;
X    int depth, i, v, pixwidth;
X    int BytePerLine;
X
X    depth = bmhd->npl;
X    pixwidth = bmhd->w;
X    BytePerLine =(pixwidth+7) / 8;
X
X
X    Raster = (char *) malloc (BytePerLine * depth);
X
X    if(!Raster ) {
X        OutErr("ProcessRows:could not allocate Raster");
X        return;
X    }
X
X    for( i = 0; i < depth; i++ ) {
X        rastlist[i] = Raster + BytePerLine*i;
X    }
X
X    for( v = 0; v < bmhd->h; v++) {
X        switch (bmhd->compress) {
X            case 0:
X                FRead (Raster, BytePerLine * depth);
X                break;
X            case 1:
X                for( i = 0; i < depth; i++) {
X                    ReadDecomLine( BytePerLine, rastlist[i]);
X                }
X                break;
X            default:
X                ABORT ("Unknown Compression type in BODY");
X
X        }
X        if(depth == 6 ) {
X            HamOut( rastlist, pixwidth, v);
X        }
X        else {
X            RastOut( rastlist, pixwidth, v, depth);
X        }
X    }
X
X    ErrorExit:
X        if( Raster ) free(Raster);
X}
X
X
Xstatic void ReadDecomLine(linebytes, rp)
X    int linebytes;
X    char *rp;
X{
X    int runlen;
X    char pixel;
X
X    while (linebytes) {
X        runlen = getc (fin);
X        if (runlen > 127)
X            runlen -= 256;
X        if (runlen >= 0) {
X            runlen++;
X            FRead (rp, runlen);
X            rp += runlen;
X            linebytes -= runlen;
X        }
X        else {
X            runlen = -runlen + 1;
X            linebytes -= runlen;
X            pixel = getc (fin);
X            do
X                *(rp++) = pixel;
X            while (--runlen);
X        }
X    }
X}
X
X /*
X  * Convert - convert (r,g,b) to hex greyscale.
X  */
X
Xstatic short Convert(r,g,b)
X    unsigned char   r,g,b;
X{
X    short   i,
X            rd, gd, bd,
X            min,
X            dist,
X            best;
X
X /* convert color according to 'Method' */
X    switch (Method) {
X        case AVERAGE:           /* average r,g,b to obtain grey level */
X            return ((short)((r + g + b) / 3));
X        case LUMIN:             /* use NTSC luminescence as grey level */
X            return ((short)((r * 30 + g * 59 + b * 11) / 100));
X        case DIST:          /* use grey with minimum distance in color */
X            min = 15*15 * 3;
X            for( i = 0; i < numcolors; i++ ) {
X                rd = r -i;
X                gd = g - i;
X                bd = b - i;
X                dist = rd * rd + gd * gd + bd * bd;
X                if( dist < min ) {
X                    min = dist; best = i;
X                }
X            }
X            return( best );
X        case REDONLY:
X            return((short)r);
X        case GREENONLY:
X            return((short)g);
X        case BLUEONLY:
X            return((short)b);
X        default:
X            exit(-1); /* error, big one */
X    }
X}                               /* Convert */
X
Xstatic void InitColorMappings()
X{
X    int     i;
X
X /* put colors in 4-bit range and Convert */
X    for (i = 0; i < 32; i++) {
X        cmap[i][RED] >>= 4;
X        cmap[i][GRN] >>= 4;
X        cmap[i][BLU] >>= 4;
X        Color[i] = Convert (cmap[i][RED], cmap[i][GRN], cmap[i][BLU]);
X    }
X}
X
X
X/*
X * leftmost pixel of byte is in most significant bit of byte
X */
Xstatic char GetIlbmVal( rastlist, h, bpp )
X    char *rastlist[6];
X    int h, bpp;
X{
X    int i;
X    char value = 0;
X    short mask, bytep;
X
X    mask = 0x80 >> ( h & 7);
X    bytep = h >> 3;
X
X    for( i = bpp-1; i >= 0; i-- ) {
X        value <<= 1;
X        value |= (*(rastlist[i]+bytep) & mask) ? 1: 0;
X    }
X    return( value );
X}
X
X /*
X  * HamOut - output ham image in hex.
X  */
Xstatic void HamOut(rastlist, pixwidth, v)
X    char *rastlist[6];
X    int pixwidth, v;
X{
X    unsigned char   lastred = 0,
X                    lastgreen = 0,
X                    lastblue = 0;
X    int     h;
X    char pixval;
X    for( h = 0; h <pixwidth; h++ ) {
X        short shade;
X
X        shade = GetIlbmVal(rastlist, h, 6);
X        pixval = shade & 0x0F;
X        switch (shade & 0x30) {
X        case 0x00:
X            lastred = cmap[pixval][RED];
X            lastgreen = cmap[pixval][GRN];
X            lastblue = cmap[pixval][BLU];
X            shade = Color[pixval];
X            break;
X        case 0x10:
X            lastblue = pixval;
X            shade = Convert(lastred,lastgreen,lastblue);
X            break;
X        case 0x20:
X            lastred = pixval;
X            shade = Convert(lastred,lastgreen,lastblue);
X            break;
X        case 0x30:
X            lastgreen = pixval;
X            shade = Convert(lastred,lastgreen,lastblue);
X        }
X        SetImgPix(h, v, shade);
X    }
X}
X
X /*
X  * RastOut - handle normal bit mapped images
X  */
Xstatic void RastOut(rastlist, pixwidth, v, depth)
X    char *rastlist[6];
X    int pixwidth, v, depth;
X{
X    int h;
X    for( h = 0; h < pixwidth; h++ ) {
X        short shade;
X        shade = Color[GetIlbmVal( rastlist, h, depth)];
X        SetImgPix( h, v, shade);
X    }
X}
X
X /*
X  * ReadChunk - read in an IFF Chunk.
X  */
X
Xstatic void ReadChunk()
X{
X    FRead (&Chunk, sizeof (Chunk));
X
X}                               /* ReadChunk */
X
X /*
X  * ReadBMHD - read the BMHD structure.
X  */
X
Xstatic void ReadBMHD(bmhd)
Xstruct BMHD *bmhd;
X{
X    FRead (bmhd, Chunk.Size);
X}                               /* ReadBMHD */
X
X
X /*
X  * FRead - read 'len' bytes to 'pointer' while checking for an error.
X  */
X
Xstatic void FRead(pointer,len)
Xchar    *pointer;
Xint     len;
X{
X    if (fread (pointer, len, 1, fin) == 0)  {
X        char outbuff[90];
X        sprintf(outbuff,"Fread Error in reading input file at %d ", ftell(fin));
X        OutErr(outbuff);
X    }
X}                               /* FRead */
END_OF_FILE
if test 8906 -ne `wc -c <'readilbm.c'`; then
    echo shar: \"'readilbm.c'\" unpacked with wrong size!
fi
# end of 'readilbm.c'
fi
if test -f 'scrnops.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'scrnops.c'\"
else
echo shar: Extracting \"'scrnops.c'\" \(8883 characters\)
sed "s/^X//" >'scrnops.c' <<'END_OF_FILE'
X#include "scrnio.ih"
X/*
X * if manx supports rand, these ifdefs could be removed (somewhat)
X */
X#ifdef MANX
Xextern double ran(); /* not in manx  math.h */
X#include <functions.h>
X#else
Xextern int rand();
X#endif
X
X#include "scrndef.h"
X#include "scrnio.h"
X#include "gadgetdef.h"
X#include "menudef.h"
X
X#include "bezpt.h"
X#include "revolve.h"
X#include "control.h"
X#include "poly.h"
X
X
Xlong BackColor = DefBkPlane;
Xshort DitherPower = 2;/* default gray levels = 4 */
Xstatic UWORD *GrayPat = null;
Xshort DitherLevels, DitherMask;
X#define RowPower 4  /* 2**4 = 16 rows */
X#define DitherLoc(LEVEL) ((LEVEL)<<RowPower)
X/*
X * free memory associated with
X * old dither patterns;
X */
Xvoid FreeOldDither() {
X    if( GrayPat ) free(GrayPat);
X    GrayPat = null;
X}
X/*
X * create grey level patterns
X */
Xbool AllocDither()
X{
X    int i;
X    float reallevels;
X    if( GrayPat) return(true);
X
X    DitherLevels = 1 << DitherPower;
X    reallevels = (float) DitherLevels - 0.5;
X    DitherMask = DitherLevels -1;
X    GrayPat = (UWORD *)malloc(DitherLoc(DitherLevels)*sizeof(UWORD));
X    if( !GrayPat ) {
X        OutErr("not enough memory for options chosen");
X        return(false);
X    }
X    ColorMax = (NumColors -1) * DitherLevels +1;
X    /*
X     * compute gray values for each grey level
X     */
X    for( i = 0; i < DitherLevels; i++ ) {
X        /*
X         * compute gray values for each row
X         */
X        int j;
X#ifdef MANX
X        float fracti;
X        fracti = (float)i/ reallevels;
X        for( j = 0; j < DitherLoc(1); j++ ) {
X            register long k, x;
X            for( k = 16, x = 0; k--; ) {
X                x <<= 1;
X                x |= (ran() < fracti) ? 1: 0;
X            }
X            GrayPat[DitherLoc(i)+j] = x;
X        }
X#else MANX
X        for( j = 0; j < DitherLoc(1); j++ ) {
X            register long k, x;
X            for( k = 16, x = 0; k--; ) {
X                x <<= 1;
X                x |= ((rand()%DitherLevels)< i) ? 1: 0;
X            }
X            GrayPat[DitherLoc(i)+j] = x;
X        }
X#endif MANX
X    }
X    return(true);
X}
X
X
Xvoid SetMono( maxrval, maxgval, maxbval )
X    short maxrval,
X          maxgval,
X          maxbval;
X{
X    long i;
X    short range;
X    long rval, gval, bval;
X
X    range = (NumColors -1) & 0x1f;  /* max 32 colours */
X    for( i = 0; i <= range; i++ ) {
X        rval = (maxrval * i )/range;
X        gval = (maxgval * i )/range;
X        bval = (maxbval * i )/range;
X
X        SetRGB4( &(SurfScrn->ViewPort),  i, rval, gval, bval );
X    }
X}
X
X
Xvoid SetRainbow()
X{
X    long i;
X    short range;
X    long rval, gval, bval;
X
X    range = NumColors>> 1;
X    /*
X     * can't do a rainbow with only 2 colors
X     */
X    if( range < 2) {
X        return;
X    }
X
X    for( i = 0; i < range; i++ ) {
X        long diff;
X
X        diff = (0xf * i )/(range-1);
X        rval = 0xf - diff;
X        bval = diff;
X        gval = 0xf;
X        SetRGB4( &(SurfScrn->ViewPort), i, rval, gval, bval);
X    }
X    for( i = 0; i < range; i++ ) {
X        long diff;
X
X        diff = (0xf * i )/(range-1);
X        rval = diff;
X        bval = 0xf;
X        gval = 0xf - diff;
X        SetRGB4( &(SurfScrn->ViewPort), i+range, rval, gval, bval);
X    }
X    SetRGB4( &(SurfScrn->ViewPort), 0L, 0L, 0L, 0L);
X}
X
X/*
X * set colours for hourglass pointer
X */
XSetHourGlassCol()
X{
X    SetRGB4( &(SurfScrn->ViewPort),17L, 6L, 2L, 3L );
X    SetRGB4( &(SurfScrn->ViewPort),18L, 0L, 0L, 0L );
X    SetRGB4( &(SurfScrn->ViewPort),19L, 9L, 7L, 6L );
X}
X
X
X
Xvoid ClrWindow(drawaxis)
Xbool drawaxis;
X{
X    long BkColAdj; /* background color adjusted for number of bit planes */
X
X    BkColAdj = (BackColor * NumColors) / 32;
X    SetRast(rp, BackColor);  /* clear the window to colour 0 */
X    SetAPen(rp, WinFgCol );
X    /*
X     * Draw axis on screen
X     */
X    if( drawaxis) {
X        Move( rp, 0, WinVOrig);    /* x axis */
X        Draw( rp, (long)SurfWinDef.Width, (long)WinVOrig );
X
X        Move( rp, WinHOrig, 0);     /* y axis */
X        Draw( rp, (long)WinHOrig, (long)SurfWinDef.Height );
X    }
X}
X
X
X
X
X
Xvoid DrawLine( x1, y1, x2, y2, mode )
Xint x1, y1, x2, y2;
Xint mode;
X{
X    SetDrMd( rp, mode );
X    Move( rp, (long)UCntrX(x1), (long)UCntrY(y1));
X    Draw(rp, (long)UCntrX(x2), (long)UCntrY(y2) );
X}
X
X
X
Xvoid PaintPoint(x,y,forecolor)
X    short x, y;
X    float forecolor;
X{
X    long shade;
X    shade = forecolor * (float) (NumColors-1);
X
X    if( shade >= NumColors) {
X        shade = NumColors-1;
X    }
X    else if ( shade < 0 ) {
X        shade = 0;
X    }
X
X    SetAPen( rp, shade );
X    WritePixel( rp, (long)UCntrX(x), (long)UCntrY(y));
X}
X
X
X
Xvoid DrawPnt( x, y, op )
Xint x, y, op;
X{
X    x = UCntrX(x);
X    y = UCntrY(y);
X    SetDrMd(rp, op );
X    RectFill( rp, (long)x, (long)y, (long)x, (long)y);
X}
X
X
Xvoid DrawSqr(x, y, op )
Xint x, y, op;
X{
X    x = UCntrX(x);
X    y = UCntrY(y);
X    SetDrMd(rp, op );
X    RectFill( rp, x - 2L, y -2L, x+ 2L, y+2L );
X}
X
X
Xvoid DrawBox( x, y, op)
Xint x, y, op;
X{
X    x = UCntrX(x);
X    y = UCntrY(y);
X    SetDrMd(rp, op );
X    RectFill( rp, x - 4L, y -4L, x+ 4L, y+4L );
X    RectFill( rp, x - 3L, y -3L, x+ 3L, y+3L );
X}
X
X
Xvoid DrawRhomShade( poly)
XRhomboid *poly;
X{
X    int i;
X    int shade;
X    long backcolor, forecolor;
X    static UWORD FullBits = 0xffff;
X
X    shade = (int)((poly->intensity) * ColorMax);
X
X    if( shade >= ColorMax -1 ) {
X        shade = 0;
X        backcolor = NumColors -1;
X    }
X    else {
X        backcolor = shade >> DitherPower;
X        forecolor = backcolor +1;
X        if( forecolor >= NumColors ) {
X            forecolor = backcolor;
X        }
X    }
X    SetDrMd( rp, JAM2);
X    SetAPen( rp, forecolor );
X    SetBPen( rp, backcolor );
X    SetAfPt( rp, &GrayPat[DitherLoc((shade & DitherMask))], RowPower);
X
X    AreaMove( rp, UCntrX(poly->pt[0].x), UCntrY(poly->pt[0].y));
X
X    for( i = 1; i < 4; i++ ) {
X        AreaDraw( rp, UCntrX(poly->pt[i].x), UCntrY(poly->pt[i].y) );
X    }
X    AreaEnd(rp);
X
X    SetAfPt( rp, &FullBits, 0);  /* reset back to solid */
X}
X
Xvoid DrawRhomFrame( inlist )
XScrnPair inlist[];
X{
X    int i;
X
X    SetDrMd( rp, JAM1);
X    SetAPen( rp, 0L );
X    SetOPen( rp, WinFgCol );
X
X    AreaMove( rp, UCntrX(inlist[0].x), UCntrY(inlist[0].y));
X
X    for( i = 1; i < 4; i++ ) {
X        AreaDraw( rp, UCntrX(inlist[i].x), UCntrY(inlist[i].y) );
X    }
X    AreaEnd(rp);
X    BNDRYOFF( rp ); /* turn off outlining */
X}
X
X
X
X
XSwitchBox()
X{
X    struct IntuiMessage mycopy,
X                        *orig;
X
X    RefreshGadgets(SurfWinDef.FirstGadget, SurfWin, NULL );
X
X    while(1) {
X        long wakeupmask;
X
X        wakeupmask = Wait( SignalMask );
X        /*
X         * for now, we ignore the wakeupmask,
X         * just read messages from each. if I notice a performance problem,
X         * I'll fix it then
X         */
X
X        /*
X         * handle messages for the control window
X         */
X        while( orig =(struct IntuiMessage *) GetMsg( CntrlWin->UserPort ) ) {
X
X            mycopy = *orig;
X            ReplyMsg( orig );
X
X            switch( mycopy.Class ) {
X                case MENUPICK:
X                    MenuHandler( mycopy.Code );
X                    break;
X
X                case GADGETUP:
X                    GadgetHandler( (struct Gadget*)mycopy.IAddress );
X                    break;
X
X                case CLOSEWINDOW:
X                    return;
X
X                default:
X                    break;
X            }
X        }
X        /*
X         * handle the button window
X         */
X        while( orig =(struct IntuiMessage *) GetMsg( GadWin->UserPort ) ) {
X
X            mycopy = *orig;
X            ReplyMsg( orig );
X
X            switch( mycopy.Class ) {
X                case GADGETUP:
X                    GadgetHandler( (struct Gadget*)mycopy.IAddress );
X                    RefreshGadgets(SurfWinDef.FirstGadget, SurfWin, NULL );
X                    break;
X
X                default:
X                    break;
X            }
X        }
X
X        /*
X         * handle messages for the other window
X         */
X        while( orig =(struct IntuiMessage *) GetMsg( SurfWin->UserPort ) ) {
X
X            mycopy = *orig;
X            ReplyMsg( orig );
X
X            switch( mycopy.Class ) {
X                case MOUSEBUTTONS:
X                    HandleMButtons(&mycopy);
X                    break;
X
X                case INTUITICKS:
X                    HandleTicks(&mycopy);
X                    break;
X
X                case MOUSEMOVE:
X                    break;
X
X                default:
X                    break;
X            }
X        }
X    }
X}
X
X/*
X * display error messages inside a requestor
X */
XOutErr(errstr)
X    char *errstr;
X{
X    static struct IntuiText errtext =
X        { -1, -1, JAM1, 10, 10, NULL, NULL, NULL };
X    static struct IntuiText negtext =
X        { -1, -1, JAM1, 80, 20, NULL,(UBYTE *)"Onwards", NULL };
X
X    errtext.IText = (UBYTE *)errstr;
X
X    WBenchToFront();
X    AutoRequest(CntrlWin, &errtext, NULL, &negtext, NULL, NULL,
X        8*strlen(errstr)+ 40, 60 );
X    WindowToFront( CntrlWin );
X
X}
X
END_OF_FILE
if test 8883 -ne `wc -c <'scrnops.c'`; then
    echo shar: \"'scrnops.c'\" unpacked with wrong size!
fi
# end of 'scrnops.c'
fi
if test -f 'tov3d.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'tov3d.c'\"
else
echo shar: Extracting \"'tov3d.c'\" \(8632 characters\)
sed "s/^X//" >'tov3d.c' <<'END_OF_FILE'
X#include <stdio.h>
X#include <math.h>
X
X#define true 1
X#define false 0
X
X/*
X * types
X */
Xtypedef float triplet[3];
Xtypedef int  quadrlat[4];
X
Xtypedef enum {
X               TminX, TminY, TminZ,
X               TmaxX, TmaxY, TmaxZ,
X               Tcolorin, Tcolorout, Tnameout } ArgType;
X
Xextern char *malloc();
Xextern double atof();
X
Xchar *ArgName[] = {
X    "minx", "miny", "minz", "maxx", "maxy", "maxz", "ci", "co", "o", NULL
X  };
X
X/*
X * command line arguments
X */
Xtriplet MinIn, MaxIn; /* define bounding box */
Xchar MinSet[3] = {false}, MaxSet[3] = {false};
X
Xint colorin = -1,
X    colorout = -1;
Xchar *namein = NULL,
X     *nameout = NULL;
X/*
X * file arguments
X */
XFILE *infile, *outfile= NULL;
Xint linenum;
X
X/*
X * mucky global variables
X */
Xtriplet *inring;
Xchar *indlist;
Xint pnt_total; /* total number of points */
Xtriplet Scale = { 1.0, 1.0, 1.0 };
Xtriplet Disp = { 0.0, 0.0, 0.0 };
X
X
Xint NumRings, /* number of curved rings */
X    PtsInPerRing, /* points read in per ring */
X    PtsOutPerRing, /* points written per ring */
X    IsClosed; /* true if revolution is 360 degrees */
X
X/*
X * parse the command line arguments
X */
Xvoid getCliArgs(argc, argv)
X    int argc;
X    char *argv[];
X{
X    int i;
X    for( i = 0; i <argc; i++ ) {
X        if( *argv[i] == '-' ) {
X            int j;
X
X            for( j = 0; ArgName[j]; j++ ) {
X                if( !strncmp(ArgName[j], argv[i]+1, strlen(ArgName[j])))
X                    break;
X            }
X
X            if( !ArgName[j] ) {
X                fprintf(stderr,"%s unknown, try one of below:\n", argv[i]);
X                for( j = 0; ArgName[j]; j++ ) {
X                    fprintf(stderr,"-%s val\n", ArgName[j] );
X                }
X                exit(-1);
X            }
X            else {
X                char *argpos;
X                register int element;
X
X                if( strlen(argv[i]+1) > strlen(ArgName[j]) ) {
X                    argpos = argv[i] + strlen(ArgName[j]) +1;
X                }
X                else {
X                    i++;
X                    if( i >= argc ) {
X                        fprintf(stderr,"missing arg for -%s\n", argv[i-1] );
X                        exit(-1);
X                    }
X                    argpos = argv[i];
X                }
X                switch( (ArgType)j ) {
X                    case TminX:
X                    case TminY:
X                    case TminZ:
X                        element = j - (int)TminX;
X                        MinIn[element] = atof(argpos);
X                        MinSet[element] = true;
X                        break;
X                    case TmaxX:
X                    case TmaxY:
X                    case TmaxZ:
X                        element = j - (int)TmaxX;
X                        MaxIn[element] = atof(argpos);
X                        MaxSet[element] = true;
X                        break;
X                    case Tcolorin: colorin = atoi(argpos); break;
X                    case Tcolorout: colorout = atoi(argpos); break;
X                    case Tnameout: nameout = argpos;
X                } /* end case */
X            }
X        }
X        else {
X                namein = argv[i];
X        }
X    } /* end for loop */
X
X    if (!namein ) {
X        fprintf(stderr,"No input file named\n");
X        exit(-1);
X    }
X    if(!nameout) {
X        nameout = (char *)malloc(200); /* replace with max path size */
X        sprintf(nameout, "%s.v3d", namein);
X    }
X}
X
X/*
X * read an integer number into variable
X */
Xvoid readInt(IntVar)
X    int *IntVar;
X{
X    char c;
X    linenum++;
X    if( !fscanf(infile, "%d", IntVar)) {
X        fprintf(stderr, "could not read integer at line %d\n", linenum);
X        exit(-1);
X    }
X    /*
X     * skip to end of line
X     */
X    while( c = getc(infile), c != EOF && c != '\n' ) ;
X}
X
Xvoid readTriplet( tripvar )
X    triplet tripvar;
X{
X    linenum++;
X    if(!fscanf(infile, "%f %f %f",tripvar, tripvar+1, tripvar+2)) {
X        fprintf(stderr,"could not read coordinate triplet at line %d\n",
X            linenum);
X        exit(-1);
X    }
X}
X/*
X * read an entire ring
X */
Xvoid readRing() {
X    int i;
X    for( i = 0; i< PtsInPerRing; i++ ) {
X        readTriplet(inring[i]);
X    }
X}
X
X/*
X * read the first few lines in the file that tell us how many
X * rings, howmany points per ring, etc
X */
Xvoid readHeader() {
X    int RevRange;
X    int RevMesh;
X
X    linenum = 0;
X    readInt( &NumRings );
X    readInt( &RevMesh );
X    readInt( &RevRange );
X
X    PtsInPerRing = RevMesh + 1;
X    if( RevRange == 360 ) {
X        IsClosed = true;
X        PtsOutPerRing = RevMesh;
X    }
X    else {
X        IsClosed = false;
X        PtsOutPerRing = PtsInPerRing;
X    }
X}
X/*
X * this procedure reads in a list of data points to determine the
X * following:
X *      total number of data points to write out
X *      maximun x,y,z spread
X */
Xvoid readPass1() {
X    triplet max3, min3;
X    int i;
X    pnt_total = 0;
X
X    inring = (triplet *)malloc(sizeof(triplet)*PtsInPerRing);
X    indlist = (char *)malloc(sizeof(char)*NumRings);
X
X    for( i = 0; i < NumRings; i++ ) {
X        int j;
X        readRing();
X
X        for( j = 0; j < PtsOutPerRing; j++ ) {
X            int k;
X            for( k = 0; k < 3; k++ ) {
X                if( max3[k] < inring[j][k] || !i && !j ) max3[k] = inring[j][k];
X                if( min3[k] > inring[j][k] || !i && !j ) min3[k] = inring[j][k];
X            }
X        }
X        if( inring[0][0] == inring[1][0] &&
X            inring[0][1] == inring[1][1] ) {
X            indlist[i] = 0;
X            pnt_total += 1;
X        }
X        else {
X            indlist[i] = 1;
X            pnt_total += PtsOutPerRing;
X        }
X    }
X    /*
X     * compute scaling and displacement
X     */
X    for( i = 0; i < 3; i++ ) {
X        if( MaxSet[i]  && !MinSet[i] )
X            MinIn[i] = -MaxIn[i];
X        else if( !MaxSet[i] && MinSet[i] )
X            MaxIn[i] = -MinIn[i];
X
X        Scale[i] = 1.0;
X        Disp[i] = 0.0;
X        if( MaxSet[i] || MinSet[i] ) {
X            float diffOut, diffIn;
X
X            diffOut = MaxIn[i] - MinIn[i];
X            diffIn = max3[i] - min3[i];
X            if( diffIn > 0 ) Scale[i] = diffOut/diffIn;
X            Disp[i] = MaxIn[i] - max3[i] * Scale[i];
X        }
X    }
X}
X
Xvoid writeTriplet(trip)
X    triplet trip;
X{
X    int i;
X    for( i = 0; i < 3; i++ ) {
X        fprintf(outfile,"%f%c", trip[i]*Scale[i]+Disp[i], i==2?'\n':' ');
X    }
X}
X
X
Xvoid writeRing()
X{
X    int i;
X    for( i = 0; i < PtsOutPerRing; i++ ) {
X        writeTriplet(inring[i]);
X    }
X}
X
X
X
Xvoid writePoints()
X{
X    int ringno;
X
X    fprintf(outfile, "%d\n", pnt_total);
X    for( ringno = 0; ringno < NumRings; ringno++ ) {
X        readRing();
X        if( indlist[ringno] )
X            writeRing();
X        else
X            writeTriplet( inring[0] );
X    }
X}
X
X
Xvoid writeQuad(quad, numpts, color, order)
X    quadrlat quad;
X    int numpts, color, order;
X{
X    int i;
X    fprintf(outfile, "%d ", numpts);
X    for(i=0; i <numpts; i++ ) {
X        fprintf(outfile,"%d ", quad[order?i:(numpts-i -1)]);
X    }
X    fprintf(outfile,"%d \n", color);
X}
X
Xvoid writePolys() {
X    int RevA, RevB;
X    int PtCntA, PtCntB;
X    int RingA, RingB;
X    int PolysPerRing;
X
X    PolysPerRing = PtsInPerRing -1;
X    PtCntB = RingA = 0;
X    for( RingB =1; PtCntA = PtCntB, RingB < NumRings; RingA = RingB++ ) {
X
X        PtCntB += indlist[RingA]? PtsOutPerRing: 1;
X        for( RevA =0; RevA < PolysPerRing; RevA++ ) {
X            quadrlat quad;
X            int qcnt;
X
X            RevB = RevA +1;
X            if( RevB >= PtsOutPerRing ) RevB = 0;
X
X            qcnt = 0;
X            if(indlist[RingA] ) {
X                quad[qcnt++] = PtCntA + RevA;
X                quad[qcnt++] = PtCntA + RevB;
X            }
X            else
X                quad[qcnt++] = PtCntA;
X
X            if(indlist[RingB] ) {
X                quad[qcnt++] = PtCntB + RevB;
X                quad[qcnt++] = PtCntB + RevA;
X            }
X            else
X                quad[qcnt++] = PtCntB;
X
X            if( qcnt >= 3 ) {
X                if( colorin >= 0 ) writeQuad(quad, qcnt, colorin, false);
X                if( colorout >=0 ) writeQuad(quad, qcnt, colorout, true);
X            }
X        }
X    }
X}
X
Xmain(argc, argv)
X    int argc;
X    char *argv[];
X{
X    getCliArgs(argc, argv);
X    infile = fopen(namein, "r");
X    if(!infile) {
X        fprintf(stderr,"can not read \"%s\"\n", namein);
X        exit(-1);
X    }
X
X    readHeader();
X    readPass1();
X    fclose(infile);
X
X    outfile = fopen(nameout, "w");
X    if( !outfile) {
X        fprintf(stderr, "can not write to \"%s\"\n", nameout);
X        exit(-1);
X    }
X
X    infile = fopen(namein, "r");
X    readHeader();
X    writePoints();
X    fclose(infile);
X    writePolys();
X    fclose(outfile);
X}
END_OF_FILE
if test 8632 -ne `wc -c <'tov3d.c'`; then
    echo shar: \"'tov3d.c'\" unpacked with wrong size!
fi
# end of 'tov3d.c'
fi
echo shar: End of archive 3 \(of 4\).
cp /dev/null ark3isdone
MISSING=""
for I in 1 2 3 4 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked all 4 archives.
    rm -f ark[1-9]isdone
else
    echo You still need to unpack the following archives:
    echo "        " ${MISSING}
fi
##  End of shell archive.
exit 0
-- 
Mail submissions (sources or binaries) to <amiga@cs.odu.edu>.
Mail comments to the moderator at <amiga-request@cs.odu.edu>.
Post requests for sources, and general dicussion to comp.sys.amiga.