forked from root-project/root
-
Notifications
You must be signed in to change notification settings - Fork 0
/
x3d.h
276 lines (209 loc) · 7.91 KB
/
x3d.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
/* @(#)root/x3d:$Id$ */
/* Author: Mark Spychalla*/
/*************************************************************************
* Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
* All rights reserved. *
* *
* For the licensing terms see $ROOTSYS/LICENSE. *
* For the list of contributors see $ROOTSYS/README/CREDITS. *
*************************************************************************/
#ifndef ROOT_x3d
#define ROOT_x3d
/*
Copyright 1992 Mark Spychalla
Permission to use, copy, modify, distribute, and sell this software and
its documentation for any purpose is hereby granted without fee,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the name of Mark Spychalla not be used
in advertising or publicity pertaining to distribution of the software
without specific, written prior permission. Mark Spychalla makes no
representations about the suitability of this software for any purpose.
It is provided "as is" without express or implied warranty.
Mark Spychalla disclaims all warranties with regard to this software,
including all implied warranties of merchantability and fitness, in no
event shall Mark Spychalla be liable for any special, indirect or
consequential damages or any damages whatsoever resulting from loss of use,
data or profits, whether in an action of contract, negligence or other
tortious action, arising out of or in connection with the use or performance
of this software.
*/
#include "X3DDefs.h"
#include <X11/Xlib.h>
/* Constants */
#define RClipWithRight 6
#define RClipWithLeft 5
#define PointBehind 4
#define BClipWithRight 3
#define BClipWithLeft 2
#define ClipWithRight 3
#define ClipWithLeft 2
#define ClipWithBottom 1
#define ClipWithTop 0
#define RRight (1 << RClipWithRight)
#define RLeft (1 << RClipWithLeft)
#define Behind (1 << PointBehind)
#define BRight (1 << BClipWithRight)
#define BLeft (1 << BClipWithLeft)
#define Right (1 << ClipWithRight)
#define Left (1 << ClipWithLeft)
#define Bottom (1 << ClipWithBottom)
#define Top (1 << ClipWithTop)
#define Bmask (~BRight & ~BLeft)
#define Rmask (~RRight & ~RLeft)
#define RBmask (Rmask & Bmask)
#define RLeftRight (RRight | RLeft)
#define ALLmask (RRight | RLeft | Behind | BRight | BLeft | Bottom | Top )
#define NUMBOUNDS 8
#define NUMSTIPPLES 17
#define MAXVALUE 6
#define VALUESCALE 51
#define MAXCOLORDIST (443.40501)
#define STIPPLESIZE 4
#define BITSPERBYTE 8
#define MAXCOLORS 256
#define MAXLINE 8192
#define MAXOPTIONLEN 256
#define TMPSTRLEN 16
#define SMALLMOVEMENT 40000
#define POINTERRATIO 0.007
#define MARGIN 30
#define TWOPI 6.2831853
#define REQUESTFACTOR 3
#define EIGHTBIT 8
#define POSTSCRIPT 1
#define HPGL 0
#define HELPLINES 40
#define MAXSTACK 100
#define STOP 10
#define EOK 0
#define ERROR -1
#define FONT "9x15"
#define TITLEFONT "12x24"
#define BOLDFONT "9x15bold"
#define FIXED "fixed"
#define LONGESTSTRING " ROTATE OBJECT ABOUT Z Horizontal "
/* Color Modes */
#define BW 1
#define STEREO 2
#define COLOR 3
/* Rendering modes */
#define WIREFRAME 1
#define HIDDENLINE 2
#define SOLID 3
/* Supported Depths */
#define ONE 1
#define EIGHT 8
/* Double buffering constants */
#define MAX_COLORS 232
#define BUFFER_CMAP 11
#define BUFFER0 240
#define BUFFER1 15
/* Segment intersection constants */
#define ENDS_INTERSECT 3
#define SAME 2
#define ABOVE 1
#define INTERSECT 0
#define BELOW -1
/* x3d macros */
#define clipWithBottom(x,y,dx,dy,V) { x -= ((dx * (V+y)) / dy); y = -V; }
#define clipWithTop(x,y,dx,dy,V) { x += ((dx * (V-y)) / dy); y = V; }
#define clipWithLeftSide(x,y,dx,dy,H) { y -= ((dy * (H+x)) / dx); x = -H; }
#define clipWithRightSide(x,y,dx,dy,H) { y += ((dy * (H-x)) / dx); x = H; }
#define FONTHEIGHT(font) (font->ascent + font->descent)
#define HelpPrint(g, x, y, string){ \
XDrawString(g->dpy, g->helpWin, g->helpGc, x, y, string, strlen(string)); \
y += FONTHEIGHT(g->font); \
}
#define swapPtrs(ptr1, ptr2) \
ptr1 = (polygon **)((long)ptr1 ^ (long)ptr2); \
ptr2 = (polygon **)((long)ptr2 ^ (long)ptr1); \
ptr1 = (polygon **)((long)ptr1 ^ (long)ptr2);
#define median5(v1,v2,v3,v4,v5) \
if((*v1)->dist < (*v2)->dist){ \
swapPtrs(v1,v2) \
} \
if((*v3)->dist < (*v4)->dist){ \
swapPtrs(v3,v4) \
} \
if((*v1)->dist < (*v3)->dist){ \
swapPtrs(v1,v3) \
swapPtrs(v2,v4) \
} \
if((*v2)->dist < (*v5)->dist){ \
swapPtrs(v2,v5) \
} \
if((*v2)->dist < (*v3)->dist){ \
swapPtrs(v2,v3) \
swapPtrs(v4,v5) \
} \
if((*v3)->dist < (*v5)->dist){ \
swapPtrs(v3,v5) \
}
/* Types */
typedef struct STACKELEMENT{
int start, end;
} StackElement;
typedef struct XSEGMENT{
_XPoint P, Q;
} xsegment;
typedef struct ANGLEPOINT{
double x, y, z;
} anglePoint;
typedef struct OINFO{
/* Geometry information */
point *points;
segment *segs;
polygon *polys;
polygon **list;
/* Clipping information */
point *bounds;
int objClip;
int Hmin, Vmin, Hmax, Vmax;
int Hmin1, Vmin1, Hmax1, Vmax1;
int Hmin2, Vmin2, Hmax2, Vmax2;
int copyX, copyY, copyWidth, copyHeight;
int fillX, fillY, fillWidth, fillHeight;
int numPoints, numSegs, numPolys;
/* Position information */
float tX, tY, tZ, dtX, dtY, dtZ;
float oX, oY, oZ, doX, doY, doZ;
double X, Y, Z,dX, dY, dZ;
double focus, scale, dscale;
float BViewpointX, viewpointY;
} Oinfo;
typedef struct GINFO{
/* Position variables */
int dpyX, dpyY;
int winX, winY, helpWinX, helpWinY;
int oldPointerX, oldPointerY;
/* Font variables */
XFontStruct *font, *titleFont, *boldFont;
/* flags */
int depth, renderMode, buffer, mono, stereo, stereoBlue;
int ColorSelect, Block, Relative, helpMenu, modeChanged;
/* Color variables */
Color *colors;
int numColors;
long stereoBlack, redMask, blueMask;
/* X window variables */
XSegment *redSegments, *blueSegments;
long *redColors;
int numberBlue, numberRed, winH, winV;
int numRedColors;
int requestSize;
long black, white, Black, Red, Blue, Purple;
polygon *edgeList;
polygon *freeList;
Window win, helpWin;
Display *dpy;
Drawable dest;
GC gc, helpGc;
Colormap colormap;
long red, blue, mask;
XColor cmapColors[3][256];
XColor wireframeColors[2][256];
char *DisplayName, *Geometry;
Pixmap stipple[NUMSTIPPLES], pix;
} Ginfo;
#endif