コード例 #1
0
ファイル: Char.js プロジェクト: XuHaoJun/daoClient
Char.prototype.handleCanvasClick = function(event) {
  event.preventDefault();
  var vector = new THREE.Vector3((event.clientX / window.innerWidth) * 2 - 1,
                                 - (event.clientY / window.innerHeight) * 2 + 1,
                                 0.5);
  var raycaster = this.scene.raycaster;
  vector.pickingRay(this.scene.camera);
  raycaster.set(this.scene.camera.position, vector);
  var objects = raycaster.intersectObjects( this.scene.threeScene.children, false );
  var itemSpriteLabelCount = 0;
  _.each(objects, function(obj) {
    var mesh = obj.object;
    if (mesh.userData instanceof Bio) {
      var bio = mesh.userData;
      event.char = this;
      bio.emit("click", event);
    } else if (mesh.userData instanceof Item) {
      var item = mesh.userData;
      event.char = this;
      if (item.spriteLabel && itemSpriteLabelCount == 0) {
        item.spriteLabel.emit("click", event);
        itemSpriteLabelCount++;
      }
    }
  }.bind(this));
};
コード例 #2
0
ファイル: SceneObject.js プロジェクト: XuHaoJun/daoClient
 _.each(this.subThreeBodys, function(body) {
   if (!body.localPosition) {
     return;
   }
   var worldPosition = new THREE.Vector3();
   worldPosition.addVectors(body.localPosition, this.threeBody.position);
   // var worldRota = new THREE.Vector3();
   body.position.add(this.threeBody.position);
   // body.rotation.add(this.threeBody.rotation);
 }, this);
コード例 #3
0
ファイル: SceneObject.js プロジェクト: XuHaoJun/daoClient
SceneObject.prototype.screenXY = function (camera) {
  var width = window.innerWidth, height = window.innerHeight;
  var widthHalf = width / 2, heightHalf = height / 2;
  var vector = new THREE.Vector3();
  vector.setFromMatrixPosition(this.threeBody.matrixWorld);
  vector.project(camera);
  vector.x = ( vector.x * widthHalf ) + widthHalf;
  vector.y = - ( vector.y * heightHalf ) + heightHalf;
  return {x: vector.x, y: vector.y};
};
コード例 #4
0
ファイル: Char.js プロジェクト: XuHaoJun/daoClient
Char.prototype.handleCanvasMousemove = function(event) {
  // console.log("mouse position: ", event.clientX, event.clientY);
  this.buttons.canvas.isMoving = true;
  var vector = new THREE.Vector3((event.clientX / window.innerWidth) * 2 - 1,
                                 - (event.clientY / window.innerHeight) * 2 + 1,
                                 0.5);
  var raycaster = this.scene.raycaster;
  vector.pickingRay(this.scene.camera);
  raycaster.set(this.scene.camera.position, vector);
  var objects = raycaster.intersectObjects( this.scene.threeScene.children, false );
  //
  var firstBio = _.find(objects, function(obj) {
    var mesh = obj.object;
    return mesh.userData instanceof Bio;
  });
  firstBio = (_.isUndefined(firstBio) ? null : firstBio.object.userData);
  if (firstBio && firstBio != this) {
    document.body.style.cursor = "pointer";
  } else {
    document.body.style.cursor = "";
  }
  if (firstBio != this) {
    this.lastMiniTarget = firstBio;
    this.lastClientX = event.clientX;
    this.lastClientY = event.clientY;
    this.world.views.game.handleMiniTarget(firstBio, false);
  }
  var firstItemSpriteLabel = _.find(objects, function(obj) {
    var mesh = obj.object;
    return ((mesh.userData instanceof Item) && mesh.userData.spriteLabel);
  });
  firstItemSpriteLabel = (_.isUndefined(firstItemSpriteLabel) ?
                          null : firstItemSpriteLabel.object.userData.spriteLabel);
  if (firstItemSpriteLabel != null && this.lastItemSpriteLabel == null) {
    firstItemSpriteLabel.emit("mouseenter");
  }
  if(this.lastItemSpriteLabel != null && this.lastItemSpriteLabel != firstItemSpriteLabel) {
    this.lastItemSpriteLabel.emit("mouseleave");
  }
  this.lastItemSpriteLabel = firstItemSpriteLabel;
  if (this.buttons.canvas.mouse.isDowning &&
      this.buttons.canvas.mouse.isHovering) {
    var foundGround = _.find(objects, function(obj) {
      var mesh = obj.object;
      return mesh.userData.isGround;
    });
    if (firstBio == this) {
      this.shutDownMove();
      return;
    } else if (firstBio instanceof Mob) {
      if (this.hotKeys.skill[0].skillBaseId > 0) {
        this.useSkillByBaseId(this.hotKeys.skill[0].skillBaseId);
      }
    } else if ((_.isObject(foundGround)) &&
               (firstBio instanceof Npc) == false &&
               ((firstBio instanceof Char) == false &&
                (this.buttons.canvas.mouse.rightDowning == false)) &&
               (this.buttons.document.key.shift == false)) {
      this.move(foundGround.point.x, foundGround.point.y);
    }
  }
};