public void PickObject(int x, int y) { if (m_simulationModel == null) { return; } m_pickRay = PickRay.Pick(x, y, m_camera, m_control.Size, ProjectionMatrix); NeuronModel neuron = FindFirstNeuron(m_pickRay, m_simulationModel.Regions); if (neuron != null) { ToggleNeuron(neuron); } }
private NeuronModel FindFirstNeuron(PickRay pickRay, IEnumerable <RegionModel> regions) { float closestDistance = float.MaxValue; NeuronModel closestNeuron = null; foreach (RegionModel region in regions) { foreach (NeuronModel neuron in region.Neurons) { float distance = neuron.DistanceToRayOrigin(pickRay); if (distance < closestDistance) { closestNeuron = neuron; closestDistance = distance; } } } return(closestNeuron); }