Geometry

The first thing that most people want to do when playing with the 3D control is add some stuff to the world. The most straightforward way to do this is via the Geometry Manager, accessible from Host.Geometry. You can modify any of the samples to contain this code, most easily in the Activate function of a plug-in or OnLoad for SimpleForm.

      Host.Geometry.AddGeometry(new PushpinGeometry(

      "My Layer", "My Id",

      LatLonAlt.CreateUsingDegrees(-47.6435, 112.1422, 100.0),

      PushpinInfo.Default));

This creates a default pin on top of Microsoft Building 116 in Redmond, WA, just in case you were wondering where that is. The first two parameters are just identifiers. You can use Layers to group items together, but it's not required. The two strings together just have to be unique. The third parameter is the position of the pin in Latitude, Longitude, Altitude. Here we’re using degrees in WGS84, and meters for the altitude.

Let me digress on units for a moment. Notice that latitude, which is the “Y” component of the coordinate, comes first. This is a long-standing convention when specifying geographic coordinates, but for our purposes is somewhat arbitrary. In other contexts, for example when we use a Coordinate2D struct, which is a more general-use structure not tied to a specific coordinate system, we’ll follow the mathematical convention of “X” first. Also, values of latitude and longitude are technically angles (from the equator and around the polar axis, respectively). When dealing with angles in computers it is convenient to store them as radians, which is how most trigonometric functions deal with them. However, degrees are usually easier to think about. So here we create the structure explicitly in degrees to reduce confusion. If you ever have trouble with your pushpin not appearing, the first thing to check is the order of your values and their units. We use meters for distances and altitudes, but the exact meaning of altitude can change depending on what AltitudeMode you are associating with the geometry.

Back to the pushpin, next we’ll want to change how it appears. If you pull the PushpinInfo.Default object into a local variable, you can then modify the various provided values, leaving others as they are.

      PushpinInfo info = PushpinInfo.Default;

      info.Resource = https://kristoffer.members.winisp.net/VE3D/jewel.png;

      info.OrientationMode = PushpinOrientationMode.UseProvided;

      info.Orientation = new Orientation(new RollPitchYaw(

      0.0,

      20 * Constants.RadiansPerDegree,

      45 * Constants.RadiansPerDegree));

      Host.Geometry.AddGeometry(new PushpinGeometry(

      "My Layer", "My Id",

      LatLonAlt.CreateUsingDegrees(47.6435, -122.1422, 10.0),

      info));

In this case we’ve added a pretty logo over the same building rather than using the default orange pin, and told it to use a specific orientation instead of always facing the camera. Roll/Pitch/Yaw (RPY) is in degrees, but we can convert using some constants. Think of the image as a face, with the nose pointing straight out of the middle of it. If you supply a RPY of (0, 0, 0) the face will point north, toward the horizon, with the head level. Rolling will be like tilting the head sideways towards the shoulders, pitch is like looking up and down, and yaw is looking side to side. In this case, we are looking slightly up and to the northwest. You can combine the values with values from the camera to get interesting effects by setting OrientationMode. AltitudeMode is set here, to control the exact meaning of the altitude component of its position.

The two other basic types of geometry are PolylineGeometry and PolygonGeometry. Their setup is similar, except that you will provide arrays of LatLonAlt values. There are also two distinct categories of each, those that are drawn on the ground and those drawn in the air.

Host.Geometry.AddGeometry(new PolygonGeometry(

      "My Layer", "My Poly",

      null,

      new LatLonAlt[] {

      LatLonAlt.CreateUsingDegrees(47.6435, -122.1422, 0.0),

      LatLonAlt.CreateUsingDegrees(47.645, -122.1422, 0.0),

      LatLonAlt.CreateUsingDegrees(47.645, -122.1412, 0.0),

      LatLonAlt.CreateUsingDegrees(47.6435, -122.1412, 0.0) },

      PolygonGeometry.PolygonFormat.Polygon2D,

      PolyInfo.DefaultPolyline));

The Format parameter specifies what type they should be, and altitude values will be ignored for 2D versions (note: LineList2D is currently not supported, but the rest all have their uses). The third parameter here is a “tag”, which is something that can be used when your user is interacting with your objects via the mouse. In the Geometry sample you can see some of these ideas (and a few other things) in play.