home *** CD-ROM | disk | FTP | other *** search
- /*
- * Macview.c
- */
- #include <MacHeaders>
- #include <Windows.h>
- #include <QuickDraw.h>
- #include <Dialogs.h>
-
- #include "common.h"
- #include "light.h"
- #include "surface.h"
- #include "geom.h"
- #include "list.h"
- #include "grid.h"
- #include "sampling.h"
- #include "csg.h"
- #include "sphere.h"
- #include "triangle.h"
- #include "box.h"
- #include "disc.h"
- #include "cone.h"
- #include "cylinder.h"
- #include "plane.h"
- #include "sampling.h"
- #include "hf.h"
- #include "blob.h"
- #include "poly.h"
- #include "csg.h"
- #include "torus.h"
- #include "instance.h"
- #include "viewing.h"
-
- #include "light.h"
- #include "point.h"
- #include "infinite.h"
- #include "spot.h"
- #include "jittered.h"
- #include "extended.h"
-
- #include "macobject.h"
- #include "maceditor.h"
-
- #define ZOOMVAL 60.
-
- extern DialogPtr editorDialog ;
-
- extern Geom *World, *hiliteobject ;
- extern Light *Lights ;
- extern RSCamera Camera ;
- extern WireObject *theObject ;
- extern Trans *transforms[MAXTRANSFORMS] ;
- extern short transdepth ;
- extern unsigned long FilterFlags ;
-
- void DisplayWireObject(register char viewdir,register Geom *obj,register Surface *surf);
-
- Vector crosshair, old_crosshair = {0.,0.,0.};
- static short ox,oy ; /* The screen x,y position of the origin */
- Float zoom = ZOOMVAL ;
-
- void DrawCoordinateInfo(Float x, Float y, Float z)
- {
- short theItem, theType ;
- DialogPtr theDialog ;
- ControlHandle itemHandle ;
- Rect itemRect ;
- Point point ;
- short currFont, currSize ;
- GrafPtr currPort ;
- Str255 value ;
- char draw = 0 ;
-
- crosshair.x = x ; crosshair.y = y ; crosshair.z = z ;
-
- if(!editorDialog) return ;
-
- GetPort(&currPort) ;
- SetPort(editorDialog) ;
- currFont = editorDialog->txFont ;
- currSize = editorDialog->txSize ;
- TextSize(9) ;
- TextFont(6) ;
- GetDItem(editorDialog,coordinfoUI,&theType,&itemHandle,&itemRect) ;
- EraseRect(&itemRect) ;
- MoveTo(itemRect.left, itemRect.top+9) ;
- sprintf(&value[1],"X: %.2f",crosshair.x) ;
- value[0] = strlen(&value[1]) ;
- DrawString(value) ;
- MoveTo(itemRect.left, itemRect.top+18) ;
- sprintf(&value[1],"Y: %.2f",crosshair.y) ; value[0] = strlen(&value[1]) ;
- DrawString(value) ;
- MoveTo(itemRect.left, itemRect.top+27) ;
- sprintf(&value[1],"Z: %.2f",crosshair.z) ; value[0] = strlen(&value[1]) ;
- DrawString(value) ;
- MoveTo(itemRect.left, itemRect.top+36) ;
- sprintf(&value[1],"z: %.2f",zoom) ; value[0] = strlen(&value[1]) ;
- DrawString(value) ;
-
- TextFont(currFont) ;
- TextSize(currSize) ;
- SetPort(currPort) ;
- }
-
-
-
-
- void DrawCrossHair()
- {
- ControlHandle itemHandle ;
- short itype, theItem ;
- Rect itemRect ;
- GrafPtr currPort ;
- short cx,cy, j, dx, dy ;
- short penMode ;
-
- GetPort(&currPort) ;
- SetPort(editorDialog) ;
- penMode = editorDialog->pnMode ;
- PenMode(patXor) ;
-
-
- GetDItem(editorDialog,topUI,&itype,&itemHandle,&itemRect) ;
- ClipRect(&itemRect) ;
- for(j = 0 ; j < 2 ; j++) {
- if(j==0)
- ProjectCoords(&dx,&dy,old_crosshair.x,old_crosshair.y,old_crosshair.z,VIEW_TOP)
- else
- ProjectCoords(&dx,&dy,crosshair.x,crosshair.y,crosshair.z,VIEW_TOP)
- cx = dx + (itemRect.left+(itemRect.right-itemRect.left)/2) ;
- cy = dy + (itemRect.top+(itemRect.bottom-itemRect.top)/2) ;
- MoveTo(cx,cy-5) ; LineTo(cx,cy+5) ;
- MoveTo(cx-5,cy) ; LineTo(cx+5,cy) ;
- }
-
- GetDItem(editorDialog,sideUI,&itype,&itemHandle,&itemRect) ;
- ClipRect(&itemRect) ;
- for(j = 0 ; j < 2 ; j++) {
- if(j==0)
- ProjectCoords(&dx,&dy,old_crosshair.x,old_crosshair.y,old_crosshair.z,VIEW_SIDE)
- else
- ProjectCoords(&dx,&dy,crosshair.x,crosshair.y,crosshair.z,VIEW_SIDE)
- cx = dx + (itemRect.left+(itemRect.right-itemRect.left)/2) ;
- cy = dy + (itemRect.top+(itemRect.bottom-itemRect.top)/2) ;
- MoveTo(cx,cy-5) ; LineTo(cx,cy+5) ;
- MoveTo(cx-5,cy) ; LineTo(cx+5,cy) ;
- }
-
- GetDItem(editorDialog,frontUI,&itype,&itemHandle,&itemRect) ;
- ClipRect(&itemRect) ;
- for(j = 0 ; j < 2 ; j++) {
- if(j==0)
- ProjectCoords(&dx,&dy,old_crosshair.x,old_crosshair.y,old_crosshair.z,VIEW_FRONT)
- else
- ProjectCoords(&dx,&dy,crosshair.x,crosshair.y,crosshair.z,VIEW_FRONT)
- cx = dx + (itemRect.left+(itemRect.right-itemRect.left)/2) ;
- cy = dy + (itemRect.top+(itemRect.bottom-itemRect.top)/2) ;
- MoveTo(cx,cy-5) ; LineTo(cx,cy+5) ;
- MoveTo(cx-5,cy) ; LineTo(cx+5,cy) ;
- }
- old_crosshair = crosshair ;
-
- ClipRect(&editorDialog->portRect) ;
- PenMode(penMode) ;
- SetPort(currPort) ;
- }
-
- void DrawLights(char mode)
- {
- register Light *l ;
- short cx,cy ;
- Vector pos ;
- Rect rect ;
-
- if(FILTER_SET(F_LIGHTS))
- return ;
- for(l = Lights ; l ; l = l->next) {
- switch(LightType(l)) {
- case L_POINT:
- pos = ((Pointlight *)l->light)->pos ;
- ProjectCoords(&cx,&cy,pos.x,pos.y,pos.z,mode) ;
- SetRect(&rect,ox+cx-6,oy+cy-6,ox+cx+6,oy+cy+6) ;
- FrameOval(&rect) ;
- MoveTo(ox+cx-2,oy+cy+3) ;
- DrawString("\pP") ;
- break ;
- case L_INFINITE:
- break ;
- case L_SPOT:
- pos = ((Spotlight *)l->light)->pos ;
- ProjectCoords(&cx,&cy,pos.x,pos.y,pos.z,mode) ;
- SetRect(&rect,ox+cx-6,oy+cy-6,ox+cx+6,oy+cy+6) ;
- FrameOval(&rect) ;
- MoveTo(ox+cx-2,oy+cy+3) ;
- DrawString("\pS") ;
- break ;
- case L_JITTERED:
- pos = ((Jittered *)l->light)->pos ;
- ProjectCoords(&cx,&cy,pos.x,pos.y,pos.z,mode) ;
- SetRect(&rect,ox+cx-6,oy+cy-6,ox+cx+6,oy+cy+6) ;
- FrameOval(&rect) ;
- MoveTo(ox+cx-2,oy+cy+3) ;
- DrawString("\pJ") ;
- break ;
- case L_EXTENDED:
- pos = ((Extended *)l->light)->pos ;
- ProjectCoords(&cx,&cy,pos.x,pos.y,pos.z,mode) ;
- SetRect(&rect,ox+cx-6,oy+cy-6,ox+cx+6,oy+cy+6) ;
- FrameOval(&rect) ;
- MoveTo(ox+cx-2,oy+cy+3) ;
- DrawString("\pE") ;
- break ;
- }
- }
- }
-
- void DrawCamera(char mode)
- {
- short cx,cy ;
-
-
- if(FILTER_SET(F_CAMERA))
- return;
- ProjectCoords(&cx,&cy,Camera.pos.x,Camera.pos.y,Camera.pos.z,mode) ;
- MoveTo(ox+cx-2,oy+cy+3) ;
- DrawString("\po") ;
- ProjectCoords(&cx,&cy,Camera.lookp.x,Camera.lookp.y,Camera.lookp.z,mode) ;
- MoveTo(ox+cx-2,oy+cy+3) ;
- DrawString("\pt") ;
- }
-
- pascal void DrawTopView(WindowPtr window, short item)
- {
- short theItem, theType ;
- ControlHandle theHandle ;
- Rect itemRect ;
- GrafPtr currPort ;
- short cx, cy, dx,dy, penMode, currFont, currSize ;
-
- GetPort(&currPort) ;
- SetPort(window) ;
- penMode = window->pnMode ;
- currFont = editorDialog->txFont ;
- currSize = editorDialog->txSize ;
- TextSize(9) ;
- TextFont(6) ;
-
- GetDItem(window,item,&theType,&theHandle,&itemRect) ;
- ClipRect(&itemRect) ;
- EraseRect(&itemRect) ;
- ox = itemRect.left+(itemRect.right-itemRect.left)/2 ;
- oy = itemRect.top+(itemRect.bottom-itemRect.top)/2 ;
- transdepth = 0 ;
- DrawObject(World,World->surf,VIEW_TOP) ;
- DrawLights(VIEW_TOP) ;
- DrawCamera(VIEW_TOP) ;
-
- PenMode(patXor) ;
- ProjectCoords(&dx,&dy,crosshair.x,crosshair.y,crosshair.z,VIEW_TOP)
- cx = ox + dx;
- cy = oy + dy;
- MoveTo(cx,cy-5) ; LineTo(cx,cy+5) ;
- MoveTo(cx-5,cy) ; LineTo(cx+5,cy) ;
-
- MoveTo(itemRect.left+3, itemRect.bottom-3) ;
- DrawString("\pTop") ;
-
- TextFont(currFont) ;
- TextSize(currSize) ;
- PenMode(penMode) ;
- ClipRect(&window->portRect) ;
- SetPort(currPort) ;
- }
-
-
- pascal void DrawSideView(WindowPtr window, short item)
- {
- short theItem, theType ;
- ControlHandle theHandle ;
- Rect itemRect ;
- GrafPtr currPort ;
- short cx, cy, dx, dy, penMode, currFont, currSize ;
-
- GetPort(&currPort) ;
- SetPort(window) ;
- penMode = window->pnMode ;
- currFont = editorDialog->txFont ;
- currSize = editorDialog->txSize ;
- TextSize(9) ;
- TextFont(6) ;
-
- GetDItem(window,item,&theType,&theHandle,&itemRect) ;
- ClipRect(&itemRect) ;
- EraseRect(&itemRect) ;
- ox = itemRect.left+(itemRect.right-itemRect.left)/2 ;
- oy = itemRect.top+(itemRect.bottom-itemRect.top)/2 ;
- transdepth = 0 ;
- DrawObject(World,World->surf,VIEW_SIDE) ;
- DrawLights(VIEW_SIDE) ;
- DrawCamera(VIEW_SIDE) ;
-
- PenMode(patXor) ;
- ProjectCoords(&dx,&dy,crosshair.x,crosshair.y,crosshair.z,VIEW_SIDE)
- cx = ox + dx;
- cy = oy + dy;
- MoveTo(cx,cy-5) ; LineTo(cx,cy+5) ;
- MoveTo(cx-5,cy) ; LineTo(cx+5,cy) ;
-
- MoveTo(itemRect.left+3, itemRect.bottom-3) ;
- DrawString("\pSide") ;
-
- TextFont(currFont) ;
- TextSize(currSize) ;
- PenMode(penMode) ;
- ClipRect(&window->portRect) ;
- SetPort(currPort) ;
- }
-
- pascal void DrawFrontView(WindowPtr window, short item)
- {
- short theItem, theType ;
- ControlHandle theHandle ;
- Rect itemRect ;
- GrafPtr currPort ;
- short cx, cy, dx, dy, penMode, currFont, currSize ;
-
- GetPort(&currPort) ;
- SetPort(window) ;
- penMode = window->pnMode ;
- currFont = editorDialog->txFont ;
- currSize = editorDialog->txSize ;
- TextSize(9) ;
- TextFont(6) ;
-
- GetDItem(window,item,&theType,&theHandle,&itemRect) ;
- ClipRect(&itemRect) ;
- EraseRect(&itemRect) ;
- ox = itemRect.left+(itemRect.right-itemRect.left)/2 ;
- oy = itemRect.top+(itemRect.bottom-itemRect.top)/2 ;
- transdepth = 0 ;
- DrawObject(World,World->surf,VIEW_FRONT) ;
- DrawLights(VIEW_FRONT) ;
- DrawCamera(VIEW_FRONT) ;
-
- PenMode(patXor) ;
- ProjectCoords(&dx,&dy,crosshair.x,crosshair.y,crosshair.z,VIEW_FRONT)
- cx = ox + dx;
- cy = oy + dy;
- MoveTo(cx,cy-5) ; LineTo(cx,cy+5) ;
- MoveTo(cx-5,cy) ; LineTo(cx+5,cy) ;
-
- MoveTo(itemRect.left+3, itemRect.bottom-3) ;
- DrawString("\pFront") ;
- TextFont(currFont) ;
- TextSize(currSize) ;
- PenMode(penMode) ;
- ClipRect(&window->portRect) ;
- SetPort(currPort) ;
- }
-
- void DisplayView()
- {
- GrafPtr currPort ;
-
- GetPort(&currPort) ;
- DrawSideView(editorDialog,sideUI) ;
- DrawTopView(editorDialog,topUI) ;
- DrawFrontView(editorDialog,frontUI) ;
- SetPort(currPort) ;
- }
-
-
- /* Displays a heightfield object */
-
- void DisplayHfObject(Hf *hf, char viewdir)
- {
- RSMatrix mat ;
- short x,y, i,j ;
- Vector pos ;
- Trans *trans ;
-
-
- /* Combine all transformations together */
- MatrixInit(&mat) ;
- for(i = transdepth-1 ; i >= 0 ; i--) {
- trans = transforms[i] ;
- while(trans) {
- MatrixMult(&mat,&trans->trans,&mat) ;
- trans = trans->next ;
- }
- }
-
- for(i = 0 ; i < hf->size; i++) {
- for(j = 0 ; j < hf->size; j++) {
- pos.x = (Float) i / hf->size ;
- pos.y = (Float) j / hf->size ;
- pos.z = hf->data[i][j] ;
- if(pos.z > HF_UNSET) {
- PointTransform(&pos,&mat) ;
- ProjectCoords(&x, &y, pos.x,pos.y,pos.z,viewdir) ;
- MoveTo(ox+x,oy+y) ;
- Line(0,0) ;
- }
- }
- }
- }
-
- /* Display a wireframe object */
-
- void DisplayWireObject(register char viewdir,register Geom *obj,register Surface *surf)
- {
- register short i,j ;
- register Trans *trans ;
- GrafPtr currPort ;
- RGBColor currCol, newCol ;
- RSMatrix mat ;
-
- GetPort(&currPort) ;
- SetPort(editorDialog) ;
- GetForeColor(&currCol) ;
- if(obj->surf) {
- surf = obj->surf ;
- newCol.red = (unsigned short) (surf->amb.r * (Float) 65535.0) ;
- newCol.green = (unsigned short) (surf->amb.g * (Float) 65535.0) ;
- newCol.blue = (unsigned short) (surf->amb.b * (Float) 65535.0) ;
- }
- else {
- newCol.red = 0 ;
- newCol.green = 0 ;
- newCol.blue = 0 ;
- }
- RGBForeColor(&newCol) ;
-
- /* Combine all transformations together */
- MatrixInit(&mat) ;
- for(i = transdepth-1 ; i >= 0 ; i--) {
- trans = transforms[i] ;
- while(trans) {
- MatrixMult(&mat,&trans->trans,&mat) ;
- trans = trans->next ;
- }
- }
-
- /* Now transform each point in our matrix and convert into the correct 2d screen coordinate */
- for(i = 0 ; i < theObject->numpoints ; i++) {
- PointTransform(&theObject->points[i],&mat) ;
- ProjectCoords(&theObject->sxpoints[i], &theObject->sypoints[i], theObject->points[i].x,theObject->points[i].y,theObject->points[i].z,viewdir) ;
- }
-
- /* Display each edge in the object */
- for(i = 0 ; i < theObject->numpoints ; i++)
- for(j = 0 ; j < theObject->numpoints ; j++) {
- if(EDGE_BETWEEN(i,j)) {
- MoveTo(theObject->sxpoints[i]+ox,theObject->sypoints[i]+oy) ;
- LineTo(theObject->sxpoints[j]+ox,theObject->sypoints[j]+oy) ;
- }
- }
- RGBForeColor(&currCol) ;
- SetPort(currPort) ;
- }
-
-