Original Post
Is there any DirectX or XNA functions that test if a point is inside a mesh? Note: This isn't collision detection, I'm trying to make a voxel map of a mesh
Quote:
Original post by MetaKnight
Is there any DirectX or XNA functions that test if a point is inside a mesh?
Note: This isn't collision detection, I'm trying to make a voxel map of a mesh
Quote:
Original post by Nik02
For each voxel position, cast 6 rays - along both positive and negative x, y and z directions. Count all the collisions with the geometry along each ray.
Now, if all of the rays' collision count with the geometry is an odd number (that is, n && 2 == 1), the current point is inside the geometry. Otherwise, it is either outside the geometry or the mesh has a hole that one of the rays escaped out from.
Quote:
Original post by Nik02
There isn't such a function out of the box, but it is relatively easy to implement a simple technique for this.
For each voxel position, cast 6 rays - along both positive and negative x, y and z directions. Count all the collisions with the geometry along each ray.
Now, if all of the rays' collision count with the geometry is an odd number (that is, n && 2 == 1), the current point is inside the geometry. Otherwise, it is either outside the geometry or the mesh has a hole that one of the rays escaped out from.
Direct3D utility library, D3DX, provides functions for testing a ray's collision against both a triangle and a full mesh. I haven't played with XNA so much as to remember whether similar functionality exists within it's class library (but it likely does).
|-------|| || * || |---------|-----------------|| |--| || |* | || |--| |------------------ Quote:
Original post by TheAdmiral Quote:
Original post by Nik02
For each voxel position, cast 6 rays - along both positive and negative x, y and z directions. Count all the collisions with the geometry along each ray.
Now, if all of the rays' collision count with the geometry is an odd number (that is, n && 2 == 1), the current point is inside the geometry. Otherwise, it is either outside the geometry or the mesh has a hole that one of the rays escaped out from.
That's an interesting method, but isn't it limited to convex meshes? I imagine placing a voxel inside a teacup.
Admiral
Quote:
Original post by MetaKnight Quote:
Original post by Nik02
There isn't such a function out of the box, but it is relatively easy to implement a simple technique for this.
For each voxel position, cast 6 rays - along both positive and negative x, y and z directions. Count all the collisions with the geometry along each ray.
Now, if all of the rays' collision count with the geometry is an odd number (that is, n && 2 == 1), the current point is inside the geometry. Otherwise, it is either outside the geometry or the mesh has a hole that one of the rays escaped out from.
Direct3D utility library, D3DX, provides functions for testing a ray's collision against both a triangle and a full mesh. I haven't played with XNA so much as to remember whether similar functionality exists within it's class library (but it likely does).
Nice technique!
Just to clarify, but if I'm inside a box like so:|-------|| || * || |---------
wont that give me an even number?(6)
but if I'm outside like so:|-----------------|| |--| || |* | || |--| |------------------
i would get a even number?(8)
This topic has been locked by a moderator. New replies are not allowed.
GameDev.net uses cookies to ensure you have the best experience on our platform. Learn more