View Single Post
Please help to make TraceHull function which can takes mins & maxs
Old
  (#1)
Immortal_BLG
Member
 
Status: Offline
Posts: 171
Join Date: Nov 2007
Location: Russian Federation
Warning Please help to make TraceHull function which can takes mins & maxs - 25-08-2009

Please help to write a TraceHull function that takes mins and maxs arguments. I already have written it, but precisely I do not know correctly, or not.
Code:
inline void TraceHull (const Math::Vector3D &source, const Math::Vector3D &destination, const Math::Vector2D &mins, const Math::Vector2D &maxs, const HalfLifeEngine::SDK::Constants::TraceIgnore_t traceIgnore, HalfLifeEngine::SDK::Classes::Edict *const entityToSkip, HalfLifeEngine::SDK::Structures::TraceResult_t &traceResult)
{
	HalfLifeEngine::SDK::Structures::TraceResult_t tempTraceResult;
	float fraction = 1.0f;
	Math::Vector2D offset;
	bool isStartSolid = false, isAllSolid = false;

	for (offset.x = mins.x; offset.x < maxs.x; ++offset.x)
		for (offset.y = mins.y; offset.y < maxs.y; ++offset.y)
		{
			HalfLifeEngine::Globals::g_halfLifeEngine->TraceLine (source + offset, destination + offset, traceIgnore, entityToSkip, tempTraceResult);

			if (tempTraceResult.isStartSolid)
				isStartSolid = true;

			if (tempTraceResult.isAllSolid)
				isAllSolid = true;

			if (tempTraceResult.fraction < fraction)
			{
				traceResult = tempTraceResult;
				fraction = tempTraceResult.fraction;
			}
		}

	traceResult.isStartSolid = isStartSolid;
	traceResult.isAllSolid = isAllSolid;
}
Maybe there no needed to add offset for start of TraceLine() function???....

Please help.

I also wrote it for given 3D mins & maxs, but it's tooooooo SLOW!!! ]:{D
Code:
inline void TraceHull (const Math::Vector3D &source, const Math::Vector3D &destination, const Math::Vector3D &mins, const Math::Vector3D &maxs, const HalfLifeEngine::SDK::Constants::TraceIgnore_t traceIgnore, HalfLifeEngine::SDK::Classes::Edict *const entityToSkip, HalfLifeEngine::SDK::Structures::TraceResult_t &traceResult)
{
	HalfLifeEngine::SDK::Structures::TraceResult_t tempTraceResult;
	float fraction = 1.0f;
	Math::Vector3D offset;
	bool isStartSolid = false, isAllSolid = false;

	for (offset.x = mins.x; offset.x < maxs.x; ++offset.x)
		for (offset.y = mins.y; offset.y < maxs.y; ++offset.y)
			for (offset.z = mins.z; offset.z < maxs.z; ++offset.z)
			{
				HalfLifeEngine::Globals::g_halfLifeEngine->TraceLine (source + offset, destination + offset, traceIgnore, entityToSkip, tempTraceResult);

				if (tempTraceResult.isStartSolid)
					isStartSolid = true;

				if (tempTraceResult.isAllSolid)
					isAllSolid = true;

				if (tempTraceResult.fraction < fraction)
				{
					traceResult = tempTraceResult;
					fraction = tempTraceResult.fraction;
				}
			}

	traceResult.isStartSolid = isStartSolid;
	traceResult.isAllSolid = isAllSolid;
}
P.S as always sorry for bad english.

Last edited by Immortal_BLG; 26-08-2009 at 05:02..
  
Reply With Quote