Skip to content

Instantly share code, notes, and snippets.

View ochanje210's full-sized avatar
🍩

Youngchan J ochanje210

🍩
View GitHub Profile
matrix = this.rotateXZ(dx, dy - 90);
this.transformOrigin(matrix, origin);
this.refViewTop.setNativeProps({style: {transform: [{perspective: 1000}, {matrix: matrix}]}});
matrix = this.rotateXZ(-dx, dy + 90);
this.transformOrigin(matrix, origin);
this.refViewBottom.setNativeProps({style: {transform: [{perspective: 1000}, {matrix: matrix}]}});
rotateXZ(dx, dy) {
const radX = (Math.PI / 180) * dx;
const cosX = Math.cos(radX);
const sinX = Math.sin(radX);
const radY = (Math.PI / 180) * dy;
const cosY= Math.cos(radY);
const sinY = Math.sin(radY);
return [
handlePanResponderMove (e, gestureState) {
const {dx, dy} = gestureState;
const origin = {x: 0, y: 0, z: -yourSquareSidelength / 2};
let matrix = this.rotateXY(dx, dy);
transformOrigin(matrix, origin);
this.refViewFront.setNativeProps({style: {transform: [{perspective: 1000}, {matrix: matrix}]}});
matrix = this.rotateXY(dx + 180, dy);
transformOrigin(matrix, origin);
this.refViewBack.setNativeProps({style: {transform: [{perspective: 1000}, {matrix: matrix}]}});
handlePanResponderMove (e, gestureState) {
const {dx, dy} = gestureState;
const sideLength = 100;
const origin = {x: 0, y: 0, z: -sideLength / 2};
let matrix = this.rotateX(dx, dy);
// from https://gist.github.com/jmurzy/0d62c0b5ea88ca806c16b5e8a16deb6a#file-foldview-transformutil-transformorigin-js
transformOrigin(matrix, origin);
this.refView.setNativeProps({style: {transform: [{perspective: 1000}, {matrix: matrix}]}});
}
rotateXY(dx, dy) {
const radX = (Math.PI / 180) * dy;
const cosX = Math.cos(radX);
const sinX = Math.sin(radX);
const radY = (Math.PI / 180) * -dx;
const cosY= Math.cos(radY);
const sinY = Math.sin(radY);
return [
const styles = {
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center'
},
rotateView: {
width: 100,
height: 100,
backgroundColor: 'white',