Schnittpunkt mit 3D-Quads in XNA?

Ich habe also erfolgreich einen Strahl erzeugt, der die Maus darstellt, die nicht in die Welt projiziert wurde, und jetzt muss ich prüfen, ob sich dieser Strahl mit einem Quad-Objekt schneiden kann. Hier ist der Code, mit dem ich den Strahl erhalte:

public Ray GetMouseRay()
    {
        Vector2 mousePosition = new Vector2(cursor.getX(), cursor.getY());

        Vector3 nearPoint = new Vector3(mousePosition, 0);
        Vector3 farPoint = new Vector3(mousePosition, 1);

        nearPoint = viewport.Unproject(nearPoint, projectionMatrix, viewMatrix, Matrix.Identity);
        farPoint = viewport.Unproject(farPoint, projectionMatrix, viewMatrix, Matrix.Identity);

        Vector3 direction = farPoint - nearPoint;
        direction.Normalize();

        return new Ray(nearPoint, direction);
    }

Und ähnlich ist dies meine Quad-Struktur, mit der ich eine "Würfelwelt" im 3D-Raum zeichne. public struct Quad {public Vector3 Origin; public Vector3 UpperLeft; public Vector3 LowerLeft; public Vector3 UpperRight; public Vector3 LowerRight; public Vector3 Normal; public Vector3 Up; public Vector3 Left;

    public VertexPositionNormalTexture[] Vertices;
      public int[] Indexes;
    public short[] Indexes;


    public Quad( Vector3 origin, Vector3 normal, Vector3 up, 
        float width, float height )
    {
        Vertices = new VertexPositionNormalTexture[4];
        Indexes = new short[6];
        Origin = origin;
        Normal = normal;
        Up = up;

        // Calculate the quad corners
        Left = Vector3.Cross( normal, Up );
        Vector3 uppercenter = (Up * height / 2) + origin;
        UpperLeft = uppercenter + (Left * width / 2);
        UpperRight = uppercenter - (Left * width / 2);
        LowerLeft = UpperLeft - (Up * height);
        LowerRight = UpperRight - (Up * height);

        FillVertices();
    }

    private void FillVertices()
    {
        // Fill in texture coordinates to display full texture
        // on quad
        Vector2 textureUpperLeft = new Vector2( 0.0f, 0.0f );
        Vector2 textureUpperRight = new Vector2( 1.0f, 0.0f );
        Vector2 textureLowerLeft = new Vector2( 0.0f, 1.0f );
        Vector2 textureLowerRight = new Vector2( 1.0f, 1.0f );

        // Provide a normal for each vertex
        for (int i = 0; i < Vertices.Length; i++)
        {
            Vertices[i].Normal = Normal;
        }

        // Set the position and texture coordinate for each
        // vertex
        Vertices[0].Position = LowerLeft;
        Vertices[0].TextureCoordinate = textureLowerLeft;
        Vertices[1].Position = UpperLeft;
        Vertices[1].TextureCoordinate = textureUpperLeft;
        Vertices[2].Position = LowerRight;
        Vertices[2].TextureCoordinate = textureLowerRight;
        Vertices[3].Position = UpperRight;
        Vertices[3].TextureCoordinate = textureUpperRight;

        // Set the index buffer for each vertex, using
        // clockwise winding
        Indexes[0] = 0;
        Indexes[1] = 1;
        Indexes[2] = 2;
        Indexes[3] = 2;
        Indexes[4] = 1;
        Indexes[5] = 3;
    }
}

Ich fand, dass die Strahlklasse eine Methode intersects () hat, die a nimmtEbene struct als Parameter, und die Ebenenstruktur nimmt im Konstruktor eine Normale und einen Abstand vom Ursprung an, aber meine Ebenen haben eine Position und eine Normale anstatt nur einen Abstand vom Ursprung, sodass ich sie nicht konvertieren kann. Wie kann ich feststellen, ob mein Strahl meine Quad-Struktur schneidet?

Bearbeiten: Mir ist klar, dass ich die ebene Struktur nicht verwenden kann, da sie nicht von endlicher Größe ist und keine Ecken enthält, wie es bei meinem Quad der Fall ist. Ich muss jetzt einen Weg finden, um festzustellen, ob dieser Strahl das von mir erstellte Quad schneidet ...

Vielen Dank fürs Lesen, mir ist klar, dass diese Frage etwas langwierig ist, und ich danke Ihnen im Voraus.

Antworten auf die Frage(3)

Ihre Antwort auf die Frage