Created
July 1, 2013 18:16
-
-
Save yoavlt/5903222 to your computer and use it in GitHub Desktop.
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
define ['app/component/ground'], (Ground) -> | |
class World | |
constructor: -> | |
@scene = new Physijs.Scene() | |
@scene.setGravity(new THREE.Vector3(0, -30, 0)) | |
@init_camera() | |
@init_light() | |
ground = new Ground(new THREE.Vector3(100, 1, 100)) | |
@scene.add ground.body | |
# mesh | |
mesh_geometry = new THREE.CubeGeometry(10, 10, 10) | |
mesh_material = new THREE.MeshLambertMaterial({ color: 0xff6666 }, | |
8, # high friction | |
2 # low restitution | |
) | |
@mesh = new Physijs.BoxMesh(mesh_geometry, mesh_material, 3) | |
@mesh.receiveShadow = true | |
@mesh.translateY(20) | |
@scene.add @mesh | |
init_camera: -> | |
@camera = new THREE.PerspectiveCamera(35, window.innerWidth / window.innerHeight, 1, 1000) | |
@camera.position.set(60, 50, 60) | |
@camera.lookAt @scene.position | |
@scene.add @camera | |
init_light: -> | |
light = new THREE.AmbientLight(0x404040) | |
@scene.add light | |
directional_light = new THREE.DirectionalLight(0xffffff) | |
directional_light.position.set(20, 40, -15) | |
directional_light.target.position.copy(@scene.position) | |
directional_light.castShadow = true | |
directional_light.shadowCameraLeft = -60 | |
directional_light.shadowCameraTop = -60 | |
directional_light.shadowCameraRight = 60 | |
directional_light.shadowCameraBottom = 60 | |
directional_light.shadowCameraNear = 20 | |
directional_light.shadowCameraFar = 200 | |
directional_light.shadowBias = -0.0001 | |
directional_light.shadowMapWidth = 2048 | |
directional_light.shadowMapHeight = 2048 | |
directional_light.shadowDarkness = 0.7 | |
@scene.add directional_light | |
update: -> | |
delta_t = 0.001 | |
@scene.simulate(undefined, delta_t) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment