-
-
Notifications
You must be signed in to change notification settings - Fork 66
/
GestureControl.js
70 lines (62 loc) · 1.61 KB
/
GestureControl.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import React, {Component} from 'react';
import {StyleSheet, Animated} from 'react-native';
import ModelView from 'react-native-gl-model-view';
const AnimatedModelView = Animated.createAnimatedComponent(ModelView);
export default class GestureControl extends Component {
constructor() {
super();
this.state = {
rotateX: new Animated.Value(-90),
rotateZ: new Animated.Value(0),
fromXY: undefined,
valueXY: undefined,
};
}
onMoveEnd = () => {
this.setState({
fromXY: undefined,
});
};
onMove = e => {
let {pageX, pageY} = e.nativeEvent,
{rotateX, rotateZ, fromXY, valueXY} = this.state;
if (!this.state.fromXY) {
this.setState({
fromXY: [pageX, pageY],
valueXY: [rotateZ.__getValue(), rotateX.__getValue()],
});
} else {
rotateZ.setValue(valueXY[0] + (pageX - fromXY[0]) / 2);
rotateX.setValue(valueXY[1] + (pageY - fromXY[1]) / 2);
}
};
render() {
let {rotateZ, rotateX, fromXY} = this.state;
return (
<AnimatedModelView
model={{
uri: 'demon.model',
}}
texture={{
uri: 'demon.png',
}}
onStartShouldSetResponder={() => true}
onResponderRelease={this.onMoveEnd}
onResponderMove={this.onMove}
animate={!!fromXY}
tint={{r: 1.0, g: 1.0, b: 1.0, a: 1.0}}
scale={0.01}
rotateX={rotateX}
rotateZ={rotateZ}
translateZ={-4}
style={styles.container}
/>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: 'transparent',
},
});