home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #6 / amigaacscoverdisc1998-061998.iso / games / descent / source / 2d / testg.c < prev    next >
Text File  |  1998-06-08  |  3KB  |  139 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/2d/rcs/testg.c $
  15.  * $Revision: 1.19 $
  16.  * $Author: john $
  17.  * $Date: 1994/09/12 19:28:10 $
  18.  *
  19.  * Program to test the graphics package.
  20.  *
  21.  */
  22.  
  23. #include <stdlib.h>
  24. #include <stdio.h>
  25. #include <conio.h>
  26. #include <math.h>
  27. #include <string.h>
  28.  
  29. #include "gr.h"
  30. #include "key.h"
  31. #include "timer.h"
  32. #include "grdef.h"
  33. #include "mono.h"
  34. #include "fix.h"
  35. #include "iff.h"
  36. #include "palette.h"
  37. #include "rle.h"
  38. #include "pcx.h"
  39.  
  40. void ReadBitmap( char * filename, grs_bitmap * bmp, ubyte * palette )
  41. {
  42.     int iff_error;
  43.  
  44.     iff_error=iff_read_bitmap( filename, bmp, BM_LINEAR, palette );
  45.     if (iff_error != IFF_NO_ERROR)    {
  46.         printf("Error loading bitmap <%s>, error=%d",filename,iff_error);
  47.         exit(1);
  48.     }
  49.             
  50. }
  51.  
  52.  
  53. ubyte getpixel( grs_bitmap * bmp, int x, int y )
  54. {
  55.     return bmp->bm_data[y*320+x];
  56. }
  57.  
  58. #define EPSILON (0.0000001)
  59.  
  60. float cfactor = 1.57;
  61.  
  62. int myx = 0;
  63.  
  64. ubyte getpixel1( grs_bitmap * bmp, int x, int y )
  65. {
  66.     float xmid, ymid, xx, yy, delta, dist, factor;
  67.     
  68.     xmid = (bmp->bm_w - 1 ) / 2.0;    xx = x - xmid;
  69.     ymid = (bmp->bm_h - 1 ) / 2.0;   yy = y - ymid;
  70.  
  71.     delta = xx*xx + yy*yy;
  72.  
  73.     if ( delta < EPSILON )
  74.         dist = 0.0;
  75.     else
  76.         dist = 1.01 * sqrt(delta) / min(xmid,ymid);
  77.     
  78.     if ( dist > 1.0 )
  79.         return 0;
  80.     else if ( dist < EPSILON )
  81.         factor = 1.0 / cfactor;
  82.     else
  83.         factor = asin(dist) / (dist * cfactor );
  84.     
  85.     xx = xx * factor; yy = yy * factor;
  86.     x = xx + xmid + myx; y = yy+ymid;
  87.     x = x % bmp->bm_w;
  88.     
  89.     return bmp->bm_data[y*320+x];
  90. }
  91.  
  92.  
  93. void circle_in_bitmap( grs_bitmap * bmp )
  94. {
  95.     int i, x, y;
  96.  
  97.     for ( i=0; i < 10; i++ )    {
  98.         for ( y=0; y<200; y++ )    {
  99.             for ( x=0; x<319; x++ )    {
  100.                  gr_setcolor(getpixel1(bmp,x,y));
  101.                 gr_pixel( x, y );
  102.             }
  103.         }
  104.         myx += 2;
  105.         getch();
  106.     }
  107. }
  108.  
  109. int descent_critical_error;
  110.  
  111.  
  112. main(int argc, char * argv[] )
  113. {
  114.     int x, y;
  115.     grs_bitmap bmp;
  116.     grs_bitmap bmp1;
  117.     ubyte palette[768];
  118.  
  119.     minit();
  120.  
  121.     printf( "Reading %s...\n", "john.pcx" );
  122.     gr_init( SM_320x200U );
  123.     bmp.bm_data = NULL;
  124.     pcx_read_bitmap( "big.pcx", &bmp, BM_LINEAR, palette );
  125.     gr_palette_load( palette );
  126.     key_init();
  127.  
  128.     x = y = 0;
  129.     while(!keyd_pressed[KEY_ESC]) {
  130.         y += keyd_pressed[KEY_UP] - keyd_pressed[KEY_DOWN];
  131.         x += keyd_pressed[KEY_LEFT] - keyd_pressed[KEY_RIGHT];
  132.         gr_bitmap( x, y, &bmp );
  133.     }
  134.  
  135. }
  136.  
  137.  
  138. 
  139.