home *** CD-ROM | disk | FTP | other *** search
- /*
- * Maceditor.c
- */
-
- #include <MacHeaders>
- #include <Windows.h>
- #include <QuickDraw.h>
- #include <Controls.h>
- #include <Dialogs.h>
- #include <Lists.h>
- #include <Types.h>
-
- #include "texture.h"
- #include "geom.h"
- #include "surface.h"
- #include "light.h"
-
- #include "list.h"
- #include "grid.h"
- #include "blob.h"
- #include "sphere.h"
- #include "box.h"
- #include "disc.h"
- #include "cone.h"
- #include "poly.h"
- #include "plane.h"
- #include "cylinder.h"
- #include "sampling.h"
- #include "csg.h"
- #include "instance.h"
- #include "triangle.h"
- #include "torus.h"
-
- #include "point.h"
- #include "infinite.h"
- #include "spot.h"
- #include "jittered.h"
- #include "extended.h"
-
- #include "macmodify.h"
- #include "maceditor.h"
- #include "macdialog.h"
-
- extern DialogPtr editorDialog ;
- extern Surface *Surfaces ; /* Named surface instances */
- extern Geom *Objects ; /* Named objects */
- extern Geom *World;
- extern Light *Lights;
-
- extern Light *CreateProtoLight(short type);
- Surface *EditSurface(Geom *obj) ;
-
- static Surface tmpsurf ;
- static ListHandle surfList ;
-
-
- pascal void ColourChoose(WindowPtr window, short itemno)
- {
- ControlHandle itemHandle ;
- Rect itemRect ;
- short itemType ;
- GrafPtr currPort ;
- Color col ;
- RGBColor maccol, oldcol ;
-
- switch(itemno) {
- case ambienceUI:
- col = tmpsurf.amb ;
- break ;
- case diffuseUI:
- col = tmpsurf.diff ;
- break ;
- case specularUI:
- col = tmpsurf.spec ;
- break ;
- case difftransUI:
- col = tmpsurf.translu ;
- break ;
- case spectransUI:
- col = tmpsurf.body ;
- break ;
- default:
- return;
- break ;
- }
- GetPort(&currPort) ;
- SetPort(window) ;
- GetForeColor(&oldcol) ;
- GetDItem(window, itemno, &itemType, &itemHandle, &itemRect);
- EraseRect(&itemRect) ;
- FrameRect(&itemRect) ;
- InsetRect(&itemRect,2,2) ;
- maccol.red = (unsigned short) (65535. * col.r) ;
- maccol.green = (unsigned short) (65535. * col.g) ;
- maccol.blue = (unsigned short) (65535. * col.b) ;
- RGBForeColor(&maccol) ;
- PaintRect(&itemRect) ;
- RGBForeColor(&oldcol) ;
- SetPort(currPort) ;
- }
-
- pascal void DrawSurfaceList(WindowPtr window, short item)
- {
- GrafPtr currPort ;
- PenState saveState;
- short itemType;
- Handle itemHandle;
- Rect itemBox;
-
- GetPort(&currPort) ;
- SetPort(window) ;
- GetPenState(&saveState);
- GetDItem(window, item, &itemType, &itemHandle, &itemBox);
- PenNormal() ;
- InsetRect(&itemBox,-1,-1) ;
- FrameRect(&itemBox);
- LUpdate(window->visRgn, surfList) ;
- SetPenState(&saveState);
- SetPort(currPort) ;
- }
-
- extern Surface predefined_surfaces[128];
-
- Surface *EditSurface(Geom *obj)
- {
- ControlHandle itemHandle ;
- Rect itemRect, bounds ;
- DialogPtr surfDialog ;
- GrafPtr currPort;
- register short i;
- short hitItem = 0, theItem, itemType, loop;
- Vector norm, pos ;
- char exit = 0 ;
- Surface *surf, *psurf ;
- char buffer[255], doubleClick;
- Point mousePoint, cellSize ;
- Cell cell = {0,0}, myCell;
-
- if(obj->surf == NULL)
- obj->surf = SurfaceCreate() ;
- else {
- for(surf = Surfaces ; surf ; surf = surf->next) {
- if(surf == obj->surf) /* Uh Oh ! Named surface. Lets warn the user */
- RLerror(RL_WARN,"This surface is a named instance !\rAll other instances will be affected by any changes you make.",0,0,0) ;
- }
- }
- if(obj->surf != NULL) {
- surf = obj->surf ;
- tmpsurf = *surf ;
- surfDialog = GetNewDialog(surfdialogR, 0L, (WindowPtr)-1) ;
-
- /* Turn our user item into a texture list */
- GetDItem(surfDialog, surflistUI, &itemType, &itemHandle, &itemRect);
- SetDItem(surfDialog, surflistUI, itemType, (ProcPtr) DrawSurfaceList, &itemRect);
- SetRect(&bounds,0,0,1,0) ;
- itemRect.right -= 15;
- cellSize.v = cellSize.h = 0;
- surfList = LNew(&itemRect,&bounds,cellSize,0,surfDialog,TRUE,FALSE,FALSE,TRUE) ;
- LAddRow(111,0,surfList) ;
- /* Insert some values */
- for(loop = 0 ; loop<111 ; loop++) {
- psurf = &predefined_surfaces[loop];
- sprintf(buffer,"%s", psurf->name) ;
- for(i = strlen(buffer) ; i < 255 ; i++) buffer[i] = ' ';
- cell.v = loop;
- LSetCell(buffer,255,cell,surfList);
- }
-
- GetDItem(surfDialog, ambienceUI, &itemType, &itemHandle, &itemRect);
- SetDItem(surfDialog, ambienceUI, itemType, (ProcPtr) ColourChoose, &itemRect);
- GetDItem(surfDialog, diffuseUI, &itemType, &itemHandle, &itemRect);
- SetDItem(surfDialog, diffuseUI, itemType, (ProcPtr) ColourChoose, &itemRect);
- GetDItem(surfDialog, specularUI, &itemType, &itemHandle, &itemRect);
- SetDItem(surfDialog, specularUI, itemType, (ProcPtr) ColourChoose, &itemRect);
- GetDItem(surfDialog, difftransUI, &itemType, &itemHandle, &itemRect);
- SetDItem(surfDialog, difftransUI, itemType, (ProcPtr) ColourChoose, &itemRect);
- GetDItem(surfDialog, spectransUI, &itemType, &itemHandle, &itemRect);
- SetDItem(surfDialog, spectransUI, itemType, (ProcPtr) ColourChoose, &itemRect);
-
- SetFloatEditText(surfDialog,specpowET,tmpsurf.srexp);
- SetFloatEditText(surfDialog,attenuationET,tmpsurf.statten);
- SetFloatEditText(surfDialog,refracindexET,tmpsurf.index);
- SetFloatEditText(surfDialog,reflectivityET,tmpsurf.reflect);
- SetFloatEditText(surfDialog,transmittanceET,tmpsurf.transp);
- SetFloatEditText(surfDialog,translucencyET,tmpsurf.translucency);
-
- DrawDialog(surfDialog) ;
- GetPort(&currPort);
- SetPort(surfDialog);
-
- DrawHilite(surfDialog,surfokBU) ;
-
-
- do {
- ModalDialog(NULL, &hitItem) ;
- switch(hitItem) {
- case surflistUI:
- GetMouse(&mousePoint);
- doubleClick = LClick(mousePoint,0,surfList) ;
- if(doubleClick) {
- myCell = LLastClick(surfList) ;
- if(myCell.v>=0 && myCell.v < 111) {
- psurf = tmpsurf.next;
- tmpsurf = predefined_surfaces[myCell.v];
- tmpsurf.next = psurf;
- SetFloatEditText(surfDialog,specpowET,tmpsurf.srexp);
- SetFloatEditText(surfDialog,attenuationET,tmpsurf.statten);
- SetFloatEditText(surfDialog,refracindexET,tmpsurf.index);
- SetFloatEditText(surfDialog,reflectivityET,tmpsurf.reflect);
- SetFloatEditText(surfDialog,transmittanceET,tmpsurf.transp);
- SetFloatEditText(surfDialog,translucencyET,tmpsurf.translucency);
- InvalRect(&surfDialog->portRect);
- }
- }
- break;
- case ambienceUI:
- PickColour(&tmpsurf.amb) ;
- DrawHilite(surfDialog,surfokBU) ;
- break ;
- case diffuseUI:
- PickColour(&tmpsurf.diff) ;
- DrawHilite(surfDialog,surfokBU) ;
- break ;
- case specularUI:
- PickColour(&tmpsurf.spec) ;
- DrawHilite(surfDialog,surfokBU) ;
- break ;
- case difftransUI:
- PickColour(&tmpsurf.translu) ;
- DrawHilite(surfDialog,surfokBU) ;
- break ;
- case spectransUI:
- PickColour(&tmpsurf.body) ;
- DrawHilite(surfDialog,surfokBU) ;
- break ;
- case surfokBU:
- if( GetFloatEditText(surfDialog,specpowET,&tmpsurf.srexp) &&
- GetFloatEditText(surfDialog,attenuationET,&tmpsurf.statten) &&
- GetFloatEditText(surfDialog,refracindexET,&tmpsurf.index) &&
- GetFloatEditText(surfDialog,reflectivityET,&tmpsurf.reflect) &&
- GetFloatEditText(surfDialog,transmittanceET,&tmpsurf.transp) &&
- GetFloatEditText(surfDialog,translucencyET,&tmpsurf.translucency)) {
- *surf = tmpsurf ;
- exit = 1 ;
- }
- else
- SysBeep(1) ;
- break ;
- case surfcancelBU:
- exit = 1 ;
- break ;
- }
- } while (!exit) ;
- LDispose(surfList) ;
- SetPort(currPort);
- DisposDialog(surfDialog) ;
- }
- else
- RLerror(RL_WARN,"Surface creation error",0,0,0) ;
- return surf ;
- }
-
- /* Blob has a maximum number of metaballs set to 30 */
-
- #define MAXMETABALLS 30
-
- void doBlobModify(Geom *obj)
- {
- GrafPtr currPort;
- ControlHandle theHandle ;
- DialogPtr blobDialog ;
- short hitItem = 0, theItem;
- Blob *tblob, *rblob ;
- MetaList *mlist ;
- MetaVector mvec ;
- char exit = 0 ;
- short i, what, ballnr ;
- Float T ;
- Point p ;
- int num ;
-
- if(ObjectType(obj) != BLOB) return ;
- rblob = (Blob *) obj->obj ;
- if(rblob->num > MAXMETABALLS) return ;
-
- /* Create a 30 metaball blob */
-
- mlist = Malloc(MAXMETABALLS * sizeof(MetaList)) ;
- if(!mlist) return ;
-
- /* First build an initialised meta list */
-
- for(i = 0 ; i < MAXMETABALLS ; i++) {
- mlist[i].next = (i != MAXMETABALLS-1) ? &mlist[i+1] : NULL ;
- mlist[i].mvec.x = 0 ;
- mlist[i].mvec.y = 0 ;
- mlist[i].mvec.z = 0 ;
- mlist[i].mvec.rs = 1. ;
- mlist[i].mvec.c0 = 1. ;
- }
- /* Create the blob with thresh 1 */
- tblob = BlobCreate(1.,mlist,MAXMETABALLS) ;
- /* Copy info from real blob across to temporary blob */
- for(i = 0 ; i < rblob->num ; i++) {
- tblob->list[i] = rblob->list[i];
- if(tblob->list[i].rs>0) tblob->list[i].rs = sqrt(tblob->list[i].rs);
- }
- tblob->num = rblob->num ;
- tblob->T = rblob->T ;
-
- /* ballnr tells us which metaball we are currently editting */
- ballnr = 0 ;
- blobDialog = GetNewDialog(blobdialogR, 0L, (WindowPtr)-1) ;
-
- SetCtlMax(SnatchHandle(blobDialog,blobmetaballchooseCI),MAXMETABALLS-1);
- SetFloatEditText(blobDialog,blobxET,tblob->list[ballnr].x) ;
- SetFloatEditText(blobDialog,blobyET,tblob->list[ballnr].y) ;
- SetFloatEditText(blobDialog,blobzET,tblob->list[ballnr].z) ;
- SetFloatEditText(blobDialog,blobstrengthET,tblob->list[ballnr].c0) ;
- SetFloatEditText(blobDialog,blobradiusET,tblob->list[ballnr].rs) ;
- SetFloatEditText(blobDialog,blobthreshET,tblob->T) ;
- SetIntEditText(blobDialog,blobsizeET,tblob->num) ;
- SetIntStringText(blobDialog,blobmetaballnrST,"Meta-Ball",0) ;
-
- mvec = tblob->list[ballnr] ;
- T = tblob->T ;
- num = tblob->num ;
-
- DrawDialog(blobDialog) ;
- GetPort(&currPort);
- SetPort(blobDialog);
- DrawHilite(blobDialog,blobuseBU) ;
- do {
- ModalDialog(NULL, &hitItem) ;
- switch(hitItem) {
- case blobuseBU:
- if(GetFloatEditText(blobDialog,blobxET,&mvec.x) &&
- GetFloatEditText(blobDialog,blobyET,&mvec.y) &&
- GetFloatEditText(blobDialog,blobzET,&mvec.z) &&
- GetFloatEditText(blobDialog,blobradiusET,&mvec.rs) &&
- GetFloatEditText(blobDialog,blobstrengthET,&mvec.c0) &&
- GetFloatEditText(blobDialog,blobthreshET,&T) &&
- GetIntEditText(blobDialog,blobsizeET,&num) &&
- (num > 0) && (num < MAXMETABALLS)) {
-
- tblob->T = T ;
- tblob->num = num ;
- tblob->list[ballnr] = mvec ;
-
- /* Completely purge and rebuild the blob */
- if(rblob->list) Free(rblob->list) ;
- if(rblob->ilist) Free(rblob->ilist) ;
- if(rblob->iarr) Free(rblob->iarr) ;
- if(obj->obj) Free(obj->obj) ;
-
- /* We build a metalist from the info stored in tblob */
- mlist = Malloc(tblob->num * sizeof(MetaList)) ;
- for(i = 0 ; i < tblob->num ; i++) {
- mlist[i].next = (i != tblob->num-1) ? &mlist[i+1] : NULL ;
- mlist[i].mvec = tblob->list[i];
- }
- /* Shove it into the new blob */
- obj->obj = BlobCreate(tblob->T,mlist,tblob->num) ;
- /* Now destroy our tblob */
- if(tblob->list) Free(tblob->list) ;
- if(tblob->ilist) Free(tblob->ilist) ;
- if(tblob->iarr) Free(tblob->iarr) ;
- if(tblob) Free(tblob) ;
- exit = 1 ;
- }
- else
- SysBeep(1) ;
- break ;
- case blobmetaballchooseCI:
- GetMouse(&p) ;
- theHandle = SnatchHandle(blobDialog,blobmetaballchooseCI) ;
- what = TestControl(theHandle,p);
- if(GetFloatEditText(blobDialog,blobxET,&mvec.x) &&
- GetFloatEditText(blobDialog,blobyET,&mvec.y) &&
- GetFloatEditText(blobDialog,blobzET,&mvec.z) &&
- GetFloatEditText(blobDialog,blobradiusET,&mvec.rs) &&
- GetFloatEditText(blobDialog,blobstrengthET,&mvec.c0)) {
- tblob->list[ballnr] = mvec ;
- switch(what) {
- case inDownButton:
- case inPageDown:
- SetCtlValue(theHandle,GetCtlValue(theHandle)+1) ; break;
- case inUpButton:
- case inPageUp:
- SetCtlValue(theHandle,GetCtlValue(theHandle)-1) ; break;
- }
- ballnr = GetCtlValue(theHandle) ;
- mvec = tblob->list[ballnr];
- SetFloatEditText(blobDialog,blobxET,tblob->list[ballnr].x) ;
- SetFloatEditText(blobDialog,blobyET,tblob->list[ballnr].y) ;
- SetFloatEditText(blobDialog,blobzET,tblob->list[ballnr].z) ;
- SetFloatEditText(blobDialog,blobstrengthET,tblob->list[ballnr].c0) ;
- SetFloatEditText(blobDialog,blobradiusET,tblob->list[ballnr].rs) ;
- SetIntStringText(blobDialog,blobmetaballnrST,"Meta-Ball",ballnr) ;
- }
- else
- SysBeep(1) ;
- break ;
- case blobcancelBU:
- exit = 1 ;
- break ;
- }
- } while (!exit) ;
- SetPort(currPort);
- DisposDialog(blobDialog) ;
- }
-
-
- void doPlaneModify(Geom *obj)
- {
- ControlHandle theHandle ;
- DialogPtr planeDialog ;
- short hitItem = 0, theItem;
- Vector norm, pos ;
- Plane *plane ;
- char exit = 0 ;
-
- if(ObjectType(obj) != PLANE) return ;
- plane = (Plane *)obj->obj ;
- pos = plane->pos ;
- norm = plane->norm ;
-
- planeDialog = GetNewDialog(planedialogR, 0L, (WindowPtr)-1) ;
-
- SetFloatEditText(planeDialog,planenormalx,norm.x) ;
- SetFloatEditText(planeDialog,planenormaly,norm.y) ;
- SetFloatEditText(planeDialog,planenormalz,norm.z) ;
- SetFloatEditText(planeDialog,planepointx,pos.x) ;
- SetFloatEditText(planeDialog,planepointy,pos.y) ;
- SetFloatEditText(planeDialog,planepointz,pos.z) ;
-
- DrawDialog(planeDialog) ;
- DrawHilite(planeDialog,planeokBU) ;
- do {
- ModalDialog(NULL, &hitItem) ;
- switch(hitItem) {
- case planeokBU:
- if(GetFloatEditText(planeDialog,planenormalx,&norm.x) &&
- GetFloatEditText(planeDialog,planenormaly,&norm.y) &&
- GetFloatEditText(planeDialog,planenormalz,&norm.z) &&
- GetFloatEditText(planeDialog,planepointx,&pos.x) &&
- GetFloatEditText(planeDialog,planepointy,&pos.y) &&
- GetFloatEditText(planeDialog,planepointz,&pos.z)) {
- if (VecNormalize(&norm) == 0.) {
- RLerror(RL_WARN, "Degenerate plane normal.\n",0,0,0);
- break;
- }
- plane->norm = norm;
- plane->pos = pos;
- plane->d = dotp(&plane->norm, &pos);
- }
- exit = 1 ;
- break ;
- case planecancelBU:
- exit = 1 ;
- break ;
- }
- } while (!exit) ;
- DisposDialog(planeDialog) ;
- }
-
-
- void doSphereModify(Geom *obj)
- {
- ControlHandle theHandle ;
- DialogPtr sphereDialog ;
- Rect theRect ;
- short hitItem = 0, theItem;
- long theType ;
- Sphere *sphere, tmpsphere ;
- Str255 number ;
- char exit = 0 ;
- Float r,x,y,z ;
-
- if(ObjectType(obj) != SPHERE) return ;
-
- sphere = obj->obj ;
- tmpsphere = *sphere;
-
- sphereDialog = GetNewDialog(spheredialogR, 0L, (WindowPtr)-1) ;
- SetFloatEditText(sphereDialog,sphereradius,tmpsphere.r) ;
- SetFloatEditText(sphereDialog,spherecentrex,tmpsphere.x) ;
- SetFloatEditText(sphereDialog,spherecentrey,tmpsphere.y) ;
- SetFloatEditText(sphereDialog,spherecentrez,tmpsphere.z) ;
- DrawDialog(sphereDialog) ;
- DrawHilite(sphereDialog,sphereokBU) ;
- do {
- ModalDialog(NULL, &hitItem) ;
- switch(hitItem) {
- case sphereokBU:
- if( GetFloatEditText(sphereDialog,spherecentrex,&tmpsphere.x) &&
- GetFloatEditText(sphereDialog,spherecentrey,&tmpsphere.y) &&
- GetFloatEditText(sphereDialog,spherecentrez,&tmpsphere.z) &&
- GetFloatEditText(sphereDialog,sphereradius,&tmpsphere.r)) {
- *sphere = tmpsphere;
- sphere->rsq = sphere->r * sphere->r ;
- exit = 1 ;
- }
- else
- SysBeep(1) ;
- break ;
- case spherecancelBU:
- exit = 1 ;
- break ;
- }
- } while (!exit) ;
- DisposDialog(sphereDialog) ;
- }
-
- void doBoxModify(Geom *obj)
- {
- ControlHandle theHandle ;
- DialogPtr boxDialog ;
- Float bounds[2][3] ;
- Box *box ;
- Str255 number ;
- short hitItem = 0, theItem;
- register short i,j ;
- char exit = 0 ;
-
- if(ObjectType(obj) != BOX) return ;
- box = obj->obj ;
- for(i = 0 ; i < 2 ; i++)
- for(j = 0 ; j < 3 ; j++)
- bounds[i][j] = box->bounds[i][j] ;
-
- boxDialog = GetNewDialog(boxdialogR, 0L, (WindowPtr)-1) ;
-
- SetFloatEditText(boxDialog,boxbound1x,bounds[0][0]) ;
- SetFloatEditText(boxDialog,boxbound1y,bounds[0][1]) ;
- SetFloatEditText(boxDialog,boxbound1z,bounds[0][2]) ;
- SetFloatEditText(boxDialog,boxbound2x,bounds[1][0]) ;
- SetFloatEditText(boxDialog,boxbound2y,bounds[1][1]) ;
- SetFloatEditText(boxDialog,boxbound2z,bounds[1][2]) ;
- DrawDialog(boxDialog) ;
- DrawHilite(boxDialog,boxokBU) ;
- do {
- ModalDialog(NULL, &hitItem) ;
- switch(hitItem) {
- case boxokBU:
- if( GetFloatEditText(boxDialog,boxbound1x,&bounds[0][0]) &&
- GetFloatEditText(boxDialog,boxbound1y,&bounds[0][1]) &&
- GetFloatEditText(boxDialog,boxbound1z,&bounds[0][2]) &&
- GetFloatEditText(boxDialog,boxbound2x,&bounds[1][0]) &&
- GetFloatEditText(boxDialog,boxbound2y,&bounds[1][1]) &&
- GetFloatEditText(boxDialog,boxbound2z,&bounds[1][2])) {
- for(i = 0 ; i < 2 ; i++)
- for(j = 0 ; j < 3 ; j++)
- box->bounds[i][j] = bounds[i][j] ;
- exit = 1 ;
- }
- else
- SysBeep(1) ;
- break ;
- case boxcancelBU:
- exit = 1 ;
- break ;
- }
- } while (!exit) ;
- DisposDialog(boxDialog) ;
- }
-
- void doDiscModify(Geom *obj)
- {
- ControlHandle theHandle ;
- DialogPtr discDialog ;
- short hitItem = 0, theItem;
- Str255 number ;
- Disc *disc ;
- Float radius ;
- Vector norm, pos ;
- char exit = 0 ;
-
- if(ObjectType(obj) != DISC) return ;
-
- disc = (Disc *) obj->obj ;
- pos = disc->pos ;
- norm = disc->norm ;
- radius = disc->radius ;
- discDialog = GetNewDialog(discdialogR, 0L, (WindowPtr)-1) ;
- SetFloatEditText(discDialog,discnormalx,norm.x) ;
- SetFloatEditText(discDialog,discnormaly,norm.y) ;
- SetFloatEditText(discDialog,discnormalz,norm.z) ;
- SetFloatEditText(discDialog,disccentrex,pos.x) ;
- SetFloatEditText(discDialog,disccentrey,pos.y) ;
- SetFloatEditText(discDialog,disccentrez,pos.z) ;
- SetFloatEditText(discDialog,discradius,radius) ;
- DrawDialog(discDialog) ;
- DrawHilite(discDialog,discokBU) ;
- do {
- ModalDialog(NULL, &hitItem) ;
- switch(hitItem) {
- case discokBU:
- if( GetFloatEditText(discDialog,discnormalx,&norm.x) &&
- GetFloatEditText(discDialog,discnormaly,&norm.y) &&
- GetFloatEditText(discDialog,discnormalz,&norm.z) &&
- GetFloatEditText(discDialog,disccentrex,&pos.x) &&
- GetFloatEditText(discDialog,disccentrey,&pos.y) &&
- GetFloatEditText(discDialog,disccentrez,&pos.z) &&
- GetFloatEditText(discDialog,discradius,&radius)) {
- disc->pos = pos ;
- disc->norm = norm ;
- disc->radius = radius ;
- exit = 1 ;
- }
- else
- SysBeep(1) ;
- break ;
- case disccancelBU:
- exit = 1 ;
- break ;
- }
- } while (!exit) ;
- DisposDialog(discDialog) ;
- }
-
- void doCylinderModify(Geom *obj)
- {
- ControlHandle theHandle ;
- DialogPtr cylinderDialog ;
- Cylinder *cyl ;
- Str255 number ;
- short hitItem = 0, theItem;
- char exit = 0 ;
- Vector dummy, bottom, top, axis ;
- Float radius, length ;
-
- if(ObjectType(obj) != CYLINDER) return ;
- cyl = (Cylinder *) obj->obj ;
-
- /* We have to be a bit more clever when determining the shape of a cylinder since everything
- * has been converted into normalized coordinates
- */
-
- /* Top and bottom of our normalized cylinder */
- bottom.x = bottom.y = bottom.z = 0. ;
- top.x = top.y = 0. ; top.z = 1. ;
- /* Dummy is a point on the edge of our normalized cylinder */
- dummy.x = 1.0 ; dummy.y = dummy.z = 0. ;
-
- /* Now transform these points */
- PointTransform(&top,&cyl->trans.trans) ;
- PointTransform(&bottom,&cyl->trans.trans) ;
- PointTransform(&dummy,&cyl->trans.trans) ;
-
- /* The radius value is the distance between bottom and dummy */
- VecSub(bottom,dummy,&dummy) ;
- radius = VecNormalize(&dummy) ;
-
- cylinderDialog = GetNewDialog(cylinderdialogR, 0L, (WindowPtr)-1) ;
-
- SetFloatEditText(cylinderDialog,cylindertopx,top.x) ;
- SetFloatEditText(cylinderDialog,cylindertopy,top.y) ;
- SetFloatEditText(cylinderDialog,cylindertopz,top.z) ;
- SetFloatEditText(cylinderDialog,cylinderbottomx,bottom.x) ;
- SetFloatEditText(cylinderDialog,cylinderbottomy,bottom.y) ;
- SetFloatEditText(cylinderDialog,cylinderbottomz,bottom.z) ;
- SetFloatEditText(cylinderDialog,cylinderradius,radius) ;
- DrawDialog(cylinderDialog) ;
- DrawHilite(cylinderDialog,cylinderokBU) ;
- do {
- ModalDialog(NULL, &hitItem) ;
- switch(hitItem) {
- case cylinderokBU:
- if(GetFloatEditText(cylinderDialog,cylindertopx,&top.x) &&
- GetFloatEditText(cylinderDialog,cylindertopy,&top.y) &&
- GetFloatEditText(cylinderDialog,cylindertopz,&top.z) &&
- GetFloatEditText(cylinderDialog,cylinderbottomx,&bottom.x) &&
- GetFloatEditText(cylinderDialog,cylinderbottomy,&bottom.y) &&
- GetFloatEditText(cylinderDialog,cylinderbottomz,&bottom.z) &&
- GetFloatEditText(cylinderDialog,cylinderradius,&radius)) {
- VecSub(top, bottom, &axis);
- length = VecNormalize(&axis);
- CoordSysTransform(&bottom, &axis, radius, length, &cyl->trans);
- exit = 1 ;
- }
- else
- SysBeep(1) ;
- break ;
- case cylindercancelBU:
- exit = 1 ;
- break ;
- }
- } while (!exit) ;
- DisposDialog(cylinderDialog) ;
- }
-
- void doConeModify(Geom *obj)
- {
- ControlHandle theHandle ;
- DialogPtr coneDialog ;
- Cone *cone ;
- Str255 number ;
- short hitItem = 0, theItem;
- char exit = 0 ;
- Vector bottomr, bottom, apex ;
- Float br, ar ;
-
- if(ObjectType(obj) != CONE) return ;
- cone = (Cone *) obj->obj ;
-
- /* We have to be a bit more clever when determining the shape of a cone since everything
- * has been converted into normalized coordinates
- */
-
- /* apex and bottom of our normalized cone */
- bottom.x = bottom.y = 0 ; bottom.z = 1. ;
- apex.x = apex.y = 0. ; apex.z = cone->start_dist ;
- /* Point on the edge of our normalized cone */
- bottomr.x = 1.0 ; bottomr.y = 0 ; bottomr.z = 1. ;
-
- /* Now transform these points */
- PointTransform(&apex,&cone->trans.trans) ;
- PointTransform(&bottom,&cone->trans.trans) ;
- PointTransform(&bottomr,&cone->trans.trans) ;
-
- /* Now calculate the radii */
- VecSub(bottom,bottomr,&bottomr) ;
- br = VecNormalize(&bottomr) ;
- ar = cone->start_dist * br ;
-
- coneDialog = GetNewDialog(conedialogR, 0L, (WindowPtr)-1) ;
- SetFloatEditText(coneDialog,coneapexx,apex.x) ;
- SetFloatEditText(coneDialog,coneapexy,apex.y) ;
- SetFloatEditText(coneDialog,coneapexz,apex.z) ;
- SetFloatEditText(coneDialog,conebottomx,bottom.x) ;
- SetFloatEditText(coneDialog,conebottomy,bottom.y) ;
- SetFloatEditText(coneDialog,conebottomz,bottom.z) ;
- SetFloatEditText(coneDialog,conebottomr,br) ;
- SetFloatEditText(coneDialog,coneapexr,ar) ;
- DrawDialog(coneDialog) ;
- DrawHilite(coneDialog,coneokBU) ;
- do {
- ModalDialog(NULL, &hitItem) ;
- switch(hitItem) {
- case coneokBU:
- if(GetFloatEditText(coneDialog,coneapexx,&apex.x) &&
- GetFloatEditText(coneDialog,coneapexy,&apex.y) &&
- GetFloatEditText(coneDialog,coneapexz,&apex.z) &&
- GetFloatEditText(coneDialog,conebottomx,&bottom.x) &&
- GetFloatEditText(coneDialog,conebottomy,&bottom.y) &&
- GetFloatEditText(coneDialog,conebottomz,&bottom.z) &&
- GetFloatEditText(coneDialog,conebottomr,&br) &&
- GetFloatEditText(coneDialog,coneapexr,&ar)) {
- Float tantheta, lprime, tlen, len, dtmp;
- Vector axis, base, tmp;
-
- if(equal(ar,br)) {
- RLerror(RL_WARN, "Top and bottom radii can not be equal",0,0,0) ;
- break;
- }
- else if(ar < br) {
- tmp = bottom;
- bottom = apex;
- apex = tmp;
- dtmp = br;
- br = ar;
- ar = dtmp;
- }
- VecSub(apex, bottom, &axis);
- len = VecNormalize(&axis);
- if (len < EPSILON) {
- RLerror(RL_WARN, "Degenerate cone.\n",0,0,0);
- break ;
- }
- tantheta = (ar - br) / len;
- lprime = br / tantheta;
- VecScale(-lprime, axis, &base);
- VecAdd(base, bottom, &base);
- tlen = lprime + len;
- cone->start_dist = lprime / tlen;
- CoordSysTransform(&base, &axis, ar, tlen, &cone->trans);
- exit = 1 ;
- }
- else
- SysBeep(1) ;
- break ;
- case conecancelBU:
- exit = 1 ;
- break ;
- }
- } while (!exit) ;
- DisposDialog(coneDialog) ;
- }
-
- #define POLYPOINTS 30
-
- void doPolygonModify(Geom *obj)
- {
- GrafPtr currPort;
- ControlHandle theHandle ;
- DialogPtr polyDialog ;
- short hitItem = 0, theItem, what, polynr,loop;
- Str255 number ;
- Point p;
- Float radius ;
- Vector vec ;
- RPolygon *tpoly, *poly;
- PointList *plist[POLYPOINTS], *next, *this;
- char exit = 0 ;
- int points;
-
- if(ObjectType(obj) != POLYGON) return ;
-
- /* Create a dummy polygon first */
- for(loop = POLYPOINTS-1 ; loop >= 0 ; loop--) {
- plist[loop] = Malloc(sizeof(PointList));
- plist[loop]->next = plist[loop+1];
- plist[loop]->vec.x = (Float)loop;
- plist[loop]->vec.y = (Float)loop*(Float)loop;
- plist[loop]->vec.z = 0;
- }
- plist[POLYPOINTS-1]->next = NULL;
- tpoly = PolygonCreate(plist[0],POLYPOINTS,FALSE);
-
- /* Now copy our poly into the temporary store */
- poly = obj->obj;
- for(loop = 0 ; loop < poly->npoints; loop++)
- tpoly->points[loop] = poly->points[loop];
-
- polynr = 0;
- polyDialog = GetNewDialog(polydialogR, 0L, (WindowPtr)-1) ;
- SetCtlMax(SnatchHandle(polyDialog,polychooseCI),POLYPOINTS-1);
- SetFloatEditText(polyDialog,polyxET,tpoly->points[polynr].x) ;
- SetFloatEditText(polyDialog,polyyET,tpoly->points[polynr].y) ;
- SetFloatEditText(polyDialog,polyzET,tpoly->points[polynr].z) ;
- SetIntEditText(polyDialog,polyverticesET,poly->npoints) ;
- SetIntStringText(polyDialog,polyvertexST,"Vertex",polynr) ;
-
- GetPort(&currPort);
- SetPort(polyDialog);
- DrawDialog(polyDialog) ;
- DrawHilite(polyDialog,polyuseBU) ;
- do {
- ModalDialog(NULL, &hitItem) ;
- switch(hitItem) {
- case polychooseCI:
- GetMouse(&p) ;
- theHandle = SnatchHandle(polyDialog,polychooseCI) ;
- what = TestControl(theHandle,p);
- if(GetFloatEditText(polyDialog,polyxET,&vec.x) &&
- GetFloatEditText(polyDialog,polyyET,&vec.y) &&
- GetFloatEditText(polyDialog,polyzET,&vec.z)) {
- tpoly->points[polynr] = vec ;
- switch(what) {
- case inDownButton:
- case inPageDown:
- SetCtlValue(theHandle,GetCtlValue(theHandle)+1) ; break;
- case inUpButton:
- case inPageUp:
- SetCtlValue(theHandle,GetCtlValue(theHandle)-1) ; break;
- }
- polynr = GetCtlValue(theHandle) ;
- vec = tpoly->points[polynr];
- SetFloatEditText(polyDialog,polyxET,tpoly->points[polynr].x) ;
- SetFloatEditText(polyDialog,polyyET,tpoly->points[polynr].y) ;
- SetFloatEditText(polyDialog,polyzET,tpoly->points[polynr].z) ;
- SetIntStringText(polyDialog,polyvertexST,"Vertex",polynr) ;
- }
- else
- SysBeep(1) ;
- break ;
- case polyuseBU:
- if(GetFloatEditText(polyDialog,polyxET,&vec.x) &&
- GetFloatEditText(polyDialog,polyyET,&vec.y) &&
- GetFloatEditText(polyDialog,polyzET,&vec.z) &&
- GetIntEditText(polyDialog,polyverticesET,&points) &&
- (points <= POLYPOINTS) && points) {
-
- /* Store the last edited point */
- polynr = GetCtlValue(SnatchHandle(polyDialog,polychooseCI)) ;
- tpoly->points[polynr] = vec ;
-
- /* Copy our data into a new pointlist */
- for(loop = (short)points-1 ; loop >= 0 ; loop--) {
- plist[loop] = Malloc(sizeof(PointList));
- plist[loop]->next = plist[loop+1];
- plist[loop]->vec = tpoly->points[loop];
- }
- plist[points-1]->next = NULL;
-
- /* Remove the old and temporary polygons */
- Free(poly->points);
- Free(poly);
- Free(tpoly->points);
- Free(tpoly);
-
- /* create a new poly with the new points */
- obj->obj=PolygonCreate(plist[0],points,FALSE);
- exit = 1 ;
- }
- else
- SysBeep(1);
- break ;
- case polycancelBU:
- exit = 1 ;
- break ;
- }
- } while (!exit) ;
- SetPort(currPort);
- DisposDialog(polyDialog) ;
- }
-
- void doTriangleModify(Geom *obj)
- {
- ControlHandle theHandle ;
- DialogPtr triangleDialog ;
- short hitItem = 0, theItem;
- Str255 number ;
- Triangle *tri ;
- Float d ;
- char exit = 0 ;
- Vector p1,p2,p3, n1,n2,n3, ptmp, anorm;
-
- if(ObjectType(obj) != TRIANGLE) return ;
-
- tri = (Triangle *) obj->obj ;
- p1 = tri->p[0];
- p2 = tri->p[1];
- p3 = tri->p[2];
- triangleDialog = GetNewDialog(triangledialogR, 0L, (WindowPtr)-1) ;
- SetFloatEditText(triangleDialog,triv1xET,p1.x) ;
- SetFloatEditText(triangleDialog,triv1yET,p1.y) ;
- SetFloatEditText(triangleDialog,triv1zET,p1.z) ;
- SetFloatEditText(triangleDialog,triv2xET,p2.x) ;
- SetFloatEditText(triangleDialog,triv2yET,p2.y) ;
- SetFloatEditText(triangleDialog,triv2zET,p2.z) ;
- SetFloatEditText(triangleDialog,triv3xET,p3.x) ;
- SetFloatEditText(triangleDialog,triv3yET,p3.y) ;
- SetFloatEditText(triangleDialog,triv3zET,p3.z) ;
- if(tri->vnorm) {
- n1 = tri->vnorm[0];
- n2 = tri->vnorm[1];
- n3 = tri->vnorm[2];
- SetFloatEditText(triangleDialog,trin1xET,n1.x) ;
- SetFloatEditText(triangleDialog,trin1yET,n1.y) ;
- SetFloatEditText(triangleDialog,trin1zET,n1.z) ;
- SetFloatEditText(triangleDialog,trin2xET,n2.x) ;
- SetFloatEditText(triangleDialog,trin2yET,n2.y) ;
- SetFloatEditText(triangleDialog,trin2zET,n2.z) ;
- SetFloatEditText(triangleDialog,trin3xET,n3.x) ;
- SetFloatEditText(triangleDialog,trin3yET,n3.y) ;
- SetFloatEditText(triangleDialog,trin3zET,n3.z) ;
- }
- SetCtlValue(SnatchHandle(triangleDialog,triphongCB), (short)tri->type) ;
- DrawDialog(triangleDialog) ;
- DrawHilite(triangleDialog,triuseBU) ;
- do {
- ModalDialog(NULL, &hitItem) ;
- switch(hitItem) {
- case triphongCB:
- if(GetCtlValue(SnatchHandle(triangleDialog,triphongCB))==1)
- SetCtlValue(SnatchHandle(triangleDialog,triphongCB),0);
- else
- SetCtlValue(SnatchHandle(triangleDialog,triphongCB),1) ;
- break;
- case triuseBU:
- if(GetFloatEditText(triangleDialog,triv1xET,&p1.x) &&
- GetFloatEditText(triangleDialog,triv1yET,&p1.y) &&
- GetFloatEditText(triangleDialog,triv1zET,&p1.z) &&
- GetFloatEditText(triangleDialog,triv2xET,&p2.x) &&
- GetFloatEditText(triangleDialog,triv2yET,&p2.y) &&
- GetFloatEditText(triangleDialog,triv2zET,&p2.z) &&
- GetFloatEditText(triangleDialog,triv3xET,&p3.x) &&
- GetFloatEditText(triangleDialog,triv3yET,&p3.y) &&
- GetFloatEditText(triangleDialog,triv3zET,&p3.z)) {
-
- if ((tri->type == PHONGTRI) &&
- (!GetFloatEditText(triangleDialog,trin1xET,&n1.x) ||
- !GetFloatEditText(triangleDialog,trin1zET,&n1.z) ||
- !GetFloatEditText(triangleDialog,trin2xET,&n2.x) ||
- !GetFloatEditText(triangleDialog,trin2yET,&n2.y) ||
- !GetFloatEditText(triangleDialog,trin2zET,&n2.z) ||
- !GetFloatEditText(triangleDialog,trin3xET,&n3.x) ||
- !GetFloatEditText(triangleDialog,trin3yET,&n3.y) ||
- !GetFloatEditText(triangleDialog,trin3zET,&n3.z))) {
- SysBeep(1);
- break;
- }
-
- VecSub(p2, p1, &tri->e[0]);
- VecSub(p3, p2, &tri->e[1]);
- VecSub(p1, p3, &tri->e[2]);
-
- /* Find plane normal. */
- VecCross(&tri->e[0], &tri->e[1], &ptmp);
- tri->nrm = ptmp;
- if (VecNormalize(&tri->nrm) == 0.) {
- RLerror(RL_ADVISE, "Degenerate triangle.\n",0,0,0);
- break;
- }
- tri->d = dotp(&tri->nrm, &p1);
- tri->p[0] = p1;
- tri->p[1] = p2;
- tri->p[2] = p3;
-
- tri->type = (int) GetCtlValue(SnatchHandle(triangleDialog,triphongCB));
- if (tri->type == PHONGTRI) {
- if (VecNormalize(&n1) == 0. || VecNormalize(&n2) == 0. ||
- VecNormalize(&n3) == 0.) {
- RLerror(RL_WARN, "Degenerate vertex normal.\n",0,0,0);
- break;
- }
- if(!tri->vnorm) tri->vnorm = (Vector *)Malloc(3 * sizeof(Vector));
- tri->vnorm[0] = n1;
- tri->vnorm[1] = n2;
- tri->vnorm[2] = n3;
- if (dotp(&tri->vnorm[0], &tri->nrm) < 0.) {
- /*
- * Reverse direction of surface normal on Phong
- * triangle if the surface normal points "away"
- * from the first vertex normal.
- * Note that this means that we trust the vertex
- * normals rather than trust that the user gave the
- * vertices in the correct order.
- */
- RLerror(RL_ADVISE, "Inconsistant triangle normals.\n",0,0,0);
- VecScale(-1., tri->nrm, &tri->nrm);
- VecScale(-1., ptmp, &ptmp);
- tri->d = -tri->d;
- VecScale(-1., tri->e[0], &tri->e[0]);
- VecScale(-1., tri->e[1], &tri->e[1]);
- VecScale(-1., tri->e[2], &tri->e[2]);
- }
- }
- /*
- * Find "dominant" part of normal vector.
- */
- anorm.x = fabs(ptmp.x);
- anorm.y = fabs(ptmp.y);
- anorm.z = fabs(ptmp.z);
-
- /*
- * Scale edges by dominant part of normal. This makes intersection
- * testing a bit faster.
- */
- if (anorm.x > anorm.y && anorm.x > anorm.z) {
- tri->index = XNORMAL;
- d = 1. / ptmp.x;
- } else if (anorm.y > anorm.z) {
- tri->index = YNORMAL;
- d = 1. / ptmp.y;
- } else {
- tri->index = ZNORMAL;
- d = 1. /ptmp.z;
- }
-
- VecScale(d, tri->e[0], &tri->e[0]);
- VecScale(d, tri->e[1], &tri->e[1]);
- VecScale(d, tri->e[2], &tri->e[2]);
-
- exit=1;
- }
- else
- SysBeep(1);
- break ;
- case tricancelBU:
- exit = 1 ;
- break ;
- }
- } while (!exit) ;
- DisposDialog(triangleDialog) ;
- }
-
- void doTorusModify(Geom *obj)
- {
- ControlHandle theHandle ;
- DialogPtr torDialog ;
- Torus *torus;
- Str255 number ;
- short hitItem = 0, theItem;
- char exit = 0 ;
- Vector centre, normal ;
- Float a,b;
-
- if(ObjectType(obj) != TORUS) return ;
- torus = (Torus *) obj->obj ;
-
- /* Stick in the canonical centre and normal */
- centre.x = centre.y = centre.z =0.;
- normal.x = normal.y = 0.; normal.z = 1.;
-
- /* Now transform these points */
- PointTransform(¢re,&torus->trans.trans) ;
- PointTransform(&normal,&torus->trans.trans) ;
- VecNormalize(&normal);
-
- a = torus->a;
- b = torus->b;
-
- torDialog = GetNewDialog(torusdialogR, 0L, (WindowPtr)-1) ;
- SetFloatEditText(torDialog,torposxET,centre.x) ;
- SetFloatEditText(torDialog,torposyET,centre.y) ;
- SetFloatEditText(torDialog,torposzET,centre.z) ;
- SetFloatEditText(torDialog,tornormxET,normal.x) ;
- SetFloatEditText(torDialog,tornormyET,normal.y) ;
- SetFloatEditText(torDialog,tornormzET,normal.z) ;
- SetFloatEditText(torDialog,torsweptET,b) ;
- SetFloatEditText(torDialog,tortubeET,a) ;
- DrawDialog(torDialog) ;
- DrawHilite(torDialog,toruseBU) ;
- do {
- ModalDialog(NULL, &hitItem) ;
- switch(hitItem) {
- case toruseBU:
- if(GetFloatEditText(torDialog,torposxET,¢re.x) &&
- GetFloatEditText(torDialog,torposyET,¢re.y) &&
- GetFloatEditText(torDialog,torposzET,¢re.z) &&
- GetFloatEditText(torDialog,tornormxET,&normal.x) &&
- GetFloatEditText(torDialog,tornormyET,&normal.y) &&
- GetFloatEditText(torDialog,tornormzET,&normal.z) &&
- GetFloatEditText(torDialog,torsweptET,&b) &&
- GetFloatEditText(torDialog,tortubeET,&a)) {
- Free(torus);
- obj->obj = TorusCreate(a,b,¢re,&normal);
- exit = 1 ;
- }
- else
- SysBeep(1) ;
- break ;
- case torcancel:
- exit = 1 ;
- break ;
- }
- } while (!exit) ;
- DisposDialog(torDialog) ;
- }
-
-
- void doObjectModify(Geom *obj)
- {
- extern void GeomBounds(Geom *obj, Float bounds[2][3]) ;
- Geom *obj2 ;
- GrafPtr currPort;
- DialogPtr objectDialog ;
- short hitItem = 0, theItem;
- char exit = 0 ;
-
- if(!obj) return ;
- for(obj2 = Objects ; obj2 ; obj2 = obj2->next) {
- if(obj == obj2)
- RLerror(RL_WARN,"This object is a named instance !\rAll other instances will be affected by any changes you make.",0,0,0) ;
- }
-
- objectDialog = GetNewDialog(objectdialogR, 0L, (WindowPtr)-1) ;
- DrawDialog(objectDialog) ;
- DrawHilite(objectDialog,objectdoneBU) ;
- GetPort(&currPort);
- SetPort(objectDialog);
- do {
- ModalDialog(NULL, &hitItem) ;
- switch(hitItem) {
- case objectdoneBU:
- exit=1;
- break;
- case objecttransformsBU:
- EditTransforms(obj) ;
- SetPort(editorDialog);
- InvalRect(&editorDialog->portRect);
- SetPort(objectDialog);
- DrawHilite(objectDialog,objectdoneBU) ;
- break ;
- case objectsurfaceBU:
- EditSurface(obj) ;
- SetPort(editorDialog);
- InvalRect(&editorDialog->portRect);
- SetPort(objectDialog);
- DrawHilite(objectDialog,objectdoneBU) ;
- break ;
- case objecttextureBU:
- EditTexture(obj) ;
- DrawHilite(objectDialog,objectdoneBU) ;
- break ;
- case objecteditBU:
- switch(ObjectType(obj)) {
- case -1: return ;
- case PLANE: doPlaneModify(obj) ; break;
- case SPHERE: doSphereModify(obj) ; break;
- case CONE: doConeModify(obj) ; break;
- case BOX: doBoxModify(obj) ; break;
- case BLOB: doBlobModify(obj) ; break;
- case DISC: doDiscModify(obj) ; break;
- case CYLINDER: doCylinderModify(obj); break;
- case POLYGON: doPolygonModify(obj); break;
- case TORUS: doTorusModify(obj); break;
- case TRIANGLE: doTriangleModify(obj); break;
- case HF:
- default:
- RLerror(RL_WARN,"No editor exists for this object\r",0,0,0);
- break;
- }
- SetPort(editorDialog);
- InvalRect(&editorDialog->portRect);
- SetPort(objectDialog);
- DrawHilite(objectDialog,objectdoneBU) ;
- break;
- }
- } while(!exit);
- SetPort(currPort);
- DisposDialog(objectDialog);
- }