Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Three OpenGL questions

MerlinMerlin Member Posts: 38
First,in OpenGL, when you define the clip planes with glFrustum, do the clip planes reside in world space, or camera space? I mean, if you set the clip plane to -20 along Z, if you move the camera to (0,0,-20) , does the clip apply to -40 (because the camera moved) or to -20? So is it camera bound or not?
Second, what is the difference between calling glFrustum and then gluLookAt and calling first gluLookAt and then glFrustum?
Third, do the normals apply to surfaces or vertices? for example, if you make a pyramid, the normals for the surfaces are easy to calc, but if the normals are for vertices, every normal is a bit strange... Besides, a vertex shouldn't have a normal, right? only a plane should.

Comments

  • gautamgautam Member Posts: 642
    [b][red]This message was edited by gautam at 2003-6-9 11:58:30[/red][/b][hr]
    Hey,

    You should really look at some help files for gluLookAt and glFrustum confusion, its really quite simple, but I'll let you learn more than what I can say in a few words by requesting you to go through this before going forward http://fly.cc.fer.hr/~unreal/theredbook/chapter03.html.

    What is a Normal ? In mathematics normal is just a perpendicular, so a perpendicular can exist for a line. However yes you would normally use normal for a surface, and as normally you would use triangles, you would have one normal per triangle as one triangle will always be in one plane. Hope I got that right !! :)

    Hope I answered your questions.


    : First,in OpenGL, when you define the clip planes with glFrustum, do the clip planes reside in world space, or camera space? I mean, if you set the clip plane to -20 along Z, if you move the camera to (0,0,-20) , does the clip apply to -40 (because the camera moved) or to -20? So is it camera bound or not?
    : Second, what is the difference between calling glFrustum and then gluLookAt and calling first gluLookAt and then glFrustum?
    : Third, do the normals apply to surfaces or vertices? for example, if you make a pyramid, the normals for the surfaces are easy to calc, but if the normals are for vertices, every normal is a bit strange... Besides, a vertex shouldn't have a normal, right? only a plane should.
    :



  • MerlinMerlin Member Posts: 38
    Well, the confusion about gluLookAt and glFrustum is no more. I understand what they do, (I already have the red book, thanks) but i had a minor glitch (read bug) in my program. I was using glFrustum on the modelview matrix. i accidentally erased a little line changing the matrix mode and so, it all blew up.
    The normals, i know what they are, i just dont know how can one calculate a normal for a vertex. It's dumb. It can only be calced for planes (including triangles). So, How do i calc my normals for each vertex. One vertex may be part of two triangles that have completely different normals. What do i do with the normal for that vertex? Average between The normals for the triangles? That's incredibly stupid and cumbersome to do for each vertex.
    That's what i dont know. what freaking value do i use for the normal knowing that a point cant have a normal.

    [blue]But thanks anyway for your help.
    Really.[/blue]
  • CroWCroW Member Posts: 348
    ok,you have one triangle (or quad) buildup with 3 (4) vertices.so all 3 vertices have the same normal-vector.that means,you have to use different normals for the same vertices in a cube,depending on which face of the cube youre drawing.

    you could calculate a normal for a triangle with the cross-product:

    triangle is a,b,c

    normal of a: crossproduct(c-a,b-a)
    normal of b: crossproduct(c-b,a-b)
    normal of c: crossproduct(a-b,b-c)

    you just takes the vectors from one vertex to the two others and calculate the cross-product of them.the resulting vector have an angle of 90 degrees to the others,its the normal.you should normalize it by dividing each component by the length of the vector.

    hope this helps.

    length = sqrt(x*x + y*y + z*z);

    crossproduct:
    x = (y1*z2 - y2*z1);
    y = (z1*x2 - z2*x1);
    z = (x1*y2 - x2*y1);
Sign In or Register to comment.