/// <summary> /// Simple function to update the size of the cylinder which visualizes the current separation distance. /// </summary> /// <param name="robot"></param>The robot for which the update should be made. private void UpdateVisualizationDistance(IRobot robot) { if (robot != null && robot.IsValid && app.World.FindComponent("SeparationVisualization_" + robot.Name) != null) { ISimComponent comp = app.World.FindComponent("SeparationVisualization_" + robot.Name); ISimNode node = robot.Component.FindNode("mountplate"); Matrix matrix = comp.TransformationInReference; matrix.SetP(new Vector3(node.TransformationInWorld.Px, node.TransformationInWorld.Py, 201)); comp.TransformationInReference = matrix; ICylinderFeature cylinder = (ICylinderFeature)app.World.FindComponent("SeparationVisualization_" + robot.Name).FindFeature("SeparationVisualization"); if (robotList[robot].currentSeperationDistance <= 100) { cylinder.GetProperty("Radius").Value = "100"; comp.GetProperty("SeparationDistance").Value = "100"; } else { cylinder.GetProperty("Radius").Value = robotList[robot].currentSeperationDistance.ToString(); comp.GetProperty("SeparationDistance").Value = robotList[robot].currentSeperationDistance; } cylinder.Rebuild(); } else { ms.AppendMessage("UpdateVisualizationDistance: Failed to find robot component!", MessageLevel.Warning); } }
/// <summary> /// Visualization of Separation Distance. A cylinder feature is added to the robot if not already present. /// Initial values are set. /// </summary> /// <param name="robot"></param>The robot for which the separation distance should be visualized. /// <param name="initialRadius"></param>The initial radius for the cylinder. private void VisualizeSeperationDistance(IRobot robot, double initialRadius) { if (robot != null && robot.IsValid && app.World.FindComponent("SeparationVisualization_" + robot.Name) == null) { ISimComponent component = app.World.CreateComponent("SeparationVisualization_" + robot.Name); component.CreateProperty(typeof(Double), PropertyConstraintType.NotSpecified, "SeparationDistance"); ISimNode node = robot.Component.FindNode("mountplate"); Matrix matrix = component.TransformationInReference; matrix.SetP(new Vector3(node.TransformationInWorld.Px, node.TransformationInWorld.Py, 201)); component.TransformationInReference = matrix; ICylinderFeature seperationVisualization = component.RootNode.RootFeature.CreateFeature <ICylinderFeature>(); // true would remove the top and bottom of the cylinder, but backfaces of the inside of the cylinder are not rendered //seperationVisualization.GetProperty("Caps").Value = false; seperationVisualization.GetProperty("Height").Value = "3000.0"; seperationVisualization.GetProperty("Sections").Value = "36.0"; seperationVisualization.GetProperty("Radius").Value = initialRadius.ToString(); seperationVisualization.GetProperty("Material").Value = app.FindMaterial("transp_yellow", false); seperationVisualization.SetName("SeparationVisualization"); } }