Skip to main content
gamedev.net
🔒 Locked

Rendering a plane

Started by sjf Sep 27, 2005 at 9:23 PM 1 replies 850+ views
Original Post
sjf
sjf
Hey all, I having real diffculity rendering a plane in opengl. I fully understand that opengl has no basic plane implementation, thus I just want to render a really big square! I have tried to work through the process of doing it myself, but without much luck... Can you see the problem, or help in general? TIA

class Plane : public Object
{
public:

...

protected:
private:
   float d;
   vector3f normal;
};

...

void Plane::Render()
{
   material->glSetMaterial();

   vector3f random(0.0f, 1.0f, 0.0f);

   vector3f u = vector3f::Cross(normal, random);
   vector3f v = vector3f::Cross(normal, u);

   vector3f v0 = -normal * d;
   vector3f fu =  u * 100000.0f;
   vector3f fv =  v * 100000.0f;
   vector3f v1 = v0 - fu - fv;
   vector3f v2 = v0 + fu - fv;
   vector3f v3 = v0 + fu + fv;
   vector3f v4 = v0 - fu + fv;

   glBegin(GL_QUADS);
   glNormal3f(normal[x], normal[y], normal[z]);
   glVertex3f(v1[x], v1[y], v1[z]);
   glVertex3f(v2[x], v2[y], v2[z]);
   glVertex3f(v3[x], v3[y], v3[z]);
   glVertex3f(v4[x], v4[y], v4[z]);
   glEnd();

   return;
}

kburkhart84
kburkhart84
I think if you took the numbers you use(10000) and made them 100, you'd be alright. I don't know much about the plane equation, but I know that a problem you will have is that the points you get must be within the OpenGL viewport, as in the near and far part of the frustum. I think it might be easier just to manually code the points to what you need instead of calculating them from the plane equation.


Zakwayda
Zakwayda
This may not be the problem, but it doesn't look like you're normalizing u and v anywhere. Also, it won't work when the plane normal is + or - the y axis.

Also, for debugging I usually draw planes as wireframe grids rather than quads, which I find to be more helpful visually.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.