@@ -14,6 +14,9 @@ const Params = new URLSearchParams(window.location.search);
14
14
15
15
let currColor = "#ff0000" ;
16
16
let isPanning = false ;
17
+ let isRotating = false ;
18
+ let rotateDistance = 0 ;
19
+ const rotateThreshold = 100 ;
17
20
let rotation = 0 ;
18
21
let panX = 0 ;
19
22
let panY = 0 ;
@@ -330,14 +333,30 @@ function share() {
330
333
let downPos = { x : 0 , y : 0 } ;
331
334
view . addEventListener ( "pointerdown" , ( e ) => {
332
335
if ( e . target === view && ! e . altKey ) {
333
- isPanning = true ;
334
- downPos = { x : e . clientX , y : e . clientY } ;
336
+ if ( e . button == 2 ) {
337
+ isRotating = true ;
338
+ } else {
339
+ isPanning = true ;
340
+ downPos = { x : e . clientX , y : e . clientY } ;
341
+ }
335
342
} else if ( e . altKey ) {
336
343
isDragging = true ;
337
344
dragStartY = e . target . style . getPropertyValue ( "--y" ) || 0 ;
338
345
}
339
346
} ) ;
340
- view . addEventListener ( "pointermove" , ( e ) => {
347
+ document . addEventListener ( "pointermove" , ( e ) => {
348
+ if ( isRotating ) {
349
+ rotateDistance -= e . movementX ;
350
+ if ( rotateDistance >= rotateThreshold ) {
351
+ rotate ( rotation + 90 * Math . floor ( rotateDistance / rotateThreshold ) ) ;
352
+
353
+ rotateDistance %= rotateThreshold ;
354
+ } else if ( rotateDistance <= - rotateThreshold ) {
355
+ rotate ( rotation - 90 * Math . floor ( rotateDistance / - rotateThreshold ) ) ;
356
+
357
+ rotateDistance %= - rotateThreshold ;
358
+ }
359
+ }
341
360
if ( isPanning ) {
342
361
pan ( e . movementX , e . movementY ) ;
343
362
}
@@ -346,7 +365,7 @@ view.addEventListener("pointermove", (e) => {
346
365
placeCube ( worldPos . x , dragStartY , worldPos . z ) ;
347
366
}
348
367
} ) ;
349
- view . addEventListener ( "pointerup" , ( e ) => {
368
+ document . addEventListener ( "pointerup" , ( e ) => {
350
369
if ( ! isPinching && isPanning && e . target === view && e . button !== 2 && e . clientX - downPos . x === 0 && e . clientY - downPos . y === 0 ) {
351
370
const worldPos = worldCoords ( e . clientX , e . clientY ) ;
352
371
placeCube ( worldPos . x , 0 , worldPos . z ) ;
@@ -358,6 +377,7 @@ view.addEventListener("pointerup", (e) => {
358
377
}
359
378
}
360
379
isPanning = false ;
380
+ isRotating = false ;
361
381
isBreaking = false ;
362
382
isPicking = false ;
363
383
isDragging = false ;
0 commit comments