This repository has been archived by the owner on Dec 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add frame loop, sample showing headlocked panels
Reviewed By: mikearmstrong001 Differential Revision: D8002028 fbshipit-source-id: c92013d4c6b6ad844076b8cfd9db0c2a6640e311
- Loading branch information
1 parent
9a6b2f3
commit fa66076
Showing
5 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import {Math as VRMath, ReactInstance, Surface} from 'react-360-web'; | ||
|
||
function init(bundle, parent, options = {}) { | ||
const horizontalPanel = new Surface(300, 300, Surface.SurfaceShape.Flat); | ||
const hvPanel = new Surface(300, 300, Surface.SurfaceShape.Flat); | ||
|
||
horizontalPanel.setAngle(0, -0.5); | ||
|
||
const cameraDirection = [0, 0, -1]; | ||
|
||
const r360 = new ReactInstance(bundle, parent, { | ||
fullScreen: true, | ||
frame: () => { | ||
const cameraQuat = r360.getCameraQuaternion(); | ||
cameraDirection[0] = 0; | ||
cameraDirection[1] = 0; | ||
cameraDirection[2] = -1; | ||
// cameraDirection will point out from the view of the camera, | ||
// we can use it to compute surface angles | ||
VRMath.rotateByQuaternion(cameraDirection, cameraQuat); | ||
const cx = cameraDirection[0]; | ||
const cy = cameraDirection[1]; | ||
const cz = cameraDirection[2]; | ||
const horizAngle = Math.atan2(cx, -cz); | ||
const vertAngle = Math.asin(cy / Math.sqrt(cx * cx + cy * cy + cz * cz)); | ||
horizontalPanel.setAngle(horizAngle, -0.5); | ||
hvPanel.setAngle(horizAngle, vertAngle); | ||
}, | ||
...options, | ||
}); | ||
|
||
r360.renderToSurface(r360.createRoot('HorizontalPanel'), horizontalPanel); | ||
r360.renderToSurface(r360.createRoot('HVPanel'), hvPanel); | ||
|
||
r360.compositor.setBackground('./static_assets/360_world.jpg'); | ||
} | ||
|
||
window.React360 = {init}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<html> | ||
<head> | ||
<title>Headlocked Surfaces Sample</title> | ||
<style>body { margin: 0; }</style> | ||
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no"> | ||
</head> | ||
<body> | ||
<div id="container"></div> | ||
<script src="./client.bundle?platform=vr"></script> | ||
<script> | ||
React360.init( | ||
'index.bundle?platform=vr&dev=true', | ||
document.getElementById('container') | ||
); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import * as React from 'react'; | ||
import {AppRegistry, StyleSheet, Text, View} from 'react-360'; | ||
|
||
const HorizontalPanel = () => ( | ||
<View style={styles.panel}> | ||
<Text style={styles.panelText}>{'Follows Horizontally'}</Text> | ||
</View> | ||
); | ||
|
||
const HVPanel = () => ( | ||
<View style={styles.panel}> | ||
<Text style={styles.panelText}>{'Follows Horizontally\nand Vertically'}</Text> | ||
</View> | ||
); | ||
|
||
const styles = StyleSheet.create({ | ||
panel: { | ||
width: 300, | ||
height: 300, | ||
backgroundColor: 'rgba(255, 255, 255, 0.8)', | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
}, | ||
panelText: { | ||
color: '#000000', | ||
fontSize: 30, | ||
textAlign: 'center', | ||
} | ||
}); | ||
|
||
AppRegistry.registerComponent('HorizontalPanel', () => HorizontalPanel); | ||
AppRegistry.registerComponent('HVPanel', () => HVPanel); |