/**
* 模型水平方向旋转——主要用于大包翻转台
* 例子正值、负值代表正反方向旋转
* modelRotate(entity,270,10);modelRotate(entity,-90,5);
* @param model 模型
* @param angle 旋转角度
* @param seconds 多少秒旋转结束
*/
function modelHeadingRotate(model,angle,seconds) {
let state = false;
if(angle>0){
state = true;
}
let modelHPR = Cesium.Transforms.fixedFrameToHeadingPitchRoll(computeModelMatrix(model,Cesium.JulianDate.now()));
let angle_ = Cesium.Math.toRadians(angle);
let starthpr={heading:modelHPR.heading},endhpr={heading:modelHPR.heading+angle_};
let center = model.position._value;
let heading_ = Math.abs((endhpr.heading-starthpr.heading)/(seconds*20));
let index = 0;
let interval = setInterval(function(){
let nowhpr = Cesium.Transforms.fixedFrameToHeadingPitchRoll(computeModelMatrix(model,Cesium.JulianDate.now()));
if(state){
if(index>angle_){
clearInterval(interval);
}else{
index+=heading_;
model.orientation=Cesium.Transforms.headingPitchRollQuaternion(center, new Cesium.HeadingPitchRoll(nowhpr.heading+=heading_,0,0));
}
}else{
if(index>angle_){
index-=heading_;
model.orientation=Cesium.Transforms.headingPitchRollQuaternion(center, new Cesium.HeadingPitchRoll(nowhpr.heading-=heading_,0,0));
}else{
clearInterval(interval);
}
}
},50);
}
/**
* 模型水平方向旋转——主要用于大包翻转台
* 例子正值、负值代表正反方向旋转
* modelRotate(entity,270,10);modelRotate(entity,-90,5);
* @param model 模型
* @param angle 旋转角度
* @param seconds 多少秒旋转结束
*/
function modelRollRotate(model,angle,seconds) {
let state = false;
if(angle>0){
state = true;
}
let modelHPR = Cesium.Transforms.fixedFrameToHeadingPitchRoll(computeModelMatrix(model,Cesium.JulianDate.now()));
let angle_ = Cesium.Math.toRadians(angle);
let starthpr={roll:modelHPR.roll},endhpr={roll:modelHPR.roll+angle_};
let center = model.position._value;
let roll_ = Math.abs((endhpr.roll-starthpr.roll)/(seconds*20));
let index = 0;
let interval = setInterval(function(){
let nowhpr = Cesium.Transforms.fixedFrameToHeadingPitchRoll(computeModelMatrix(model,Cesium.JulianDate.now()));
if(state){
if(index>angle_){
clearInterval(interval);
}else{
index+=roll_;
model.orientation=Cesium.Transforms.headingPitchRollQuaternion(center, new Cesium.HeadingPitchRoll(0,0,nowhpr.roll+=roll_));
}
}else{
if(index>angle_){
index-=roll_;
model.orientation=Cesium.Transforms.headingPitchRollQuaternion(center, new Cesium.HeadingPitchRoll(0,0,nowhpr.roll-=roll_));
}else{
clearInterval(interval);
}
}
},50);
}
Cesium控制模型旋转2019-11-15
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- cesium编程入门(七)3D Tiles,模型旋转 上一节介绍了3D Tiles模型的位置移动,和贴地的操作,这...