Find a point in a square

Post your scripting questions / solutions here

Moderator: Moderators

Post Reply
$oldier Of Ra
Lieutenant Colonel
Posts: 404
Joined: Sun Oct 16, 2005 7:16 pm
Location: Belgium
Contact:

Find a point in a square

Post by $oldier Of Ra »

The title might look a bit vague but it's basically what I want to do. I don't want to use a script_origin with isTouching nor a trigger. I don't want to spawn entities.

What I want to do is save some coordinates which would form a cuboid or a cube (like a floor in a building; check to see if the player is on that floor). And at a time I want to see if a player is within this cuboid/cube.

My questions are these:

- What method would be best to record this? Save its length, width and depth in an array? Or save 8 coords (each corresponding with 1 corner of this 3D box into an array? Or something easier?

- What calculations would I need to do to seek if a player ( X Y Z ) is within the 3D box according to the way I saved the 3D box?

Thank you in advance! :)
Our official website: http://www.mohaairborne.co.cc
(Still accessible through http://mohaaclantb.tk and http://users.skynet.be/mohaaclantb/)

For all your bot needs!!!!

$oldier Of Ra.
User avatar
HandyTech
Corporal
Posts: 30
Joined: Mon Aug 07, 2006 7:02 am
Location: Michigan, USA
Contact:

Post by HandyTech »

This feature would be very valuable to me, so I'm "subscribing" to this post. Sorry for the "false alarm" if you were expecting a good answer to your question.
Respectfully,
Nicolae Crisan
Profound Systems
Stable Files . net
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post by jv_map »

Hehe I see... well multiple interested fellows seems a good reason to write a reply :)

The 'standard' way to describe a (bounding) box, in mohaa, is by means of a 'mins' and a 'maxs' vector. Conceptually, the mins vector points to the lower left corner while the maxs vector points to the upper right corner. All values in mins must be smaller than those in maxs for a positive volume (otherwise your box is 'inside out'). These vectors are defined with respect to a particular coordinate system (for you to choose). Typically you would take the world coordinate system. That was the part on how to store the information.

Now how to determine whether a particular object is inside it... if your bounding box is axis aligned, which essentially means its sides coincide with (x,y,z) grid lines, this check is relatively easy. A point (e.g. the origin of a player) is inside the rectangle if and only if:
mins[0] < point[0] < maxs[0]
mins[1] < point[1] < maxs[1]
mins[2] < point[2] < maxs[2]
Thus you consecutively check for the x, y and z coordinates to be within the bounding box. Only if all these 6 conditions are satisfied, the point is inside the box proper.

If your box is not axis aligned, i.e. rotated in some way with respect to the grid, things get a bit more complicated. In that case you have to transform either the coordinates of the point or those of the box bounds to the rotated coordinate system. It's definitely doable, but I'll skip that part for now as I'm assuming you only need an axis aligned box.

Hope this helps! :)

Hint: you can find lots of help on this topic if you google for axis-aligned bounding box (AABB) intersection test.
Image
$oldier Of Ra
Lieutenant Colonel
Posts: 404
Joined: Sun Oct 16, 2005 7:16 pm
Location: Belgium
Contact:

Post by $oldier Of Ra »

You make it sound and prove so easy jv :) I doubt I'll be needing to check for OBB's etc... I'll keep it simple.

So I need to record those boxes like the setsize of a trigger? Which is indeed, if I'm dealing with a cuboid (a perfect cube -> very unlikely), the coords of the lower left and upper right.

Thank you jv :D
Our official website: http://www.mohaairborne.co.cc
(Still accessible through http://mohaaclantb.tk and http://users.skynet.be/mohaaclantb/)

For all your bot needs!!!!

$oldier Of Ra.
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post by jv_map »

No problem, happy to help, good luck!
Image
$oldier Of Ra
Lieutenant Colonel
Posts: 404
Joined: Sun Oct 16, 2005 7:16 pm
Location: Belgium
Contact:

Post by $oldier Of Ra »

Jv, what method of recording/tracking would you recommend from a mathematical point of view :)? Because using the previous method I found out that there isn't always a coord with all the max vectors and one with all the min vectors :?

I don't understand the english sources about this issue you posted earlier. :( I speak english but don't learn maths in English. Are there any dutch sources where I could learn these sort of things? Or how would you solve this problem?

I found out sorrid uses info landmark and it seems less work to record; it records the name of the place, an origin in that place and it's highest and lowest heights. And according to what I understood of the script, returns the landmark where the player is closest to.
Last edited by $oldier Of Ra on Fri Dec 12, 2008 10:30 pm, edited 3 times in total.
Our official website: http://www.mohaairborne.co.cc
(Still accessible through http://mohaaclantb.tk and http://users.skynet.be/mohaaclantb/)

For all your bot needs!!!!

$oldier Of Ra.
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post by jv_map »

$oldier Of Ra wrote:... I found out that there isn't always a coord with all the max vectors and one with all the min vectors :?
I don't understand what you mean? :?
Image
$oldier Of Ra
Lieutenant Colonel
Posts: 404
Joined: Sun Oct 16, 2005 7:16 pm
Location: Belgium
Contact:

Post by $oldier Of Ra »

Well depending on how the map was made, when I fly into a room as spectator I check all corners for the coords and find that there isn't always a coordinate with all the highest values and a coordinate with all the lowest values for this to work:
mins[0] < point[0] < maxs[0]
mins[1] < point[1] < maxs[1]
mins[2] < point[2] < maxs[2]
Does this mean that this "room" isn't axis-aligned? But I'll check again, I might be mistaking, I will keep you informed.
Our official website: http://www.mohaairborne.co.cc
(Still accessible through http://mohaaclantb.tk and http://users.skynet.be/mohaaclantb/)

For all your bot needs!!!!

$oldier Of Ra.
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post by jv_map »

There must be! ;)
Image
Post Reply