JSFiddle - React, Tailwind, and code Playground
JavaScript
SM = {};
SM.Reel = (function () {
function Reel(scene, timeSpan) {
var geometry = new THREE.CubeGeometry( 200, 200, 200 );
var material = new THREE.MeshBasicMaterial( { color: 0xff0000, wireframe: true } );
this.mesh = new THREE.Mesh(geometry, material);
this.timeSpan = this.time = timeSpan;
this.startVelocity = 0.01;
this.velocity = this.startVelocity;
this.speedUp = Math.abs(this.startVelocity / this.timeSpan);
scene.add(this.mesh);
}
/**
* Rotates the cube
* Here I'm trying to implement the smooth rotation
*/
Reel.prototype.move = function (delta) {
if (this.velocity < 0 && this.mesh.rotation.x == 0) {
return false;
}
if (this.velocity < 0 && this.mesh.rotation.x != 0) {
this.mesh.rotation.x += Math.abs(delta * this.speedUp * 0.5 * this.timeSpan);
if (Math.abs(this.mesh.rotation.x - 2 * Math.PI) < 0.1) {
this.mesh.rotation.x = 0;
}
}
else {
this.mesh.rotation.x += delta * this.velocity;
this.time -= delta;
this.velocity = this.speedUp * this.time;
}
}
return Reel;
})();var camera, scene, renderer, reel;
/**
* Inits the scene and camera
*/
function init() {
camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 1, 10000 );
camera.position.z = 400;
scene = new THREE.Scene();
reel = new SM.Reel(scene, 1000);
renderer = new THREE.CanvasRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
}
/**
* Starts/Animates the cube
*/
function animate(time) {
if (!animate.lastTime) {
animate.lastTime = time;
}
var delta = time - animate.lastTime;
animate.lastTime = time;
...