Draw arbitrary plane from plane equation, OpenGL

Viewed 9539

I have a plane defined by the standard plane equation a*x + b*y + c*z + d = 0, which I would like to be able to draw using OpenGL. How can I derive the four points needed to draw it as a quadrilateral in 3D space?

My plane type is defined as:

struct Plane {
    float x,y,z; // plane normal
    float d;
};

void DrawPlane(const Plane & p)
{
    ???
}

EDIT:

So, rethinking the question, what I actually wanted was to draw a discreet representation of a plane in 3D space, not an infinite plane. Base on the answer provided by @a.lasram, I have produced this implementation, which doest just that:

void DrawPlane(const Vector3 & center, const Vector3 & planeNormal, float planeScale, float normalVecScale, const fColorRGBA & planeColor, const fColorRGBA & normalVecColor)
{
    Vector3 tangent, bitangent;
    OrthogonalBasis(planeNormal, tangent, bitangent);

    const Vector3 v1(center - (tangent * planeScale) - (bitangent * planeScale));
    const Vector3 v2(center + (tangent * planeScale) - (bitangent * planeScale));
    const Vector3 v3(center + (tangent * planeScale) + (bitangent * planeScale));
    const Vector3 v4(center - (tangent * planeScale) + (bitangent * planeScale));

    // Draw wireframe plane quadrilateral:
    DrawLine(v1, v2, planeColor);
    DrawLine(v2, v3, planeColor);
    DrawLine(v3, v4, planeColor);
    DrawLine(v4, v1, planeColor);

    // And a line depicting the plane normal:
    const Vector3 pvn(
       (center[0] + planeNormal[0] * normalVecScale),
       (center[1] + planeNormal[1] * normalVecScale),
       (center[2] + planeNormal[2] * normalVecScale)
    );
    DrawLine(center, pvn, normalVecColor);
}

Where OrthogonalBasis() computes the tangent and bi-tangent from the plane normal.

2 Answers
Related