Vector Math

So I finally figured out my ray casting problem, now the new problem I am facing is the math for line/plane intersection, I have learned a lot so far on the topic, just not enough. I have now figured out the whole Vector Math problem, here is my code:

Vector3f A = new Vector3f(0, 0, 0);
        Vector3f B = new Vector3f(1, 0, 0);
        Vector3f C = new Vector3f(1, 1, 0);
        float x = 0, x1 = A.x, x2 = B.x, x3 = C.x;
        float y = 0, y1 = A.y, y2 = B.y, y3 = C.y;
        float z = 0, z1 = A.z, z2 = B.z, z3 = C.z;
        float[] xC = new float[] {x - x1, x2 - x1, x3 - x1};
        float[] yC = new float[] {y - y1, y2 - y1, y3 - y1};
        float[] zC = new float[] {z - z1, z2 - z1, z3 - z1};
        float addI = (yC[1] * zC[2]) - (yC[2] * zC[1]);
        float addJ = -((xC[1] * zC[2]) - (xC[2] * zC[1]));
        float addK = (xC[1] * yC[2]) - (xC[2] * yC[1]);
        
        float numOfTs = (addI * (end.x - start.x)) + (addJ * (end.y - start.y)) + (addK * (end.z - start.z));
        float num = (addI * (x1)) + (addJ * (y1)) + (addK * (z1)) - (addI * start.x) - (addJ * start.y) - (addK * start.z);
        float t = num / numOfTs;
        x = start.x + ((end.x - start.x) * t);
        y = start.y + ((end.y - start.y) * t);
        z = start.z + ((end.z - start.z) * t);
        float vectX = (x + xC[0]);
        float vectY = (y + yC[0]);
        float vectZ = (z + zC[0]);
        Vector3f intersection = new Vector3f(vectX, vectY, vectZ);

On top of that, here is my Ray Casting bit if anyone needs it: (The compileBuffer methods just make Float and Int Buffers)

float[] matModelView = new float[16], matProjView = new float[16];
        int[] view = new int[16];
        float mouseX = width / 2;
        float mouseY = height / 2;
        Vector3f start = new Vector3f();
        Vector3f end = new Vector3f();

        FloatBuffer modelBuffer = compileBuffer(matModelView);
        FloatBuffer projBuffer = compileBuffer(matProjView);
        FloatBuffer startBuffer = compileBuffer(new float[]{start.x, start.y, start.z, 1});
        FloatBuffer endBuffer = compileBuffer(new float[]{end.x, end.y, end.z, 1});
        IntBuffer viewBuffer = compileBuffer(view);

        glGetFloat(GL_MODELVIEW_MATRIX, modelBuffer);
        glGetFloat(GL_PROJECTION_MATRIX, projBuffer);
        glGetInteger(GL_VIEWPORT, viewBuffer);

        gluUnProject(mouseX, mouseY, 0.0f, modelBuffer, projBuffer, viewBuffer, startBuffer);
        gluUnProject(mouseX, mouseY, 1.0f, modelBuffer, projBuffer, viewBuffer, endBuffer);

        start = new Vector3f(startBuffer.get(0), startBuffer.get(1), startBuffer.get(2));
        end = new Vector3f(endBuffer.get(0), endBuffer.get(1), endBuffer.get(2));

The one problem I am facing when implementing my code into my game is finding the first plane that my line intersects, what it is doing now is going through the order that I test them in, and if the line happens to intersect that plane, that is the detected intersection, how can I make sure I am detecting the FIRST plane that my line intersects?

So the ray is actually a line segment from start to end. What you have to do is test this line segment for intersection with your geometry. The form this takes depends on the geometry but it will probably be either line\plane or line\sphere intersection test. Then maybe sort the intersections to find the closest if you need to do that.

I get that, but how? I don’t have a physical line segment. All I have is the start and end positions, nothing in between to test for intersections.

That is all you need. Because a start and end point completely describe a line segment. Here http://paulbourke.net/geometry/pointlineplane/. Scroll down to line plane intersection. This may not be the best tutorial but to give you an idea. Literally Googling line plane intersection will give you a plethora of good tutorials. If you’re unsure about the whole vector maths then I advice this tutorial http://www.wildbunny.co.uk/blog/vector-maths-a-primer-for-games-programmers/.

I changed the original question.

Don’t do that…it’s annoying and impossible to follow. If you want to pose a new question do it in a new post or thread.

Essentially, I think so. Your description is quite hard to follow. It would be simpler if you worked in traditional algebra and I think would help you when it came to programming the test as well. Write it algebraically.

What’s the question anyway?

The plane equation differs depending on the points given, but to find the point in which the line intersects is:
<X0, Y0, Z0> + t<X1 - X0, Y1 - Y0, Z1 - Z0>
Where 0 is the first point, and 1 is the second point.
Then, solving that equation gives a Vector, these points are the one you have to plug back into the plane equation to get the x, y, z intersection point.

The numbers I have given in the OP are completely random and I have no idea if they actually intersect.

The one time where it would be fine to answer a question with another question … and you don’t do it. Hilarious.

But yeah you seem to know what you’re doing.

The plane equation has only three degrees of freedom. Any positive scale factor applied to the terms represents the same plane. So:

No it’s the same equation…just scaled differently.

I guess you’re correct, but what I am saying is that (x + y + z = 0) will not work for every value passed through, it differs.

Also, I plan to release a text tutorial on this (once I perfect my method) , since I had so much trouble finding out how to do it.

Added another question in the OP.

Did I mention that’s an annoying thing to do?

Sorry, I felt like making new threads for everything was a dumb idea and a useless waste of server space.

No need. Instead of posting “I changed the first post”. Pose your new question instead. Everyone changing the contents of posts makes the thread worthless because it can’t be followed.

Glancing at the first post to guess your new question: it looks like your asking questions related to “how” you think you need to solve a problem than the real problem itself. Example if you want to see if/where a ray intersects an AABB or an AABB-like structure (say a tree)…then the approaches are totally different.

Well I figured it out, so now my system works near flawlessly. I think I will be posting that tutorial now.