|
Monica Jewell
Registered User
Join date: 9 Feb 2007
Posts: 9
|
06-24-2007 06:32
Hello,
I am trying to figgure out a way to find out whether a position (vector) is inside a bounding box. Searching this forum and the web I only found functions that work with an aligned bounding box. Is there any way to do the same with a rotated box too?
Basicly I am having a box like object with I know the center position, the rotation and the dimensions of and a vector describing a position of a second object. Now im looking for a function that returns true or false depending on if the point is inside the box or not. Unfortunately a collision handler wont work.
Could anyone provide me with a link or function how to solve this problem?
Any help is greatly appreciated!
Thanks in advance
Monica
|
|
Clover Mills
Registered User
Join date: 15 Mar 2007
Posts: 4
|
06-24-2007 06:39
Find the rotation (Orientation) of the box. You have the vector for the position you are interested in. Rotate that vector so that it aligns with the box, and then you can check if it falls within the box.
|
|
Monica Jewell
Registered User
Join date: 9 Feb 2007
Posts: 9
|
06-24-2007 07:05
Hi Clover, and thanks for answering  Ok, I admit I suck with quaternations... So I get you right that all I need to do is: vector = vector * llGetRot(); and then I can use the normal bounding box formulas which work with alligned boxes for the check?
|
|
Clover Mills
Registered User
Join date: 15 Mar 2007
Posts: 4
|
06-24-2007 07:21
Yes, that's it Here's a link to my tutorial on rotations http://eowyn.bigpondhosting.com/SecondLife.html
|
|
Monica Jewell
Registered User
Join date: 9 Feb 2007
Posts: 9
|
06-24-2007 08:59
hmm.... so i would try it like this:
integer isIn(vector queryPos, vector boxCenter, vector boxDimension, rotation boxRotation) { // get min and max corners assuming an alligned box vector min; min.x = boxCenter.x - (boxDimension.x / 2); min.y = boxCenter.y - (boxDimension.y / 2); min.z = boxCenter.z - (boxDimension.z / 2);
vector max; max.x = boxCenter.x + (boxDimension.x / 2); max.y = boxCenter.y + (boxDimension.y / 2); max.z = boxCenter.z + (boxDimension.z / 2); // reposition the point according to the rotation of the box queryPos = queryPos * boxRotation; // find out if point is inside the box if ((queryPos.x > min.x) && (queryPos.x < max.x) && (queryPos.y > min.y) && (queryPos.y < max.y) && (queryPos.z > min.z) && (queryPos.z < max.z)) return TRUE; else return FALSE; }
default { touch_start(integer total_number) { integer value = isIn(llDetectedPos(0), llGetPos(), llGetScale(), llGetRot()); llSay(0, "Result: " + (string)value); } }
I put this into a phantom box to try it out. As long as the box is alligned the results seem fine. But as soon as I rotate the box I keep getting false results (which is also the case if I rotate min and max). The results seem to be the same as if I had not rotated the box.
Am I missing something? I would expect lots of sinus/cosinus functions to be required?
|