Пример #1
0
VOID	NormalizeEnv(MATRIX normMat)
	{
	View.eye[3] = 1.0;
	VecMatMult(View.eye, normMat, View.eye);

	View.coi[3] = 1.0;
	VecMatMult(View.coi, normMat, View.coi);

	TransformLights(normMat);
	}
Пример #2
0
VOID	SphTransform(OBJECT *po, MATRIX xtrans, MATRIX xinvT)
	{
	INT	i;
	INT	numelems;		/* Number of object elements.	  */
	REAL	new_rad;
	SPHERE	*ps;			/* Ptr to sphere data.		     */
	ELEMENT *pe;			/* Ptr to sphere element.	     */
	POINT	surf_point;		/* Point on surface.		     */
	POINT	center_point;		/* Center_point.		     */
	POINT	rad_vector;		/* Radius vector.		     */

	pe	 = po->pelem;
	numelems = po->numelements;

	for (i = 0; i < numelems; i++)
		{
		ps = (SPHERE *)pe->data;

		/* See if radius has changed with a scale. */

		surf_point[0]	= ps->center[0] + ps->rad;
		surf_point[1]	= ps->center[1];
		surf_point[2]	= ps->center[2];
		surf_point[3]	= 1.0;

		center_point[0] = ps->center[0];
		center_point[1] = ps->center[1];
		center_point[2] = ps->center[2];
		center_point[3] = 1.0;

		/* Transform center point. */

		VecMatMult(center_point, xtrans, center_point);
		VecMatMult(surf_point, xtrans, surf_point);

		/* Find radius. */

		VecSub(rad_vector, surf_point, center_point);
		VecCopy(ps->center, center_point);

		new_rad = VecLen(rad_vector);

		if (new_rad != ps->rad)
			{
			ps->rad  = new_rad;
			ps->rad2 = ps->rad * ps->rad;
			}

		pe++;
		}
	}
Пример #3
0
VOID	PolyDataNormalize(OBJECT *po, MATRIX normMat)
	{
	INT	i;
	POINT	coord;
	VEC3	*pv;			/* Ptr to vertex list.		     */
	POLY	*pp;			/* Ptr to polygon data. 	     */
	ELEMENT *pe;			/* Ptr to polygon element.	     */


	/* Normalize bounding box. */

	pe = po->pelem;
	NormalizeBoundBox(&po->bv, normMat);


	/* Normalize vertex list. */

	pp = (POLY *)pe->data;
	pv = pp->vptr;

	coord[0] = (*pv)[0];
	coord[1] = (*pv)[1];
	coord[2] = (*pv)[2];
	coord[3] = 1.0;


	/* Transform coordinate by xform matrix. */

	while (coord[0] != HUGE_REAL && coord[1] != HUGE_REAL && coord[2] != HUGE_REAL)
		{
		VecMatMult(coord, normMat, coord);

		(*pv)[0] = coord[0];
		(*pv)[1] = coord[1];
		(*pv)[2] = coord[2];

		pv++;

		coord[0] = (*pv)[0];
		coord[1] = (*pv)[1];
		coord[2] = (*pv)[2];
		coord[3] = 1.0;
		}


	/* Normalize bounding boxes of object elements. */

	for (i = 0; i < po->numelements; i++)
		{
		pp = (POLY *)pe->data;
		NormalizeBoundBox(&pe->bv, normMat);

		/* Find new d of plane equation. */

		pv    =   pp->vptr + (*(pp->vindex));
		pp->d = -(pp->norm[0]*(*pv)[0] + pp->norm[1]*(*pv)[1] + pp->norm[2]*(*pv)[2]);

		pe++;
		}
	}
Пример #4
0
VOID	SphDataNormalize(OBJECT *po, MATRIX normMat)
	{
	INT	i;
	SPHERE	*ps;			/* Ptr to sphere data.		     */
	ELEMENT *pe;			/* Ptr to sphere element.	     */
	POINT	surf_point;		/* Point on surface.		     */
	POINT	center_point;		/* Center point.		     */
	POINT	rad_vector;		/* Radius vector.		     */

	NormalizeBoundBox(&po->bv, normMat);

	pe = po->pelem;

	for (i = 0; i < po->numelements; i++)
		{
		ps = (SPHERE *)pe->data;

		NormalizeBoundBox(&pe->bv, normMat);

		surf_point[0]	= ps->center[0] + ps->rad;
		surf_point[1]	= ps->center[1];
		surf_point[2]	= ps->center[2];
		surf_point[3]	= 1.0;

		center_point[0] = ps->center[0];
		center_point[1] = ps->center[1];
		center_point[2] = ps->center[2];
		center_point[3] = 1.0;


		/* Transform center point. */

		VecMatMult(center_point, normMat, center_point);
		VecMatMult(surf_point, normMat, surf_point);


		/* Find new radius. */

		VecSub(rad_vector, surf_point, center_point);
		VecCopy(ps->center, center_point);

		ps->rad  = VecLen(rad_vector);
		ps->rad2 = ps->rad * ps->rad;

		pe++;
		}
	}
Пример #5
0
VOID	TransformLights(MATRIX m)
	{
	INT	i;
	LIGHT	*lp;

	lp = lights;
	for (i = 0; i < nlights; i++)
		{
		VecMatMult(lp->pos, m, lp->pos);
		lp = lp->next;
		}
	}
Пример #6
0
VOID	PolyTransform(OBJECT *po, MATRIX xtrans, MATRIX xinvT)
	{
	INT	i;			/* Indices.			     */
	INT	numelems;		/* # of elements.		     */
	VEC3	*vptr, *vp;		/* Vertex list pointers.	     */
	VEC4	norm, coord;		/* Transform 4 vectors. 	     */
	POLY	*pp;			/* Ptr to polygon data. 	     */
	ELEMENT *pe;			/* Ptr to polygon element.	     */


	pe = po->pelem;
	numelems = po->numelements;

	/* Get vertex list address and transform vertices. */

	pp   = (POLY *)pe->data;
	vptr = pp->vptr;

	coord[0] = (*vptr)[0];
	coord[1] = (*vptr)[1];
	coord[2] = (*vptr)[2];
	coord[3] = 1.0;

	while (coord[0] != HUGE_REAL && coord[1] != HUGE_REAL && coord[2] != HUGE_REAL)
		{
		/* Transform coordinate by xform matrix. */

		VecMatMult(coord, xtrans, coord);

		(*vptr)[0] = coord[0];
		(*vptr)[1] = coord[1];
		(*vptr)[2] = coord[2];

		vptr++;

		coord[0] = (*vptr)[0];
		coord[1] = (*vptr)[1];
		coord[2] = (*vptr)[2];
		coord[3] = 1.0;
		}


	/* Transform polygon list. */

	for (i = 0; i < numelems; i++)
		{
		pp = (POLY *)pe->data;

		/* Transform face normal by view matrix inverse. */

		norm[0] = pp->norm[0];
		norm[1] = pp->norm[1];
		norm[2] = pp->norm[2];
		norm[3] = 0.0;

		VecMatMult(norm, xinvT, norm);
		VecNorm(norm);

		pp->norm[0] = norm[0];
		pp->norm[1] = norm[1];
		pp->norm[2] = norm[2];


		/* Calculate plane equation variable d. */

		vp = pp->vptr + *(pp->vindex);
		pp->d = -(pp->norm[0]*(*vp)[0] + pp->norm[1]*(*vp)[1] + pp->norm[2]*(*vp)[2]);


		/* Set best axis projection. */

		norm[0] = ABS(pp->norm[0]);
		norm[1] = ABS(pp->norm[1]);
		norm[2] = ABS(pp->norm[2]);

		if (norm[0] >= norm[1] && norm[0] >= norm[2])
			pp->axis_proj = X_AXIS;
		else
		if (norm[1] >= norm[0] && norm[1] >= norm[2])
			pp->axis_proj = Y_AXIS;
		else
			pp->axis_proj = Z_AXIS;

		pe++;
		}
	}
Пример #7
0
VOID	TransformViewRay(POINT tray)
	{
	VecMatMult(tray, View.vtransInv, tray);
	}