@@ -14,16 +14,8 @@ function validateNumber(numberValue) {
1414 throw `Invalid number ${ numberValue } ` ;
1515}
1616
17- function areInitialRotationValues ( horizontalRotation , verticalRotation ) {
18- return horizontalRotation === 0 && verticalRotation === 0 ;
19- }
20-
2117function createNewViewportData ( ) {
2218 return {
23- horizontalRotation : 0 ,
24- verticalRotation : 0 ,
25- initialViewUp : [ 0 , 1 , 0 ] ,
26- initialSliceNormal : [ 0 , 0 , 1 ] ,
2719 viewUp : [ 0 , 1 , 0 ] ,
2820 sliceNormal : [ 0 , 0 , 1 ] ,
2921 } ;
@@ -46,71 +38,41 @@ export default class {
4638 return this . eventWindow ;
4739 } ;
4840
49- getHRotation = ( ) => {
50- return this . _state . horizontalRotation ;
51- } ;
52-
53- getVRotation = ( ) => {
54- return this . _state . verticalRotation ;
55- } ;
41+ rotate = ( dThetaX , dThetaY ) => {
42+ validateNumber ( dThetaX ) ;
43+ validateNumber ( dThetaY ) ;
5644
57- rotate = ( horizontalRotation , verticalRotation ) => {
58- validateNumber ( horizontalRotation ) ;
59- validateNumber ( verticalRotation ) ;
60-
61- if (
62- ! areInitialRotationValues ( horizontalRotation , verticalRotation ) &&
63- this . _state . horizontalRotation === horizontalRotation &&
64- this . _state . verticalRotation === verticalRotation
65- ) {
66- return ;
67- }
45+ let xAxis = [ ] ;
46+ vec3 . cross ( xAxis , this . _state . viewUp , this . _state . sliceNormal ) ;
47+ vec3 . normalize ( xAxis , xAxis ) ;
6848
49+ let yAxis = this . _state . viewUp ;
6950 // rotate around the vector of the cross product of the
7051 // plane and viewup as the X component
71- const sliceXRot = [ ] ;
52+
7253 const sliceNormal = [ ] ;
7354 const sliceViewUp = [ ] ;
7455
75- vec3 . cross (
76- sliceXRot ,
77- this . _state . initialViewUp ,
78- this . _state . initialSliceNormal
79- ) ;
80- vec3 . normalize ( sliceXRot , sliceXRot ) ;
81-
8256 const planeMat = mat4 . create ( ) ;
8357
84- // Rotate around the vertical (slice-up) vector
85- mat4 . rotate (
86- planeMat ,
87- planeMat ,
88- degrees2radians ( - horizontalRotation ) ,
89- this . _state . initialViewUp
90- ) ;
91-
92- // Rotate around the horizontal (screen-x) vector
93- mat4 . rotate (
94- planeMat ,
95- planeMat ,
96- degrees2radians ( - verticalRotation ) ,
97- sliceXRot
98- ) ;
99-
100- vec3 . transformMat4 ( sliceNormal , this . _state . initialSliceNormal , planeMat ) ;
101- vec3 . transformMat4 ( sliceViewUp , this . _state . initialViewUp , planeMat ) ;
102-
103- this . _state . horizontalRotation = horizontalRotation ;
104- this . _state . verticalRotation = verticalRotation ;
58+ //Rotate around the vertical (slice-up) vector
59+ mat4 . rotate ( planeMat , planeMat , degrees2radians ( dThetaY ) , yAxis ) ;
60+
61+ //Rotate around the horizontal (screen-x) vector
62+ mat4 . rotate ( planeMat , planeMat , degrees2radians ( dThetaX ) , xAxis ) ;
63+
64+ vec3 . transformMat4 ( sliceNormal , this . _state . sliceNormal , planeMat ) ;
65+ vec3 . transformMat4 ( sliceViewUp , this . _state . viewUp , planeMat ) ;
66+
10567 this . _state . sliceNormal = sliceNormal ;
106- this . _state . sliceViewUp = sliceViewUp ;
68+ this . _state . viewUp = sliceViewUp ;
10769
10870 var event = new CustomEvent ( EVENTS . VIEWPORT_ROTATED , {
10971 detail : {
110- horizontalRotation,
111- verticalRotation,
11272 sliceNormal,
11373 sliceViewUp,
74+ dThetaX,
75+ dThetaY,
11476 } ,
11577 bubbles : true ,
11678 cancelable : true ,
@@ -119,32 +81,19 @@ export default class {
11981 this . eventWindow . dispatchEvent ( event ) ;
12082 } ;
12183
122- getInitialViewUp = ( ) => {
123- return this . _state . initialViewUp ;
124- } ;
125-
126- getInitialSliceNormal = ( ) => {
127- return this . _state . initialSliceNormal ;
128- } ;
129-
130- setInitialOrientation = ( initialSliceNormal , initialViewUp = [ 0 , 1 , 0 ] ) => {
131- this . _state . initialSliceNormal = initialSliceNormal ;
132- this . _state . initialViewUp = initialViewUp ;
84+ setOrientation = ( sliceNormal , viewUp = [ 0 , 1 , 0 ] ) => {
85+ this . _state . sliceNormal = sliceNormal ;
86+ this . _state . viewUp = viewUp ;
13387 } ;
13488
135- getviewUp = ( ) => {
89+ getViewUp = ( ) => {
13690 return this . _state . viewUp ;
13791 } ;
13892
139- getsliceNormal = ( ) => {
93+ getSliceNormal = ( ) => {
14094 return this . _state . sliceNormal ;
14195 } ;
14296
143- // this.setOrientation = (viewUp, sliceNormal) => {
144- // state.viewUp = viewUp;
145- // state.sliceNormal = sliceNormal;
146- // };
147-
14897 getReadOnlyViewPort = ( ) => {
14998 const readOnlyState = JSON . parse ( JSON . stringify ( this . _state ) ) ;
15099
0 commit comments