2.5.2 视点获取及定位


视点获取及定位

包括四个小功能,分别是视点获取、飞行定位(目标点)、飞行定位(观察点)和定向观察。

  1. 视点获取是指获取当前场景相机的相关参数信息,包括:相机目标点、观察点、旋转角、俯仰角、视点到目标点距离五个参数。具体方法可见: 视点获取
  2. 飞行定位(目标点)功能是指模拟飞行的方式,在一定时间内飞到目标点位置。飞行定位需要设定目标点坐标、旋转角、俯仰角、到目标点的距离和飞行时间5个参数。具体方法可见: 飞行定位(目标点)
  3. 飞行定位(观察点)功能是指模拟飞行的方式,在一定时间内飞到观察点位置。飞行定位需要设定目标点坐标、旋转角、俯仰角、到目标点的距离和飞行时间5个参数。具体方法可见: 飞行定位(观察点)
  4. 定向观察功能是指通过两个坐标点来确定场景相机的位置和观察方向。它是以第一个点为观察点,第二个点为目标点,并以Y轴作为向上方向来设定观察相机的位置的。具体方法可见: 定向观察

代码调用示例

Javascript调用

//Html部分代码
目标经度<input id="focalPosX" type="number" value="">
目标纬度<input id="focalPosY" type="number" value="">
目标高度<input id="focalPosZ" type="number" value=""><br>
视点经度<input id="eyePosX" type="number" value="">
视点纬度<input id="eyePosY" type="number" value="">
视点高度<input id="eyePosZ" type="number" value=""><br>
方位旋转角<input id="azimuth" type="number" value="">
垂直俯仰角<input id="pitch" type="number" value="">
视点与目标点距离<input id="range" type="number" value="">
飞行时间<input id="time" type="number" value="3">
<input id="Button0" type="button" value="获取当前视点" onclick="getViewPoint()" />
<input id="Button1" type="button" value="飞行定位(目标点)" onclick="flyToDest()" />
<input id="Button1" type="button" value="飞行定位(观察点)" onclick="flyToCamera()" />
<input id="Button2" type="button" value="定向观察" onclick="srcToDest()" />
//JS代码
var navigation = map.CreateNavigation();//创建导航接口对象
var focalPosXObj = document.getElementById("focalPosX");
var focalPosYObj = document.getElementById("focalPosY");
var focalPosZObj = document.getElementById("focalPosZ");
var eyePosXObj = document.getElementById("eyePosX");
var eyePosYObj = document.getElementById("eyePosY");
var eyePosZObj = document.getElementById("eyePosZ");
var azimuthObj = document.getElementById("azimuth");
var pitchObj = document.getElementById("pitch");
var rangeObj = document.getElementById("range");
var timeObj = document.getElementById("time");

//获取视点信息
function getViewPoint(){
    var info = navigation.GetViewpoint();//获取当前视点信息
    var infoMap = info.split(";");
    var geoPos = infoMap[0].substring(infoMap[0].indexOf(':') + 1, infoMap[0].length);
    var focalMap = geoPos.split(","); 
    focalPosXObj.value = focalMap[0];
    focalPosYObj.value = focalMap[1];
    focalPosZObj.value = focalMap[2];

    var eyePos = infoMap[1].substring(infoMap[1].indexOf(':') + 1, infoMap[1].length);
    var eyeMap = eyePos.split(",");
    eyePosXObj.value = eyeMap[0];
    eyePosYObj.value = eyeMap[1];
    eyePosZObj.value = eyeMap[2];

    var azimuth = infoMap[2].substring(infoMap[2].indexOf(':') + 1, infoMap[2].length);
    azimuthObj.value = azimuth;
    var pitch = infoMap[3].substring(infoMap[3].indexOf(':') + 1, infoMap[3].length);
    pitchObj.value = pitch;
    var range = infoMap[4].substring(infoMap[4].indexOf(':') + 1, infoMap[4].length);
    rangeObj.value = range;
}

//飞行定位(目标点)
function flyToDest(){
    var desP = map.CreatePosition(focalPosXObj.value, focalPosYObj.value, focalPosZObj.value);//创建坐标对象 
    navigation.FlyToDest(desP, azimuthObj.value, pitchObj.value, rangeObj.value, timeObj.value);//飞行定位(目标点)。坐标、旋转角、俯仰角、距离、飞行时间
}

