| Topic | Description |
|---|---|
| Default Camera Behavior | The 3D control automatically provides rotating and zooming. |
| Viewing Parameters | The viewer's position, direction and up vectors. |
| Viewing Central Bodies | ViewCentralBody zooms so an entire central body is visible. |
| Viewing Extents | ViewExtent zooms to a rectangular extent on the globe. |
| General Viewing | View and ViewDirection provide direct control over the viewer's position, direction, and up vector. |
| Untethered Viewing | ViewUntethered allows the user to move freely in space. |
With no effort on your part, the 3D control automatically provides rotating and zooming in a 3D scene using the mouse.
- Hold down the left mouse button and move the mouse to rotate.
- Hold down the right mouse button and move to zoom in and out. Zooming uses a logarithmic scale; as the viewer approaches the viewed object, the zooming speed slows down.
- Hold down the shift key and the left mouse button and move to change the view direction without changing the viewer position.
- Hold down control and the left mouse button and move to lock horizontal movement so you can rotate vertically without accidentally changing your horizontal axis.
- Hold down alt and the left mouse button and move to lock vertical movement.
The 3D control also provides the ZoomIn method. Once executed, the next time the user clicks the left mouse button, they can move out a box on the screen. The camera then zooms to the rectangular extent on the globe under the box.
The camera, AgGxCamera, provides full control over the viewer's position and orientation. These are defined by three primary parameters:
- Viewer Position – The position of the virtual viewer in the 3D scene.
- Direction – A unit length vector indicating the direction the viewer is looking.
- Up – A unit length vector indicating the orientation of the viewer. Informally, this can be thought of as how the viewer's head is tilted.
The viewer's position can be retrieved in any reference frame using the camera's GetPosition method. Similarly, the direction and up vectors can be retrieved in any axes using GetDirection and GetUp, respectively. The following example retrieves the position in the earth's fixed frame and the direction and up vectors in the earth's fixed axes.
IAgGxCamera camera = scene.Camera; IAgGxReferenceFrame fixedFrame = earth.FixedFrame; IAgGxConstantCartesian viewer = camera.GetPosition(fixedFrame); IAgGxConstantCartesian direction = camera.GetDirection(fixedFrame.Axes); IAgGxConstantCartesian up = camera.GetUp(fixedFrame.Axes);
ViewCentralBody is used to set the viewer's position so an entire central body is visible. The view direction is set so the viewer is looking toward the center of the central body. ViewCentralBody is commonly used to restore a default view or view different central bodies as shown below.
IAgGxCentralBody moon = sceneManager.CentralBodies("Moon");
scene.Camera.ViewCentralBody(moon, moon.InertialFrame.Axes);
scene.Draw();
The second parameter to ViewCentralBody defines the axes of rotation. When the user holds down the left mouse button and moves, this is the axes the viewer is rotated around.
ViewExtent zooms to a rectangular extent on the globe. In the HowTo, this is used to set the camera such that an entire image inlay is visible. After executing ViewExtent, the camera is in an east-north-up axes: x points toward local east, y points toward local north, and z points along the surface normal. The camera is looking straight down at the extent; the camera's up vector is local north (y) and the camera's direction is opposite of the surface normal (-z). To achieve a more 3-dimensional view, call SetPositionAzimuthElevation after ViewExtent as shown below.
IAgGxCamera camera = scene.Camera; camera.ViewExtent(earth, 0, 0, Trig.DegreesToRadians(1), Trig.DegreesToRadians(1)); camera.SetPositionAzimuthElevation( Trig.DegreesToRadians(45), // azimuth Trig.DegreesToRadians(25)); // elevation scene.Draw();
|
|
|
Azimuth is an angle from the positive x axis, in this case local east, to rotate around z. Elevation is an angle to rotate from the xy plane toward z.
In the rotation axes used by the camera after a ViewExtent, an azimuth of 90 degrees is looking south, and an azimuth of 0 is looking west. An elevation of 90 degrees is looking straight down, and an elevation of 0 is looking toward the horizon.
View and ViewDirection are used for general purpose viewing. They provide direct control over the viewer's position, direction, and up vector, as opposed to ViewCentralBody and ViewExtent, which set these parameters implicitly. The following example, views from one point to another point.
EarthCentralBody earth = CentralBodiesFacet.GetFromContext().Earth; PointCartographic viewerPosition = new PointCartographic(earth, new Cartographic(Trig.DegreesToRadians(-77.04), Trig.DegreesToRadians(36.85), 100000)); PointCartographic referencePoint = new PointCartographic(earth, new Cartographic(Trig.DegreesToRadians(-77.04), Trig.DegreesToRadians(38.85), 0)); Axes axes = new AxesEastNorthUp(earth, referencePoint); IAgGxAxes gxAxes = DGLTypeConverter.CreateAxes(axes); IAgGxPoint gxViewerPosition = DGLTypeConverter.CreatePoint(viewerPosition); IAgGxPoint gxReferencePoint = DGLTypeConverter.CreatePoint(referencePoint); IAgGxCartesian up = new AgGxCartesian(); up.Set(0, 1, 0); scene.Camera.ConstrainedUpAxis = AgGxConstrainedUpAxis.ConstrainedUpAxisNegativeZ; scene.Camera.View(gxViewerPosition, gxReferencePoint, up as IAgGxConstantCartesian, gxAxes); scene.Draw();
DGL is used to create a view position and a reference point – the point the viewer will look at. Next an axes of rotation is created using east-north-up axes, similar to the axes created by ViewExtent. The DGL types are converted to Insight3D types and then the view is set.
Use SetPositionRadius to ensure a primitive is visible. Retrieve the primitive's bounding sphere using GetBoundingSphere. Use the camera's View method with the reference point equal to the sphere's center position. Then call SetPositionRadius with the sphere's radius to move the viewer's position back so the entire sphere, and thus the primitive, is visible.
Untethered viewing allows the user to move freely in space. The view is not constrained along a direction.
- Hold down the left mouse button and move to change the view direction. This is similar to a pilot looking out of a cockpit.
- Hold down the right mouse button and move to change the viewer position.
- Hold down the shift key and left mouse button and move to pan left, right, up, or down.
ViewUntethered is used for untethered viewing. It is similar to the View method. In addition, it takes a zooming speed in meters per second.
Cartographic position = new Cartographic(Trig.DegreesToRadians(-95.25), Trig.DegreesToRadians(39.88), 2500000); EarthCentralBody earth = CentralBodiesFacet.GetFromContext().Earth; PointCartographic origin = new PointCartographic(earth, position); Axes axes = new AxesEastNorthUp(earth, origin); Vector direction = new VectorFixed(axes, new Cartesian(0, 0, -1)); // View down IAgGxAxes gxAxes = DGLTypeConverter.CreateAxes(axes); IAgGxPoint gxOrigin = DGLTypeConverter.CreatePoint(origin); IAgGxVector gxVector = DGLTypeConverter.CreateVector(direction); IAgGxCartesian up = new AgGxCartesian(); up.Set(0, 1, 0); // North scene.Camera.ViewUntethered(gxOrigin, gxVector, up as IAgGxConstantCartesian, gxAxes, 400000); scene.Draw();