Original Post
Hi, i am trying to do picking with c#, but it dosent work.
I basically converted the picking c++ sample to c# and managed directX, so here is my code.
Microsoft.DirectX.Direct3D.IntersectInformation hitInfo = new Microsoft.DirectX.Direct3D.IntersectInformation();
foreach ( Piece piece in mChessForm.Board.WhitePieces )
{
System.Drawing.Point ptCursor = System.Windows.Forms.Cursor.Position;
Microsoft.DirectX.Matrix matProj = mChessForm.Renderer.Device.Transform.Projection;
Microsoft.DirectX.Matrix matView = mChessForm.Renderer.Device.Transform.View;
Microsoft.DirectX.Matrix matWorld = piece.WorldMatrix;
// Compute the vector of the pick ray in screen space
Microsoft.DirectX.Vector3 v = new Microsoft.DirectX.Vector3();
v.X = ( ( ( 2.0f * ptCursor.X ) / mChessForm.Renderer.Device.Viewport.Width ) - 1 ) / matProj.M11;
v.Y = -( ( ( 2.0f * ptCursor.Y ) / mChessForm.Renderer.Device.Viewport.Height ) - 1 ) / matProj.M22;
v.Z = 1.0f;
Microsoft.DirectX.Matrix m = matWorld * matView;
m.Invert();
Microsoft.DirectX.Vector3 vPickRayDir = new Microsoft.DirectX.Vector3();
Microsoft.DirectX.Vector3 vPickRayOrig = new Microsoft.DirectX.Vector3();
// Transform the screen space pick ray into 3D space
vPickRayDir.X = v.X*m.M11 + v.Y*m.M21 + v.Z*m.M31;
vPickRayDir.Y = v.X*m.M12 + v.Y*m.M22 + v.Z*m.M32;
vPickRayDir.Z = v.X*m.M13 + v.Y*m.M23 + v.Z*m.M33;
vPickRayOrig.X = m.M41;
vPickRayOrig.Y = m.M42;
vPickRayOrig.Z = m.M43;
if ( piece.Model.Model.Intersect ( new Microsoft.DirectX.Vector3(0,0,0), vPickRayDir, ref hitInfo ) == true)
{
System.Windows.Forms.MessageBox.Show(piece.ToString());
}
}
if someone can help me with this, ill be gratefull
thanx