/*****************************************************************************
 * $Id: eng_class_math.hh,v 1.8 2006/07/23 00:44:37 devel Exp $
 * @file
 * @author	Jim E. Brooks  http://www.jimbrooks.org
 * @brief	Math functions.
 *//*
 * LEGAL:	COPYRIGHT (C) 2004 JIM E. BROOKS
 *          THIS SOURCE CODE IS RELEASED UNDER THE TERMS
 *          OF THE GNU GENERAL PUBLIC LICENSE (GPL).
 *****************************************************************************/

// -- included inside the Engine class --

public:

/*****************************************************************************
 * Quickly calculate the distance^2 between the eye and object.
 * For speed, skips calculating the square root of the distance.
 *****************************************************************************/
inline fp
DistanceEyeObjectSkipSqrt( const WorldVertex* v )
{
	fp xd = v->x + mEye.mCm[Ox]; // yes, add is written (eye[Oxyz] are negative)
	fp yd = v->y + mEye.mCm[Oy];
	fp zd = v->z + mEye.mCm[Oz];
	return xd*xd + yd*yd + zd*zd;
}

/*****************************************************************************
 * Faster variants of TransformVertex() (see gfx/gfx/src/gfx_math.hh).
 *****************************************************************************/
inline void
TransformVertex( EyeVertex& v2, const WorldVertex& v )
{
	fp x = v.x + mEye.mCm[Ox];
	fp y = v.y + mEye.mCm[Oy];
	fp z = v.z + mEye.mCm[Oz];
	v2.x = x * mEye.mCm[Xx] + y * mEye.mCm[Xy] + z * mEye.mCm[Xz];
	v2.y = x * mEye.mCm[Yx] + y * mEye.mCm[Yy] + z * mEye.mCm[Yz];
	v2.z = x * mEye.mCm[Zx] + y * mEye.mCm[Zy] + z * mEye.mCm[Zz];
}
inline void
TransformVertex( EyeVertex* v2, const Position& pos )
{
	fp x = pos.x + mEye.mCm[Ox];
	fp y = pos.y + mEye.mCm[Oy];
	fp z = pos.z + mEye.mCm[Oz];
	v2->x = x * mEye.mCm[Xx] + y * mEye.mCm[Xy] + z * mEye.mCm[Xz];
	v2->y = x * mEye.mCm[Yx] + y * mEye.mCm[Yy] + z * mEye.mCm[Yz];
	v2->z = x * mEye.mCm[Zx] + y * mEye.mCm[Zy] + z * mEye.mCm[Zz];
}

/*****************************************************************************
 * Useful for testing if an object is facing by calculating only eye Z.
 *****************************************************************************/
inline fp
TransformZ( const WorldVertex& v )
{
	fp x = v.x + mEye.mCm[Ox];
	fp y = v.y + mEye.mCm[Oy];
	fp z = v.z + mEye.mCm[Oz];
	return x * mEye.mCm[Zx] + y * mEye.mCm[Zy] + z * mEye.mCm[Zz];
}

private:
