Skip to content

Instantly share code, notes, and snippets.

@nickarthur
Forked from lnickers2004/Ball.js
Created August 9, 2017 22:55
Show Gist options
  • Save nickarthur/7900795b03df8b153c65e3b02619ddff to your computer and use it in GitHub Desktop.
Save nickarthur/7900795b03df8b153c65e3b02619ddff to your computer and use it in GitHub Desktop.
import React from 'react';
import {
Sphere
} from 'react-vr';
import * as CANNON from 'cannon/build/cannon.js'
export default class Particle extends React.Component {
constructor(props) {
this.body = new CANNON.Body({
mass: 1,
shape: new Cannon.Sphere(1),
})
props.world.add(this.body)
this.state = {
position: [0, 0, 0]
}
}
componentDidMount() {
this.animate()
}
componentWillUnmount() {
cancelAnimationFrame(this.request)
}
animate() {
this.request = requestAnimationFrame( this.animate );
this.setState({
position: this.body.position
})
}
render() {
return (
<Sphere
style={{
transform: [{
translate: [
this.state.position.x / 10,
this.state.position.y / 10,
this.state.position.z / 10
]
}]
}}
/>
)
}
}
import React, { PropTypes } from 'react';
import {
AppRegistry,
View,
DirectionalLight,
AmbientLight,
} from 'react-vr';
import * as CANNON from 'cannon/build/cannon.js'
import Ball from './vr/components/ball'
export default class KenReactVR extends React.Component {
constructor() {
super()
this.world = new CANNON.World()
this.world.gravity = new CANNON.Vec3(0, -1, 0)
}
componentDidMount() {
this.tick()
}
tick() {
requestAnimationFrame( this.tick );
world.step(dt);
}
render() {
return (
<View>
<Ball world={this.world} />
</View>
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment