Normalize Zero Vector?
#8
Maybe something like this?
I'm not sure how much of a performance impact an if statement and 3 divides will make.

	inline void Normalize(void)
	{
		double Len = Length();

		// If the length is zero, the vector cannot possibly have a direction.
		if (Len == 0.0d)
		{
			x = static_case<T>(0);
			y = static_case<T>(0);
			z = static_case<T>(0);
			return;
		}

		x = static_cast<T>(x / Len);
		y = static_cast<T>(y / Len);
		z = static_cast<T>(z / Len);
	}

I guess this also applies to Vector3::NormalizeCopy().
Reply
Thanks given by:


Messages In This Thread
Normalize Zero Vector? - by DiamondToaster - 07-17-2015, 08:34 AM
RE: Normalize Zero Vector? - by NiLSPACE - 07-17-2015, 07:09 PM
RE: Normalize Zero Vector? - by DiamondToaster - 07-18-2015, 01:38 AM
RE: Normalize Zero Vector? - by NiLSPACE - 07-18-2015, 02:31 AM
RE: Normalize Zero Vector? - by DiamondToaster - 07-19-2015, 05:40 AM
RE: Normalize Zero Vector? - by NiLSPACE - 07-19-2015, 06:18 AM
RE: Normalize Zero Vector? - by xoft - 07-19-2015, 06:25 AM
RE: Normalize Zero Vector? - by DiamondToaster - 07-20-2015, 03:03 AM
RE: Normalize Zero Vector? - by xoft - 07-20-2015, 04:15 AM



Users browsing this thread: 1 Guest(s)