@@ -9,7 +9,7 @@ import React, { useState, FunctionComponent, useEffect, useCallback } from 'reac
9
9
import { SafeAreaView , StatusBar , Button , View , Text , ViewProps , Image } from 'react-native' ;
10
10
11
11
import { EngineView , useEngine , EngineViewCallbacks } from '@babylonjs/react-native' ;
12
- import { Scene , Vector3 , ArcRotateCamera , Camera , WebXRSessionManager , SceneLoader , TransformNode , DeviceSourceManager , DeviceType , DeviceSource , PointerInput , WebXRTrackingState , Nullable } from '@babylonjs/core' ;
12
+ import { Scene , Vector3 , ArcRotateCamera , Camera , WebXRSessionManager , SceneLoader , TransformNode , DeviceSourceManager , DeviceType , PointerInput , WebXRTrackingState , IMouseEvent } from '@babylonjs/core' ;
13
13
import '@babylonjs/loaders' ;
14
14
import Slider from '@react-native-community/slider' ;
15
15
@@ -40,24 +40,23 @@ const EngineScreen: FunctionComponent<ViewProps> = (props: ViewProps) => {
40
40
setRootNode ( rootNode ) ;
41
41
42
42
const deviceSourceManager = new DeviceSourceManager ( engine ) ;
43
- const handlePointerInput = ( inputIndex : PointerInput , previousState : Nullable < number > , currentState : Nullable < number > ) => {
44
- if ( inputIndex === PointerInput . Horizontal &&
45
- currentState && previousState ) {
46
- rootNode . rotate ( Vector3 . Down ( ) , ( currentState - previousState ) * 0.005 ) ;
43
+ const handlePointerInput = ( event : IMouseEvent ) => {
44
+ if ( event . inputIndex === PointerInput . Move && event . movementX ) {
45
+ rootNode . rotate ( Vector3 . Down ( ) , event . movementX * 0.005 ) ;
47
46
} ;
48
47
} ;
49
48
50
49
deviceSourceManager . onDeviceConnectedObservable . add ( device => {
51
50
if ( device . deviceType === DeviceType . Touch ) {
52
- const touch : DeviceSource < DeviceType . Touch > = deviceSourceManager . getDeviceSource ( device . deviceType , device . deviceSlot ) ! ;
51
+ const touch = deviceSourceManager . getDeviceSource ( device . deviceType , device . deviceSlot ) ! ;
53
52
touch . onInputChangedObservable . add ( touchEvent => {
54
- handlePointerInput ( touchEvent . inputIndex , touchEvent . previousState , touchEvent . currentState ) ;
53
+ handlePointerInput ( touchEvent ) ;
55
54
} ) ;
56
55
} else if ( device . deviceType === DeviceType . Mouse ) {
57
- const mouse : DeviceSource < DeviceType . Mouse > = deviceSourceManager . getDeviceSource ( device . deviceType , device . deviceSlot ) ! ;
56
+ const mouse = deviceSourceManager . getDeviceSource ( device . deviceType , device . deviceSlot ) ! ;
58
57
mouse . onInputChangedObservable . add ( mouseEvent => {
59
58
if ( mouse . getInput ( PointerInput . LeftClick ) ) {
60
- handlePointerInput ( mouseEvent . inputIndex , mouseEvent . previousState , mouseEvent . currentState ) ;
59
+ handlePointerInput ( mouseEvent ) ;
61
60
}
62
61
} ) ;
63
62
}
0 commit comments