#ifndef lint
static char *sccsid = "@(#)addstuff.c	1.2 (UKC) 9/12/87";
#endif  lint
/*
 *	Stuff to create lists of lines to clip and plot,
 *	and of obscuring triangles. Called by genpoly.
 */
#include "types.h"

extern char *malloc();

/*
 *	add lines to the end of the list to preserve continuity of drawing
 */
addline(xP, yP, zP, xQ, yQ, zQ)
double xP, yP, zP, xQ, yQ, zQ;
{
	/* pointer to null pointer in last cell in list */
	static linelist_t **lastptr = &linelist;
	linelist_t *newline;

	newline = (linelist_t *) malloc(sizeof(linelist_t));
	if (newline == NULLLINE) {
		error("Out of memory in newline");
		exit(1);
	}

	newline->P.x = xP; newline->P.y = yP; newline->P.z = zP;
	newline->Q.x = xQ; newline->Q.y = yQ; newline->Q.z = zQ;

	/* perform viewing transformations */
	dotrans(&newline->P);
	dotrans(&newline->Q);

	newline->link = NULLLINE;
	*lastptr = newline; lastptr = &(newline->link);
}

addtri(xA, yA, zA, xB, yB, zB, xC, yC, zC)
double xA, yA, zA, xB, yB, zB, xC, yC, zC;
{
	trilist_t *newtri;

	newtri = (trilist_t *) malloc(sizeof(trilist_t));
	if (newtri == NULLTRI) {
		error("Out of memory in newtri");
		exit(1);
	}

	newtri->A.x = xA; newtri->A.y = yA; newtri->A.z = zA;
	newtri->B.x = xB; newtri->B.y = yB; newtri->B.z = zB;
	newtri->C.x = xC; newtri->C.y = yC; newtri->C.z = zC;

	/* perform viewing transformations */
	dotrans(&newtri->A);
	dotrans(&newtri->B);
	dotrans(&newtri->C);

	newtri->link = trilist; trilist = newtri;
}
