home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 501.lha / ProjectileMotion_v1.01 / src / fire.c next >
Encoding:
C/C++ Source or Header  |  1991-04-09  |  2.0 KB  |  97 lines

  1. /*
  2.  * Fire.c
  3.  * ~~~~~~
  4.  * This function gets struct XY from graph.c and 
  5.  * plots the object from given info
  6.  * © Copyright 1991 Christian E. Hopps
  7. */
  8.  
  9.  
  10. #include <exec/types.h>
  11. #include <intuition/intuition.h>
  12. #include <libraries/mathffp.h>
  13. #include <graphics/gfx.h>
  14. #include <graphics/rastport.h>
  15. #define CLIPx1 xy->clip->clipx1
  16. #define CLIPy1 xy->clip->clipy1
  17. #define CLIPx2 xy->clip->clipx2
  18. #define CLIPy2 xy->clip->clipy2
  19. #define FX xy->x
  20. #define FY xy->y
  21. #define FXP SPFlt(xy->xp)
  22. #define FYP SPFlt(xy->yp)
  23. #define M SPDiv((SPSub(FX,FXP)),(SPSub(FY,FYP)))
  24. #define B    SPSub(SPMul(M,FX),FY)
  25. extern struct IntuitionBase     *IntuitionBase;
  26. extern struct GfxBase        *GfxBase;
  27. extern struct MathBase        *MathBase;
  28. extern struct MathTransBase    *MathTransBase;
  29. extern struct RastPort        *rp;
  30. extern struct Clip
  31. {
  32.     short clipx1;
  33.     short clipy1;
  34.     short clipx2;
  35.     short clipy2;
  36. };
  37. extern struct XY
  38. {
  39.     float voy;
  40.     float vox;
  41.     float x;
  42.     float y;
  43.     short xp;
  44.     short yp;
  45.     BOOL clipped;
  46.     int scale;
  47.     struct Clip *clip;
  48. };
  49.  
  50.  
  51. void Fire(xy,rp)
  52. struct XY *xy;
  53. struct RastPort *rp;
  54. {
  55.     short x,y,b,m;
  56.     m=0;
  57.     b=0;
  58.     x = SPFix(xy->x);            
  59.     y = SPFix(xy->y);        /* Convert to short int */
  60.  
  61.     x = ( x + CLIPx1);        /* Set up X and Y in standard  */
  62.     y = ( CLIPy2 - y);        /* form for graphing (offsets) */
  63.  
  64.  
  65.     /* ENGLISH TRANSLATION
  66.     ~~~~~~~~~~~~~~~~~~~~~~ 
  67.     If X is greater than leftedge OR Y is less than(above) top OR
  68.     Y is greater than(below) bottom THEN go into clip mode 
  69.     (ie. set clip bool) */        
  70.  
  71.     if((x > CLIPx2) | (y < CLIPy1) | (y > (CLIPy2+1))) 
  72.     {
  73.         xy->clipped = 1;
  74.         xy->xp = x;
  75.         xy->yp = y;
  76.     } 
  77.     else
  78.     {
  79.         /* ENGLISH TRANSLATION
  80.         ~~~~~~~~~~~~~~~~~~~~~~ 
  81.         IF WE ARE IN CLIPPED MODE (ie. clip bool TRUE) AND
  82.         prev. X is less than leftedge OR prev. Y is greater than(below) top
  83.         OR prev. Y is less than(above) bottom then move to new location and
  84.         reset clip bool */
  85.  
  86.         if(xy->clipped & ( xy->xp < CLIPx2 | xy->yp > CLIPy1 | xy->yp < CLIPy2 ))
  87.         {
  88.             xy->clipped =0;
  89.             Move(rp,xy->xp,xy->yp);
  90.         }
  91.         /* Draw and store previous */ 
  92.  
  93.         Draw(rp,x,y);
  94.         xy->xp = x;
  95.         xy->yp = y;
  96.     }
  97. }