mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
correct lint for physijs
This commit is contained in:
parent
531d89c5d4
commit
b97cdffa5f
@ -11,30 +11,30 @@ initScene = function() {
|
||||
projector = new THREE.Projector;
|
||||
|
||||
renderer = new THREE.WebGLRenderer({ antialias: true });
|
||||
renderer.setSize( window.innerWidth, window.innerHeight );
|
||||
renderer.setSize(window.innerWidth, window.innerHeight);
|
||||
renderer.shadowMapEnabled = true;
|
||||
// // renderer.shadowMapSoft = true;
|
||||
document.getElementById( 'viewport' ).appendChild( renderer.domElement );
|
||||
// // renderer.shadowMapSoft = true;
|
||||
document.getElementById('viewport').appendChild(renderer.domElement);
|
||||
|
||||
render_stats = new Stats();
|
||||
render_stats.dom.style.position = 'absolute';
|
||||
render_stats.dom.style.top = '1px';
|
||||
render_stats.dom.style.zIndex = '100';
|
||||
document.getElementById( 'viewport' ).appendChild( render_stats.dom );
|
||||
document.getElementById('viewport').appendChild(render_stats.dom);
|
||||
|
||||
physics_stats = new Stats();
|
||||
physics_stats.dom.style.position = 'absolute';
|
||||
physics_stats.dom.style.top = '50px';
|
||||
physics_stats.dom.style.zIndex = '100';
|
||||
document.getElementById( 'viewport' ).appendChild( physics_stats.dom );
|
||||
document.getElementById('viewport').appendChild(physics_stats.dom);
|
||||
|
||||
scene = new Physijs.Scene();
|
||||
scene.setGravity(new THREE.Vector3( 0, -30, 0 ));
|
||||
scene.setGravity(new THREE.Vector3(0, -30, 0));
|
||||
scene.addEventListener(
|
||||
'update',
|
||||
function() {
|
||||
applyForce();
|
||||
scene.simulate( undefined, 1 );
|
||||
scene.simulate(undefined, 1);
|
||||
physics_stats.update();
|
||||
}
|
||||
);
|
||||
@ -45,14 +45,14 @@ initScene = function() {
|
||||
1,
|
||||
1000
|
||||
);
|
||||
camera.position.set( 60, 50, 60 );
|
||||
camera.lookAt( scene.position );
|
||||
scene.add( camera );
|
||||
camera.position.set(60, 50, 60);
|
||||
camera.lookAt(scene.position);
|
||||
scene.add(camera);
|
||||
|
||||
// Light
|
||||
light = new THREE.DirectionalLight( 0xFFFFFF );
|
||||
light.position.set( 20, 40, -15 );
|
||||
light.target.position.copy( scene.position );
|
||||
light = new THREE.DirectionalLight(0xFFFFFF);
|
||||
light.position.set(20, 40, -15);
|
||||
light.target.position.copy(scene.position);
|
||||
light.castShadow = true;
|
||||
light.shadowCameraLeft = -60;
|
||||
light.shadowCameraTop = -60;
|
||||
@ -63,11 +63,11 @@ initScene = function() {
|
||||
light.shadowBias = -.0001
|
||||
light.shadowMapWidth = light.shadowMapHeight = 2048;
|
||||
//// light.shadowDarkness = .7;
|
||||
scene.add( light );
|
||||
scene.add(light);
|
||||
|
||||
// Materials
|
||||
ground_material = Physijs.createMaterial(
|
||||
new THREE.MeshLambertMaterial({ map: THREE.ImageUtils.loadTexture( 'images/rocks.jpg' ) }),
|
||||
new THREE.MeshLambertMaterial({ map: THREE.ImageUtils.loadTexture('images/rocks.jpg') }),
|
||||
.8, // high friction
|
||||
.4 // low restitution
|
||||
);
|
||||
@ -75,7 +75,7 @@ initScene = function() {
|
||||
// ground_material.map.repeat.set( 3, 3 );
|
||||
|
||||
box_material = Physijs.createMaterial(
|
||||
new THREE.MeshLambertMaterial({ map: THREE.ImageUtils.loadTexture( 'images/plywood.jpg' ) }),
|
||||
new THREE.MeshLambertMaterial({ map: THREE.ImageUtils.loadTexture('images/plywood.jpg') }),
|
||||
.4, // low friction
|
||||
.6 // high restitution
|
||||
);
|
||||
@ -89,11 +89,11 @@ initScene = function() {
|
||||
0 // mass
|
||||
);
|
||||
ground.receiveShadow = true;
|
||||
scene.add( ground );
|
||||
scene.add(ground);
|
||||
|
||||
for ( var i = 0; i < 10; i++ ) {
|
||||
for (var i = 0; i < 10; i++) {
|
||||
box = new Physijs.BoxMesh(
|
||||
new THREE.BoxGeometry( 4, 4, 4 ),
|
||||
new THREE.BoxGeometry(4, 4, 4),
|
||||
box_material
|
||||
);
|
||||
box.position.set(
|
||||
@ -112,46 +112,46 @@ initScene = function() {
|
||||
Math.random() * 1 + .5
|
||||
);
|
||||
box.castShadow = true;
|
||||
scene.add( box );
|
||||
boxes.push( box );
|
||||
scene.add(box);
|
||||
boxes.push(box);
|
||||
}
|
||||
|
||||
renderer.domElement.addEventListener( 'mousemove', setMousePosition );
|
||||
renderer.domElement.addEventListener('mousemove', setMousePosition);
|
||||
|
||||
requestAnimationFrame( render );
|
||||
requestAnimationFrame(render);
|
||||
scene.simulate();
|
||||
};
|
||||
|
||||
render = function() {
|
||||
requestAnimationFrame( render );
|
||||
renderer.render( scene, camera );
|
||||
requestAnimationFrame(render);
|
||||
renderer.render(scene, camera);
|
||||
render_stats.update();
|
||||
};
|
||||
|
||||
setMousePosition = function( evt ) {
|
||||
setMousePosition = function(evt) {
|
||||
// Find where mouse cursor intersects the ground plane
|
||||
var vector = new THREE.Vector3(
|
||||
( evt.clientX / renderer.dom.clientWidth ) * 2 - 1,
|
||||
-( ( evt.clientY / renderer.dom.clientHeight ) * 2 - 1 ),
|
||||
(evt.clientX / renderer.dom.clientWidth) * 2 - 1,
|
||||
-((evt.clientY / renderer.dom.clientHeight) * 2 - 1),
|
||||
.5
|
||||
);
|
||||
projector.unprojectVector( vector, camera );
|
||||
vector.sub( camera.position ).normalize();
|
||||
projector.unprojectVector(vector, camera);
|
||||
vector.sub(camera.position).normalize();
|
||||
|
||||
var coefficient = (box.position.y - camera.position.y) / vector.y
|
||||
mouse_position = camera.position.clone().add( vector.multiplyScalar( coefficient ) );
|
||||
mouse_position = camera.position.clone().add(vector.multiplyScalar(coefficient));
|
||||
};
|
||||
|
||||
applyForce = function() {
|
||||
if (!mouse_position) return;
|
||||
var strength = 35, distance, effect, offset, box;
|
||||
|
||||
for ( var i = 0; i < boxes.length; i++ ) {
|
||||
for (var i = 0; i < boxes.length; i++) {
|
||||
box = boxes[i];
|
||||
distance = mouse_position.distanceTo( box.position ),
|
||||
effect = mouse_position.clone().sub( box.position ).normalize().multiplyScalar( strength / distance ).negate(),
|
||||
offset = mouse_position.clone().sub( box.position );
|
||||
box.applyImpulse( effect, offset );
|
||||
distance = mouse_position.distanceTo(box.position);
|
||||
effect = mouse_position.clone().sub(box.position).normalize().multiplyScalar(strength / distance).negate();
|
||||
offset = mouse_position.clone().sub(box.position);
|
||||
box.applyImpulse(effect, offset);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user