Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# DirectX Game 3D XNA
I need a function that return if a certain point is inside a directx 3d model(.x)...
 
I have tried but i can´t get it to work so i need some help.
 
Something like this:
 
public bool IsInsideModel(Vector3 point, Model model)
{
    //This would of course be nice but i don't think such function exists...
    //return model.Contains(point);
}
 
Any suggestions will be appreciated.
 

This is not for a game engine or realtime rendering so the computing time is not an issue.
Please provide some examples.
Posted 21-Mar-11 11:40am
Edited 25-Mar-11 8:08am
v4
Comments
orc_orc_orc at 21-Mar-11 17:45pm
   
http://stackoverflow.com/questions/4963110/determine-if-x-y-z-point-is-inside-a-shape-defined-by-an-array-of-points
 
http://www.softsurfer.com/Archive/algorithm_0104/algorithm_0104B.htm
 
i dont know if they will help but take a look at it.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

The good news: it can be done. The bad news: A precise test is computationally expensive and therefore probably too slow to be of any use in real time rendering.
 
First off, it works only on convex objects. Concave objects would have to be broken down into two or more convex objects and then tested individually.
 
http://en.wikipedia.org/wiki/Concave_polygon[^]
 
Let's call the point you want to test P, the verices of the object VX and their normals NX. Then you will have to compute the cross product between the NX and (VX - P). The cross product will tell you wether P is inside the object or not and this must be true for every VX of the object.
 

Seriously, you are probably trying to program a collision test for some 3D engine, right? In this case The test is usually done against a much simpler object as a substitute for the real 3D object, usually those are boxes or spheres which approximate the space filled by the real 3D object and are far easier to test. It's very common in graphics to sacrifice some precision in order to gain performance.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 410
1 Jochen Arndt 200
2 Richard MacCutchan 135
3 DamithSL 105
4 PIEBALDconsult 90
0 OriginalGriff 6,045
1 DamithSL 4,601
2 Maciej Los 4,032
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,220


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 25 Mar 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100