This topic describes how to control the camera in Insight3D, which determines which objects are visible in the scene.
By default, 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 camera 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 camera 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 Zooming property. When this property is set to true, the next time the user drags using the left mouse button, a box will be drawn on the screen. When complete, the camera will then zoom to the rectangular extent on the globe under the box.
Camera provides full control over the camera's position and orientation. These are defined by three primary parameters:
Camera Position – The position of the virtual camera in the 3D scene.
Direction – A unit length vector indicating the direction the camera is looking.
Up Vector – A unit length vector indicating the orientation of the camera. Informally, this can be thought of as how the camera's head is tilted.
The camera's position can be retrieved using the camera's Position property. The position is defined in the PositionReferenceFrame. Similarly, the direction and up vectors can be retrieved using Direction and UpVector properties. They are returned in the camera's Axes. The following example converts the position to the Earth's fixed frame and rotates the direction and up vectors to the Earth's fixed axes:
Camera camera = Scene.Camera; CentralBody earth = CentralBodiesFacet.GetFromContext().Earth; // Create ReferenceFrameEvaluator that converts a Cartesian from the // Camera's reference frame to Earth's Fixed Frame ReferenceFrameEvaluator evaluator = GeometryTransformer.GetReferenceFrameTransformation(camera.PositionReferenceFrame, earth.FixedFrame); // Convert the position to Earth's Fixed Frame Cartesian positionInFixed = evaluator.Evaluate(SceneManager.Time).Transform(camera.Position); // Get the UnitQuaternion that rotates the Camera's Axes to Earth's Fixed Axes. UnitQuaternion rotation = GeometryTransformer.GetAxesTransformation(camera.Axes, earth.FixedFrame.Axes).Evaluate(SceneManager.Time); // Rotate the Direction and UpVector to Earth's Fixed Axes UnitCartesian direction = camera.Direction.Rotate(rotation); UnitCartesian up = camera.UpVector.Rotate(rotation);
The ViewCentralBody method sets the camera's position and direction so an entire central body is visible, with the camera looking toward the center of the central body. This method is commonly used as a default view or to switch between different central bodies, as shown below:
CentralBody moon = CentralBodiesFacet.GetFromContext().Moon; Scene.Camera.ViewCentralBody(moon, moon.InertialFrame.Axes); Scene.Render();
The second parameter defines the axes of rotation. When the user holds down the left mouse button and moves, this is the axes the camera is rotated around.
The ViewExtent method zooms to a rectangular extent on the globe. In the HowTo, this is used to set the camera such that an entire image overlay is visible. After calling 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).
Camera camera = Scene.Camera; camera.ViewExtent(CentralBodiesFacet.GetFromContext().Earth, new CartographicExtent(0, 0, Trig.DegreesToRadians(1), Trig.DegreesToRadians(1))); Cartesian offset = new Cartesian(new AzimuthElevationRange(Trig.DegreesToRadians(45), Trig.DegreesToRadians(-25), camera.Distance)); camera.Position = camera.ReferencePoint.Add(offset); Scene.Render();
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 viewing an extent, 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.
The View and ViewDirection methods are used for general purpose viewing. They provide direct control over the camera's position, direction, and up vector, unlike ViewCentralBody and ViewExtent, which set these parameters implicitly. The following example views one Point from 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); UnitCartesian up = new UnitCartesian(0, 1, 0); Scene.Camera.ConstrainedUpAxis = ConstrainedUpAxis.NegativeZ; Scene.Camera.View(axes, viewerPosition, referencePoint, up); Scene.Render();
We create a viewer position and a reference point – the point the camera will look at. Next, an axes of rotation is created using east-north-up axes, similar to the axes created by ViewExtent. The camera will evaluate the points at the current Time and position the Camera accordingly. To improve efficiency, the camera caches the evaluator for each point. If the evaluator becomes invalid, for example, if the definition of a point changes, then RefreshEvaluators must be called.