Jump to content
• ### What is your GameDev Story?

• Advertisement

# Drawing a Plane as a Quad

This topic is 4900 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

## Recommended Posts

Anyone know how to quickly make a quad that lies on a plane? Drawing it as a giant quad seems like the best solution (or as 2 triangles, but both methods need 4 seperate points). first one to reply with the correct answer gets a cookie.

#### Share this post

##### Share on other sites
Advertisement
hmm... there are no planes actually... everything's triangles and/or quads (which are triangles too...)

so, if you've drawn a plane - that should mean you've drawn a "flat" quad too...?

maybe you should rephrase your question, if the question wasn't answered... :)

#### Share this post

##### Share on other sites
Title: Drawing a Plane as a Quad

That should give an idea of what I'm trying to achieve.

Content: Anyone know how to quickly make a quad that lies on a plane? Drawing it as a giant quad seems like the best solution (or as 2 triangles, but both methods need 4 seperate points).

How I intend on drawing it. As the first sentance says, I want to know how to calculate 4 points on a plane that make up a quad. I also point out that I can also draw it as 2 triangles, but regardless I still need those 4 points for either method.

maybe you should reread my question, if the question wasn't clear... :)

#### Share this post

##### Share on other sites
What is your plane equation?

Btw, you can render infinite planes if you really want:
glBegin(GL_QUADS);	glVertex4f(-1, -1, 0, 0);	glVertex4f(-1, 1, 0, 0);	glVertex4f(1, 1, 0, 0);	glVertex4f(1, -1, 0, 0);glEnd();
Renders the infinite plane z = 0.

Enigma

#### Share this post

##### Share on other sites
My planes are defined by the normal (abc) and distance from [0,0,0] (d).

I was originally using the code you posted, but I now need the ability to render arbitry planes :/

#### Share this post

##### Share on other sites
Quote:
 Original post by MENTALAnyone know how to quickly make a quad that lies on a plane? Drawing it as a giant quad seems like the best solution (or as 2 triangles, but both methods need 4 seperate points).

What is not clear is: do you want render a quad on a plane or render a quad that seems a plane ? [smile]

#### Share this post

##### Share on other sites
Should be easy enough. Off the top of my head, create a new vector tx by cross producting your normal with a random vector which is not parallel to your normal. Create a second new vector ty by cross producting your normal and tx. Now specify your vertices as:
glBegin(GL_QUADS);	glVertex4f((tx.x + ty.x) + n * d, (tx.y + ty.y) + n * d, (tx.z + ty.z) + n * d, 0);	glVertex4f((tx.x - ty.x) + n * d, (tx.y - ty.y) + n * d, (tx.z - ty.z) + n * d, 0);	glVertex4f((-tx.x - ty.x) + n * d, (-tx.y - ty.y) + n * d, (-tx.z - ty.z) + n * d, 0);	glVertex4f((-tx.x + ty.x) + n * d, (-tx.y + ty.y) + n * d, (-tx.z + ty.z) + n * d, 0);glEnd();
Enigma

#### Share this post

##### Share on other sites
I read your second post. Ok...you want to render arbitrary planes.
You can do somothing like this

I suppose your plane is in the implicit form

 n * P  + d = 0       where n : unitary length normal             d : distance from the origin O = (0,0,0)

Pseudo code (again I suppose Len(n)~1 )

Vector u,v;if( n~z ){ // similar -> you are lucky!!!   u = Vector(1,0,0); // x   v = Vector(0,1,0); // y}else{   u = N ^ z; // cross product -> note that u lies on the plane   v = N ^ u; // v is orthogonal to both N and u (again is in the plane)  }// now simply draw a quad centered in a arbitrary point of the plane// and large enough to seems a planeVector P0 = - N * d;        // "arbitrary" pointfloat  f  = zfar_distance;  // large enoughVector fu =  u * f;Vector fv =  v * f;Vector P1 = P0 - fu - fv;Vector P2 = P0 + fu - fv;Vector P3 = P0 + fu + fv;Vector P4 = P0 - fu + fv;// draw your verticesVertex(P1);Vertex(P2);Vertex(P3);Vertex(P4);

#### Share this post

##### Share on other sites
Here's a sketch of how to do it, the arithmetic may not be precise:

First, take your
plane normal and determine the rotation required to transform (0,0,1) to
that normal. i.e.

Let n be your plane's normal
Then since dotProduct( n, (0,0,1)) = n.z => cos(theta) = n.z
=> theta = acos( n.z )
and axis = Normalize( crossProduct( (0,0,1) , n ))

So then, the rotation required to take (0,0,1) to n is theta around axis. You use this rotation to transform the four points that correspond to the 'edges' of Z=0 plane, and the resulting points represent something parallel to the desired plane.

To get the desired plane, translate each point by d*n. Once again, just look a the overall method and DONT trust the precise math.

SporadicFire

#### Share this post

##### Share on other sites
Quote:
 Original post by SporadicFireHere's a sketch of how to do it, the arithmetic may not be precise:First, take your plane normal and determine the rotation required to transform (0,0,1) tothat normal. i.e.Let n be your plane's normalThen since dotProduct( n, (0,0,1)) = n.z => cos(theta) = n.z => theta = acos( n.z )and axis = Normalize( crossProduct( (0,0,1) , n ))So then, the rotation required to take (0,0,1) to n is theta around axis. You use this rotation to transform the four points that correspond to the 'edges' of Z=0 plane, and the resulting points represent something parallel to the desired plane.To get the desired plane, translate each point by d*n. Once again, just look a the overall method and DONT trust the precise math.SporadicFire

This can be interesting in the case you describe your plane by spherical coordinates...the problem can also reduced to simply fill the change base matrix (similar to gluLookAt) and pass it to GL as MODELVIEW; but it need attention [smile]
And I think this is a case in which the computing optimization is not important due to the large fill rate (you draw 1,4,8 planes not 10000!)

#### Share this post

##### Share on other sites

• Advertisement
• Advertisement
• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

(You must login to your GameDev.net account.)

• ### Popular Now

• 15
• 9
• 11
• 9
• 9
• Advertisement
• ### Forum Statistics

• Total Topics
634135
• Total Posts
3015753
×

## Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!