AGI Components with Insight3D Alpha 2008 r8
Dynamic Updates

Primitives support dynamic updates to their position or vertices via Set and SetPartial methods.

Primitives that are defined by a single position, such as AgGxPrimitiveModel, provide SetPosition and SetPositionCartographic methods, which are called to change the primitive's position. Primitives that are defined by a list of vertices, such as AgGxPrimitivePolyline and AgGxPrimitivePointBatch, provide both Set and SetPartial methods to update either all of their vertices or a subset of them.

Use a Set method to update all of the vertices in a primitive. The primitive's old vertices will be replaced with the vertices passed to Set. The code below shows how to update a polyline with SetFromSurfacePoints. Perhaps the polyline represents a range ring around an object. When the object moves, the range ring needs to also move, so all of its vertices are updated.

CopyC#
IAgGxPointsCircle circlePts = new AgGxPointsCircle();
circlePts.InitializeCartographic(earth, latitude, longitude, altitude, 30000);
line.SetFromSurfacePoints(circlePts);
Tip: If you plan on calling a Set method frequently initialize the primitive with VertexUpdateSet as described in the Vertex Update Performance Overview.

Use a SetPartial method to update a subset of vertices in a primitive. For example, if one point batch primitive represents thousands of objects and only a few dozen move at a time, use SetPartial to update just those vertices instead of calling Set to update all of the vertices. To call SetPartial, the primitive must be initialized with VertexUpdateSetPartial. See the Vertex Update Performance Overview.

SetPartial takes an array of doubles, where every three elements define the x, y, and z coordinates for a vertex. In addition, SetPartial also takes an array of indices that maps the corresponding vertex from the vertices array to a vertex already in the primitive. The following example creates a point batch with 10 vertices then updates 4 of the vertices with SetPartial.

CopyC#
double[] originalVertices = new double[]
{
    6500000, 0, 0,      // v0
    6600000, 0, 0,      // v1
    6700000, 0, 0,      // v2
    6800000, 0, 0,      // v3
    6900000, 0, 0,      // v4
    7000000, 0, 0,      // v5
    7100000, 0, 0,      // v6
    7200000, 0, 0,      // v7
    7300000, 0, 0,      // v8
    7400000, 0, 0       // v9
};
Array aryOriginalVertices = originalVertices;

IAgGxPrimitivePointBatch batch = new AgGxPrimitivePointBatch();
batch.Initialize(earth,
    AgGxReferenceFrame.ReferenceFrameFixed,
    AgGxVertexUpdate.VertexUpdateSetPartial,
    ref aryOriginalVertices);
batch.PixelSize = 5;
sceneManager.Primitives.Add(batch);

// 
// Modify 4 vertices with SetPartial
// 
double[] newVertices = new double[]
{
    8000000, 0, 0,      // u0
    8100000, 0, 0,      // u1
    8200000, 0, 0,      // u2
    8300000, 0, 0       // u3
};
Array aryNewVertices = newVertices;

int[] indices = new int[] { 3, 6, 8, 9 };
Array aryIndices = indices;

batch.SetPartial(ref aryNewVertices, ref aryIndices,
    AgGxIndicesOrder.IndicesOrderSortedAscending);

The indices allow random access updates to vertices in the primitives. The indices do not need to be consecutive nor do they need to be sorted. Although if you can easily provide vertices sorted in ascending order, pass IndicesOrderSortedAscending for best performance.