Original Post
Hai, I am new to DirectX.I wrote a code to render directx file and its working fine.But what I need now is to pick the mesh.I used the following way, Note: I call below MeshPick function in MouseDown function private bool MeshPick(Mesh mesh, int x, int y) { bool intersects; string status; private float vert1x,vert1y,vert1z,vert2x,vert2y,vert2z,vert3x,vert3y,vert3z; private CustomVertex.TransformedColored[] vert; Vector3 v3Near = new Vector3(x, y, 0); Vector3 v3Far = new Vector3(x, y, 1); v3Near.Unproject(device.Viewport,device.Transform.Projection,device.Transform.View,device.Transform.World); v3Far.Unproject(device.Viewport,device.Transform.Projection,device.Transform.View,device.Transform.World); v3Far.Subtract(v3Near); // Retrieve intersection information IntersectInformation closestIntersection = new IntersectInformation(); intersects = mesh.Intersect(v3Near,v3Far,out closestIntersection); if (intersects) { status = string.Format("Face={0},tu={1},tv={2}",closestIntersection.FaceIndex,closestIntersection.U,closestIntersection.V); HighlightIntersectedFace(closestIntersection); return true; } else return false; } private void HighlightIntersectedFace(IntersectInformation ii) { // create an array to hold the indices for the intersected face short[] intersectedIndices = new short[3]; // fetch indices for the intersected face from the mesh short[] indices = (short[])mesh.LockIndexBuffer(typeof(short), LockFlags.ReadOnly, mesh.NumberFaces * 3); Array.Copy(indices, ii.FaceIndex * 3, intersectedIndices, 0, 3); mesh.UnlockIndexBuffer(); CustomVertex.PositionNormalTextured[] tempIntersectedVertices = new CustomVertex.PositionNormalTextured[3]; // extract vertex data from mesh, using our indices we obtained earlier CustomVertex.PositionNormalTextured[] meshVertices = (CustomVertex.PositionNormalTextured[])mesh.LockVertexBuffer(typeof(CustomVertex.PositionNormalTextured), LockFlags.ReadOnly, mesh.NumberVertices); tempIntersectedVertices[0] = meshVertices[intersectedIndices[0]]; tempIntersectedVertices[1] = meshVertices[intersectedIndices[1]]; tempIntersectedVertices[2] = meshVertices[intersectedIndices[2]]; mesh.UnlockVertexBuffer(); this.intersectedVertices = tempIntersectedVertices; vert =new CustomVertex.TransformedColored[3]; //Get vertices1 x,y and z position vert1x = this.intersectedVertices[0].Position.X; vert1y = this.intersectedVertices[0].Position.Y; vert1z = this.intersectedVertices[0].Position.Z; //Get vertices2 x,y and z position vert2x = this.intersectedVertices[1].Position.X; vert2y = this.intersectedVertices[1].Position.Y; vert2z = this.intersectedVertices[1].Position.Z; //Get vertices3 x,y and z position vert3x = this.intersectedVertices[2].Position.X; vert3y = this.intersectedVertices[2].Position.Y; vert3z = this.intersectedVertices[2].Position.Z; vert[0].Position = new Vector3(vert1x,vert1y,vert1z); vert[0].Color = Color.Yellow.ToArgb(); vert[1].Position = new Vector3(vert2x,vert2y,vert2z); vert[1].Color = Color.Yellow.ToArgb(); vert[2].Position = new Vector3(vert3x,vert3y,vert3z); vert[2].Color = Color.Yellow.ToArgb(); device.VertexFormat = CustomVertex.TransformedColored.Format; device.DrawUserPrimitives(PrimitiveType.TriangleList, 1, vert); } I get the ray intersected position vertices from this.intersectedVertices .But Triangle not drawn. I don't know whether the vertices are the correct one or not. I want to get ray intersected near triangle vertices.By those vertices draw triangle andthen highlight that triangle using color.Please help me. How to do it?