   Interesting sphere from the camera
  I am trying to click on my screen at a sphere and I am running into a problem. I understand ray/sphere collision, however, my problem is that when applying it to click on the screen I am not sure how to get the direction of the ray.I can't just use the look at vector, because that does not take into account of where on the x, y that I clicked on the screen. Does anyone know how I can construct a directional vector of where I clicked on the screen?   
Quote:Original post by johnnuI am trying to click on my screen at a sphere and I am running into a problem. I understand ray/sphere collision, however, my problem is that when applying it to click on the screen I am not sure how to get the direction of the ray.I can't just use the look at vector, because that does not take into account of where on the x, y that I clicked on the screen. Does anyone know how I can construct a directional vector of where I clicked on the screen?This is called 'picking', and is discussed frequently on the forums. If you search the forum archives for 'picking', you should find some good references.Meanwhile though, the standard method is to 'unproject' the mouse position twice, once at the near plane and once at the far plane, to yield a 'picking segment' (this will work for both perspective and orthographic projections).   ;  Practically, this is something that is going to be dependent on your API.  OpengGL, DirectX/XNA, etc..   ;Quote:Practically, this is something that is going to be dependent on your API.Not really. Depending on what API you're using, you may be able to leverage existing functionality (e.g. DX math library, gluUnproject(), etc.), but all the necessary math can easily be done independently of any particular API.   ;  I have done picking before, I suppose I am more confused about how to do it for this situation. Typically I normally just do a line segment to triangle to all of my triangles, but I want to it just to a sphere.Here is what I am trying, I am just confused as to how to set this up correctly. my interestRaySphere function takes in (Point, Direction, SpherePosition, SphereRadius) and is based off the technique from Real Time Collision Detection. How should I set this up correctly?PickSphere(tViewport &vpViewport, D3DXMATRIX &mWorldViewProjection,    D3DXVECTOR3 camLookAt, D3DXVECTOR3 spherePosition, float fRadus, float fMouseX, float fMouseY){D3DXVECTOR3 vStart = Unproject(D3DXVECTOR3(fMouseX, fMouseY, 0.0f), (float)vpViewport.dwLocationX,(float)vpViewport.dwLocationY, (float)vpViewport.dwWidth,(float)vpViewport.dwHeight, vpViewport.fMinZ, vpViewport.fMaxZ, mWorldViewProjection);return interestRaySphere(vStart, camLookAt, spherePosition, fRadus);};Quote:interestRaySphereHehe...do you mean 'intersect'? (Or did you really mean to ask about 'interesting spheres'? :-)Quote:Here is what I am trying, I am just confused as to how to set this up correctly. my interestRaySphere function takes in (Point, Direction, SpherePosition, SphereRadius) and is based off the technique from Real Time Collision Detection. How should I set this up correctly?You're close, but read this again:Quote:Original post by jykMeanwhile though, the standard method is to 'unproject' the mouse position twice, once at the near plane and once at the far plane, to yield a 'picking segment' (this will work for both perspective and orthographic projections).What you need to do is 'unproject' a second point, and then build the ray direction vector from the two points.   ;  I did mean "intersect", these spheres just are not that interesting ... yet :)I built an end vector like I normally do for picking and did a End-Start/magnitude to get the direction and everyone seems to be working great now. Thank you for help :)   