Raised This Month: $ Target: $400
 0% 

Box collision/distance functions


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
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
 



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 20:19.


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