示例#1
0
  public void testProj3() {
    Camera camera = new Camera();
    camera.lookAt(0, 0, -30, 0, 0, 0);
    camera
        .getFrustrum()
        .setPerspectiveProjection(90, Frustrum.FovType.AUTO_FIT, 0.1f, 10, 1080, 1920);

    TouchToRay touchToRay = new TouchToRay(1080, 1920);

    Ray ray = touchToRay.getRay(camera, 540, 960);

    ray.getOrigin(mOrigin);
    ray.getDirection(mDirection);
    assertEquals(-29.9f, mOrigin.z, FloatUtil.EPS);
    assertTrue(mDirection.equals(new Vec3(0, 0, 1)));
  }
示例#2
0
  public void testOrtho2() {
    AndroidRenderNode androidRenderNode = new AndroidRenderNode(1080, 1920);
    Camera camera = androidRenderNode.findCamera();

    TouchToRay touchToRay = new TouchToRay(1080, 1920);

    Ray ray = touchToRay.getRay(camera, 0, 960);

    float left = camera.getFrustrum().getLeft();
    float near = camera.getFrustrum().getNear();

    /** Touch at left/center. The ray should strike the left frustrum plane. */
    Vec3 rayDirection = new Vec3();
    Vec3.createVecFromPoints(new Vec3(0, 0, 0), new Vec3(left, 0, -near), rayDirection);
    rayDirection.norm();

    ray.getOrigin(mOrigin);
    ray.getDirection(mDirection);
    assertEquals(2.9f, mOrigin.z, FloatUtil.EPS);
    assertTrue(mDirection.equals(rayDirection));
  }
示例#3
0
  public void testProj4() {
    Camera camera = new Camera();
    camera.lookAt(0, 0, 3, 0, 0, -1);
    camera
        .getFrustrum()
        .setPerspectiveProjection(90, Frustrum.FovType.AUTO_FIT, 0.1f, 10, 1080, 1920);

    TouchToRay touchToRay = new TouchToRay(1080, 1920);

    Ray ray = touchToRay.getRay(camera, 0, 960);

    float left = camera.getFrustrum().getLeft();
    float near = camera.getFrustrum().getNear();

    /** Touch at left/center. The ray should strike the left frustrum plane. */
    Vec3 rayDirection = new Vec3();
    Vec3.createVecFromPoints(new Vec3(0, 0, 0), new Vec3(left, 0, -near), rayDirection);
    rayDirection.norm();

    ray.getOrigin(mOrigin);
    ray.getDirection(mDirection);
    assertEquals(2.9f, mOrigin.z, FloatUtil.EPS);
    assertTrue(mDirection.equals(rayDirection));
  }