IsInside function for bounding meshes
Blitz3D Forums/Blitz3D Beginners Area/IsInside function for bounding meshes
| ||
Here's a little thing some of you might enjoy! Perhaps some of you aren't enjoying the collider system blitz has to offer. The bounding meshes can be hidden and don't have to be rendered. I wrote a simple BOXOID-BASED solution if you're sick of sphereoids. It seems pretty accurate to me. Even the Col_Det library seemed to be giving me woe with larger flat planes for some unknown reason so I wrote this thing. Took a bit. I also found IsAbove and IsBelow to be useful for rotated bounding PLANES, just change the final if statement to suit your needs! Enjoy! About the optional pivot point ===================== The reason for the pivot point is that your bounding object might have a non-centered nature and/or be part of an object heirarchy (as a child entity of another object for example) Px,Py,Pz are basically: "the object's xyz positions in space" MINUS "the center of the bounding box's xyz positions in space" So xo2=x2-cx yo2=y2-cy zo2=z2-cz In your own 3D object editor. Whatever you use. With these values added, you can still detect collisions even if your box is rotating off center BECAUSE: Meshwidth,height, depth only return the SIZE of the mesh, not WHERE it is relative to it's pivot point! Caveat: If you've made a bounding heirarchy of some sort...? Good luck! Scaling parents affects their children, so... I dunno. If it works out for you... Let us all know! I found a bug recently in the MeshDepth command I think, so you'd better Track the mesh's vertex extremities yourself if ACCURACY is a must. Some mesh scale and a hodegpoge of junk you might want also: |
| ||
I use the default sphere, but I make it as narrow as a pencil. I've also theorized collider zones: reshapeable custom cubes that have X shaped planes within them, so when used with MeshesIntersect you get a lot more coverage than with just a cube based zone. |
| ||
You could use the tformpoint command for a simpler solution ...Function IsInside(e1,e2, ox#=0,oy#=0,oz#=0) Local mw#=MeshWidth#(e2)*.5 Local mh#=MeshHeight#(e2)*.5 Local md#=MeshDepth#(e2)*.5 TFormPoint ox,oy,oz,e1,e2 Return ( Abs(TFormedX()) < mw and Abs(TFormedY()) < mh and Abs(TFormedZ()) < md ) End Function |