6.2 IPlane5
主要用来控制相机(三维场景观察点)的坐标位置、角度、速度等参数;提供实现飞行定位和浏览缩放的操作方法;
Speed |
设置飞行速度,可用GetSpeed方法来获取速度; |
FieldOfView |
相机视域范围; |
FlyTo |
飞行到某一位置; |
SetPosition |
设置跳转到视角的位置; |
MovePosition |
设置移动到视角的位置; |
GetPosition |
获取当前视角的位置; |
FlyToObject |
飞行到某一对象; |
SetSpeed |
设置相机速度; |
GetSpeed |
获取相机的速度; |
Zoom |
缩放操作; |
GetPositionEx |
获取相机的位置和方向; |
代码示例:
【C#】
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using TerraExplorerX;
namespace ExCodeIPlane
{
public partial class Form1 : Form
{
private TerraExplorer TE;
private ITerraExplorer51 TE51;
private IPlane5 IPlane;
public Form1()
{
InitializeComponent();
this.TE = new TerraExplorerClass();
this.IPlane = (IPlane5)TE;
this.TE51 = (ITerraExplorer51)TE;
TE51.Load(Application.StartupPath + "\\Default.fly");
}
private void btnFlyTo_Click(object sender, EventArgs e)
{
new Random().Next(1,36);
Random rd = new Random(DateTime.Now.Millisecond);
IPlane.FlyTo(128 + 2 * rd.Next(0, 10), 36 + 2 * rd.Next(0, 10), 1111111, 1000000, 0, -89, "FlyToLocation");
}
private void btnZoom_Click(object sender, EventArgs e)
{
object dX, dH, dY, dYaw, dPitch, dRoll, dcYaw, dcPitch;
IPlane.GetPosition(out dX, out dY, out dH, out dYaw, out dPitch, out dRoll, out dcYaw, out dcPitch);
if (Convert.ToDouble(dH) > 100000)
{
IPlane.Zoom(Convert.ToDouble(dH) / 100);
}
else
{
IPlane.Zoom(Convert.ToDouble(dH) * 100);
}
}
}
}
【javascript】
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="IPlane5.aspx.cs" Inherits="ExCode_IPlane5" %>
<!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 runat="server">
<title>Skyline二次开发教程【配套示例】</title>
<script type ="text/javascript">
function Init() {
var TE = _$SGCreateTEObj();
var ITerraExplorer = TE.interface("ITerraExplorer51");
ITerraExplorer.Load("D:\\2010售前演示系统\\WPFA-DEMO\\WPFA-DEMO\\bin\\Debug\\FLY\\Default.fly");
}
//缩放
function ZoomFlyTo() {
var IPlane = TE.interface("IPlane5");
var myparam = new _$SGWorldParam();
GetPosition(myparam);
if (myparam.h > 100000) {
IPlane.Zoom(myparam.h / 100);
}
else {
IPlane.Zoom(myparam.h * 100);
}
}
//定位
function RadomFlyTo() {
var IPlane = TE.interface("IPlane5");
IPlane.FlyTo(128 + 20 * Math.random(), 36 + 20 * Math.random(), 1111111, 1000000, 0, -89, "FlyToLocation");
}
//------------------------------------------------------------
// 创建三维对象 赵贺 2009.01.25.
//------------------------------------------------------------
function _$SGCreateTEObj() {
var obj = window.document.getElementById("TE");
if (obj == null) {
obj = document.createElement('object');
document.body.appendChild(obj);
obj.name = "TE";
obj.id = "TE";
obj.classid = "CLSID:3a4f9191-65a8-11d5-85c1-0001023952c1";
}
return obj;
}
//------------------------------------------------------------
// 定义集合参数 赵贺 2009.01.25.
//------------------------------------------------------------
function _$SGWorldParam() {
this.x = 0;
this.y = 0;
this.h = 0;
this.yaw = 0;
this.pitch = 0;
this.roll = 0;
this.OID = 0;
this.OType = 0;
}
</script>
<script type ="text/vbscript">
'------------------------------------------------------------
' IPlane GetPosition 赵贺 2009.01.25.
'------------------------------------------------------------
sub GetPosition(param)
Dim dx,dy,dh,dyaw,dpitch,droll,dcyaw,dcpitch
Dim IPlane
Set IPlane = TE.interface("IPlane5")
IPlane.GetPosition dx,dy,dh,dyaw,dpitch,droll,dcyaw,dcpitch
param.x = dx
param.y = dy
param.h = dh
param.yaw = dyaw+dcyaw
param.pitch = dpitch+dcpitch
param.roll = droll
param = dh
end sub
</script>
</head>
<body onload = "Init()">
<form id="form1" runat="server">
<div id = "Title">
<input id="Button1" type="button" value="缩放" onclick = "ZoomFlyTo()" />
<input id="Button2" type="button" value="定位" onclick = "RadomFlyTo()" />
</div>
<div id="Main">
<object id="TerraExplorer3DWindow" classid="CLSID:3a4f9192-65a8-11d5-85c1-0001023952c1"
width="521" height="521">
</object>
</div>
</form>
</body>
</html>