0

I have my world rendered. Based on some specific requirements it includes (some time) some lights on the floor. I am rendering these lights using triangle primitives. Right now I have the following code to zoom and limit the rendering area:

            if(aspect>1)    
                gl.glOrtho(-scale*aspect, scale*aspect, -scale, scale, 0, 2);
            else
                gl.glOrtho(-scale, scale, -scale/aspect, scale/aspect, 0, 2);

As you can see in this image, the far plane is cutting the light throught a line (parallel to the line on the circle between B and D)

enter image description here

The problem arises when I rotate my scene... the glOrtho "box" stays fix. You can notice it by looking always at the cutting line on the light. It is no more parallel to the line between B and D...

enter image description here

One of my friend suggested my this document. Basically it explains how to extract frustum planes...

But this would mean that I should check manually each primitive if it is inside or not..

Is there a method using the glOrtho call?

I would like to obtain something like this:

enter image description here

elect
  • 6,765
  • 10
  • 53
  • 119
  • 1
    Sorry, what exactly is your problem and what did you try alread. What do you mean by "light"? All I see is some yellow-ish shape overlaid. – datenwolf Jul 30 '12 at 16:21
  • @datenwolf Yeah, by "light" I mean that yellowish shape. The problem is that I would like to have the far plane rotating as my scene rotates. Instead it remains fixed. You can see that in the first image, the far plane cut the scene always perpendicular to the viewer direction (or the line between the font B and D). In the second image my scene is rotated, but the far plane not. Tell me if it is still unclear – elect Jul 30 '12 at 20:15
  • 1
    If I understand your question correctly, you want to know if the far plane of the frustum can rotate with the scene? In that case, I don't believe that you can, by how the view frustum is used to render a scene. If you need a plane constantly perpendicular to the line between B and D, you'll need to draw that plane yourself. – AlcoJaguar Jul 30 '12 at 20:30
  • @AlcoJaguar Ah ok, thanks for the info. However, drawing a plane would work only when the BD line is in a specific 180° range.. Do you have an idea how I could do to get it always working? – elect Jul 31 '12 at 07:51

1 Answers1

1

Okay, after explanation by elect in the comments the answer is: You've got a misconception of what the viewing volume clip planes are.

They are not some sort of bounding box aligned with the scene.

The near and far clipping plane are sort of projections of the screen into the world and they are, by definition, alway aligned with the view. There's nothing you can do about this, because this is fundamental to the math used by OpenGL.

It is also impossible in OpenGL to let primitives expand toward infinity, so geometry has to be limited in some way anyhow.

datenwolf
  • 159,371
  • 13
  • 185
  • 298
  • Thanks for the explanation. However, do you know some technique to create a sort of bounding box? @datenwolf – elect Jul 31 '12 at 07:54
  • @elect: Well that depends on your desired visual outcome. How about you use Photoshop to draw manually, what you'd like to see and post it here? – datenwolf Jul 31 '12 at 11:27
  • @elect: Why don't you draw simply a triangle with the far edge at the desired distance? – datenwolf Jul 31 '12 at 19:39