topical media & game development

talk show tell print

mobile-query-three-plugins-physics-examples-index.htm / htm



  <!doctype html><title>Minimal tQuery Page</title>
  <script src="../../../build/tquery-bundle.js"></script>
  
  <script src="../../physics/vendor/physijs/physi.js"></script>
  <script src="../../physics/tquery.physijs.js"></script>
  
  <body><script>
          var world        = tQuery.createWorld().boilerplate().start();
  
          world.tCamera().translateZ(-100);
  
          world.enablePhysics();
  
          var texture        = THREE.ImageUtils.loadTexture( "images/rocks.jpg" );
          texture.wrapS        = texture.wrapT = THREE.RepeatWrapping;
          texture.repeat.set( 3, 3 );
          setInterval(function(){
                  var value        = Math.random();
                  // Cube
                  if( value < 0.33 )        var object	= tQuery.createCube()
                  else if( value < 0.66 )        var object	= tQuery.createSphere()
                  else if( value <= 1.0 )        var object	= tQuery.createCylinder()
                  
                  object.addTo(world)
                          .setBasicMaterial().color(Math.random()*0xffffff).map(texture).back()
                          .geometry().scaleBy(4, 4, 4).back()
                          .rotation(Math.random()*Math.PI*2, Math.random()*Math.PI*2, Math.random()*Math.PI*2)
                          .position(Math.random()*2-1, 15, Math.random()*2-1)
                          .enablePhysics({
                                  //tGeometry        : new THREE.SphereGeometry(),
                                  friction        : 0.5,
                                  restitution        : 1
                          });
                  object.physics().addEventListener('collision', function(){
                          object.get(0).material.color.setHex(0xffffff*Math.random());
                  })
          }, 1000);
  
          // Ground
          tQuery.createCube().addTo(world)
                  .setBasicMaterial().map(texture).back()
                  .geometry().scaleBy(100, 1, 100).back()
                  .translateY(-10)
                  .enablePhysics({
                          mass                : 0,
                          friction        : 0.5,
                          restitution        : 1
                  });
  
  </script></body>


(C) Æliens 04/09/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.