   XNA - Ray / Coords Problem
  Hi guys,The problem:  I'm not being able to figure out Screen Coords, mouse movement & Ray Casting...Situation:  I'm working on a game in which u control a model. There are 2 cameras: one attached to a bone in the eyes (1st person). The other orbits around (3rd person).U are able to move the model (human): walk, run, move head (& attached cam), etc. & u can also control its arm. As u can grab objects, I'm trying to develop an inventory system. Basically u press "i" & u see in front of ur eyes, this:<-  object  ->so: left arrow to go to the previous item, the actual current item in the middle & a right arrow to go to the next item.In the "Inventory mode" u move the model hand, which has a BoundingSphere in the index item so u can pick.Firstly I created the arrows as sprites (spritebatch). Then i turned them into 3d cubes with a BoundingSphere on each not to mix 2D with 3D.I read a bit about Rays & tried to cast one from the index finger of the hand (to intersect with the arrow cube BoundingSphere, but i didn't succeed...I really don't know where to head, i'm like naked & lost in the jungle...If u could please help me, that would be awesome...! Please any tip???[Edited by - Synthesizer on April 25, 2009 9:21:41 PM]
  Well, I'll try to be more clear.This is my Ray code right now (I'm previously centering the mouse, but i guess it doesn't matter):Vector3 fingerPos = myPlayer.leftIndexFinger.collisionDetector.Center;    Vector3 nearSource = fingerPos;    Vector3 farSource = fingerPos + new Vector3(0, 0, 1);    Vector3 nearPoint = GraphicsDevice.Viewport.Unproject(nearSource, projectionMatrix, viewMatrix, Matrix.Identity);    Vector3 farPoint = GraphicsDevice.Viewport.Unproject(farSource, projectionMatrix, viewMatrix, Matrix.Identity);   // find the direction vector that goes from the nearPoint to the farPoint    // and normalize it....    Vector3 direction = farPoint - nearPoint;    direction.Normalize();    Ray ray = new Ray(nearPoint,direction);    int a = 0;    BoundingSphere newSphere = new BoundingSphere(GraphicsDevice.Viewport.Unproject(myPlayer.inventory.leftButton.collisionDetector.Center, projectionMatrix, viewMatrix, Matrix.Identity), 0.5f);    if(newSphere.Intersects(ray).HasValue == false)   {   a = 1;   }In farSource i tried with (0,0,-1), (0,0,1), (0,0,-1000), (0,0,1000)... & it doesn't work. Never gets inside the last "if".After posting my first ramble, I thought more & more & i understood i need to translate the coords into screen coords (i guess Unproject does that).So I Unproject the finger BoundingSphere coords & the arrow cube BoundingSphere*, but altough i SEE the spheres in the same screen coords X & Y (i'm rendering them), the Ray doesn't work.Any Ideas...?Thank u!*I'm using a BoundingSphere in a cube just because i can render BoundingSpheres.   ;  Come on people!EVERYONE goes thru this when developing an inventory system. If u have any tip just any idea, please post, it will be welcome! If it's abstract, it's ok, i don't ask for code necessarily.The problem can be related to the Ray direction i guess. Or maybe the Unproject?Help please!!!Thanks :)   