/*
 * Fire.c
 * ~~~~~~
 * This function gets struct XY from graph.c and 
 * plots the object from given info
 * © Copyright 1991 Christian E. Hopps
*/


#include <exec/types.h>
#include <intuition/intuition.h>
#include <libraries/mathffp.h>
#include <graphics/gfx.h>
#include <graphics/rastport.h>
#define CLIPx1 xy->clip->clipx1
#define CLIPy1 xy->clip->clipy1
#define CLIPx2 xy->clip->clipx2
#define CLIPy2 xy->clip->clipy2
#define FX xy->x
#define FY xy->y
#define FXP SPFlt(xy->xp)
#define FYP SPFlt(xy->yp)
#define M SPDiv((SPSub(FX,FXP)),(SPSub(FY,FYP)))
#define B	SPSub(SPMul(M,FX),FY)
extern struct IntuitionBase 	*IntuitionBase;
extern struct GfxBase		*GfxBase;
extern struct MathBase		*MathBase;
extern struct MathTransBase	*MathTransBase;
extern struct RastPort		*rp;
extern struct Clip
{
	short clipx1;
	short clipy1;
	short clipx2;
	short clipy2;
};
extern struct XY
{
	float voy;
	float vox;
	float x;
	float y;
	short xp;
	short yp;
	BOOL clipped;
	int scale;
	struct Clip *clip;
};


void Fire(xy,rp)
struct XY *xy;
struct RastPort *rp;
{
	short x,y,b,m;
	m=0;
	b=0;
	x = SPFix(xy->x);			
	y = SPFix(xy->y);		/* Convert to short int */

	x = ( x + CLIPx1);		/* Set up X and Y in standard  */
	y = ( CLIPy2 - y);		/* form for graphing (offsets) */


	/* ENGLISH TRANSLATION
	~~~~~~~~~~~~~~~~~~~~~~ 
	If X is greater than leftedge OR Y is less than(above) top OR
	Y is greater than(below) bottom THEN go into clip mode 
	(ie. set clip bool) */		

	if((x > CLIPx2) | (y < CLIPy1) | (y > (CLIPy2+1))) 
	{
		xy->clipped = 1;
		xy->xp = x;
		xy->yp = y;
	} 
	else
	{
		/* ENGLISH TRANSLATION
		~~~~~~~~~~~~~~~~~~~~~~ 
		IF WE ARE IN CLIPPED MODE (ie. clip bool TRUE) AND
		prev. X is less than leftedge OR prev. Y is greater than(below) top
		OR prev. Y is less than(above) bottom then move to new location and
		reset clip bool */
 
		if(xy->clipped & ( xy->xp < CLIPx2 | xy->yp > CLIPy1 | xy->yp < CLIPy2 ))
		{
			xy->clipped =0;
			Move(rp,xy->xp,xy->yp);
		}
		/* Draw and store previous */ 

		Draw(rp,x,y);
		xy->xp = x;
		xy->yp = y;
	}
}