Raised This Month: $ Target: $400
 0% 

Box collision/distance functions


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Kraugh
Senior Member
Join Date: Jan 2006
Location: barrington, ri
Old 03-02-2006 , 01:49   Box collision/distance functions
Reply With Quote #1

original code is from the HLSDK (UTIL_EntitiesInBox). you can use these functions to determine if two entities are touching each other. i'm not going to explain what you can use this for.

functions are as follows:

find_ent_in_box ( StartEntity, Float:mins[3], Float:maxs[3] )
Code:
// PARAMETERS
// -
// StartEntity:	which entity to start searching from
// mins:	the absmin of your collision box
// maxs:	the absmax of your collision box
//
//
// RETURN VALUES
// -
// returns the index of the first entity found.
// if no entities were found this returns 0.
find_box_list ( Float:mins[3], Float:maxs[3], entlist[], maxents, param[] = "", type = 0 )
Code:
// PARAMETERS
// -
// mins:	the absmin of your collision box
// maxs:	the absmax of your collision box
// entlist:	array to store entities found in
// maxents:	maximum amount of entities to store
// param:	(optional, default "") the string to compare collisions with (see below). if blank, ignored.
// type:	(optional, default 0)  0: find by classname, 1: find by target, 2: find by targetname
//
//
// RETURN VALUES
// -
// returns the amount of entities saved into entlist
check_collision ( entity1, entity2 )
Code:
// PARAMETERS
// -
// entity1:	the first entity to compare
// entity2:	the second entity to compare
//
//
// RETURN VALUES
// -
// returns 1 if the two entities collide, otherwise 0.
check_collision_ext ( StartEntity, entity, param[], type = 0 )
Code:
// PARAMETERS
// -
// StartEntity:	which entity to start searching from
// entity:	the entity of which to check collisions for
// param:	the string to compare collisions with (see below)
// type:	(optional, default 0) 0: find by classname, 1: find by target, 2: find by targetname
//
//
// RETURN VALUES
// -
// returns the index of the first colliding entity found with the matching field.
// if no valid entities were found this returns 0.
Float: get_box_distance ( Float:mins1[3], Float:maxs1[3], Float:mins2[3], Float:maxs2[3] )
Code:
*    PARAMETERS:
*        mins1 - mins of the first  box, Float:{min_x1, min_y1, min_z1}
*        maxs1 - maxs of the first  box, Float:{max_x1, max_y1, max_z1}
*        mins2 - mins of the second box, Float:{min_x2, min_y2, min_z2}
*        maxs2 - maxs of the second box, Float:{max_x2, max_y2, max_z2}
*
*    RETURN RESULT:
*        Float value of distance between first and second box.
*        If result is 0.0 then boxes are colliding/touching.
requires engine. find_ent_in_box as well as find_box_list is not tested (sorry) but i see no reason why they shouldn't work. check_collision_ext (and thus check_collision) works marvelously. this does work if two entities are touching (ie: if you walk up to a hostage), aka they do not have to be actually overlapping.

feel free to make suggestions. you don't have to use the include, you can just copy out the functions. check_collision_ext requires check_collision to work.

get_box_distance written by VEN.
Attached Files
File Type: inc box.inc (6.3 KB, 268 views)
__________________
"You can not restrain a fool from speaking, but nothing obliges you to listen."
Kraugh is offline
Send a message via AIM to Kraugh
VEN
Veteran Member
Join Date: Jan 2005
Old 03-02-2006 , 14:06  
Reply With Quote #2

Gj, wanted to see that.

Is there a way to get maxEntities with fakemeta?
Also not sure but isn't it should be "<= maxEntities"?
Or it counts world (0) either?

Suggestion:
To not confuse the coders change StartEntity to StartSearchAfter
StartSearchAfter == StartEntity - 1
Since fakemeta and engine find_ent_* functions uses that method.


EDIT:

Now i see why this method seems so simple to me.
Because actually i wanted not that exactly.

