ftp.nice.ch/pub/next/graphics/3d/Raytracers.N.bs.tar.gz#/raytracers/ohta/src/dindex.c

This is dindex.c in view mode; [Download] [Up]

#include "ray.h"

dindex(v)
struct vector v;
{double x,y,z,ax,ay,az;
	x=v.x;
	y=v.y;
	z=v.z;
	ax=(x>0)?x:-x;
	ay=(y>0)?y:-y;
	az=(z>0)?z:-z;
	if(ax>=ay&&ax>=az)
		if(x>0)
			return index2(y,z,ax);
		else
			return index2(y,z,ax)+(NRECTS*NRECTS);
	else if(ay>=ax&&ay>=az)
		if(y>0)
			return index2(z,x,ay)+(2*NRECTS*NRECTS);
		else
			return index2(z,x,ay)+(3*NRECTS*NRECTS);
	else
		if(z>0)
			return index2(x,y,az)+(4*NRECTS*NRECTS);
		else
			return index2(x,y,az)+(5*NRECTS*NRECTS);
}

index2(x,y,r)
double r,x,y;
{register int m,n;
	m=(r+x)/(r*2)*NRECTS;
	if(m==NRECTS)
		m=NRECTS-1;
	n=(r+y)/(r*2)*NRECTS;
	if(n==NRECTS)
		n=NRECTS-1;
	return n*NRECTS+m;
}

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.