SuperMap iClient3D for WebGL教程-orientation

作者:桔子

本文同步更新于简书文章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。
本节教程就到这里,欢迎转发、评论、留言。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值