Raised This Month: $ Target: $400
 0% 

Trace Hull, I just don't get it


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
h3bus
AlliedModders Donor
Join Date: Nov 2013
Old 02-25-2014 , 03:26   Trace Hull, I just don't get it
Reply With Quote #1

Hi there,

I'm pretty lost with TR_TraceHull.
I guessed it could find intersection between a box and entities.

But then:
Code:
/**
 * Starts up a new trace hull using a global trace result.
 *
 * @param pos			Starting position of the ray.
 * @param vec			Ending position of the ray.
 * @param mins			Hull minimum size.
 * @param maxs			Hull maximum size.
 * @param flags			Trace flags.
 * @noreturn
 */
native TR_TraceHull(const Float:pos[3],
					const Float:vec[3],
					const Float:mins[3],
					const Float:maxs[3],
					flags);
I thought I could use mins and maxs to define that box, but what would be pos and vec arguments then?
I just don't get it.

Also, if TR_TraceHull DidHit, What will fetch TR_GetEndPosition, TR_GetPlaneNormal and other hit functions? The nearest hit?

Any pointers would be great!
h3bus is offline
MasterOfTheXP
Veteran Member
Join Date: Aug 2011
Location: Cloudbank
Old 02-25-2014 , 10:56   Re: Trace Hull, I just don't get it
Reply With Quote #2

This code snippet (IsPlayerStuck) has the "origin point" of the box as both of the first two arguments, and it works. Just remember that mins and maxs are the size variables for the box, not the location of the box. (Although if you set pos and vec to Float:{0.0, 0.0, 0.0}, then maybe they could be...)
__________________
Plugins / My Steam / TF2 Sandbox (plugin beta testing!)
MasterOfTheXP is offline
h3bus
AlliedModders Donor
Join Date: Nov 2013
Old 02-25-2014 , 18:43   Re: Trace Hull, I just don't get it
Reply With Quote #3

Well it seems that if pos and vec are different, TraceHull will slide the defined box (by min and max relative to sliding point). Thus if pos = vec, TraceHull will detect hits in the box defined by the two corners pos + min and pos + max.

As for my second question, it seems that when TR_DidHit, TR_GetEndPosition gives the nearest hit point to ppos (TR_GetPlaneNormal works too).

This is pretty darn powerfull!
h3bus is offline
MikeJS
Senior Member
Join Date: Nov 2008
Old 02-27-2014 , 07:37   Re: Trace Hull, I just don't get it
Reply With Quote #4

(yay i rambled again)

Let's start with TR_TraceRay:

Code:
native TR_TraceRay(const Float:pos[3],                    const Float:vec[3],                    flags,                    RayType:rtype);

pos is the start point of the ray and vec is either the end point of the ray, or the direction the ray is facing.

This function then shoots the ray through the world and intersects it with all of the world geometry, and entities depending on the value of flags. Note that this is exactly how bullets behave!

TR_DidHit will return true if and only if the ray actually intersected with anything. If you're using rtype = RayType_Infinite (i.e. vec is the direction of the ray), then for any reasonable ray it will eventually intersect with some world geometry. If you're using rtype = RayType_EndPoint, then there are situations where this can return false. An example would be trying to pick something up: the game might fire a ray ahead of you a short distance and see if it intersects with any entities you can carry - TR_DidHit would return false if you're not looking at anything.

If TR_DidHit was true, TR_GetEndPosition will return the point of intersection closest to the start point (pos). Otherwise it probably just gives you garbage.

TR_GetPlaneNormal is slightly more tricky: it gives you a vector normal to the surface at the closest point of intersection. I guess a simpler explanation is that if you stood on whatever object you hit (this might be a wall, ceiling, explosive barrel, etc), GetPlaneNormal gives you the "up" direction at that point.


Now TR_TraceHull:

Code:
native TR_TraceHull(const Float:pos[3],                     const Float:vec[3],                     const Float:mins[3],                     const Float:maxs[3],                     flags);

pos is the start point of the origin (not necessarily the centre) of your axis aligned bounding box (AABB), vec is the end point. (always an end point this time)

An axis aligned bounding box is one which is lined up with the axes of the coordinate system and can't rotate. An example would be player bounding boxes. Also see: https://developer.valvesoftware.com/wiki/Bounding_box

mins and maxs are the extents of your box from its origin. If you had a box with side length 32, you could have:

mins = { -16, -16, -16 } maxs = { 16, 16, 16 } box centred on the origin
mins = { -16, -16, 0 } maxs = { 16, 16, 32 } box is sitting on top of the origin
mins = { 100, 100, 100 } maxs = { 132, 132, 132 } box you are drunk

...and so on.

TraceHull behaves similarly to TraceRay. It sweeps the box (without rotating it!) through the world, and tests if any part of it intersects any other object at any point in time.

TR_DidHit and TR_GetPlaneNormal are the same as before. TR_GetEndPosition (I think, please correct me this is wrong!) returns the position of the origin when the box hit something.

There are some special cases to observe: if pos and vec are the same, then we are just seeing if anything is intersecting with the box where it is. If mins and maxs are { 0, 0, 0 }, we are just tracing a ray!

Another useful function in the TR_* family is TR_GetFraction. If you are tracing a segment (ie TraceHull or RayType_EndPoint) the result of this will be between 0 and 1 and be the "fraction" of how far along the ray you were when you collided. ie:

let d = vec - pos
end = vec + d * fraction

With infinite rays, GetFraction gives you the number of times you needed to travel vec distance to reach the endpoint. Note if vec is normalised, this is just the distance travelled.


I hope this helps and do let me know if anything needs clarifying.
__________________
MikeJS is offline
h3bus
AlliedModders Donor
Join Date: Nov 2013
Old 03-02-2014 , 09:39   Re: Trace Hull, I just don't get it
Reply With Quote #5

On TraceHull:
Quote:
TR_DidHit and TR_GetPlaneNormal are the same as before. TR_GetEndPosition (I think, please correct me this is wrong!) returns the position of the origin when the box hit something
You are right and I misunderstood that.

From my trials:
TR_DidHit return the center position at the moment of hit. Thus if pos == vec, it will always return pos in case of hit, not matter where the hit occured in the hull.
TR_GetPlaneNormal Returns {0, 0, 0}.

I'm trying to get the real hit position in the hull. I'm quite sutck there.
Going to start a new thread on that maybe.

Last edited by h3bus; 03-02-2014 at 09:39.
h3bus is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 22:19.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode