public bool IsPlanePicked(int mouseX, int mouseY) { // Construct our ray Ray ray = Utilitys.CalculateRayFromCursor(Game.GraphicsDevice, Camera, mouseX, mouseY); Vector3 min = new Vector3(Vertices[0].Position.X, Vertices[0].Position.Y, Vertices[0].Position.Z); Vector3 max = new Vector3(Vertices[Vertices.Length - 1].Position.X, Vertices[Vertices.Length - 1].Position.Y, Vertices[Vertices.Length - 1].Position.Z); BoundingBox bb = new BoundingBox(min, max); if (bb.Intersects(ray) > 0) { // TODO: This needs reworking because we should almost segregate the difference between a Vertice Picking operation and the whole Object Picking operation! // Invoke our delegate so we can manipulate this from outside our class if (PickingOperation != null) { PickingOperation.Invoke(0); } } return(false); }
public bool IsVertPicked(int mouseX, int mouseY) { // Construct our ray Ray ray = Utilitys.CalculateRayFromCursor(Game.GraphicsDevice, Camera, mouseX, mouseY); // Calculate our Vertice Array for (int x = 0; x < _width; x++) { for (int z = 0; z < _height; z++) { // Calc our Bounding Boxes Vector3 min = new Vector3(Vertices[x + z * _width].Position.X, Vertices[x + z * _width].Position.Y, Vertices[x + z * _width].Position.Z); Vector3 max = new Vector3(Vertices[x + z * _width].Position.X + 1, Vertices[x + z * _width].Position.Y + 1, Vertices[x + z * _width].Position.Z + 1); BoundingBox bb = new BoundingBox(min, max); // If we found a hit return it if (bb.Intersects(ray) > 0) { // Invoke our delegate so we can manipulate this from outside our class if (PickingOperation != null) { PickingOperation.Invoke(x + z * _width); } // Rebuild our vert array VertexBuffer = new VertexBuffer(Game.GraphicsDevice, typeof(VertexPositionColorTexture), _width * _height, BufferUsage.WriteOnly); VertexBuffer.SetData(Vertices); return(true); } } } return(false); }