SkylineGlobe7.0.1版本 通过鼠标左右平移模型对象

时间:2021-10-19 21:43:17

帮同事写了一段测试代码,如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>MoveObject</title> <script type = "text/javascript" language = "javascript">
function Init() {
try{
var SGWorld = new CreateSGObj();
SGWorld.Open("C:\\Users\\Administrator\\Desktop\\a.FLY");
}
catch (e)
{ }
} function MoveObject()
{
var SGWorld = new CreateSGObj();
SGWorld.AttachEvent("OnLButtonDown", OnLButtonDown);
SGWorld.AttachEvent("OnRButtonDown", OnRButtonDown);
} var sobj = null;
function OnLButtonDown(Flags, X, Y)
{
var SGWorld = CreateSGObj();
var CursorCoord = SGWorld.Window.pixelToWorld(X, Y, 1);//第三个参数设置为1,表示鼠标点选对象的时候,只选择Model类型的对象
if (CursorCoord.ObjectID == null || CursorCoord.ObjectID=="")
return false;
var obj = SGWorld.Creator.GetObject(CursorCoord.ObjectID);
var opos = obj.Position.Copy();
var campos = SGWorld.Navigate.GetPosition(3);
var tpos = obj.Position.Move(100, campos.Yaw+90, 0);//将当前模型对象位置向右侧平移100米
tpos.Yaw = opos.Yaw;
obj.Position = tpos;
} function OnRButtonDown(Flags, X, Y) {
var SGWorld = CreateSGObj();
var CursorCoord = SGWorld.Window.pixelToWorld(X, Y, 1);
if (CursorCoord.ObjectID == null || CursorCoord.ObjectID == "")
return false;
var obj = SGWorld.Creator.GetObject(CursorCoord.ObjectID);
var opos = obj.Position.Copy();
var campos = SGWorld.Navigate.GetPosition(3);
var tpos = obj.Position.Move(100, campos.Yaw - 90, 0);//将当前模型对象位置向左侧平移100米
tpos.Yaw = opos.Yaw;
obj.Position = tpos;
return true;
} // SGWorld701
function CreateSGObj() {
try {
var obj = document.getElementById("SGWorld");
if (obj == null) {
obj = document.createElement('object');
obj.setAttribute("name", "SGWorld");
obj.setAttribute("id", "SGWorld");
obj.style.height = "1px";
obj.style.width = "1px";
obj.setAttribute("classid", "CLSID:3A4F919C-65A8-11D5-85C1-0001023952C1");
document.body.appendChild(obj);
}
return obj;
}
catch (e) {
alert(e);
}
}
</script>
</head>
<body onload="Init();" >
<table style="margin: 0px; border: 0px;">
<tr>
<td colspan="4">
<input id="Button1" type="button" value="button" onclick="MoveObject()" />
</td>
</tr>
</table>
<object id="TerraExplorerInformationWindow" classid="CLSID:3a4f9193-65a8-11d5-85c1-0001023952c1" style="width: 19%; height: 560px;"></object>
<object id="TerraExplorer3DWindow" classid="CLSID:3a4f9192-65a8-11d5-85c1-0001023952c1" style="width: 80%; height: 560px;"></object>
</body>
</html>