home *** CD-ROM | disk | FTP | other *** search
/ gondwana.ecr.mu.oz.au/pub/ / Graphics.tar / Graphics / atomart.tar.gz / atomart.tar / gram.c < prev    next >
C/C++ Source or Header  |  1990-06-21  |  24KB  |  991 lines

  1.  
  2. # line 6 "gram.y"
  3. #include <stdio.h>
  4. #include <math.h>
  5. #include "atomart.h"
  6. #include "macro.h"
  7.  
  8. extern object    *sphereinit(),
  9.         *polygoninit();
  10.  
  11. extern light    *lightinit();
  12. extern tlist    *tileinit();
  13. extern tlist    *textureinit();
  14.  
  15. extern attr    *astackp;
  16. extern object    *oblist;
  17. extern light    *lights;
  18.  
  19. extern vector    org, up;
  20.  
  21. extern matrix    trans;
  22. extern float    focallength;
  23.  
  24. extern char    *title;
  25. extern int    maxhitlevel, raysperpix;
  26. extern long    filetype;
  27.  
  28. extern colour    backcol;
  29.  
  30. #ifndef M_PI
  31. #define M_PI    3.14159265358979323846
  32. #endif
  33.  
  34.  
  35. # line 39 "gram.y"
  36. typedef union {
  37.     object    *y_obj;
  38.     light    *y_lht;
  39.     vector    *y_pnt;
  40.     details    *y_det;
  41.     char    *y_str;
  42.     float    y_flt;
  43.     int    y_int;
  44. } YYSTYPE;
  45. # define STREE 257
  46. # define SPHERE 258
  47. # define POLYGON 259
  48. # define COMPOSITE 260
  49. # define FLOAT 261
  50. # define INTEGER 262
  51. # define FILETYPE 263
  52. # define OPTION 264
  53. # define STRING 265
  54. # define NAME 266
  55. # define LBRACE 267
  56. # define RBRACE 268
  57. # define LP 269
  58. # define RP 270
  59. # define RADIUS 271
  60. # define RADII 272
  61. # define COLOUR 273
  62. # define CENTER 274
  63. # define VERTEX 275
  64. # define COMMA 276
  65. # define PCENT 277
  66. # define MATERIAL 278
  67. # define REFI 279
  68. # define MINUS 280
  69. # define AMBIENT 281
  70. # define LIGHT 282
  71. # define INTENSITY 283
  72. # define LOCATION 284
  73. # define DOLS 285
  74. # define EQUATION 286
  75. # define TILE 287
  76. # define OFFFILE 288
  77. # define BASE 289
  78. # define TOP 290
  79. # define CONST 291
  80. # define COEFFS 292
  81. # define SCALE 293
  82. # define ROTATE 294
  83. # define TRANSLATE 295
  84. # define TITLE 296
  85. # define REFLECTANCE 297
  86. # define DOT 298
  87. # define ON 299
  88. # define OFF 300
  89. # define LOOKAT 301
  90. # define FIELDOFVIEW 302
  91. # define TRANSPARENCY 303
  92. # define RAYSPERPIXEL 304
  93. # define BACKGROUND 305
  94. # define SIZE 306
  95. # define MAXHITLEVEL 307
  96. # define OUTPUT 308
  97. # define ORDER 309
  98. # define ABSORPTION 310
  99. # define VREF1 311
  100. # define VREF2 312
  101. # define NUMRAYS 313
  102. # define OBJECT 314
  103. # define TEXTURE 315
  104. # define DIRECTION 316
  105. # define ANGLE 317
  106. # define UP 318
  107. # define TWENTYFIVEBIT 319
  108. # define RANGE 320
  109. # define MAP 321
  110. # define BLENDCOLOR 322
  111. # define SCALEFACTORS 323
  112. # define VORTFILE 324
  113. # define PLUS 325
  114. # define MULT 326
  115. # define DIV 327
  116. # define COMBINE 328
  117. # define POWER 329
  118. # define UMINUS 330
  119. # define EQUALS 331
  120. #define yyclearin yychar = -1
  121. #define yyerrok yyerrflag = 0
  122. extern int yychar;
  123. extern short yyerrflag;
  124. #ifndef YYMAXDEPTH
  125. #define YYMAXDEPTH 150
  126. #endif
  127. YYSTYPE yylval, yyval;
  128. # define YYERRCODE 256
  129. short yyexca[] ={
  130. -1, 1,
  131.     0, -1,
  132.     -2, 0,
  133.     };
  134. # define YYNPROD 72
  135. # define YYLAST 564
  136. short yyact[]={
  137.  
  138.   15,  83, 121, 122, 146,  50,  51,  72, 238,  20,
  139.  236,  54, 162, 224,  21,  42,  43,  22, 223, 113,
  140.  222, 173, 117,  19, 114, 221, 220, 240, 218,  28,
  141.   26,  27,  55,  23,  41, 116, 217, 211, 202,  24,
  142.  200, 199, 143, 198, 197, 193,  25,  16,  17, 192,
  143.  191,  18,  71,  73,  74, 190, 141, 140, 142, 144,
  144.  145,  15, 181, 180, 118, 137, 179, 120, 119, 167,
  145.   20, 166, 164,  38, 163,  21, 150, 149,  22, 148,
  146.  147, 134, 112, 111,  19, 110, 103, 102, 100,  99,
  147.   28,  26,  27,  86,  23,  85,  84,  78, 235, 234,
  148.   24, 233, 232, 143, 210, 209, 204,  25,  16,  17,
  149.  203, 201,  18,  15, 178, 160, 159, 141, 140, 142,
  150.  144, 145,  20, 155,  65,  64,  63,  21,  53,  52,
  151.   22,  29,  46,  45,  82,  81,  19,  70,  69,  68,
  152.   66, 168,  28,  26,  27,   6,  23, 151,  56,  91,
  153.   10,   7,  24,   8,  11,  49,  12,  13,  34,  25,
  154.   16,  17,  36,  37,  18,  92, 104,   9,  15,  42,
  155.   43,   2, 131,   1, 138, 127, 115,  20, 126, 128,
  156.  125,  90,  21,   4,  30,  22,  36,  37,  35,   5,
  157.  124,  19,  14,  31,  33,   3,  32,  28,  26,  27,
  158.    0,  23,   0,   0,   0,   0,   0,  24,   0,   0,
  159.    0,  36,  37,   0,  25,  16,  17,  15,   0,  18,
  160.   67, 130,   0,   0, 127,   0,  20, 126, 128,   0,
  161.    0,  21,   0,   0,  22,  93,  94,   0,   0,   0,
  162.   19,   0,   0,   0,   0,   0,  28,  26,  27, 105,
  163.   23, 129, 129, 129,   0,   0,  24,   0,   0,   0,
  164.   36,  37,   0,  25,  16,  17,  15,   0,  18,   0,
  165.  123,   0,   0, 127,   0,  20, 126, 128,   0,   0,
  166.   21,   0,   0,  22,  40, 139, 139,   0,   0,  19,
  167.    0,   0,  15,   0,   0,  28,  26,  27,   0,  23,
  168.    0,  20,   0,   0,   0,  24,  21,   0,   0,  22,
  169.   29,   0,  25,  16,  17,  19,   0,  18,   0,   0,
  170.    0,  28,  26,  27,  39,  23,  75,   0,   0,   0,
  171.    0,  24,   0,  44,   0,   0,  47,  48,  25,  16,
  172.   17,   0,   0,  18,   0,  57,  58,  59,  60,  61,
  173.   62,   0,   0,   0,   0,   0,  95,  96,  97,  98,
  174.    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
  175.   76,  77,   0,   0,   0,   0,   0,  79,  80,   0,
  176.    0,   0,   0,   0,   0,   0,   0,   0,  87,  88,
  177.   89,   0,   0,   0,   0,   0,   0,   0,   0,   0,
  178.    0,   0,   0, 101,   0,   0,   0,   0, 106, 107,
  179.  108, 109,   0,   0,   0,   0,   0,   0,   0,   0,
  180.    0,   0,   0,   0, 132, 133,   0, 135, 136,   0,
  181.    0,   0,   0,   0,   0,   0, 152, 153,   0, 154,
  182.    0,   0, 156, 157, 158,   0,   0,   0,   0,   0,
  183.    0,   0, 161,   0,   0,   0,   0,   0,   0, 165,
  184.    0,   0,   0,   0,   0,   0, 169, 170, 171, 172,
  185.    0,   0, 174, 175, 176, 177,   0,   0,   0,   0,
  186.  182,   0,   0,   0, 183, 184,   0, 185, 186, 187,
  187.    0, 188, 189,   0,   0,   0,   0,   0,   0,   0,
  188.    0,   0,   0,   0, 194, 195, 196,   0,   0,   0,
  189.    0,   0,   0,   0,   0, 205, 206, 207, 208,   0,
  190.    0,   0, 212, 213, 214, 215,   0, 216,   0,   0,
  191.    0,   0,   0,   0,   0,   0, 219,   0,   0,   0,
  192.    0,   0, 225, 226,   0, 227, 228, 229, 230, 231,
  193.    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
  194.    0, 237,   0, 239 };
  195. short yypact[]={
  196.  
  197. -1000,-1000,-151,  28,-1000, -72,-192,-246,-246,-136,
  198. -137,-246,-246,-108,-1000,-294,-140,-141,-255,-118,
  199. -246,-246,-246,-246,-246,-246,-143,-144,-145,-127,
  200. -1000, -72,-1000, -72,-1000,-128,-129,-130,-1000,-1000,
  201. -273, -92,-1000,-1000,-1000,-246,-246,-179,-1000,-1000,
  202. -1000,-1000,-246,-246,-132,-133,-305,-180,-181,-183,
  203. -1000,-1000,-1000,-246,-246,-246,-115, -72,-1000,-1000,
  204. -1000, -92, -92, -92, -92,-1000,-187,-188,-246,-189,
  205. -190,-1000,-1000,-246,-246,-246,-246,-191,-193,-194,
  206. -249,-297,   2, -47, -96,-1000,-1000,-1000,-1000,-246,
  207. -246,-195,-246,-246,-203,-264,-196,-197,-199,-200,
  208. -119,-246,-246,-1000,-246,-1000,-146,-246,-246,-246,
  209. -153,-1000,-1000,-1000,-1000,-1000,-154,-246,-257,-1000,
  210. -1000,-1000,-202,-204,-246,-205,-207,-1000,-1000,-1000,
  211. -125,-246,-246,-246,-246,-245,-1000,-246,-246,-246,
  212. -246,-156,-210,-213,-214,-246,-1000,-1000,-1000,-246,
  213. -246,-1000,-246,-246,-246,-1000,-246,-246,-1000,-1000,
  214. -221,-226,-227,-1000,-1000,-1000,-231,-1000,-1000,-246,
  215. -246,-246,-232,-233,-235,-236,-159,-238,-160,-164,
  216. -246,-246,-246,-246,-165,-166,-239,-246,-246,-246,
  217. -246,-1000,-246,-1000,-1000,-240,-1000,-248,-1000,-1000,
  218. -1000,-246,-250,-251,-256,-258,-263,-246,-246,-1000,
  219. -246,-246,-246,-246,-246,-1000,-1000,-168,-169,-171,
  220. -172,-266,-1000,-1000,-1000,-1000,-246,-268,-246,-243,
  221. -1000 };
  222. short yypgo[]={
  223.  
  224.    0, 192, 195, 324, 284, 158, 189, 165, 190, 180,
  225.  181, 176, 166, 174, 173, 171 };
  226. short yyr1[]={
  227.  
  228.    0,  14,  14,  14,  14,  15,  15,  15,  15,  15,
  229.   15,  15,  15,  15,   2,   2,   1,  10,  10,  10,
  230.   10,  10,  11,  11,  11,  11,  11,   6,   6,   6,
  231.    5,   5,   7,   7,   7,   8,   8,   8,   8,   9,
  232.    9,   9,   9,   9,   9,   9,   9,   9,   9,   9,
  233.    9,   9,   9,   9,   9,  12,  12,  12,  13,  13,
  234.   13,  13,  13,  13,   3,   3,   3,   3,   3,   3,
  235.    4,   4 };
  236. short yyr2[]={
  237.  
  238.    0,   4,   3,   3,   2,   0,   3,   3,   3,   9,
  239.   17,   7,   3,   3,   1,   2,   4,   0,   7,   2,
  240.    2,   2,   8,   2,   2,   2,   8,   0,   2,   5,
  241.    4,   4,   0,   2,   2,   8,   2,   8,   1,   2,
  242.    2,   8,   8,   5,   5,   6,   6,   8,   6,   2,
  243.    2,   2,   6,   8,   8,   0,   2,   2,   2,   2,
  244.    6,   4,   6,   2,   1,   3,   3,   3,   3,   2,
  245.    1,   1 };
  246. short yychk[]={
  247.  
  248. -1000, -14, -15,  -2,  -9,  -6, 296, 302, 304, 318,
  249.  301, 305, 307, 308,  -1, 264, 311, 312, 315, 287,
  250.  273, 278, 281, 297, 303, 310, 294, 295, 293, 282,
  251.   -9,  -6,  -1,  -6,  -5, 260, 258, 259, 265,  -3,
  252.   -4, 280, 261, 262,  -3, 269, 269,  -3,  -3, 263,
  253.  299, 300, 269, 269, 266, 287, 266,  -3,  -3,  -3,
  254.   -3,  -3,  -3, 269, 269, 269, 267,  -6, 267, 267,
  255.  267, 325, 280, 326, 327,  -4,  -3,  -3, 276,  -3,
  256.   -3, 267, 267, 306, 276, 276, 276,  -3,  -3,  -3,
  257.  -10, 264,  -7,  -7,  -7,  -4,  -4,  -4,  -4, 276,
  258.  276,  -3, 276, 276, -12, -12,  -3,  -3,  -3,  -3,
  259.  276, 276, 276, 268, 273, -11, 284, 271, 313, 317,
  260.  316, 299, 300, 268,  -8,  -9, 274, 271, 275,  -5,
  261.  268, 268,  -3,  -3, 276,  -3,  -3, 268, -13,  -9,
  262.  321, 320, 322, 306, 323, 324, 268, 276, 276, 276,
  263.  276, 266,  -3,  -3,  -3, 269,  -3,  -3,  -3, 269,
  264.  269,  -3, 269, 276, 276,  -3, 276, 276, 266,  -3,
  265.   -3,  -3,  -3, 266,  -3,  -3,  -3,  -3, 270, 276,
  266.  276, 276,  -3,  -3,  -3,  -3,  -3,  -3,  -3,  -3,
  267.  276, 276, 276, 276,  -3,  -3,  -3, 276, 276, 276,
  268.  276, 270, 276, 270, 270,  -3,  -3,  -3,  -3, 270,
  269.  270, 276,  -3,  -3,  -3,  -3,  -3, 276, 276,  -3,
  270.  276, 276, 276, 276, 276,  -3,  -3,  -3,  -3,  -3,
  271.   -3,  -3, 270, 270, 270, 270, 276,  -3, 276,  -3,
  272.  270 };
  273. short yydef[]={
  274.  
  275.    5,  -2,  27,  27,  27,   4,   0,   0,   0,   0,
  276.    0,   0,   0,   0,  14,   0,   0,   0,   0,   0,
  277.    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
  278.   27,   3,  15,   2,  28,   0,   0,   0,   6,   7,
  279.   64,   0,  70,  71,   8,   0,   0,   0,  12,  13,
  280.   39,  40,   0,   0,   0,   0,   0,   0,   0,   0,
  281.   49,  50,  51,   0,   0,   0,  17,   1,  32,  32,
  282.   32,   0,   0,   0,   0,  69,   0,   0,   0,   0,
  283.    0,  55,  55,   0,   0,   0,   0,   0,   0,   0,
  284.    0,   0,   0,   0,   0,  65,  66,  67,  68,   0,
  285.    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
  286.    0,   0,   0,  16,   0,  21,   0,   0,   0,   0,
  287.    0,  19,  20,  29,  33,  34,   0,   0,   0,  38,
  288.   30,  31,   0,   0,   0,   0,   0,  43,  56,  57,
  289.    0,   0,   0,   0,   0,   0,  44,   0,   0,   0,
  290.    0,   0,   0,   0,   0,   0,  23,  24,  25,   0,
  291.    0,  36,   0,   0,   0,  11,   0,   0,  58,  59,
  292.    0,   0,   0,  63,  45,  46,   0,  48,  52,   0,
  293.    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
  294.    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
  295.    0,   9,   0,  41,  42,   0,  61,   0,  47,  53,
  296.   54,   0,   0,   0,   0,   0,   0,   0,   0,  18,
  297.    0,   0,   0,   0,   0,  60,  62,   0,   0,   0,
  298.    0,   0,  22,  26,  35,  37,   0,   0,   0,   0,
  299.   10 };
  300. #ifndef lint
  301. static    char yaccpar_sccsid[] = "@(#)yaccpar 1.6 88/02/08 SMI"; /* from UCB 4.1 83/02/11 */
  302. #endif
  303.  
  304. #
  305. # define YYFLAG -1000
  306. # define YYERROR goto yyerrlab
  307. # define YYACCEPT return(0)
  308. # define YYABORT return(1)
  309.  
  310. /*    parser for yacc output    */
  311.  
  312. #ifdef YYDEBUG
  313. int yydebug = 0; /* 1 for debugging */
  314. #endif
  315. YYSTYPE yyv[YYMAXDEPTH]; /* where the values are stored */
  316. int yychar = -1; /* current input token number */
  317. int yynerrs = 0;  /* number of errors */
  318. short yyerrflag = 0;  /* error recovery flag */
  319.  
  320. yyparse() {
  321.  
  322.     short yys[YYMAXDEPTH];
  323.     short yyj, yym;
  324.     register YYSTYPE *yypvt;
  325.     register short yystate, *yyps, yyn;
  326.     register YYSTYPE *yypv;
  327.     register short *yyxi;
  328.  
  329.     yystate = 0;
  330.     yychar = -1;
  331.     yynerrs = 0;
  332.     yyerrflag = 0;
  333.     yyps= &yys[-1];
  334.     yypv= &yyv[-1];
  335.  
  336.  yystack:    /* put a state and value onto the stack */
  337.  
  338. #ifdef YYDEBUG
  339.     if( yydebug  ) printf( "state %d, char 0%o\n", yystate, yychar );
  340. #endif
  341.         if( ++yyps>= &yys[YYMAXDEPTH] ) { yyerror( "yacc stack overflow" ); return(1); }
  342.         *yyps = yystate;
  343.         ++yypv;
  344.         *yypv = yyval;
  345.  
  346.  yynewstate:
  347.  
  348.     yyn = yypact[yystate];
  349.  
  350.     if( yyn<= YYFLAG ) goto yydefault; /* simple state */
  351.  
  352.     if( yychar<0 ) if( (yychar=yylex())<0 ) yychar=0;
  353.     if( (yyn += yychar)<0 || yyn >= YYLAST ) goto yydefault;
  354.  
  355.     if( yychk[ yyn=yyact[ yyn ] ] == yychar ){ /* valid shift */
  356.         yychar = -1;
  357.         yyval = yylval;
  358.         yystate = yyn;
  359.         if( yyerrflag > 0 ) --yyerrflag;
  360.         goto yystack;
  361.         }
  362.  
  363.  yydefault:
  364.     /* default state action */
  365.  
  366.     if( (yyn=yydef[yystate]) == -2 ) {
  367.         if( yychar<0 ) if( (yychar=yylex())<0 ) yychar = 0;
  368.         /* look through exception table */
  369.  
  370.         for( yyxi=yyexca; (*yyxi!= (-1)) || (yyxi[1]!=yystate) ; yyxi += 2 ) ; /* VOID */
  371.  
  372.         while( *(yyxi+=2) >= 0 ){
  373.             if( *yyxi == yychar ) break;
  374.             }
  375.         if( (yyn = yyxi[1]) < 0 ) return(0);   /* accept */
  376.         }
  377.  
  378.     if( yyn == 0 ){ /* error */
  379.         /* error ... attempt to resume parsing */
  380.  
  381.         switch( yyerrflag ){
  382.  
  383.         case 0:   /* brand new error */
  384.  
  385.             yyerror( "syntax error" );
  386.         yyerrlab:
  387.             ++yynerrs;
  388.  
  389.         case 1:
  390.         case 2: /* incompletely recovered error ... try again */
  391.  
  392.             yyerrflag = 3;
  393.  
  394.             /* find a state where "error" is a legal shift action */
  395.  
  396.             while ( yyps >= yys ) {
  397.                yyn = yypact[*yyps] + YYERRCODE;
  398.                if( yyn>= 0 && yyn < YYLAST && yychk[yyact[yyn]] == YYERRCODE ){
  399.                   yystate = yyact[yyn];  /* simulate a shift of "error" */
  400.                   goto yystack;
  401.                   }
  402.                yyn = yypact[*yyps];
  403.  
  404.                /* the current yyps has no shift onn "error", pop stack */
  405.  
  406. #ifdef YYDEBUG
  407.                if( yydebug ) printf( "error recovery pops state %d, uncovers %d\n", *yyps, yyps[-1] );
  408. #endif
  409.                --yyps;
  410.                --yypv;
  411.                }
  412.  
  413.             /* there is no state on the stack with an error shift ... abort */
  414.  
  415.     yyabort:
  416.             return(1);
  417.  
  418.  
  419.         case 3:  /* no shift yet; clobber input char */
  420.  
  421. #ifdef YYDEBUG
  422.             if( yydebug ) printf( "error recovery discards char %d\n", yychar );
  423. #endif
  424.  
  425.             if( yychar == 0 ) goto yyabort; /* don't discard EOF, quit */
  426.             yychar = -1;
  427.             goto yynewstate;   /* try again in the same state */
  428.  
  429.             }
  430.  
  431.         }
  432.  
  433.     /* reduction by production yyn */
  434.  
  435. #ifdef YYDEBUG
  436.         if( yydebug ) printf("reduce %d\n",yyn);
  437. #endif
  438.         yyps -= yyr2[yyn];
  439.         yypvt = yypv;
  440.         yypv -= yyr2[yyn];
  441.         yyval = yypv[1];
  442.         yym=yyn;
  443.             /* consult goto table to find next state */
  444.         yyn = yyr1[yyn];
  445.         yyj = yypgo[yyn] + *yyps + 1;
  446.         if( yyj>=YYLAST || yychk[ yystate = yyact[yyj] ] != -yyn ) yystate = yyact[yypgo[yyn]];
  447.         switch(yym){
  448.             
  449. case 6:
  450. # line 89 "gram.y"
  451. {
  452.         title = yypvt[-0].y_str;
  453.       } break;
  454. case 7:
  455. # line 93 "gram.y"
  456. {
  457.         if (yypvt[-0].y_flt == 0.0 || yypvt[-0].y_flt == 360.0)
  458.             fatal("art: idiotic angle in field of view.\n");
  459.  
  460.         focallength = -1.0 / tan(M_PI / 360.0 * yypvt[-0].y_flt);
  461.       } break;
  462. case 8:
  463. # line 100 "gram.y"
  464. {
  465.         raysperpix = yypvt[-0].y_flt;
  466.       } break;
  467. case 9:
  468. # line 104 "gram.y"
  469. {
  470.         up.x = yypvt[-5].y_flt;
  471.         up.y = yypvt[-3].y_flt;
  472.         up.z = yypvt[-1].y_flt;
  473.       } break;
  474. case 10:
  475. # line 110 "gram.y"
  476. {
  477.         vector    t, u, s;
  478.         matrix    m, tmp;
  479.         double    vy, vz, sinval, cosval;
  480.  
  481.         /*
  482.          * apply the twist
  483.          */
  484.         sinval = sin(yypvt[-1].y_flt * M_PI / 180.0);
  485.         cosval = cos(yypvt[-1].y_flt * M_PI / 180.0);
  486.         mident4(m);
  487.         m[0][0] = cosval;
  488.         m[0][1] = -sinval;
  489.         m[1][0] = sinval;
  490.         m[1][1] = cosval;
  491.         mcpy4(tmp, trans);
  492.         mmult4(trans, tmp, m);
  493.  
  494.         /*
  495.          * calculate the lookat
  496.          */
  497.         t.x = yypvt[-13].y_flt - yypvt[-7].y_flt;
  498.         t.y = yypvt[-11].y_flt - yypvt[-5].y_flt;
  499.         t.z = yypvt[-9].y_flt - yypvt[-3].y_flt;
  500.  
  501.         u.x = up.x;
  502.         u.y = up.y;
  503.         u.z = up.z;
  504.  
  505.         normalise(t);
  506.  
  507.         normalise(u);
  508.  
  509.         vz = dprod(t, u);
  510.  
  511.         if (fabs(vz) >= 1.0)
  512.             fatal("atomart: up vector and direction of view are the same.\n");
  513.  
  514.         vy = sqrt(1.0 - vz * vz);
  515.  
  516.         u.x = (u.x - vz * t.x) / vy;
  517.         u.y = (u.y - vz * t.y) / vy;
  518.         u.z = (u.z - vz * t.z) / vy;
  519.  
  520.         xprod(s, u, t);
  521.  
  522.         mident4(m);
  523.  
  524.         m[0][0] = s.x;
  525.         m[0][1] = s.y;
  526.         m[0][2] = s.z;
  527.  
  528.         m[1][0] = u.x;
  529.         m[1][1] = u.y;
  530.         m[1][2] = u.z;
  531.  
  532.         m[2][0] = t.x;
  533.         m[2][1] = t.y;
  534.         m[2][2] = t.z;
  535.  
  536.         mcpy4(tmp, trans);
  537.         mmult4(trans, tmp, m);
  538.  
  539.         mident4(m);
  540.         m[3][0] = yypvt[-13].y_flt;
  541.         m[3][1] = yypvt[-11].y_flt;
  542.         m[3][2] = yypvt[-9].y_flt;
  543.         mcpy4(tmp, trans);
  544.         mmult4(trans, tmp, m);
  545.  
  546.         astackp->mcopy = TRUE;
  547.       } break;
  548. case 11:
  549. # line 183 "gram.y"
  550. {
  551.         backcol.r = yypvt[-4].y_flt;
  552.         backcol.g = yypvt[-2].y_flt;
  553.         backcol.b = yypvt[-0].y_flt;
  554.       } break;
  555. case 12:
  556. # line 189 "gram.y"
  557. {
  558.         maxhitlevel = yypvt[-0].y_flt;
  559.       } break;
  560. case 13:
  561. # line 193 "gram.y"
  562. {
  563.         filetype = yypvt[-0].y_int;
  564.       } break;
  565. case 14:
  566. # line 199 "gram.y"
  567. {
  568.         lights = yypvt[-0].y_lht;
  569.         lights->nxt = (light *)NULL;
  570.       } break;
  571. case 15:
  572. # line 204 "gram.y"
  573. {
  574.         yypvt[-0].y_lht->nxt = lights;
  575.         lights = yypvt[-0].y_lht;
  576.       } break;
  577. case 16:
  578. # line 211 "gram.y"
  579. {
  580.         yyval.y_lht = lightinit(yypvt[-1].y_det);
  581.         astackp--;
  582.       } break;
  583. case 17:
  584. # line 218 "gram.y"
  585. {
  586.         yyval.y_det = (details *)NULL;
  587.       } break;
  588. case 18:
  589. # line 222 "gram.y"
  590. {
  591.         astackp->s.c.r = yypvt[-4].y_flt;
  592.         astackp->s.c.g = yypvt[-2].y_flt;
  593.         astackp->s.c.b = yypvt[-0].y_flt;
  594.         yyval.y_det = yypvt[-6].y_det;
  595.       } break;
  596. case 19:
  597. # line 229 "gram.y"
  598. {
  599.         astackp->options |= yypvt[-1].y_int;
  600.       } break;
  601. case 20:
  602. # line 233 "gram.y"
  603. {
  604.         astackp->options &= ~yypvt[-1].y_int;
  605.       } break;
  606. case 21:
  607. # line 237 "gram.y"
  608. {
  609.         yypvt[-0].y_det->nxt = yypvt[-1].y_det;
  610.         yyval.y_det = yypvt[-0].y_det;
  611.       } break;
  612. case 22:
  613. # line 244 "gram.y"
  614. {
  615.         yyval.y_det = (details *)smalloc(sizeof(details));
  616.         yyval.y_det->type = CENTER;
  617.         yyval.y_det->u.v.x = yypvt[-5].y_flt;
  618.         yyval.y_det->u.v.y = yypvt[-3].y_flt;
  619.         yyval.y_det->u.v.z = yypvt[-1].y_flt;
  620.         yyval.y_det->nxt = (details *)NULL;
  621.       } break;
  622. case 23:
  623. # line 253 "gram.y"
  624. {
  625.         yyval.y_det = (details *)smalloc(sizeof(details));
  626.         yyval.y_det->type = RADIUS;
  627.         yyval.y_det->u.f = yypvt[-0].y_flt;
  628.         yyval.y_det->nxt = (details *)NULL;
  629.       } break;
  630. case 24:
  631. # line 260 "gram.y"
  632. {
  633.         yyval.y_det = (details *)smalloc(sizeof(details));
  634.         yyval.y_det->type = NUMRAYS;
  635.         yyval.y_det->u.f = yypvt[-0].y_flt;
  636.         yyval.y_det->nxt = (details *)NULL;
  637.       } break;
  638. case 25:
  639. # line 267 "gram.y"
  640. {
  641.         yyval.y_det = (details *)smalloc(sizeof(details));
  642.         yyval.y_det->type = ANGLE;
  643.         yyval.y_det->u.f = yypvt[-0].y_flt;
  644.         yyval.y_det->nxt = (details *)NULL;
  645.       } break;
  646. case 26:
  647. # line 274 "gram.y"
  648. {
  649.         yyval.y_det = (details *)smalloc(sizeof(details));
  650.         yyval.y_det->type = DIRECTION;
  651.         yyval.y_det->u.v.x = yypvt[-5].y_flt;
  652.         yyval.y_det->u.v.y = yypvt[-3].y_flt;
  653.         yyval.y_det->u.v.z = yypvt[-1].y_flt;
  654.         yyval.y_det->nxt = (details *)NULL;
  655.       } break;
  656. case 27:
  657. # line 286 "gram.y"
  658. {
  659.         oblist = (object *)NULL;
  660.       } break;
  661. case 28:
  662. # line 290 "gram.y"
  663. {
  664.         yypvt[-0].y_obj->nxt = oblist;
  665.         oblist = yypvt[-0].y_obj;
  666.       } break;
  667. case 29:
  668. # line 295 "gram.y"
  669. {
  670.         details *d, *nxtd;
  671.  
  672.         for (d = yypvt[-1].y_det; d != (details *)NULL; d = nxtd) {
  673.             nxtd = d->nxt;
  674.             if (d->type == OBJECT) {
  675.                 d->u.obj->nxt = oblist;
  676.                 oblist = d->u.obj;
  677.             }
  678.             free(d);
  679.         }
  680.       } break;
  681. case 30:
  682. # line 310 "gram.y"
  683. {
  684.         yyval.y_obj = sphereinit(yypvt[-1].y_det);
  685.  
  686.         astackp--;
  687.       } break;
  688. case 31:
  689. # line 316 "gram.y"
  690. {
  691.         yyval.y_obj = polygoninit(yypvt[-1].y_det);
  692.         astackp--;
  693.       } break;
  694. case 32:
  695. # line 323 "gram.y"
  696. {
  697.         yyval.y_det = (details *)NULL;
  698.       } break;
  699. case 33:
  700. # line 327 "gram.y"
  701. {
  702.         yypvt[-0].y_det->nxt = yypvt[-1].y_det;
  703.         yyval.y_det = yypvt[-0].y_det;
  704.       } break;
  705. case 34:
  706. # line 332 "gram.y"
  707. {
  708.         yyval.y_det = yypvt[-1].y_det;
  709.       } break;
  710. case 35:
  711. # line 338 "gram.y"
  712. {
  713.         yyval.y_det = (details *)smalloc(sizeof(details));
  714.         yyval.y_det->type = CENTER;
  715.         yyval.y_det->u.v.x = yypvt[-5].y_flt;
  716.         yyval.y_det->u.v.y = yypvt[-3].y_flt;
  717.         yyval.y_det->u.v.z = yypvt[-1].y_flt;
  718.         yyval.y_det->nxt = (details *)NULL;
  719.       } break;
  720. case 36:
  721. # line 347 "gram.y"
  722. {
  723.         yyval.y_det = (details *)smalloc(sizeof(details));
  724.         yyval.y_det->type = RADIUS;
  725.         yyval.y_det->u.f = yypvt[-0].y_flt;
  726.         yyval.y_det->nxt = (details *)NULL;
  727.       } break;
  728. case 37:
  729. # line 354 "gram.y"
  730. {
  731.         yyval.y_det = (details *)smalloc(sizeof(details));
  732.         yyval.y_det->type = VERTEX;
  733.         yyval.y_det->u.v.x = yypvt[-5].y_flt;
  734.         yyval.y_det->u.v.y = yypvt[-3].y_flt;
  735.         yyval.y_det->u.v.z = yypvt[-1].y_flt;
  736.         yyval.y_det->nxt = (details *)NULL;
  737.       } break;
  738. case 38:
  739. # line 363 "gram.y"
  740. {
  741.         yyval.y_det = (details *)smalloc(sizeof(details));
  742.         yyval.y_det->type = OBJECT;
  743.         yyval.y_det->u.obj = yypvt[-0].y_obj;
  744.         yyval.y_det->nxt = (details *)NULL;
  745.       } break;
  746. case 39:
  747. # line 372 "gram.y"
  748. {
  749.         astackp->options |= yypvt[-1].y_int;
  750.       } break;
  751. case 40:
  752. # line 376 "gram.y"
  753. {
  754.         astackp->options &= ~yypvt[-1].y_int;
  755.       } break;
  756. case 41:
  757. # line 380 "gram.y"
  758. {
  759.         astackp->s.txtlist->txt.refset = TRUE;
  760.         astackp->s.txtlist->txt.vref1.x = yypvt[-5].y_flt;
  761.         astackp->s.txtlist->txt.vref1.y = yypvt[-3].y_flt;
  762.         astackp->s.txtlist->txt.vref1.z = yypvt[-1].y_flt;
  763.  
  764.         normalise(astackp->s.txtlist->txt.vref1);
  765.       } break;
  766. case 42:
  767. # line 389 "gram.y"
  768. {
  769.         astackp->s.txtlist->txt.vref2.x = yypvt[-5].y_flt;
  770.         astackp->s.txtlist->txt.vref2.y = yypvt[-3].y_flt;
  771.         astackp->s.txtlist->txt.vref2.z = yypvt[-1].y_flt;
  772.  
  773.         normalise(astackp->s.txtlist->txt.vref2);
  774.       } break;
  775. case 43:
  776. # line 397 "gram.y"
  777. {
  778.         tlist    *tl;
  779.  
  780.         tl = textureinit(yypvt[-3].y_str, yypvt[-1].y_det);
  781.  
  782.         astackp--;
  783.  
  784.         tl->nxt = astackp->s.txtlist;
  785.         astackp->s.txtlist = tl;
  786.       } break;
  787. case 44:
  788. # line 408 "gram.y"
  789. {
  790.         tlist    *tl;
  791.  
  792.         tl = textureinit("tile", yypvt[-1].y_det);
  793.  
  794.         astackp--;
  795.  
  796.         tl->nxt = astackp->s.txtlist;
  797.         astackp->s.txtlist = tl;
  798.       } break;
  799. case 45:
  800. # line 419 "gram.y"
  801. {
  802.         tlist    *tl;
  803.         matrix    tmp;
  804.  
  805.         tl = (tlist *)smalloc(sizeof(tlist));
  806.         tl->txt.type = TILE;
  807.         tl->txtcol = (void (*)())NULL;
  808.         tl->txt.refset = FALSE;
  809.         tl->txt.scalew = 1.0;
  810.         tl->txt.scaleh = 1.0;
  811.  
  812.         tileinit(&tl->txt, yypvt[-4].y_str, yypvt[-2].y_flt, yypvt[-0].y_flt);
  813.  
  814.         mmult4(tmp, trans, astackp->m);
  815.         cp3x3(tl->txt.mat, tmp);
  816.  
  817.         tl->txt.scales = astackp->scales;
  818.  
  819.         tl->txt.trans.x = tmp[3][0];
  820.         tl->txt.trans.y = tmp[3][1];
  821.         tl->txt.trans.z = tmp[3][2];
  822.  
  823.         tl->nxt = astackp->s.txtlist;
  824.         astackp->s.txtlist = tl;
  825.       } break;
  826. case 46:
  827. # line 445 "gram.y"
  828. {
  829.         astackp->s.c.r = yypvt[-4].y_flt;
  830.         astackp->s.c.g = yypvt[-2].y_flt;
  831.         astackp->s.c.b = yypvt[-0].y_flt;
  832.       } break;
  833. case 47:
  834. # line 451 "gram.y"
  835. {
  836.         astackp->s.ri = yypvt[-6].y_flt;
  837.         astackp->s.kd = yypvt[-4].y_flt;
  838.         astackp->s.ks = yypvt[-2].y_flt;
  839.         astackp->s.ksexp = yypvt[-0].y_flt;
  840.       } break;
  841. case 48:
  842. # line 458 "gram.y"
  843. {
  844.         astackp->s.a.r = yypvt[-4].y_flt;
  845.         astackp->s.a.g = yypvt[-2].y_flt;
  846.         astackp->s.a.b = yypvt[-0].y_flt;
  847.       } break;
  848. case 49:
  849. # line 464 "gram.y"
  850. {
  851.         astackp->s.refl = yypvt[-0].y_flt;
  852.       } break;
  853. case 50:
  854. # line 468 "gram.y"
  855. {
  856.         astackp->s.trans = yypvt[-0].y_flt;
  857.       } break;
  858. case 51:
  859. # line 472 "gram.y"
  860. {
  861.         astackp->s.absorb = yypvt[-0].y_flt;
  862.       } break;
  863. case 52:
  864. # line 476 "gram.y"
  865. {
  866.         rotate(yypvt[-3].y_flt, *yypvt[-1].y_str);
  867.       } break;
  868. case 53:
  869. # line 480 "gram.y"
  870. {
  871.         translate(yypvt[-5].y_flt, yypvt[-3].y_flt, yypvt[-1].y_flt);
  872.       } break;
  873. case 54:
  874. # line 484 "gram.y"
  875. {
  876.         scale(yypvt[-5].y_flt, yypvt[-3].y_flt, yypvt[-1].y_flt);
  877.       } break;
  878. case 55:
  879. # line 490 "gram.y"
  880. {
  881.         yyval.y_det = (details *)NULL;
  882.       } break;
  883. case 56:
  884. # line 494 "gram.y"
  885. {
  886.         yypvt[-0].y_det->nxt = yypvt[-1].y_det;
  887.         yyval.y_det = yypvt[-0].y_det;
  888.       } break;
  889. case 57:
  890. # line 499 "gram.y"
  891. {
  892.         yyval.y_det = yypvt[-1].y_det;
  893.       } break;
  894. case 58:
  895. # line 505 "gram.y"
  896. {
  897.         yyval.y_det = (details *)smalloc(sizeof(details));
  898.         yyval.y_det->type = MAP;
  899.         yyval.y_det->u.s = yypvt[-0].y_str;
  900.         yyval.y_det->nxt = (details *)NULL;
  901.       } break;
  902. case 59:
  903. # line 512 "gram.y"
  904. {
  905.         yyval.y_det = (details *)smalloc(sizeof(details));
  906.         yyval.y_det->type = RANGE;
  907.         yyval.y_det->u.f = yypvt[-0].y_flt;
  908.         yyval.y_det->nxt = (details *)NULL;
  909.       } break;
  910. case 60:
  911. # line 519 "gram.y"
  912. {
  913.         yyval.y_det = (details *)smalloc(sizeof(details));
  914.         yyval.y_det->type = BLENDCOLOR;
  915.         yyval.y_det->u.v.x = yypvt[-4].y_flt;
  916.         yyval.y_det->u.v.y = yypvt[-2].y_flt;
  917.         yyval.y_det->u.v.z = yypvt[-0].y_flt;
  918.         yyval.y_det->nxt = (details *)NULL;
  919.       } break;
  920. case 61:
  921. # line 528 "gram.y"
  922. {
  923.         yyval.y_det = (details *)smalloc(sizeof(details));
  924.         yyval.y_det->type = SIZE;
  925.         yyval.y_det->u.v.x = yypvt[-2].y_flt;
  926.         yyval.y_det->u.v.y = yypvt[-0].y_flt;
  927.         yyval.y_det->nxt = (details *)NULL;
  928.       } break;
  929. case 62:
  930. # line 536 "gram.y"
  931. {
  932.         yyval.y_det = (details *)smalloc(sizeof(details));
  933.         yyval.y_det->type = SCALEFACTORS;
  934.         yyval.y_det->u.v.x = yypvt[-4].y_flt;
  935.         yyval.y_det->u.v.y = yypvt[-2].y_flt;
  936.         yyval.y_det->u.v.z = yypvt[-0].y_flt;
  937.         yyval.y_det->nxt = (details *)NULL;
  938.       } break;
  939. case 63:
  940. # line 545 "gram.y"
  941. {
  942.         yyval.y_det = (details *)smalloc(sizeof(details));
  943.         yyval.y_det->type = VORTFILE;
  944.         yyval.y_det->u.s = yypvt[-0].y_str;
  945.         yyval.y_det->nxt = (details *)NULL;
  946.       } break;
  947. case 64:
  948. # line 554 "gram.y"
  949. {
  950.         yyval.y_flt = yypvt[-0].y_flt;
  951.       } break;
  952. case 65:
  953. # line 558 "gram.y"
  954. {
  955.         yyval.y_flt = yypvt[-2].y_flt + yypvt[-0].y_flt;
  956.       } break;
  957. case 66:
  958. # line 562 "gram.y"
  959. {
  960.         yyval.y_flt = yypvt[-2].y_flt - yypvt[-0].y_flt;
  961.       } break;
  962. case 67:
  963. # line 566 "gram.y"
  964. {
  965.         yyval.y_flt = yypvt[-2].y_flt * yypvt[-0].y_flt;
  966.       } break;
  967. case 68:
  968. # line 570 "gram.y"
  969. {
  970.         yyval.y_flt = yypvt[-2].y_flt / yypvt[-0].y_flt;
  971.       } break;
  972. case 69:
  973. # line 574 "gram.y"
  974. {
  975.         yyval.y_flt = -yypvt[-0].y_flt;
  976.       } break;
  977. case 70:
  978. # line 580 "gram.y"
  979. {
  980.         yyval.y_flt = yypvt[-0].y_flt;
  981.       } break;
  982. case 71:
  983. # line 584 "gram.y"
  984. {
  985.         yyval.y_flt = yypvt[-0].y_int;
  986.       } break;
  987.         }
  988.         goto yystack;  /* stack new state and value */
  989.  
  990.     }
  991.