Page 1 of 1

Find a point in a square

Posted: Tue Dec 09, 2008 2:55 pm
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! :)

Posted: Tue Dec 09, 2008 4:46 pm
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.

Posted: Tue Dec 09, 2008 10:41 pm
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.

Posted: Tue Dec 09, 2008 11:38 pm
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

Posted: Wed Dec 10, 2008 3:47 pm
by jv_map
No problem, happy to help, good luck!

Posted: Fri Dec 12, 2008 6:10 pm
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.

Posted: Sat Dec 13, 2008 11:10 am
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? :?

Posted: Sat Dec 13, 2008 11:20 am
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.

Posted: Sun Dec 14, 2008 9:32 am
by jv_map
There must be! ;)