open-axiom repository from github
/*1Copyright (C) 1991-2002, The Numerical ALgorithms Group Ltd.2All rights reserved.3Copyright (C) 2007-2010, Gabriel Dos Reis.4All rights reserved.56Redistribution and use in source and binary forms, with or without7modification, are permitted provided that the following conditions are8met:910- Redistributions of source code must retain the above copyright11notice, this list of conditions and the following disclaimer.1213- Redistributions in binary form must reproduce the above copyright14notice, this list of conditions and the following disclaimer in15the documentation and/or other materials provided with the16distribution.1718- Neither the name of The Numerical ALgorithms Group Ltd. nor the19names of its contributors may be used to endorse or promote products20derived from this software without specific prior written permission.2122THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS23IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED24TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A25PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER26OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,27EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,28PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR29PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF30LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING31NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS32SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.33*/3435#define view3D363738#include <X11/Xlib.h>39#include <X11/Xresource.h>40#include <X11/Xutil.h>41#include <setjmp.h>4243#include "hash.h"4445#include "view.h"464748#include "view3D.h"49#include "actions.h"50#include "viewCommand.h"51#include "XDefs.h"52#include "override.h"53#include "G.h" /* Gdraw functions header file */5455/**********************************/56/*** axes stuff ***/57/**********************************/5859#define viewportCreateMASK CWBackPixel | CWBorderPixel | CWEventMask | CWCursor | CWColormap60#define viewportTitleCreateMASK CWBackPixel | CWBorderPixel | CWCursor | CWColormap | CWEventMask | CWOverrideRedirect61#define carefullySetFont(gc,font) if (font != serverFont) XSetFont(dsply,gc,font->fid)6263#define viewportMASK (KeyPressMask + ButtonPressMask + ExposureMask)64#define titleMASK (ExposureMask)6566#define lineWidth 167#define lineHeight 16869#define titleColor monoColor(36)70#define titleHeight 2471#define appendixHeight 07273#define viewWidth 40074#define viewHeight 40075#define viewYmax vwInfo.height76#define viewYmin vwInfo.y77#define viewXmax vwInfo.width78#define viewXmin vwInfo.x7980#define GC9991 ((GC)9991)818283/* For smooth shading buffers. Should be screen resolution size,84and one for each of screen width and height may be needed, or85it can be changed dynamically if desired. */8687#ifdef RIOSplatform88#define ARRAY_WIDTH 1280 + 1 /* DisplayWidth(dsply,scrn) */89#define ARRAY_HEIGHT 1024 + 1 /* DisplayHeight(dsply,scrn) */90#else91#define ARRAY_WIDTH 1300 /* DisplayWidth(dsply,scrn) */92#define ARRAY_HEIGHT 1100 /* DisplayHeight(dsply,scrn) */93#endif9495#define viewBorderWidth 0 /* make sure ps.h (postscript header) is the same */9697#define initDeltaX 0.098#define initDeltaY 0.099#define initTheta pi_half/2.0100#define initPhi -pi_half/2.0101102#define maxDeltaX 1500.0103#define maxDeltaY 1500.0104#define minScale 0.01105#define maxScale 1000.0106107#define rotateFactor 0.2108#define scaleFactor 0.2109#define translateFactor 8110111#define viewCursorForeground monoColor(166)112#define viewCursorBackground monoColor(5)113114#define axesColor 52115#define buttonColor 120116#define labelColor 12117118/**********************************/119/*** graph stuff ***/120/**********************************/121122#define graphBarLeft 76123#define graphBarTop 180124#define graphBarWidth graphFont->max_bounds.width + 5125#define graphBarHeight graphFont->max_bounds.ascent + graphFont->max_bounds.descent126#define graphBarDefaultColor monoColor(85)127#define graphBarShowingColor monoColor(45)128#define graphBarHiddenColor monoColor(146)129#define graphBarSelectColor monoColor(45)130#define graphBarNotSelectColor monoColor(145)131132/******************************/133/*** colors ***/134/******************************/135136#define totalHuesConst 27137138#define hueEnd 360139140#undef hueStep141#define hueStep (hueEnd/totalHuesConst)142143#define black BlackPixel(dsply,scrn)144#define white WhitePixel(dsply,scrn)145#define numPlanes 1146#define numColors 10147#define startColor 0148#define maxColors (DisplayCells(dsply,scrn)-1)149#define maxPlanes (DefaultVisual((dpy),(scr))->bits_per_rgb)150151/**********************************/152/*** Screen and Window Sizes */153/**********************************/154155#define physicalWidth DisplayWidth(dsply,scrn)156#define physicalHeight DisplayHeight(dsply,scrn)157#define deep DisplayPlanes(dsply,scrn)158159#define basicScreen 19160161#define yes 1162#define no 0163164#define pi_half 1.57079632165#define pi 3.14159265166#define three_pi_halves 4.71238898167#define two_pi 6.28318530168#define pi_sq 9.86960440169170#define degrees_in_two_pi 57171#define d2Pi 57172173#define nbuckets 128174175176#define anywhere 0177178#ifdef DEBUG179#include "eventnames.h"180#endif181182#define intSize sizeof(int)183#define floatSize sizeof(float)184185/* Types so far are X, PS */186#define drawViewport(type) { drawPreViewport(type); drawTheViewport(type); }187#define spadDrawViewport() spadMode++; drawTheViewport(X); spadMode--;188189190/********************************/191/*** lighting panel ***/192/********************************/193194/* These are the lighting panel buttons, they start at 101195(numbers less than 101 are reserved for control panel buttons */196197/* From ../include/actions.h */198199#define lightingButtonsStart controlButtonsEnd3D200201#define lightMove (lightingButtonsStart)202#define lightMoveXY (lightingButtonsStart+1)203#define lightMoveZ (lightingButtonsStart+2)204#define lightAbort (lightingButtonsStart+3)205#define lightReturn (lightingButtonsStart+4)206#define lightTranslucent (lightingButtonsStart+5)207208#define maxlightingButtons 6209#define lightingButtonsEnd (lightingButtonsStart + maxlightingButtons)210211/***********************************/212/*** view volume panel ***/213/***********************************/214215/* These are the volume panel buttons, they start at 200216(numbers less than 101 are reserved for control panel buttons */217218#define volumeButtonsStart lightingButtonsEnd219220#define volumeReturn (volumeButtonsStart)221#define frustrumBut (volumeButtonsStart+1)222#define clipXBut (volumeButtonsStart+2)223#define clipYBut (volumeButtonsStart+3)224#define clipZBut (volumeButtonsStart+4)225#define perspectiveBut (volumeButtonsStart+5)226#define clipRegionBut (volumeButtonsStart+6)227#define clipSurfaceBut (volumeButtonsStart+7)228#define volumeAbort (volumeButtonsStart+8)229230#define maxVolumeButtons 9231#define volumeButtonsEnd (volumeButtonsStart + maxVolumeButtons)232233/**** quit panel ****/234235#define quitButtonsStart volumeButtonsEnd236237#define quitAbort (quitButtonsStart)238#define quitReturn (quitButtonsStart+1)239#define maxQuitButtons 2240#define quitButtonsEnd (quitButtonsStart + maxQuitButtons)241242/**** save panel ****/243244#define saveButtonsStart quitButtonsEnd245246#define saveExit (saveButtonsStart)247#define pixmap (saveButtonsStart+1)248#define ps (saveButtonsStart+2)249#define maxSaveButtons 3250#define saveButtonsEnd (saveButtonsStart + maxSaveButtons)251252/******************************************/253/*** buttons to be allocated ***/254/******************************************/255256#define maxButtons3D saveButtonsEnd257258259/************************ Type Declarations *************************/260261/**********************************/262/*** control stuff ***/263/**********************************/264265typedef struct _buttonStruct {266int buttonKey, pot, mask;267short buttonX, buttonY, buttonWidth, buttonHeight, xHalf, yHalf;268Window self;269const char* text;270int textColor,textHue,textShade;271} buttonStruct;272273typedef struct _controlPanelStruct {274Window controlWindow, messageWindow, colormapWindow;275char message[40];276buttonStruct buttonQueue[maxButtons3D];277} controlPanelStruct;278279typedef struct _mouseCoord {280float x, y;281} mouseCoord;282283284/**********************************/285/*** mesh stuff ***/286/**********************************/287288typedef struct _meshStruct {289float N0[4], N1[4]; /* the fourth element is Zmin */290} meshStruct;291292typedef struct _points3D {293float xmin, xmax,294ymin, ymax,295xstep, ystep,296zmin, zmax,297scaleToView;298float *zPoints;299int xnum, ynum,300nextRow,301style;302meshStruct *normData; /* list of normals */303} points3D;304305306307typedef struct _colorBuffer {308int indx;309char axes;310} colorBuffer;311312313/**********************************/314/*** axes stuff ***/315/**********************************/316317typedef struct _point {318float x, y, z;319int flag;320} point;321322323/**** one of the (many) sloppy things that need to be324cleaned up is the viewPoints structure. a lot of325stuff in it is used solely for the function of326two variables stuff. they should be moved to327the fun2Var substructure. ****/328329typedef struct _viewPoints {330int viewportKey;331char title[80];332Window viewWindow, titleWindow;333float deltaX, deltaY,334scale, scaleX, scaleY, scaleZ,335theta, phi,336deltaX0, deltaY0, /* initial values */337scale0, transX, transY, transZ, thetaObj, phiObj,338theta0, phi0, theta1, phi1, axestheta, axesphi;339float deltaZ, deltaZ0;340controlPanelStruct *controlPanel;341int axesOn, regionOn, monoOn;342int zoomXOn, zoomYOn, zoomZOn;343int originrOn, objectrOn;344int xyOn, xzOn, yzOn;345int originFlag;346int justMadeControl, haveControl,347closing, allowDraw, needNorm;348points3D meshData;349float lightVector[3], translucency;350int hueOffset, numberOfHues, hueTop, diagonals;351struct _viewPoints *prevViewport, *nextViewport;352} viewPoints;353354355typedef struct _controlXY {356int putX, putY;357} controlXY;358359360361/************************** Bitmap Files ***************************/362#if 0363#include "../include/purty/mouse11.bitmap"364#include "../include/purty/mouse11.mask"365#include "../include/purty/spadBitmap.bitmap"366#include "../include/purty/spadMask.mask"367#include "../include/purty/light11.bitmap"368#include "../include/purty/light11.mask"369#endif370371372/******* useful definitions *******/373374#define CONTROLpanel 1375#define LIGHTpanel 2376#define VOLUMEpanel 3377#define CONTOURpanel 4378#define QUITpanel 5379#define SAVEpanel 6380381#define machine0 0.0002382383#include "globals.h"384385386387