[RESOLVED] Checking a vector is inside a box Author Message
aceio76
Silver Supporter

 Post: #1 [RESOLVED] Checking a vector is inside a box Guys, is there a native function that checks if a vector is inside a box? I have Cuts(), but that doesn't work if the vector start off already inside the box. Let me know if I need to create my own function. www.thinkplaystudios.com (This post was last modified: 02-04-2012 06:56 AM by aceio76.)
02-01-2012 05:43 AM
Esenthel

 Post: #2 RE: Checking a vector is inside a box Bool SweepPointBox(C Vec &point, C Vec &move, C Box &box , Flt *hit_frac=NULL, Vec *hit_pos=NULL); // if moving point cuts through a static box Bool SweepPointBox(C Vec &point, C Vec &move, C OBox &obox, Flt *hit_frac=NULL, Vec *hit_pos=NULL); // if moving point cuts through a static oriented box
02-01-2012 03:02 PM
aceio76
Silver Supporter

 Post: #3 RE: Checking a vector is inside a box Let's assume the point is not moving. (this could happen when a player logs in already inside the box, for instance). www.thinkplaystudios.com
02-01-2012 10:39 PM
Zervox
Member

 Post: #4 RE: Checking a vector is inside a box Code: ```inline bool contains(const Vec3& point,const Box box) {     if ((point.x >= box.min.x && point.x <= box.max.x) &&         (point.y >= box.min.y && point.y <= box.max.y) &&         (point.z >= box.min.z && point.z <= box.max.z))     {         return true;     }     return false; }```
02-01-2012 10:51 PM
aceio76
Silver Supporter

 Post: #5 RE: Checking a vector is inside a box Hehe I already did it last night. www.thinkplaystudios.com
02-01-2012 11:02 PM
aceio76
Silver Supporter

 Post: #6 RE: Checking a vector is inside a box Esenthel, do you think it makes sense for you to include this in the base code for box, obox and others like it? Code: ```inline Bool Inside(C Vec &point, C OBox &obox) {    return ((point.x >= obox.box.min.x && point.x <= obox.box.max.x) &&            (point.y >= obox.box.min.y && point.y <= obox.box.max.y) &&            (point.z >= obox.box.min.z && point.z <= obox.box.max.z)); }``` www.thinkplaystudios.com
02-03-2012 03:36 PM
Abril
Member

 Post: #7 RE: Checking a vector is inside a box (02-03-2012 03:36 PM)aceio76 Wrote:  Esenthel, do you think it makes sense for you to include this in the base code for box, obox and others like it? Code: ```inline Bool Inside(C Vec &point, C OBox &obox) {    return ((point.x >= obox.box.min.x && point.x <= obox.box.max.x) &&            (point.y >= obox.box.min.y && point.y <= obox.box.max.y) &&            (point.z >= obox.box.min.z && point.z <= obox.box.max.z)); }``` This is wrong tho, for the oriented bounding boxes, because the box can be rotated (oriented). Works only for the aabb because it is axis aligned. For the oriented bounding box you need to check the box planes or rotate the point/box.
02-03-2012 03:53 PM
aceio76
Silver Supporter

 Post: #8 RE: Checking a vector is inside a box I thought the OBox.box is already the transformed box? www.thinkplaystudios.com
02-03-2012 07:10 PM
Esenthel

 Post: #9 RE: Checking a vector is inside a box (02-03-2012 03:36 PM)aceio76 Wrote:  Esenthel, do you think it makes sense for you to include this in the base code for box, obox and others like it? but there is already "Cuts()" like you mentioned in the first post for both Box and OBox
02-03-2012 11:22 PM
aceio76
Silver Supporter

 Post: #10 RE: Checking a vector is inside a box Cuts() doesn't seem to work if the vector starts out already inside the box. It seems to return false. www.thinkplaystudios.com
02-04-2012 02:59 AM
aceio76
Silver Supporter

 Post: #11 RE: Checking a vector is inside a box I stand corrected, Cuts() does work even if the point starts inside the box. I will close this thread now. Thanks for bearing with me. www.thinkplaystudios.com
02-04-2012 06:56 AM
 « Next Oldest | Next Newest »