Model Primitive
The model primitive can load and render AGI's MDL models. MDL is the 3D model format used by STK. Models can be downloaded from AGI's website.
Models can be initialized as shown below:
The orientation of the model depends on the model itself. For example, in the hellfire.mdl model, the missile is laid out lengthwise along the positive x axis. To change the orientation, use the Orientation property and provide an IAgOrientation that defines the rotation from the model's local axes to the axes of the reference frame in which the model's position is defined. In this case, the model's position is defined in the central body's fixed frame. A convenient way to compute the orientation is shown below:
[C#] | ![]() |
|
---|---|---|
|
A topographic axes is created based on the model's position where the x axis points in the local north direction, the y axis points in the local east direction and the z axis points in the local down direction. An IAgOrientation that defines the rotation from these axes to the fixed frame axes is created. To point the model in the local up direction, the IAgOrientation is modified to rotate an extra 90 degrees around the y axis.
Like orientation, the size of the model depends on the model itself. To change the size of the model, use the Scale property. After a model is initialized, its position can be changed with Position.
See the Video Streams on Models overview for more information.
Model Articulations
The model primitive supports model articulations, which allow different parts of the model to be rotated, scaled, and/or translated. If the model supports articulations, they can be accessed through the ModelPrimitive'sArticulations property.
An example of how to modify a model's articulations is shown below.
The model primitive without modifying the spin ModelTransformation of the propeller's ModelArticulation:
The same model with the spin of the propellers modified to be 135 degrees:
[C#] | ![]() |
|
---|---|---|
|
The Articulations property of the ModelPrimitive is an instance of ModelArticulationCollection. ModelArticulationCollection contains a collection of ModelArticulations. ModelArticulation contains a collection of ModelTransformations. Both the ModelArticulationCollection and ModelArticulation classes accept an integer index to access its values. Use the ModelTransformation.CurrentValue property to set the value of the transformation as shown in the code above. The Type of transformation can also be retrieved using the ModelTransformation.Type property which returns a value of the ModelTransformationType enumeration.
Within your shader code, you have access to scene data that is useful for shading your model. We refer to these as Preset Uniforms because they are accessed as uniform variables in your vertex or fragment shader. These variables must be declared as uniforms and then can be used. Here is an example using STK Engine's animation time to move a vertex.
[GLSL] | ![]() |
|
---|---|---|
|
Preset Uniform | Type | Description |
---|---|---|
agi_ActiveLights | bool[gl_MaxLights] | Light i is active if agi_ActiveLights[i] is true and inactive if false. Light properties can be accessed through gl_LightSources. |
agi_CameraPosition | vec3 | Position of the camera relative to the model's reference frame. |
agi_CentralBodyDepthTexture0, agi_CentralBodyDepthTexture1, ..., agi_CentralBodyDepthTexture7 |
sampler2D | A texture that contains the depth values after rendering the Central Body. The number binds the texture to a particular texture unit. See example image below. |
agi_LightingEnabled | float | 1 if lighting is enabled and 0 otherwise |
agi_LODGeometricToleranceOverDistance | float | When multiplied by the distance from the vertex or fragment to the viewer, the result is the geometric error in world space. |
agi_LODNegativeGeometricToleranceOverDistance | float | Negative of agi_LODGeometricToleranceOverDistance |
agi_ModelViewMatrix | mat4 | Modelview matrix |
agi_ModelViewMatrixRelativeToCameraPosition | mat4 | Modelview matrix relative to the camera position |
agi_ModelViewMatrixRelativeToPrimitiveCenter | mat4 | Modelview matrix relative to the model's center |
agi_ModelViewProjectionMatrix | mat4 | Modelview projection matrix |
agi_ModelViewProjectionMatrixRelativeToCameraPosition | mat4 | Modelview projection matrix relative to the camera position |
agi_ModelViewProjectionMatrixRelativeToPrimitiveCenter | mat4 | Modelview projection matrix relative to the model's center |
agi_OrthographicProjectionMatrix | mat4 | Orthographic projection matrix |
agi_PerspectiveProjectionMatrix | mat4 | Perspective projection matrix |
agi_PrimitiveBoundingSphere | vec4 | The model's bounding sphere relative to the model's reference frame. The structure is xyz components are the position and w is the radius in meters. |
agi_PrimitiveBoundingSphereRelativeToCameraPosition | vec4 | The model's bounding sphere relative to the camera position. The structure is xyz components are the position and w is the radius in meters. |
agi_PrimitiveColor | vec4 | The color of the primitive |
agi_SnapshotPixelScale | float | Scale for when rendering high resolution snap shots. Otherwise it is 1. |
agi_TerrainSilhouetteTexture0, agi_TerrainSilhouetteTexture1, ..., agi_TerrainSilhouetteTexture7 |
sampler2D | A texture that contains the silhouette of the terrain. The number binds the texture to a particular texture unit. See example image below. |
agi_Time | float | Number of seconds since the time specified to StartTime property. |
agi_Viewport | vec4 | The viewport in the format (left, bottom, width, height) |
![]() |
![]() |
Central Body rendered normally | Central Body Depth Texture |
![]() |
Example of Terrain Silhouette Texture |
Resources
GLSL Specification
GLSL Tutorial
BRDF explanation and examples