A while ago i tried to create get_box_distance(Float:mins1[3], Float:maxs1[3], Float:mins2[3], Float:maxs2[3]) function (minimal possible distance between two points of different boxes).

In my opinion this function would be even more useful because it may indicate not only if two boxes are touching but even it's distance.
Also i think that such function would be more complicated.

At the current time i can find distance between box corners but this isn't always actual (minimal) box dsistance.
VEN is offline
knekter
Senior Member
Join Date: Mar 2004
Location: PA
Old 03-02-2006 , 14:41  
Reply With Quote #3

For those who don't want to manually tab things ect. (My web browser opens it as 1 line :/)
Attached Files
File Type: inc box.inc (3.0 KB, 197 views)
__________________
More updates for Matrix Mod!
knekter is offline
Send a message via AIM to knekter Send a message via MSN to knekter
Kraugh
Senior Member
Join Date: Jan 2006
Location: barrington, ri
Old 03-02-2006 , 16:42  
Reply With Quote #4

Quote:
Originally Posted by VEN
Is there a way to get maxEntities with fakemeta?
i don't think so. why?

Quote:
Originally Posted by VEN
Also not sure but isn't it should be "<= maxEntities"?
maybe. but this is how the HLSDK does it.

Quote:
Originally Posted by VEN
Suggestion:
To not confuse the coders change StartEntity to StartSearchAfter
StartSearchAfter == StartEntity - 1
Since fakemeta and engine find_ent_* functions uses that method.
i got the name StartEntity from the wiki's find_ent_in_sphere definition. i see no reason to start searching one entity below what it was told to search at.

Quote:
Originally Posted by knekter
For those who don't want to manually tab things ect. (My web browser opens it as 1 line :/)
just download the file instead of viewing it from the web. also, i don't understand why you went through it and changed all of the spacing?

[edit]
i am renaming get_collision_by_class to get_collision_ext and allowing you to specify whether to search by classname, target, or targetname like find_ent_by_owner. i am also adding find_box_list which functions nearly like find_sphere_class (aka, like the original UTIL_EntitiesInBox). i just need to test these.
__________________
"You can not restrain a fool from speaking, but nothing obliges you to listen."
Kraugh is offline
Send a message via AIM to Kraugh
VEN
Veteran Member
Join Date: Jan 2005
Old 03-03-2006 , 04:54  
Reply With Quote #5

Quote:
i don't think so. why?
Wanted to port.
Quote:
maybe. but this is how the HLSDK does it
That weird. I think they count it from zero (world).

Quote:
i got the name StartEntity from the wiki's find_ent_in_sphere definition
Then wiki is incorrect. If you mean amxx wiki (not func wiki) i'll fix it later. If it's func wiki it needs to be fixed either.
Quote:
i see no reason to start searching one entity below what it was told to search at
I agree BUT as i said before ALL FAKEMETA/ENGINE search entity function use StartSearchAfter method.
I.E. if you would specify "1" it would start search from "2".
I just tested find_ent_in_sphere and got the same thing.
I know that weird but not me created that functions.
And as i said before the only reason of my suggestion was to not confuse the coders.
Anyway it's just a "non-obligate suggestion".
VEN is offline
VEN
Veteran Member
Join Date: Jan 2005
Old 03-03-2006 , 04:56  
Reply With Quote #6

Finally i done get_box_distance function.
Though it's untested yet but i think it should work correctly.
Feel free to test it or leave suggestions / comments.

