Controlling the Camera

TerraExplorer allows the client application to set and retrieve the camera position via its INavigate66 interface. There are several typical scenarios in which this interface is needed:

Getting the current position of the camera

In this scenario the client needs to know where the TerraExplorer user is currently located in the 3D World in order to perform a task. An example for this might be a client HTML page with a button that, when pressed, gives the user directions to the closest movie theater or other points of interest. In this scenario, the client should use the INavigate66 interface to call the GetPosition method:

 

var pos = SGWorld.Navigate.GetPosition();

 

Jumping to a new location

In this scenario, the client application prompts the camera to jump to a new position in the 3D World. In this example the client application should create the position using the ICreator66 interface and then call the INavigate66.SetPosition method:

 

var pos = SGWorld.Creator.CreatePosition(-71.05216, // X

                                                       42.34569, // Y

                                                       1000,     // Altitude

                                                       0, //AltitudeTypeCode.ATC_TERRAIN_RELATIVE, // Altitude type

                                                       0.0,      // Yaw

                                                      -43.0);     // Pitch

SGWorld.Navigate.SetPosition(pos);

 

Flying to a new location

A destination location can be a specific position in the 3D World or the current coordinates of locations or objects in the project. To fly to a specific position, the client application should create the position using the ICreator66 interface and call the FlyTo method. To fly to the current position of a location or object, the client application should pass the object to the FlyTo method:

 

var circle = SGWorld.Creator.CreateCircle(SGWorld.Creator.CreatePosition(-71.00864, 42.36229,0,2), 

1000.0,  SGWorld.Creator.CreateColor(0, 0, 0, 0), SGWorld.Creator.CreateColor(200, 50, 50, 128) );

circle.Position.Distance = 3000;// The camera will look at the object from a distance of 3000 meters

SGWorld.Navigate.FlyTo(circle);

Dynamically controlling the position of the camera in each frame

This is the most advanced technique for controlling the camera. In this scenario, the client application might need to move the camera position in each frame as a dependency in other inputs. There are two steps the client application needs to follow:

1.       Using the _ISGWorld66Events.OnFrame event handler – TerraExplorer sends this event before it is about to render a new frame. The client application can use this opportunity to move the plane to a new position.

2.       In the event handler routine, call INavigate66.SetPosition.

Note: This solution does not work well with scripted languages because of a severe performance penalty.

 

SGWorld.AttachEvent("onFrame", onFrame);

function onFrame()

{

            var pos = SGWorld.Navigate.GetPosition();

            pos.X += 0.5;

            pos.Y -= 0.2;

            SGWorld.Navigate.SetPosition(pos);                       

}