library logo

Event

Module: Event

Provides the Events object to bind events to the canvas to interact with 3D objects. The first parameter of each event callback function is an event wrapper object that contains as properties:

Events Method: create

Creates a set of events for the given domElement that can be handled through a callback.

Syntax:

PhiloGL.Events.create(domElement, options);	

Arguments:

  1. domElement - (element) A domElement. Generally a canvas element.
  2. options - (object) An object containing the following options:

Options:

Notes:

Even though the Events object is accessible via the PhiloGL function the events are often set in the PhiloGL constructor. For more information about the PhiloGL constructor check the Core Script.

Examples:

Setting rotation and zoom to a moon object with drag and drop and mousewheel events.

    var pos, camera, moon, canvas;
    
    //create and assign variables to objects...

    PhiloGL.Events.create(canvas, {
      onDragStart: function(e) {
        pos = {
          x: e.x,
          y: e.y
        };
      },
      onDragMove: function(e) {
        var z = camera.position.z,
            sign = Math.abs(z) / z;

        moon.rotation.y += -(pos.x - e.x) / 100;
        moon.rotation.x += sign * (pos.y - e.y) / 100;
        moon.update();
        pos.x = e.x;
        pos.y = e.y;
      },
      onMouseWheel: function(e) {
        e.stop();
        camera.position.z += e.wheel;
        camera.update();
      }
  });