//飞行定位(观察点)
function flyToCamera(){
    var desP = map.CreatePosition(eyePosXObj.value, eyePosYObj.value, eyePosZObj.value);//创建坐标对象 
    navigation.FlyToCamera(desP, azimuthObj.value, pitchObj.value, rangeObj.value, timeObj.value);//飞行定位(观察点)。坐标、旋转角、俯仰角、距离、飞行时间
}
//定向观察
function srcToDest(){
    var srcPos = map.CreatePosition(eyePosXObj.value, eyePosYObj.value, eyePosZObj.value);//创建坐标对象 
    var destPos = map.CreatePosition(focalPosXObj.value, focalPosYObj.value, focalPosZObj.value);//创建坐标对象 
    navigation.LocateByEyeToCenter(srcPos, destPos);//从起始坐标到目的坐标观察
}

C++调用

NavigationCOMLib::INavigatePtr navigation;//导航接口对象
CEdit focalPosXObj;//目标经度
CEdit focalPosYObj;//目标纬度
CEdit focalPosZObj;//目标高度
CEdit eyePosXObj;//视点经度
CEdit eyePosYObj;//视点纬度
CEdit eyePosZObj;//视点高度
CEdit azimuthObj;//方位旋转角
CEdit pitchObj;//垂直俯仰角
CEdit rangeObj;//视点与目标点距离
DOUBLE focalPosX;//目标经度获取值
DOUBLE focalPosY;//目标纬度获取值
DOUBLE focalPosZ;//目标高度获取值
DOUBLE eyePosX;//视点经度获取值
DOUBLE eyePosY;//视点纬度获取值
DOUBLE eyePosZ;//视点高度获取值
DOUBLE azimuth;//方位旋转角获取值
DOUBLE pitch;//垂直俯仰角获取值
DOUBLE range;//视点与目标点距离获取值
//获取输入框内容
void Cf4c1ViewPointDlg::getEditValue()
{
    CString m_paramname;
    focalPosXObj.GetWindowText(m_paramname);
    focalPosX = _ttof(m_paramname);
    focalPosYObj.GetWindowText(m_paramname);
    focalPosY = _ttof(m_paramname);
    focalPosZObj.GetWindowText(m_paramname);
    focalPosZ = _ttof(m_paramname);
    eyePosXObj.GetWindowText(m_paramname);
    eyePosX = _ttof(m_paramname);
    eyePosYObj.GetWindowText(m_paramname);
    eyePosY = _ttof(m_paramname);
    eyePosZObj.GetWindowText(m_paramname);
    eyePosZ = _ttof(m_paramname);
    azimuthObj.GetWindowText(m_paramname);
    azimuth = _ttof(m_paramname);
    pitchObj.GetWindowText(m_paramname);
    pitch = _ttof(m_paramname);
    rangeObj.GetWindowText(m_paramname);
    range = _ttof(m_paramname);
}

//获取视点信息
void Cf4c1ViewPointDlg::OnBnClickedgetviewpoint()
{
    std::string info = navigation->GetViewpoint();//获取当前视点信息
    std::vector<std::string> infoMap,focalMap,eyeMap;
    SplitString(info,infoMap,";");
    std::string geoPos = infoMap[0].substr(infoMap[0].find(":")+1,infoMap[0].size());
    SplitString(geoPos,focalMap,",");
    _bstr_t t = focalMap[0].c_str();
    focalPosXObj.SetWindowText(t);
    t = focalMap[1].c_str();
    focalPosYObj.SetWindowText(t);
    t = focalMap[2].c_str();
    focalPosZObj.SetWindowText(t);

    std::string eyePos = infoMap[1].substr(infoMap[1].find(":")+1,infoMap[1].size());
    SplitString(eyePos,eyeMap,",");
    t = eyeMap[0].c_str();
    eyePosXObj.SetWindowText(t);
    t = eyeMap[1].c_str();
    eyePosYObj.SetWindowText(t);
    t = eyeMap[2].c_str();
    eyePosZObj.SetWindowText(t);

    std::string azimuth = infoMap[2].substr(infoMap[2].find(":")+1,infoMap[2].size());
    t = azimuth.c_str();
    azimuthObj.SetWindowText(t);

    std::string pitch = infoMap[3].substr(infoMap[3].find(":")+1,infoMap[3].size());
    t = pitch.c_str();
    pitchObj.SetWindowText(t);

    std::string range = infoMap[4].substr(infoMap[4].find(":")+1,infoMap[4].size());
    t = range.c_str();
    rangeObj.SetWindowText(t);

}

