Esempio n. 1
0
  public Raycaster pickingRay(Vector3 vector, Camera camera) {
    vector.z = -1.0f;
    Vector3 end = new Vector3(vector.x, vector.y, 1.0f);

    unprojectVector(vector, camera);
    unprojectVector(end, camera);

    end.sub(vector).normalize();

    return new Raycaster(vector, end);
  }
Esempio n. 2
0
 public Vector3 unprojectVector(Vector3 vector, Camera camera) {
   camera.projectionMatrix.getInverse(camera.projectionMatrix);
   viewProjectionMatrix.multiplyMatrices(camera.matrixWorld, camera.projectionMatrixInverse);
   return vector.applyProjection(viewProjectionMatrix);
 }
Esempio n. 3
0
  private void projectObject(Object3D parent) {

    for (Object3D object : parent.children) {

      if (object.visible == false) continue;

      if (object instanceof Light) {

        renderData.lights.add((Light) object);

      } else if (object instanceof Mesh || object instanceof Line) {

        if (object.frustumCulled == false || frustum.intersectObject(object) == true) {

          this.object = getNextObjectInPool();
          this.object.object = object; // TODO fix casting here.

          if (object.renderDepth != Float.NaN) {

            this.object.z = object.renderDepth;

          } else {

            vector3.getPositionFromMatrix(object.matrixWorld);
            vector3.applyProjection(viewProjectionMatrix);
            this.object.z = vector3.z;
          }

          renderData.objects.add(this.object);
        }

      } else if (object instanceof Sprite || object instanceof Particle) {

        this.object = getNextObjectInPool();
        this.object.object = object;

        if (object.renderDepth != Float.NaN) {

          this.object.z = object.renderDepth;

        } else {

          vector3.getPositionFromMatrix(object.matrixWorld);
          vector3.applyProjection(viewProjectionMatrix);
          this.object.z = vector3.z;
        }

        renderData.sprites.add(this.object);

      } else {

        this.object = getNextObjectInPool();
        this.object.object = object;

        if (object.renderDepth != Float.NaN) {

          this.object.z = object.renderDepth;

        } else {

          vector3.getPositionFromMatrix(object.matrixWorld);
          vector3.applyProjection(viewProjectionMatrix);
          this.object.z = vector3.z;
        }
      }
    }

    projectObject(object);
  }