Ray.class method: intersect

I’m confused about the description of the intersection between ray and quad. It says:

u,v is the intersection point in terms of the quad plane


My method so far is:

     * Calculates intersection between an arena and a ray from the client
     * @param ray the ray from the client camera mouse click, into the
     * worldspace
     * @param arena the arena the client is playing in
     * @return Vec3d holding the point of intersection
    public Vec3d getCollisionCoords(Ray ray, ArenaId arena) {
         * For different arenas, we use different Z-offsets. Our planes are in
         * the x,y-plane using different z's for different arenas
        int zOffset = this.arenaOffsetMap.get(arena.getArenaId());

        //Construct topleft, topright and bottomleft of quad
        Vector3f quadCoordBottomLeft = new Vector3f(-100, -100, zOffset);
        Vector3f quadCoordTopRight = new Vector3f(100, 100, zOffset);
        Vector3f quadCoordTopLeft = new Vector3f(-100, 100, zOffset);

        //initiate vec3f to store collision info (t,u,v)
         * t: distance from origin to collision u,v: is the intersection point
         * in terms of the quad plane
        Vector3f collisionLoc = new Vector3f();

         * TODO: Use correct intersect method
        Boolean intersects = ray.intersectWherePlanarQuad(quadCoordTopLeft, quadCoordTopRight, quadCoordBottomLeft, collisionLoc);
        if (intersects) {
             * Return correct Vec3d
            return new Vec3d(collisionLoc.y, collisionLoc.z, zOffset);
        } else {
            return null;

But I dont understand the u,v-coordinates. If my plane is 200 wu in width and height centered on 0,0 - how do I use the u,v-coordinates to figure out where, in world space, my ray intersected the plane?

Kind regards,

You’d have to use it to interpolate from the corner positions.

What is this for? It seems a long way to go to do an otherwise simple thing.

Simply put - when the user clicks, I send the ray to the server and the server calculates the intersection between the ray and the active playing field (the x,y-plane). Any ideas?

If your quads are all square and flat like that then the math is pretty easy… either if you want to calculate the intersection yourself or just want to convert u,v to x,y.

In the first case, just project the ray to zOffset.

Vector3f rayOrigin = …
Vector3f rayDir = …
float dist = rayOrigin.z - zOffset;
Vector3f loc = rayOrigin.add(rayDir.mult(dist));

…then figure out if loc is within the bounds.

But presuming u/v is sensible, just multiple u and v times width/height and add them to your quad’s origin.

Thank you. Projection is the answer.