Beispiel #1
0
 public void screen2spaceVecHud(float x, float y, float[] vec) {
   float c[] = new float[3];
   y = mViewport[3] - y;
   GMath.unProject(x, y, 1.0f, mLookAtHud, 0, mProjectionHud, 0, mViewport, 0, c, 0);
   vec[0] = c[0] - this.mCameraEyeHud[0];
   vec[1] = c[1] - this.mCameraEyeHud[1];
   vec[2] = c[2] - this.mCameraEyeHud[2];
 }
Beispiel #2
0
  public void screen2space(float x, float y, float[] spacecoords) {
    float c[] = new float[3];
    float f[] = new float[3];
    y = mViewport[3] - y;

    GMath.unProject(x, y, 1.0f, mLookAt, 0, mProjection, 0, mViewport, 0, f, 0);
    GMath.unProject(x, y, 0.0f, mLookAt, 0, mProjection, 0, mViewport, 0, c, 0);

    f[0] -= c[0];
    f[1] -= c[1];
    f[2] -= c[2];
    float rayLength = (float) Math.sqrt(c[0] * c[0] + c[1] * c[1] + c[2] * c[2]);
    // normalize
    f[0] /= rayLength;
    f[1] /= rayLength;
    f[2] /= rayLength;

    float dot1, dot2;

    float pointInPlaneX = 0;
    float pointInPlaneY = 0;
    float pointInPlaneZ = 0;
    float planeNormalX = 0;
    float planeNormalY = 0;
    float planeNormalZ = -1;

    pointInPlaneX -= c[0];
    pointInPlaneY -= c[1];
    pointInPlaneZ -= c[2];

    dot1 =
        (planeNormalX * pointInPlaneX)
            + (planeNormalY * pointInPlaneY)
            + (planeNormalZ * pointInPlaneZ);
    dot2 = (planeNormalX * f[0]) + (planeNormalY * f[1]) + (planeNormalZ * f[2]);

    float t = dot1 / dot2;

    f[0] *= t;
    f[1] *= t;

    spacecoords[0] = f[0] + c[0];
    spacecoords[1] = f[1] + c[1];
  }