Advertisement Jump to content
Malonn

Coordinates intersecting - ballpark answer needed

Recommended Posts

I have a problem.  Some of the numbers are going to be approximations.  Here it is:

I have rough dimensions of a cube.  I have XYZ coordinates for the cube (I don't know where in the cube these coordinates originate--I just need a ballpark answer).  I am drawing objects around the cube.  Of course I have coordinates for each object being drawn.  How can I tell if an object would be placed within the cube?

I've been looking at (i.e. Googling) math to determine if a point intersects a line, but that's way too specific.  I need to know if a point (XYZ coordinate) will be placed within the dimensions of a cube.

I hope I'm being clear.  Let me know what other info you need if you think it can be done.

Thanks

Share this post


Link to post
Share on other sites
Advertisement

Hey, Septopus.  Thanks for such a quick response.  I think that may be exactly what I'm looking for.  Two days of aimless Googling later, GameDev.net answers (at least I'm confident it'll solve my problem).

Share this post


Link to post
Share on other sites

I have questions, sorry.  How do I determine which axis the AABB is projected?  The length of an edge can be just one of it's dimensions, right?  My dimensions come from roughly x = L + W + H / 3.  I have "x" in that formula and have to approximate the actual dimensions.  Because what I'm working on is for a mod of a game, not actual game code, I'm limited to the scripting engine of the game.

Share this post


Link to post
Share on other sites

I'm just posting to say the question is unclear to me, and it seems possible it could be unclear to others as well. Among other things, you mention cubes, but the mention of L, W, and H (length, width, and height?) seems to suggest the size may differ for each axis.

In any case, if you don't get the answers you need, it might be worth restating the question.

Share this post


Link to post
Share on other sites

Hey, Zakwayda.  Sorry.  Let me explain more clearly:  I'm using a game's scripting (so it's not in C/C++) language.  Basically, there is one mesh (an AABB or it may be an OBB--I'm fuzzy on the difference) placed in a cell, I'll call that mesh "X".  At runtime via script, I'm placing game objects around this mesh (X).  I'm just trying to detect if the objects being placed would intersect with the mesh (X).  That's it.  Because it's a game scripting language, what I have access to for calculations is limited.

I can get the scale of "X" and the objects being placed around "X".  I can get the "editor size" of "X" and the objects placed around it, which is documented as being a "rough scalar approximation of the dimensions", which is thought to be width + depth + height / 3.  That's why I say I can get rough dimensions.  There are other things I can work with, but those are the most important to me.  And, of course, I can get the XYZ coordinates of the objects being placed around "X" and of "X".

Share this post


Link to post
Share on other sites

I've never implemented it directly myself, always rely on an engine or library to provide it.  Is the scripting language LUA by any chance?  Just Google the language name and AABB, if it's a common language there's probably an example available somewhere.

Share this post


Link to post
Share on other sites

Yeah, I'm Googling.  You pointed out what I'm doing in simple terms so a whole new flood gate of info opened up.  I found this formula:

( P x >= B m i n X ∧ P x <= B m a x X ) ∧ ( P y >= B m i n Y ∧ P y <= B m a x Y ) ∧ ( P z >= B m i n Z ∧ P z <= B m a x Z )

that detects if a point is inside an AABB.  So how do I get the ranges of each axis (BmaxX, BminX, etc.)?  I can easily get XYZ coordinates for the mesh in space, but where those coordinates are relative to the mesh, I don't know.  It confuses me because the mesh ("X" to use the above post) is roughly a cube and the game only returns one set of XYZ coordinates for the cube to describe where it is.

So, does the game have to provide me with "minX", "maxX", "minY", etc., etc.?  Or can I calculate that somehow?  I understand you all may not be familiar with the game's scripting language (it's TES IV Oblivion, by the way), so it may be harder to answer.

Thanks again.

Share this post


Link to post
Share on other sites

Yeah, if you don't have/can't get the actual bounding box dimensions, l/w/h of the mesh itself then you'll have to approximate them or choose a standard cube size that will prevent any of the objects from crossing paths.  I would probably choose the later.

Share this post


Link to post
Share on other sites

If you have access to OBSE, then you can call the function GetBoundingBox, which gives you the center and size of the bounding box. Testing if (Abs(PointX - BcenterX) <= BsizeX/2), and also the same for Y and Z, will give you whether the point is in the box.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!