Description
A single result from Pick.
Public Properties
Depth | Gets the depth of the picked location in the 3D scene. |
Objects | Gets a collection of objects that were on the pick stack for the picked object. |
Position | Gets the position of the picked location in the central body's fixed reference frame. The array contains the components of the position arranged in the order x, y, z. |
Example
Change a model's color on mouse over
[C#] |
---|
//
// Get a collection of picked objects under the mouse location.
// The collection is sorted with the closest object at index zero.
//
IAgStkGraphicsPickResultCollection collection = scene.Pick(mouseX, mouseY);
if (collection.Count != 0)
{
IAgStkGraphicsObjectCollection objects = collection[0].Objects;
IAgStkGraphicsCompositePrimitive composite = objects[0] as IAgStkGraphicsCompositePrimitive;
//
// Was a model in our composite picked?
//
if (composite == m_Models)
{
IAgStkGraphicsPrimitive model = objects[1] as IAgStkGraphicsPrimitive;
//
// Selected Model
//
model.Color = Color.Cyan;
if (model != m_SelectedModel)
{
//
// Unselect previous model
//
if (m_SelectedModel != null)
{
m_SelectedModel.Color = Color.Red;
}
m_SelectedModel = model;
scene.Render();
}
return;
}
}
//
// Unselect previous model
//
if (m_SelectedModel != null)
{
m_SelectedModel.Color = Color.Red;
m_SelectedModel = null;
scene.Render();
}
|
|
Zoom to a particular marker in a batch
[C#] |
---|
Array selectedMarkerCartesianPosition = null;
//
// Get a collection of picked objects under the mouse location.
// The collection is sorted with the closest object at index zero.
//
IAgStkGraphicsPickResultCollection collection = scene.Pick(mouseX, mouseY);
if (collection.Count != 0)
{
IAgStkGraphicsObjectCollection objects = collection[0].Objects;
IAgStkGraphicsMarkerBatchPrimitive batchPrimitive = objects[0] as IAgStkGraphicsMarkerBatchPrimitive;
//
// Was a marker in our marker batch picked?
//
if (batchPrimitive == m_MarkerBatch)
{
//
// Get the index of the particular marker we picked
//
IAgStkGraphicsBatchPrimitiveIndex markerIndex = objects[1] as IAgStkGraphicsBatchPrimitiveIndex;
//
// Get the position of the particular marker we picked
//
Array markerCartographic = markerPositions[markerIndex.Index];
IAgPosition markerPosition = root.ConversionUtility.NewPositionOnEarth();
markerPosition.AssignPlanetodetic(
(double)markerCartographic.GetValue(0),
(double)markerCartographic.GetValue(1),
(double)markerCartographic.GetValue(2));
double x, y, z;
markerPosition.QueryCartesian(out x, out y, out z);
selectedMarkerCartesianPosition = new object[] { x, y, z };
}
}
IAgStkGraphicsSceneManager manager = ((IAgScenario)root.CurrentScenario).SceneManager;
IList positions = new List();
positions.Add(new object[] {39.88, -75.25, 3000.0 });
positions.Add(new object[] {38.85, -77.04, 3000.0 });
positions.Add(new object[] {38.85, -77.04, 0.0 });
positions.Add(new object[] {29.98, -90.25, 0.0 });
positions.Add(new object[] {37.37, -121.92, 0.0 });
Array positionsArray = Array.CreateInstance(typeof(object), positions.Count * 3);
for (int i = 0; i < positions.Count; ++i)
{
Array position = positions[i];
position.CopyTo(positionsArray, i * 3);
}
IAgStkGraphicsMarkerBatchPrimitive markerBatch = manager.Initializers.MarkerBatchPrimitive.Initialize();
markerBatch.Texture = manager.Textures.LoadFromStringUri(
markerFile);
markerBatch.SetCartographic("Earth", ref positionsArray);
// Save the positions of the markers for use in the pick event
markerPositions = positions;
// Enable per item picking
markerBatch.PerItemPickingEnabled = true;
manager.Primitives.Add((IAgStkGraphicsPrimitive)markerBatch);
|
|
Change model colors within a rectangular region
[C#] |
---|
IAgStkGraphicsSceneManager manager = ((IAgScenario)root.CurrentScenario).SceneManager;
//
// Get a collection of picked objects in a 100 by 100 rectangular region.
// The collection is sorted with the closest object at index zero.
//
List newModels = new List();
IAgStkGraphicsPickResultCollection collection = scene.PickRectangular(mouseX - 50, mouseY + 50, mouseX + 50, mouseY - 50);
foreach (IAgStkGraphicsPickResult pickResult in collection)
{
IAgStkGraphicsObjectCollection objects = pickResult.Objects;
IAgStkGraphicsCompositePrimitive composite = objects[0] as IAgStkGraphicsCompositePrimitive;
//
// Was a model in our composite picked?
//
if (composite == m_Models)
{
IAgStkGraphicsModelPrimitive model = objects[1] as IAgStkGraphicsModelPrimitive;
//
// Selected Model
//
((IAgStkGraphicsPrimitive)model).Color = Color.Cyan;
newModels.Add(model);
}
}
//
// Reset color of models that were previous selected but were not in this pick.
//
foreach (IAgStkGraphicsModelPrimitive selectedModel in SelectedModels)
{
if (!newModels.Contains(selectedModel))
{
((IAgStkGraphicsPrimitive)selectedModel).Color = Color.Red;
}
}
SelectedModels = newModels;
manager.Render();
|
|
Zoom to a model on double click
[C#] |
---|
IAgStkGraphicsPrimitive selectedModel = null;
//
// Get a collection of picked objects under the mouse location.
// The collection is sorted with the closest object at index zero.
//
IAgStkGraphicsPickResultCollection collection = scene.Pick(mouseX, mouseY);
if (collection.Count != 0)
{
IAgStkGraphicsObjectCollection objects = collection[0].Objects;
IAgStkGraphicsCompositePrimitive composite = objects[0] as IAgStkGraphicsCompositePrimitive;
//
// Was a model in our composite picked?
//
if (composite == m_Models)
{
selectedModel = objects[1] as IAgStkGraphicsPrimitive;
}
}
|
|
Change a model's color on mouse over
[Visual Basic .NET] |
---|
'
' Get a collection of picked objects under the mouse location.
' The collection is sorted with the closest object at index zero.
'
Dim collection As IAgStkGraphicsPickResultCollection = scene.Pick(mouseX, mouseY)
If collection.Count <> 0 Then
Dim objects As IAgStkGraphicsObjectCollection = collection(0).Objects
Dim composite As IAgStkGraphicsCompositePrimitive = TryCast(objects(0), IAgStkGraphicsCompositePrimitive)
'
' Was a model in our composite picked?
'
If composite Is m_Models Then
Dim model As IAgStkGraphicsPrimitive = TryCast(objects(1), IAgStkGraphicsPrimitive)
'
' Selected Model
'
model.Color = Color.Cyan
If model IsNot m_SelectedModel Then
'
' Unselect previous model
'
If m_SelectedModel IsNot Nothing Then
m_SelectedModel.Color = Color.Red
End If
m_SelectedModel = model
scene.Render()
End If
Return
End If
End If
'
' Unselect previous model
'
If m_SelectedModel IsNot Nothing Then
m_SelectedModel.Color = Color.Red
m_SelectedModel = Nothing
scene.Render()
|
|
Zoom to a particular marker in a batch
[Visual Basic .NET] |
---|
Dim selectedMarkerCartesianPosition As Array = Nothing
'
' Get a collection of picked objects under the mouse location.
' The collection is sorted with the closest object at index zero.
'
Dim collection As IAgStkGraphicsPickResultCollection = scene.Pick(mouseX, mouseY)
If collection.Count <> 0 Then
Dim objects As IAgStkGraphicsObjectCollection = collection(0).Objects
Dim batchPrimitive As IAgStkGraphicsMarkerBatchPrimitive = TryCast(objects(0), IAgStkGraphicsMarkerBatchPrimitive)
'
' Was a marker in our marker batch picked?
'
If batchPrimitive Is m_MarkerBatch Then
'
' Get the index of the particular marker we picked
'
Dim markerIndex As IAgStkGraphicsBatchPrimitiveIndex = TryCast(objects(1), IAgStkGraphicsBatchPrimitiveIndex)
'
' Get the position of the particular marker we picked
'
Dim markerCartographic As Array = markerPositions(markerIndex.Index)
Dim markerPosition As IAgPosition = root.ConversionUtility.NewPositionOnEarth()
markerPosition.AssignPlanetodetic(CDbl(markerCartographic.GetValue(0)), CDbl(markerCartographic.GetValue(1)), CDbl(markerCartographic.GetValue(2)))
Dim x As Double, y As Double, z As Double
markerPosition.QueryCartesian(x, y, z)
selectedMarkerCartesianPosition = New Object() {x, y, z}
End If
End If
Dim manager As IAgStkGraphicsSceneManager = DirectCast(root.CurrentScenario, IAgScenario).SceneManager
Dim positions As IList(Of Array) = New List(Of Array)()
positions.Add(New Object() {39.88, -75.25, 3000.0})
positions.Add(New Object() {38.85, -77.04, 3000.0})
positions.Add(New Object() {38.85, -77.04, 0.0})
positions.Add(New Object() {29.98, -90.25, 0.0})
positions.Add(New Object() {37.37, -121.92, 0.0})
Dim positionsArray As Array = Array.CreateInstance(GetType(Object), positions.Count * 3)
For i As Integer = 0 To positions.Count - 1
Dim position As Array = positions(i)
position.CopyTo(positionsArray, i * 3)
Next
Dim markerBatch As IAgStkGraphicsMarkerBatchPrimitive = manager.Initializers.MarkerBatchPrimitive.Initialize()
markerBatch.Texture = manager.Textures.LoadFromStringUri( _
markerFile)
markerBatch.SetCartographic("Earth", positionsArray)
' Save the positions of the markers for use in the pick event
markerPositions = positions
' Enable per item picking
markerBatch.PerItemPickingEnabled = True
manager.Primitives.Add(DirectCast(markerBatch, IAgStkGraphicsPrimitive))
|
|
Change model colors within a rectangular region
[Visual Basic .NET] |
---|
Dim manager As IAgStkGraphicsSceneManager = DirectCast(root.CurrentScenario, IAgScenario).SceneManager
'
' Get a collection of picked objects in a 100 by 100 rectangular region.
' The collection is sorted with the closest object at index zero.
'
Dim newModels As New List(Of IAgStkGraphicsModelPrimitive)()
Dim collection As IAgStkGraphicsPickResultCollection = scene.PickRectangular(mouseX - 50, mouseY + 50, mouseX + 50, mouseY - 50)
For Each pickResult As IAgStkGraphicsPickResult In collection
Dim objects As IAgStkGraphicsObjectCollection = pickResult.Objects
Dim composite As IAgStkGraphicsCompositePrimitive = TryCast(objects(0), IAgStkGraphicsCompositePrimitive)
'
' Was a model in our composite picked?
'
If composite Is m_Models Then
Dim model As IAgStkGraphicsModelPrimitive = TryCast(objects(1), IAgStkGraphicsModelPrimitive)
'
' Selected Model
'
DirectCast(model, IAgStkGraphicsPrimitive).Color = Color.Cyan
newModels.Add(model)
End If
Next
'
' Reset color of models that were previous selected but were not in this pick.
'
For Each selectedModel As IAgStkGraphicsModelPrimitive In SelectedModels
If Not newModels.Contains(selectedModel) Then
DirectCast(selectedModel, IAgStkGraphicsPrimitive).Color = Color.Red
End If
Next
SelectedModels = newModels
|
|
Zoom to a model on double click
[Visual Basic .NET] |
---|
Dim selectedModel As IAgStkGraphicsPrimitive = Nothing
'
' Get a collection of picked objects under the mouse location.
' The collection is sorted with the closest object at index zero.
'
Dim collection As IAgStkGraphicsPickResultCollection = scene.Pick(mouseX, mouseY)
If collection.Count <> 0 Then
Dim objects As IAgStkGraphicsObjectCollection = collection(0).Objects
Dim composite As IAgStkGraphicsCompositePrimitive = TryCast(objects(0), IAgStkGraphicsCompositePrimitive)
'
' Was a model in our composite picked?
'
If composite Is m_Models Then
selectedModel = TryCast(objects(1), IAgStkGraphicsPrimitive)
End If
|
|
See Also