home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #6 / amigaacscoverdisc1998-061998.iso / games / descent / source / main / photos.c < prev    next >
Text File  |  1998-06-08  |  6KB  |  226 lines

  1. /*
  2. THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
  3. SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
  4. END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
  5. ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
  6. IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
  7. SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
  8. FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
  9. CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
  10. AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.  
  11. COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
  12. */
  13. /*
  14.  * $Source: f:/miner/source/main/rcs/photos.c $
  15.  * $Revision: 2.1 $
  16.  * $Author: john $
  17.  * $Date: 1995/03/06 15:23:34 $
  18.  * 
  19.  * Take multiple-view "photos" of an object
  20.  * 
  21.  * $Log: photos.c $
  22.  * Revision 2.1  1995/03/06  15:23:34  john
  23.  * New screen techniques.
  24.  * 
  25.  * Revision 2.0  1995/02/27  11:29:34  john
  26.  * New version 2.0, which has no anonymous unions, builds with
  27.  * Watcom 10.0, and doesn't require parsing BITMAPS.TBL.
  28.  * 
  29.  * Revision 1.8  1993/12/09  15:07:27  john
  30.  * Changed palette stuff majorly... no more grd_curscreen->palette
  31.  * 
  32.  * Revision 1.7  1993/12/05  22:47:49  matt
  33.  * Reworked include files in an attempt to cut down on build times
  34.  * 
  35.  * Revision 1.6  1993/12/01  00:27:08  yuan
  36.  * Implemented new bitmap structure system...
  37.  * overall bitmap scheme still needs some work.
  38.  * 
  39.  * Revision 1.5  1993/11/29  19:50:11  matt
  40.  * Change vertex allocation
  41.  * 
  42.  * Revision 1.4  1993/11/29  18:57:49  matt
  43.  * Changed vertex numbering around a bit
  44.  * 
  45.  * Revision 1.3  1993/11/23  14:35:50  matt
  46.  * Don't do perspecive on photos; save up vectors to file
  47.  * 
  48.  * Revision 1.2  1993/11/22  10:53:05  matt
  49.  * Now use correct uvl structure (not just array of uvs)
  50.  * 
  51.  * Revision 1.1  1993/11/21  22:53:24  matt
  52.  * Initial revision
  53.  * 
  54.  * 
  55.  */
  56.  
  57.  
  58. #pragma off (unreferenced)
  59. static char rcsid[] = "$Id: photos.c 2.1 1995/03/06 15:23:34 john Exp $";
  60. #pragma on (unreferenced)
  61.  
  62. #include <stdio.h>
  63.  
  64. #include "inferno.h"
  65. #include "segment.h"
  66. #include "error.h"
  67. #include "vecmat.h"
  68. #include "3d.h"
  69. #include "iff.h"
  70. #include "game.h"
  71. #include "textures.h"
  72. #include "screens.h"
  73. #include "segpoint.h"
  74.  
  75. #include "editor\editor.h"
  76.  
  77. extern byte Vertex_active[];    // !0 means vertex is in use, 0 means not in use.
  78.  
  79. #define CUBE_SIZE i2f(5)
  80.  
  81. //the ordering here is the same as for a segment
  82. vms_vector cube_coords[] =    {
  83.                                         { CUBE_SIZE, CUBE_SIZE,-CUBE_SIZE},
  84.                                         { CUBE_SIZE,-CUBE_SIZE,-CUBE_SIZE},
  85.                                         {-CUBE_SIZE,-CUBE_SIZE,-CUBE_SIZE},
  86.                                         {-CUBE_SIZE, CUBE_SIZE,-CUBE_SIZE},
  87.  
  88.                                         { CUBE_SIZE, CUBE_SIZE, CUBE_SIZE},
  89.                                         { CUBE_SIZE,-CUBE_SIZE, CUBE_SIZE},
  90.                                         {-CUBE_SIZE,-CUBE_SIZE, CUBE_SIZE},
  91.                                         {-CUBE_SIZE, CUBE_SIZE, CUBE_SIZE},
  92.  
  93.                                         {0,0,0}    //center of cube
  94.                                     };
  95.  
  96.  
  97. vms_vector cube_position={0,0,0};
  98.  
  99. uvl cube_uvls[] =    {
  100.                             i2f(64),0,0,
  101.                             i2f(64),i2f(64),0,
  102.                             0,i2f(64),0,
  103.                             0,0,0,
  104.                         };
  105.  
  106. //put a cube on the screen
  107. draw_cube()
  108. {
  109.     int i,sn;
  110.     short cube_vert_nums[9];
  111.  
  112.     //find 8 free vertices
  113.  
  114.     for (i=0;i<9;i++) {
  115.         int vn;
  116.  
  117.         vn = cube_vert_nums[i] = alloc_vert();
  118.  
  119.         vm_vec_add(&Vertices[vn],&cube_position,&cube_coords[i]);
  120.     }
  121.  
  122.     g3_rotate_list(9,cube_vert_nums);
  123.  
  124.     //fudge perspecive by using z value from cube center for all verts
  125.  
  126.     for (i=0;i<8;i++)
  127.         Segment_points[cube_vert_nums[i]].z = Segment_points[cube_vert_nums[8]].z;
  128.     
  129.     //draw six sides
  130.  
  131.     for (sn=0;sn<6;sn++) {
  132.         short side_vert_nums[4];
  133.  
  134.         for (i=0;i<4;i++) side_vert_nums[3-i] = cube_vert_nums[Side_to_verts[sn][i]];
  135.  
  136. //        gr_setcolor(sn+1);
  137. //        g3_check_and_draw_poly(4,side_vert_nums,NULL);
  138.  
  139.         g3_check_and_draw_tmap(4,side_vert_nums,cube_uvls,Texture[39+sn]->bitmap,NULL);
  140.     }
  141.  
  142.     //free 8 free vertices
  143.  
  144.     for (i=0;i<8;i++) free_vert(cube_vert_nums[i]);
  145.  
  146. }
  147.  
  148. #define PHOTO_DIST (CUBE_SIZE * 7 / 2)
  149.  
  150. //make a series of photographs
  151. do_photos()
  152. {
  153.     FILE *vfile,*upvfile;
  154.     int photo_num=0;
  155.     char savename[13];
  156.     grs_canvas *photo_canvas;
  157.     vms_vector viewer_pos;
  158.     vms_matrix viewer_orient;
  159.  
  160.     vfile=fopen("vectors.lst","rt");
  161.     upvfile=fopen("upvecs.c","wt");
  162.  
  163.     Assert(vfile!=NULL && upvfile!=NULL);
  164.  
  165.     fprintf(upvfile,"\n\n#include \"vecmat.h\"\n\nvms_vector up_vecs[] = {\n");
  166.  
  167.     photo_canvas = gr_create_canvas(64,64);
  168.  
  169.     gr_set_current_canvas(photo_canvas);
  170.  
  171.     while (!feof(vfile)) {
  172.         vms_vector v;
  173.         vms_matrix m;
  174.         float x,y,z;
  175.         int nf;
  176.  
  177.         nf = fscanf(vfile,"%f %f %f",&x,&y,&z);
  178.  
  179.         if (nf!=3) break;
  180.  
  181.         vm_vec_make(&v,fl2f(x),fl2f(y),fl2f(z));
  182.  
  183.         vm_vector_2_matrix(&m,&v,NULL,NULL);
  184.  
  185.         fprintf(upvfile,"\t\t\t{%#x,%#x,%#x},\n",m.uvec.x,m.uvec.y,m.uvec.z);
  186.  
  187.         vm_vec_scale(&v,PHOTO_DIST);
  188.  
  189.         vm_vec_add(&viewer_pos,&cube_position,&v);
  190.  
  191.         viewer_orient = m;
  192.         vm_vec_negate(&viewer_orient.fvec);
  193.         vm_vec_negate(&viewer_orient.rvec);
  194.  
  195.         gr_clear_canvas(129);
  196.         g3_start_frame();
  197.  
  198.         g3_set_view_matrix(&viewer_pos,&viewer_orient,0x9000);
  199.  
  200.         draw_cube();
  201.  
  202.         g3_end_frame();
  203.  
  204. gr_set_current_canvas(Canv_game);
  205. gr_ubitmap(0,0,&photo_canvas->cv_bitmap);
  206. gr_set_current_canvas(photo_canvas);
  207.  
  208.         sprintf(savename,"cube_%02d.bbm",photo_num);
  209.  
  210.         iff_write_bitmap(savename,&photo_canvas->cv_bitmap,gr_palette);
  211.  
  212.         photo_num++;
  213.  
  214.     }
  215.  
  216.     gr_free_canvas(photo_canvas);
  217.  
  218.     fprintf(upvfile,"\t\t};\n");
  219.  
  220.     fclose(vfile);
  221.     fclose(upvfile);
  222.  
  223. }
  224.  
  225. 
  226.