Code:
/* *   DESCRIPTION: *       Function returns distance between two boxes, i.e. their two closest points. *       As result feature function indicates if two boxes are colliding/touching. *       No modules required. * *   PARAMETERS: *       mins1 - mins of the first  box, Float:{min_x1, min_y1, min_z1} *       maxs1 - maxs of the first  box, Float:{max_x1, max_y1, max_z1} *       mins2 - mins of the second box, Float:{min_x2, min_y2, min_z2} *       maxs2 - maxs of the second box, Float:{max_x2, max_y2, max_z2} * *   RETURN RESULT: *       Float value of distance between first and second box. *       If result is 0.0 then boxes are colliding/touching. */ stock Float:get_box_distance(Float:mins1[3], Float:maxs1[3], Float:mins2[3], Float:maxs2[3]) {     new Float:distance[3], Float:min1, Float:max1, Float:min2, Float:max2     for (new i = 0; i < 3; ++i) {         min1 = mins1[i]         max2 = maxs2[i]         if (min1 > max2) {             distance[i] = min1 - max2             continue         }         min2 = mins2[i]         max1 = maxs1[i]         if (min2 > max1)             distance[i] = min2 - max1     }     new Float:dist0 = distance[0], Float:dist1 = distance[1], Float:dist2 = distance[2]     return floatsqroot(dist0 * dist0 + dist1 * dist1 + dist2 * dist2) }

Kraugh:
Probably it's better to add word "distance" to the topic title.
I think better keep box functions in the one topic.
Also if you wish you can:
- merge our functions
- create more distance functions like get_box_entity_distance, etc
VEN is offline
Kraugh
Senior Member
Join Date: Jan 2006
Location: barrington, ri
Old 03-03-2006 , 15:10  
Reply With Quote #7

Quote:
Originally Posted by VEN
Wanted to port.
fakemeta is much less efficient than engine. no need to port.

Quote:
Originally Posted by VEN
Then wiki is incorrect.
i checked and the include uses "start_from_ent" instead of "StartEntity". regardless, the actual name of the variable doesn't matter.

Quote:
Originally Posted by VEN
I agree BUT as i said before ALL FAKEMETA/ENGINE search entity function use StartSearchAfter method.
I.E. if you would specify "1" it would start search from "2".
in your last post you told me they started at index - 1, not index + 1. index + 1 actually makes sense. this won't function as intended without it. thanks.
__________________
"You can not restrain a fool from speaking, but nothing obliges you to listen."
Kraugh is offline
Send a message via AIM to Kraugh
Zenith77
Veteran Member
Join Date: Aug 2005
Old 03-03-2006 , 15:16  
Reply With Quote #8

Quote:
Originally Posted by Kraugh
Quote:
Originally Posted by VEN
Wanted to port.
fakemeta is much less efficient than engine. no need to port.


You're joking yourself right ?
__________________
Quote:
Originally Posted by phorelyph View Post
your retatred
Zenith77 is offline
Kraugh
Senior Member
Join Date: Jan 2006
Location: barrington, ri
Old 03-03-2006 , 15:26  
Reply With Quote #9

no.

[edit]
expanding on that: the only thing fakemeta does better than engine is the forwards. no matter what, engine will hook into server_frame, client_PreThink, client_PostThink, and any others there might be, whether or not you intend to use them.

other than that, engine is much better. http://forums.alliedmods.net/showthr...t=11567&page=2

the only reason to use fakemeta is for pdata and calls/hooks you couldn't otherwise access.
__________________
"You can not restrain a fool from speaking, but nothing obliges you to listen."
Kraugh is offline
Send a message via AIM to Kraugh
knekter
Senior Member
Join Date: Mar 2004
Location: PA
Old 03-03-2006 , 16:44  
Reply With Quote #10

Quote:
Originally Posted by Kraugh
no.

[edit]
expanding on that: the only thing fakemeta does better than engine is the forwards. no matter what, engine will hook into server_frame, client_PreThink, client_PostThink, and any others there might be, whether or not you intend to use them.

other than that, engine is much better. http://forums.alliedmods.net/showthr...t=11567&page=2

the only reason to use fakemeta is for pdata and calls/hooks you couldn't otherwise access.
For one, engine is constantly running. With fakemeta, the module only starts when a command is started, making your server less laggy...
__________________
More updates for Matrix Mod!
knekter is offline
Send a message via AIM to knekter Send a message via MSN to knekter
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 05:14.


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