0 Replies - 175 Views - Last Post: 26 January 2014 - 08:11 PM Rate Topic: -----

#1 zFollette  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 26-January 14

Line-Plane Intersection

Posted 26 January 2014 - 08:11 PM

I am making a Ray Picking method for my game (LWJGL), so far the only thing that works in that method is Line-Plane intersection when the player is clicking 100% perpendicular to the surface of the plane. This is because when making an equation for the plane using 3 points (1, 0, -1)(0, 1, -1)(1, 1, -1), the equation only needs to utilize the Z axis. Is there any way to account for the X and Y axes?

The code I am currently using:
  Vector3f A = new Vector3f(1, 0, -1);
        Vector3f B = new Vector3f(0, 1, -1);
        Vector3f C = new Vector3f(1, 1, -1);

        Vector3f v1 = new Vector3f(B.x - A.x, B.y - A.y, B.z - A.z);
        Vector3f v2 = new Vector3f(C.x - A.x, C.y - A.y, C.z - A.z);

        float[] i = new float[]{v1.x, v2.x};
        float[] j = new float[]{v1.y, v2.y};
        float[] k = new float[]{v1.z, v2.z};

        float a = (j[0] * k[1]) - (j[1] * k[0]);
        float b = (i[0] * k[1]) - (i[1] * k[0]);
        float c = (i[0] * j[1]) - (i[1] * j[0]);

        float eX = ((a * -C.x));
        float eY = ((b * -C.y));
        float eZ = ((c * -C.z));

        Vector3f v3 = start;
        Vector3f v4 = new Vector3f(end.x - v3.x, end.y - v3.y, end.z - v3.z);

        float tX = v4.x, tY = v4.y, tZ = v4.z;
        float x, y, z;

        float rem = (((a * v3.x) + eX + (b * v3.y) + eY + (c * v3.z) + eZ));
        float t = rem / (tX + tY + tZ);

        x = v3.x + (tX * t);
        y = v3.y + (tY * t);
        z = v3.z + (tZ * t);

        Vector3f v5 = new Vector3f(x, y, z);


The equation for that plane is
(-z - 1 = 0)
So clearly it will not work if you change the X and Y axis values. So does anyone know how to get the line-plane intersect while relying on all axes?

Here is what happens when I cast a ray perpendicular to the plane:
Attached Image

And this is what happens when I am not perpendicular to the plane:
Attached Image

Is This A Good Question/Topic? 0
  • +

Page 1 of 1