1.距离和角度:
<html>
<head>
<title>Coordinates 1</title>
<object id="SGWorld" classid="CLSID:3a4f91b1-65a8-11d5-85c1-0001023952c1" style="visibility:hidden;height:0 "></object>
<script type="text/javascript">
var popup = null;
function Init()
{
// defining two coordinates
var coord1 = SGWorld.Creator.CreatePosition(-71.07542, 42.34930, 232.0); // The Hancock building
var coord2 = SGWorld.Creator.CreatePosition(-71.05507, 42.35561, 105.0); // Target building
// Placing some annotation on the terrain
SGWorld.Creator.CreateTextLabel(coord1, "Hancock Building",SGWorld.Creator.CreateLabelStyle());
SGWorld.Creator.CreateTextLabel(coord2, "Building 2",SGWorld.Creator.CreateLabelStyle());
SGWorld.Creator.CreatePolyline(SGWorld.Creator.GeometryCreator.CreateLineStringGeometry([coord1, coord2]), SGWorld.Creator.CreateColor(255, 255, 0), 0, 0, "line");
// Set a good view point for the scene
SGWorld.Navigate.SetPosition(SGWorld.Creator.CreatePosition(-71.07802, 42.33974, 550.0,0, 34, -13));
// Calculating the distance and angles from the Hancock building to building #2
var distance = coord1.DistanceTo(coord2);
var angles = coord1.AimTo(coord2);
// Display a message to the user
popup = SGWorld.Creator.CreatePopupMessage("Coordinate sample","",0,0,450,120);
popup.InnerText = "The aerial distance between the roofs of the\r\nHancock building and building #2 is " + Math.floor(distance) + " Meters\r\n\r\n" +
"The aiming angles from the Hancock building to building #2 are:\r\nyaw: " + angles.Yaw.toFixed(5) + " pitch: " + angles.Pitch.toFixed(5);
popup.Align = "TopLeft";
SGWorld.Window.ShowPopup(popup);
}
function Uninit()
{
if(SGWorld.Project.Name == "")
return;
if(popup)
SGWorld.Window.RemovePopup(popup);
}
</script>
</head>
<body onload="Init();" onunload="Uninit()">
</body>
</html>
<head>
<title>Coordinates 1</title>
<object id="SGWorld" classid="CLSID:3a4f91b1-65a8-11d5-85c1-0001023952c1" style="visibility:hidden;height:0 "></object>
<script type="text/javascript">
var popup = null;
function Init()
{
// defining two coordinates
var coord1 = SGWorld.Creator.CreatePosition(-71.07542, 42.34930, 232.0); // The Hancock building
var coord2 = SGWorld.Creator.CreatePosition(-71.05507, 42.35561, 105.0); // Target building
// Placing some annotation on the terrain
SGWorld.Creator.CreateTextLabel(coord1, "Hancock Building",SGWorld.Creator.CreateLabelStyle());
SGWorld.Creator.CreateTextLabel(coord2, "Building 2",SGWorld.Creator.CreateLabelStyle());
SGWorld.Creator.CreatePolyline(SGWorld.Creator.GeometryCreator.CreateLineStringGeometry([coord1, coord2]), SGWorld.Creator.CreateColor(255, 255, 0), 0, 0, "line");
// Set a good view point for the scene
SGWorld.Navigate.SetPosition(SGWorld.Creator.CreatePosition(-71.07802, 42.33974, 550.0,0, 34, -13));
// Calculating the distance and angles from the Hancock building to building #2
var distance = coord1.DistanceTo(coord2);
var angles = coord1.AimTo(coord2);
// Display a message to the user
popup = SGWorld.Creator.CreatePopupMessage("Coordinate sample","",0,0,450,120);
popup.InnerText = "The aerial distance between the roofs of the\r\nHancock building and building #2 is " + Math.floor(distance) + " Meters\r\n\r\n" +
"The aiming angles from the Hancock building to building #2 are:\r\nyaw: " + angles.Yaw.toFixed(5) + " pitch: " + angles.Pitch.toFixed(5);
popup.Align = "TopLeft";
SGWorld.Window.ShowPopup(popup);
}
function Uninit()
{
if(SGWorld.Project.Name == "")
return;
if(popup)
SGWorld.Window.RemovePopup(popup);
}
</script>
</head>
<body onload="Init();" onunload="Uninit()">
</body>
</html>
2.位置和方向:
<html>
<head>
<title>Coordinates 1</title>
<object id="SGWorld" classid="CLSID:3a4f91b1-65a8-11d5-85c1-0001023952c1" style="visibility:hidden;height:0 "></object>
<script type="text/javascript">
var popup = null;
function Init()
{
// defining two coordinates
var coord1 = SGWorld.Creator.CreatePosition(-71.07542, 42.34930, 232.0);
var coord2 = SGWorld.Creator.CreatePosition(-71.05507, 42.35561, 105.0);
// Placing some annotation on the terrain
SGWorld.Creator.CreateTextLabel(coord1, "Hancock Building",SGWorld.Creator.CreateLabelStyle());
SGWorld.Creator.CreateTextLabel(coord2, "Building 2",SGWorld.Creator.CreateLabelStyle());
var pos = coord1.AimTo(coord2);
SGWorld.Navigate.SetPosition(pos);
// Display a message to the user
popup = SGWorld.Creator.CreatePopupMessage("Coordinate sample");
popup.innerText = "This sample shows how to place the camera at a specific position\r\nwhile aiming it to a desired point of interest";
popup.align = "TopLeft";
SGWorld.Window.ShowPopup(popup);
}
function Uninit()
{
if(SGWorld.Project.Name == "")
return;
if(popup)
SGWorld.Window.RemovePopup(popup);
}
</script>
</head>
<body onload="Init();" onunload="Uninit()">
</body>
</html>
<head>
<title>Coordinates 1</title>
<object id="SGWorld" classid="CLSID:3a4f91b1-65a8-11d5-85c1-0001023952c1" style="visibility:hidden;height:0 "></object>
<script type="text/javascript">
var popup = null;
function Init()
{
// defining two coordinates
var coord1 = SGWorld.Creator.CreatePosition(-71.07542, 42.34930, 232.0);
var coord2 = SGWorld.Creator.CreatePosition(-71.05507, 42.35561, 105.0);
// Placing some annotation on the terrain
SGWorld.Creator.CreateTextLabel(coord1, "Hancock Building",SGWorld.Creator.CreateLabelStyle());
SGWorld.Creator.CreateTextLabel(coord2, "Building 2",SGWorld.Creator.CreateLabelStyle());
var pos = coord1.AimTo(coord2);
SGWorld.Navigate.SetPosition(pos);
// Display a message to the user
popup = SGWorld.Creator.CreatePopupMessage("Coordinate sample");
popup.innerText = "This sample shows how to place the camera at a specific position\r\nwhile aiming it to a desired point of interest";
popup.align = "TopLeft";
SGWorld.Window.ShowPopup(popup);
}
function Uninit()
{
if(SGWorld.Project.Name == "")
return;
if(popup)
SGWorld.Window.RemovePopup(popup);
}
</script>
</head>
<body onload="Init();" onunload="Uninit()">
</body>
</html>
3.移动指向位置:
<html>
<head>
<title>Coordinates 1</title>
<object id="SGWorld" classid="CLSID:3a4f91b1-65a8-11d5-85c1-0001023952c1" style="visibility:hidden;height:0 "></object>
<script type="text/javascript">
var popup = null;
var coord1, coord2, pos, distance;
var time;
function Init()
{
SGWorld.AttachEvent("OnFrame", onFrame);
time = new Date().getTime();
// defining two coordinates
coord1 = SGWorld.Creator.CreatePosition(-71.07542, 42.34930, 232.0);
coord2 = SGWorld.Creator.CreatePosition(-71.05507, 42.35561, 105.0);
// Placing some annotation on the terrain
SGWorld.Creator.CreateTextLabel(coord1, "Hancock Building",SGWorld.Creator.CreateLabelStyle());
SGWorld.Creator.CreateTextLabel(coord2, "Building 2",SGWorld.Creator.CreateLabelStyle());
distance = coord1.DistanceTo(coord2);
pos = coord1.AimTo(coord2);
// Set the start position at the top of the Hancock building
SGWorld.Navigate.SetPosition(pos);
// Display a message to the user
popup = SGWorld.Creator.CreatePopupMessage("Coordinate sample");
popup.InnerText = "This sample shows how to move a coordinate toward another coordinate";
popup.Align = "TopLeft";
SGWorld.Window.ShowPopup(popup);
}
function onFrame()
{
var elapsedTime = (new Date().getTime() - time) / 1000 // elapsed time in seconds
time = new Date().getTime();
pos = pos.MoveToward(coord2, 200*elapsedTime); // 200 meters/sec
var newDist = pos.DistanceTo(coord2);
if (newDist > distance)
{
// Stop condition. if we are here, then we have passed building 2
SGWorld.DetachEvent("OnFrame", onFrame);
return;
}
SGWorld.Navigate.SetPosition(pos);
distance = newDist;
}
function Uninit()
{
if(SGWorld.Project.Name == "")
return;
if(popup)
SGWorld.Window.RemovePopup(popup);
}
</script>
</head>
<body onload="Init();" onunload="Uninit()">
</body>
</html>
<head>
<title>Coordinates 1</title>
<object id="SGWorld" classid="CLSID:3a4f91b1-65a8-11d5-85c1-0001023952c1" style="visibility:hidden;height:0 "></object>
<script type="text/javascript">
var popup = null;
var coord1, coord2, pos, distance;
var time;
function Init()
{
SGWorld.AttachEvent("OnFrame", onFrame);
time = new Date().getTime();
// defining two coordinates
coord1 = SGWorld.Creator.CreatePosition(-71.07542, 42.34930, 232.0);
coord2 = SGWorld.Creator.CreatePosition(-71.05507, 42.35561, 105.0);
// Placing some annotation on the terrain
SGWorld.Creator.CreateTextLabel(coord1, "Hancock Building",SGWorld.Creator.CreateLabelStyle());
SGWorld.Creator.CreateTextLabel(coord2, "Building 2",SGWorld.Creator.CreateLabelStyle());
distance = coord1.DistanceTo(coord2);
pos = coord1.AimTo(coord2);
// Set the start position at the top of the Hancock building
SGWorld.Navigate.SetPosition(pos);
// Display a message to the user
popup = SGWorld.Creator.CreatePopupMessage("Coordinate sample");
popup.InnerText = "This sample shows how to move a coordinate toward another coordinate";
popup.Align = "TopLeft";
SGWorld.Window.ShowPopup(popup);
}
function onFrame()
{
var elapsedTime = (new Date().getTime() - time) / 1000 // elapsed time in seconds
time = new Date().getTime();
pos = pos.MoveToward(coord2, 200*elapsedTime); // 200 meters/sec
var newDist = pos.DistanceTo(coord2);
if (newDist > distance)
{
// Stop condition. if we are here, then we have passed building 2
SGWorld.DetachEvent("OnFrame", onFrame);
return;
}
SGWorld.Navigate.SetPosition(pos);
distance = newDist;
}
function Uninit()
{
if(SGWorld.Project.Name == "")
return;
if(popup)
SGWorld.Window.RemovePopup(popup);
}
</script>
</head>
<body onload="Init();" onunload="Uninit()">
</body>
</html>
4.朝着某个对象移动:
<html>
<head>
<title>Coordinates 1</title>
<object id="SGWorld" classid="CLSID:3a4f91b1-65a8-11d5-85c1-0001023952c1" style="visibility:hidden;height:0 "></object>
<script type="text/javascript">
var popup = null;
var coordHancock, pos;
var time;
function Init()
{
SGWorld.AttachEvent("OnFrame", onFrame);
setTimeout(function () { SGWorld.DetachEvent("OnFrame", onFrame); }, 15000);
time = new Date().getTime();
coordHancock = SGWorld.Creator.CreatePosition(-71.07542, 42.34930, 232.0);
SGWorld.Creator.CreateTextLabel(coordHancock, "Hancock Building",SGWorld.Creator.CreateLabelStyle());
pos = SGWorld.Creator.CreatePosition(-71.10055, 42.31624, 350.0,0, 15.0); // x,y,height,height_type,yaw
SGWorld.Navigate.SetPosition(pos);
// Display a message to the user
popup = SGWorld.Creator.CreatePopupMessage("Coordinate sample");
popup.InnerText = "This sample shows how you can move a coordinate in one direction while aiming to another";
popup.Align = "TopLeft";
SGWorld.Window.ShowPopup(popup);
}
function onFrame()
{
var elapsedTime = (new Date().getTime() - time) / 1000 // elapsed time in seconds
time = new Date().getTime();
pos = pos.Move(400*elapsedTime, 15.0, 0.0).AimTo(coordHancock); // 400 meters/sec
SGWorld.Navigate.SetPosition(pos);
}
function Uninit()
{
if(SGWorld.Project.Name == "")
return;
if(popup)
SGWorld.Window.RemovePopup(popup);
}
</script>
</head>
<body onload="Init();" onunload="Uninit()">
</body>
</html>
<head>
<title>Coordinates 1</title>
<object id="SGWorld" classid="CLSID:3a4f91b1-65a8-11d5-85c1-0001023952c1" style="visibility:hidden;height:0 "></object>
<script type="text/javascript">
var popup = null;
var coordHancock, pos;
var time;
function Init()
{
SGWorld.AttachEvent("OnFrame", onFrame);
setTimeout(function () { SGWorld.DetachEvent("OnFrame", onFrame); }, 15000);
time = new Date().getTime();
coordHancock = SGWorld.Creator.CreatePosition(-71.07542, 42.34930, 232.0);
SGWorld.Creator.CreateTextLabel(coordHancock, "Hancock Building",SGWorld.Creator.CreateLabelStyle());
pos = SGWorld.Creator.CreatePosition(-71.10055, 42.31624, 350.0,0, 15.0); // x,y,height,height_type,yaw
SGWorld.Navigate.SetPosition(pos);
// Display a message to the user
popup = SGWorld.Creator.CreatePopupMessage("Coordinate sample");
popup.InnerText = "This sample shows how you can move a coordinate in one direction while aiming to another";
popup.Align = "TopLeft";
SGWorld.Window.ShowPopup(popup);
}
function onFrame()
{
var elapsedTime = (new Date().getTime() - time) / 1000 // elapsed time in seconds
time = new Date().getTime();
pos = pos.Move(400*elapsedTime, 15.0, 0.0).AimTo(coordHancock); // 400 meters/sec
SGWorld.Navigate.SetPosition(pos);
}
function Uninit()
{
if(SGWorld.Project.Name == "")
return;
if(popup)
SGWorld.Window.RemovePopup(popup);
}
</script>
</head>
<body onload="Init();" onunload="Uninit()">
</body>
</html>
5.以上效果叠加:
<html>
<head>
<title>Coordinates 5</title>
<object id="SGWorld" classid="CLSID:3a4f91b1-65a8-11d5-85c1-0001023952c1" style="visibility:hidden;height:0 "></object>
<script type="text/javascript" src="abspath.js"></script>
<script type="text/javascript">
var popup = null;
var model = null;
var labelF16 = null;
var yaw = 45.0;
var totalTime = 0;
function Init()
{
SGWorld.AttachEvent("OnFrame", onFrame);
setTimeout(function () { SGWorld.DetachEvent("OnFrame", onFrame); }, 10000); // remove event handler after 10 seconds
time = new Date().getTime();
model = SGWorld.Creator.CreateModel(SGWorld.Creator.CreatePosition(-71.10055, 42.31624, 125.0,0, 28), toAbspath("data/f16.xpc"), 1);
labelF16 = SGWorld.Creator.CreateTextLabel(SGWorld.Creator.CreatePosition(0, 0), "F-16",SGWorld.Creator.CreateLabelStyle());
// Display a message to the user
popup = SGWorld.Creator.CreatePopupMessage("Coordinate sample");
popup.InnerText = "This sample shows how, by manipulating coordinates, you can create a complex scene\r\n" +
"In this sample you can see how to:\r\n" +
"1. Move an object (F16)\r\n" +
"2. Make another object, a label in this case, to follow the first object\r\n" +
"3. Make the camera follow the first object while circling it";
popup.Align = "TopLeft";
SGWorld.Window.ShowPopup(popup);
}
function onFrame() // elapsedTime is the time in seconds elapsed from the previous frame
{
var elapsedTime = (new Date().getTime() - time) / 1000 // elapsedTime is the time in seconds elapsed from the previous frame
time = new Date().getTime();
var modelPos = model.Position;
modelPos.Roll = modelPos.Roll + 4.5;
modelPos = modelPos.Move(700 * elapsedTime, modelPos.Yaw, modelPos.Pitch); // move the object in its current direction at a speed of 700 m/s
if (totalTime > 6)
modelPos.Pitch += 20*elapsedTime; // increase pitch by 20 degree per sec
model.Position = modelPos;
// Make the label object to be positioned 40 meters above (pitch = 90) the first object
labelF16.Position = modelPos.Move(40.0, 0.0, 90.0);
// Move the camera in relation to the first object while looking at it.
yaw += 40.0*elapsedTime; // increase yaw by 40 degree per sec
var cameraPos = modelPos.Move(700, yaw, 5).AimTo(modelPos);
cameraPos.Roll = 0; // plane is rolling, but we do not want the camera to use this roll, so we zero it.
SGWorld.Navigate.SetPosition(cameraPos);
totalTime += elapsedTime;
}
function Uninit()
{
if(SGWorld.Project.Name == "")
return;
if(popup)
SGWorld.Window.RemovePopup(popup);
}
</script>
</head>
<body onload="Init();" onunload="Uninit()">
</body>
</html>
<head>
<title>Coordinates 5</title>
<object id="SGWorld" classid="CLSID:3a4f91b1-65a8-11d5-85c1-0001023952c1" style="visibility:hidden;height:0 "></object>
<script type="text/javascript" src="abspath.js"></script>
<script type="text/javascript">
var popup = null;
var model = null;
var labelF16 = null;
var yaw = 45.0;
var totalTime = 0;
function Init()
{
SGWorld.AttachEvent("OnFrame", onFrame);
setTimeout(function () { SGWorld.DetachEvent("OnFrame", onFrame); }, 10000); // remove event handler after 10 seconds
time = new Date().getTime();
model = SGWorld.Creator.CreateModel(SGWorld.Creator.CreatePosition(-71.10055, 42.31624, 125.0,0, 28), toAbspath("data/f16.xpc"), 1);
labelF16 = SGWorld.Creator.CreateTextLabel(SGWorld.Creator.CreatePosition(0, 0), "F-16",SGWorld.Creator.CreateLabelStyle());
// Display a message to the user
popup = SGWorld.Creator.CreatePopupMessage("Coordinate sample");
popup.InnerText = "This sample shows how, by manipulating coordinates, you can create a complex scene\r\n" +
"In this sample you can see how to:\r\n" +
"1. Move an object (F16)\r\n" +
"2. Make another object, a label in this case, to follow the first object\r\n" +
"3. Make the camera follow the first object while circling it";
popup.Align = "TopLeft";
SGWorld.Window.ShowPopup(popup);
}
function onFrame() // elapsedTime is the time in seconds elapsed from the previous frame
{
var elapsedTime = (new Date().getTime() - time) / 1000 // elapsedTime is the time in seconds elapsed from the previous frame
time = new Date().getTime();
var modelPos = model.Position;
modelPos.Roll = modelPos.Roll + 4.5;
modelPos = modelPos.Move(700 * elapsedTime, modelPos.Yaw, modelPos.Pitch); // move the object in its current direction at a speed of 700 m/s
if (totalTime > 6)
modelPos.Pitch += 20*elapsedTime; // increase pitch by 20 degree per sec
model.Position = modelPos;
// Make the label object to be positioned 40 meters above (pitch = 90) the first object
labelF16.Position = modelPos.Move(40.0, 0.0, 90.0);
// Move the camera in relation to the first object while looking at it.
yaw += 40.0*elapsedTime; // increase yaw by 40 degree per sec
var cameraPos = modelPos.Move(700, yaw, 5).AimTo(modelPos);
cameraPos.Roll = 0; // plane is rolling, but we do not want the camera to use this roll, so we zero it.
SGWorld.Navigate.SetPosition(cameraPos);
totalTime += elapsedTime;
}
function Uninit()
{
if(SGWorld.Project.Name == "")
return;
if(popup)
SGWorld.Window.RemovePopup(popup);
}
</script>
</head>
<body onload="Init();" onunload="Uninit()">
</body>
</html>