@@ -14,16 +14,8 @@ function validateNumber(numberValue) {
14
14
throw `Invalid number ${ numberValue } ` ;
15
15
}
16
16
17
- function areInitialRotationValues ( horizontalRotation , verticalRotation ) {
18
- return horizontalRotation === 0 && verticalRotation === 0 ;
19
- }
20
-
21
17
function createNewViewportData ( ) {
22
18
return {
23
- horizontalRotation : 0 ,
24
- verticalRotation : 0 ,
25
- initialViewUp : [ 0 , 1 , 0 ] ,
26
- initialSliceNormal : [ 0 , 0 , 1 ] ,
27
19
viewUp : [ 0 , 1 , 0 ] ,
28
20
sliceNormal : [ 0 , 0 , 1 ] ,
29
21
} ;
@@ -46,71 +38,41 @@ export default class {
46
38
return this . eventWindow ;
47
39
} ;
48
40
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 ) ;
56
44
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 ) ;
68
48
49
+ let yAxis = this . _state . viewUp ;
69
50
// rotate around the vector of the cross product of the
70
51
// plane and viewup as the X component
71
- const sliceXRot = [ ] ;
52
+
72
53
const sliceNormal = [ ] ;
73
54
const sliceViewUp = [ ] ;
74
55
75
- vec3 . cross (
76
- sliceXRot ,
77
- this . _state . initialViewUp ,
78
- this . _state . initialSliceNormal
79
- ) ;
80
- vec3 . normalize ( sliceXRot , sliceXRot ) ;
81
-
82
56
const planeMat = mat4 . create ( ) ;
83
57
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
+
105
67
this . _state . sliceNormal = sliceNormal ;
106
- this . _state . sliceViewUp = sliceViewUp ;
68
+ this . _state . viewUp = sliceViewUp ;
107
69
108
70
var event = new CustomEvent ( EVENTS . VIEWPORT_ROTATED , {
109
71
detail : {
110
- horizontalRotation,
111
- verticalRotation,
112
72
sliceNormal,
113
73
sliceViewUp,
74
+ dThetaX,
75
+ dThetaY,
114
76
} ,
115
77
bubbles : true ,
116
78
cancelable : true ,
@@ -119,32 +81,19 @@ export default class {
119
81
this . eventWindow . dispatchEvent ( event ) ;
120
82
} ;
121
83
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 ;
133
87
} ;
134
88
135
- getviewUp = ( ) => {
89
+ getViewUp = ( ) => {
136
90
return this . _state . viewUp ;
137
91
} ;
138
92
139
- getsliceNormal = ( ) => {
93
+ getSliceNormal = ( ) => {
140
94
return this . _state . sliceNormal ;
141
95
} ;
142
96
143
- // this.setOrientation = (viewUp, sliceNormal) => {
144
- // state.viewUp = viewUp;
145
- // state.sliceNormal = sliceNormal;
146
- // };
147
-
148
97
getReadOnlyViewPort = ( ) => {
149
98
const readOnlyState = JSON . parse ( JSON . stringify ( this . _state ) ) ;
150
99
0 commit comments