/// <summary> /// Picking a geometry in the scene with the near and far vector /// </summary> public void PerformPicking(MouseEventArgs e) { //Get the line Vector3 near, far; GenerateLine(e.X, e.Y, out near, out far); //Do picking float distance = 0.0f; int index = 0; GEMSSingleRender pickedSingle = null; foreach (GEMSSingleRender render in singleRenders) { // Retrieve intersection information IntersectInformation closestIntersection; bool intersects = render.Intersect(near, far, out closestIntersection); if (intersects) { if (index == 0) { distance = closestIntersection.Dist; pickedSingle = render; } else { if (distance > closestIntersection.Dist) { distance = closestIntersection.Dist; pickedSingle = render; } } index++; } } if (pickedSingle != null) { m_project.CurrentSelectedObject = pickedSingle.Source; } else { m_project.CurrentSelectedObject = null; } }
private void UpdateSingleRenders(GEMSProject.DataChangedEventArgs e) { if (e.changedSingle is GEMSSingle) { GEMSSingle changedSingle = e.changedSingle as GEMSSingle; switch (e.changedType) { case GEMSProject.DataChangedEventArgs.DataChangeType.SingleCutted: case GEMSProject.DataChangedEventArgs.DataChangeType.SingleDeleted: { //Delete one single painter GEMSSingleRender targetSingleRender = null; foreach (GEMSSingleRender singleRender in singleRenders) { if (singleRender.Source == changedSingle) { targetSingleRender = singleRender; } } this.singleRenders.Remove(targetSingleRender); targetSingleRender.Dispose( ); } break; case GEMSProject.DataChangedEventArgs.DataChangeType.SinglePasted: case GEMSProject.DataChangedEventArgs.DataChangeType.SingleCreated: //Create one single painter { GEMSSingleRender newSingleRender = new GEMSSingleRender(d3d, changedSingle, this); newSingleRender.Initialize( ); this.singleRenders.Add(newSingleRender); } break; } } //Re-generate bounding box GenerateBoundingBox( ); if (currentMode == SceneMode.Preview) { isFit = true; } }
/// <summary> /// Create single painters for each single object /// </summary> private void CreateSingleRenders( ) { foreach (GEMSSingleRender singleRender in singleRenders) { singleRender.Dispose( ); } singleRenders.Clear( ); if (m_project != null && m_project.Singles != null) { foreach (GEMSSingle single in m_project.Singles) { GEMSSingleRender render = new GEMSSingleRender(d3d, single, this); render.Initialize( ); singleRenders.Add(render); } GenerateBoundingBox( ); } }