博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SuperMap iClient3D for WebGL教程-orientation
阅读量:4160 次
发布时间:2019-05-26

本文共 2016 字,大约阅读时间需要 6 分钟。

作者:桔子

本文同步更新于简书文章https://www.jianshu.com/p/98b24e06d981

本节教程来讲解entity的一个重要属性-orientation,直译过来是方向,小编更喜欢称之为姿态。也就是说实体放到场景中的的形态。在一些应用场景中,需要调整实体对象的方向,尤其是模型对象,需要设置初始方向。
姿态
在这之前需要了解下三维球上控制对象姿态的参数,heading、pitch、roll。
headingpitchroll
pitch是围绕X轴旋转,也叫做俯仰角。
heading是围绕Y轴旋转,也叫偏航角。
roll是围绕Z轴旋转,也叫翻滚角。
orientation属性设置的值类型为Quaternion四元数,由x、y、z、w分量构成,其中w分量为时间分量,这节课程先不涉及。通过空间x、y、z上不用的分量值,控制实体对象在空间中的姿态。
下面来看一个综合的应用,通过改变heading、pitch、roll来改变实体的姿态,Quaternion的获取通过headin、pitch、roll来转化,Cesium.Quaternion.fromHeadingPitchRoll(Cesium.HeadingPitchRoll.fromDegrees(heading,pitch,roll))。
方向

define([], function () {  'use strict';  var modelControl = function (viewer, position, url) {    this._viewer = viewer    this._position = position    this._url = url    this._heading = 0    this._pitch = 30    this._roll = 315    let _that = this    var fixedFrameTransform = Cesium.Transforms.localFrameToFixedFrameGenerator('north', 'west')    this._controlmodel= this._viewer.entities.add({      name: this._url,      position: this._position,      model: {        uri: this._url,        scale:100      },      orientation: new Cesium.CallbackProperty(function () {        return Cesium.Quaternion.fromHeadingPitchRoll(Cesium.HeadingPitchRoll.fromDegrees(_that._heading, _that._pitch, _that._roll))    });    document.addEventListener('keydown', function (e) {      switch (e.keyCode) {        case 39:          let _heading = _that._heading          _heading +=5          if (_heading >= 360) {            _heading-=360          }          _that._heading = _heading          break;        case 38:          let _pitch = _that._pitch          _pitch += 5          if (_pitch >= 360) {            _pitch -= 360          }          _that._pitch = _pitch          break;        case 37:          let _roll = _that._roll          _roll += 5          if (_roll >= 360) {            _roll -= 360          }          _that._roll = _roll          break;        default:      }    });  }  return modelControl});

范例中实现了键盘按键的监听,对应不断修改人物模型的heading、picth、roll。

本节教程就到这里,欢迎转发、评论、留言。

转载地址:http://nnvxi.baihongyu.com/

你可能感兴趣的文章
【Python基础8】函数参数
查看>>
【Python基础9】浅谈深浅拷贝及变量赋值
查看>>
Jenkins定制一个具有筛选功能的列表视图
查看>>
【Python基础10】探索模块
查看>>
【Python】将txt文件转换为html
查看>>
[Linux]Shell脚本实现按照模块信息拆分文件内容
查看>>
idea添加gradle模块报错The project is already registered
查看>>
在C++中如何实现模板函数的外部调用
查看>>
在C++中,关键字explicit有什么作用
查看>>
C++中异常的处理方法以及使用了哪些关键字
查看>>
内存分配的形式有哪些? C++
查看>>
什么是内存泄露,如何避免内存泄露 C++
查看>>
什么是缓冲区溢出 C++
查看>>
sizeof C++
查看>>
使用指针有哪些好处? C++
查看>>
引用还是指针?
查看>>
checkio-non unique elements
查看>>
checkio-medium
查看>>
checkio-house password
查看>>
checkio-moore neighbourhood
查看>>