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