@@ -43,6 +43,79 @@ goog.require('olcs.core.OlLayerPrimitive');
4343 } ;
4444
4545
46+ /**
47+ * @param {!Cesium.Camera } camera
48+ * @param {number } angle
49+ * @param {!Cesium.Cartesian3 } axis
50+ * @param {!Cesium.Matrix4 } transform
51+ * @param {olcsx.core.RotateAroundAxisOption= } opt_options
52+ * @api
53+ */
54+ olcs . core . rotateAroundAxis = function ( camera , angle , axis , transform ,
55+ opt_options ) {
56+ var clamp = Cesium . Math . clamp ;
57+ var defaultValue = Cesium . defaultValue ;
58+
59+ var options = opt_options || { } ;
60+ var duration = defaultValue ( options . duration , 500 ) ; // ms
61+ var easing = defaultValue ( options . easing , ol . easing . linear ) ;
62+ var callback = options . callback ;
63+
64+ var start = goog . now ( ) ;
65+ var lastProgress = 0 ;
66+ var oldTransform = new Cesium . Matrix4 ( ) ;
67+
68+ var animation = new goog . async . AnimationDelay ( function ( millis ) {
69+ var progress = easing ( clamp ( ( millis - start ) / duration , 0 , 1 ) ) ;
70+ goog . asserts . assert ( progress > lastProgress ) ;
71+
72+ camera . transform . clone ( oldTransform ) ;
73+ var stepAngle = ( progress - lastProgress ) * angle ;
74+ lastProgress = progress ;
75+ camera . setTransform ( transform ) ;
76+ camera . rotate ( axis , stepAngle ) ;
77+ camera . setTransform ( oldTransform ) ;
78+
79+ if ( progress < 1 ) {
80+ animation . start ( ) ;
81+ } else if ( callback ) {
82+ callback ( ) ;
83+ }
84+ } ) ;
85+ animation . start ( ) ;
86+ } ;
87+
88+
89+ /**
90+ * @param {!Cesium.Scene } scene
91+ * @param {number } heading
92+ * @param {!Cesium.Cartesian3 } bottomCenter
93+ * @api
94+ */
95+ olcs . core . setHeadingUsingBottomCenter = function ( scene , heading ,
96+ bottomCenter ) {
97+ var camera = scene . camera ;
98+ // Compute the camera position to zenith quaternion
99+ var angleToZenith = olcs . core . computeAngleToZenith ( scene , bottomCenter ) ;
100+ var axis = camera . right ;
101+ var quaternion = Cesium . Quaternion . fromAxisAngle ( axis , angleToZenith ) ;
102+ var rotation = Cesium . Matrix3 . fromQuaternion ( quaternion ) ;
103+
104+ // Get the zenith point from the rotation of the position vector
105+ var vector = new Cesium . Cartesian3 ( ) ;
106+ Cesium . Cartesian3 . subtract ( camera . position , bottomCenter , vector ) ;
107+ var zenith = new Cesium . Cartesian3 ( ) ;
108+ Cesium . Matrix3 . multiplyByVector ( rotation , vector , zenith ) ;
109+ Cesium . Cartesian3 . add ( zenith , bottomCenter , zenith ) ;
110+
111+ // Actually rotate around the zenith normal
112+ var transform = Cesium . Matrix4 . fromTranslation ( zenith ) ;
113+ var rotateAroundAxis = olcs . core . rotateAroundAxis ;
114+ rotateAroundAxis ( camera , heading , zenith , transform ) ;
115+ } ;
116+
117+
118+
46119 /**
47120 * Get 3D positiion of the point at the bottom-center of the screen.
48121 * @param {!Cesium.Scene } scene
0 commit comments