//飞行定位(目标点)
void Cf4c1ViewPointDlg::OnBnClickedflytodest()
{
    getEditValue();
    BaseObjectCOMLib::IPositionPtr desP = map->CreatePosition(focalPosX, focalPosY, focalPosZ);//创建坐标对象 
    navigation->FlyToDest(desP, azimuth, pitch, range, 3);//飞行定位(目标点)。坐标、旋转角、俯仰角、距离、飞行时间
}
//飞行定位(观察点)
void Cf4c1ViewPointDlg::OnBnClickedflytocamera()
{
    getEditValue();
    BaseObjectCOMLib::IPositionPtr desP = map->CreatePosition(eyePosX, eyePosY, eyePosZ);//创建坐标对象 
    navigation->FlyToCamera(desP, azimuth, pitch, range, 3);//飞行定位(观察点)。坐标、旋转角、俯仰角、距离、飞行时间
}

//定向观察
void Cf4c1ViewPointDlg::OnBnClickedsrctodest()
{
    BaseObjectCOMLib::IPositionPtr srcPos = map->CreatePosition(eyePosX, eyePosY, eyePosZ);//创建坐标对象 
    BaseObjectCOMLib::IPositionPtr destPos = map->CreatePosition(focalPosX, focalPosY, focalPosZ);//创建坐标对象 
    navigation->LocateByEyeToCenter(srcPos, destPos);//从起始坐标到目的坐标观察
}

void  Cf4c1ViewPointDlg::SplitString(const std::string& s,std::vector<std::string>& v,const std::string& c)
{
    std::string::size_type pos1,pos2;
    pos2 = s.find(c);
    pos1 = 0;
    while(std::string::npos !=pos2)
    {
        v.push_back(s.substr(pos1,pos2-pos1));
        pos1 = pos2 + c.size();
        pos2= s.find(c,pos1);
    }
    if(pos1 !=s.length())
    {
        v.push_back(s.substr(pos1));
    }
}

C#调用

INavigate navigation;//导航接口对象 
navigation = map.CreateNavigation();//创建导航接口对象
//获取视点信息
private void getViewPoint_Click(object sender, EventArgs e)
{
    var info = navigation.GetViewpoint();//获取当前视点信息
    var infoMap = info.Split(';');
    var geoPos = infoMap[0].Substring(infoMap[0].IndexOf(':') + 1);
    var focalMap = geoPos.Split(',');
    textBox1.Text = focalMap[0];
    textBox2.Text = focalMap[1];
    textBox3.Text = focalMap[2];

    var eyePos = infoMap[1].Substring(infoMap[1].IndexOf(':') + 1);
    var eyeMap = eyePos.Split(',');
    textBox4.Text = eyeMap[0];
    textBox5.Text = eyeMap[1];
    textBox6.Text = eyeMap[2];

    var azimuth = infoMap[2].Substring(infoMap[2].IndexOf(':') + 1);
    textBox8.Text = azimuth;
    var pitch = infoMap[3].Substring(infoMap[3].IndexOf(':') + 1);
    textBox7.Text = pitch;
    var range = infoMap[4].Substring(infoMap[4].IndexOf(':') + 1);
    textBox10.Text = range;
    textBox9.Text = "3";
}
//飞行定位(目标点)
private void flyToDest_Click(object sender, EventArgs e)
{
    var desP = map.CreatePosition(double.Parse(textBox1.Text), double.Parse(textBox2.Text), double.Parse(textBox3.Text));//创建坐标对象 
    navigation.FlyToDest(desP, double.Parse(textBox8.Text), double.Parse(textBox7.Text), double.Parse(textBox10.Text), double.Parse(textBox9.Text));//飞行定位(目标点)。坐标、旋转角、俯仰角、距离、飞行时间
}
//飞行定位(观察点)
private void flyToCamera_Click(object sender, EventArgs e)
{
    var desP = map.CreatePosition(double.Parse(textBox4.Text), double.Parse(textBox5.Text), double.Parse(textBox6.Text));//创建坐标对象 
    navigation.FlyToCamera(desP, double.Parse(textBox8.Text), double.Parse(textBox7.Text), double.Parse(textBox10.Text), double.Parse(textBox9.Text));//飞行定位(观察点)。坐标、旋转角、俯仰角、距离、飞行时间
}
//定向观察
private void srcToDest_Click(object sender, EventArgs e)
{
    var srcPos = map.CreatePosition(double.Parse(textBox4.Text), double.Parse(textBox5.Text), double.Parse(textBox6.Text));//创建坐标对象 
    var destPos = map.CreatePosition(double.Parse(textBox1.Text), double.Parse(textBox2.Text), double.Parse(textBox3.Text));//创建坐标对象 
    navigation.LocateByEyeToCenter(srcPos, destPos);//从起始坐标到目的坐标观察
}

results matching ""

    No results matching ""