Brian, thank you for the ideas. See answers below.

Here's an improvement on quad strip normals, as shown 
in Light.c from (note change in normals assignment)
http://www.eecs.tulane.edu/www/Terry/OpenGL/Lighting.html

The caps get correct normals, but only first patch of the
quad strip is lit correctly -- all area is flatly lit. 
The others have the effect of a vertical gradient, which also
shows on the reverse side (should not), as seen in the initial 
view (second face).


NB. =========================================================

gsngon=: 3 : '+. (_1^2%y)*^:(<y) 1'

P=:  gsngon 4    NB. regular planar polygon
P0=: P,._1
P1=: P,. 1
Q=: _3]\,P0,.P1  NB. quad strip (last not added to look inside)

GS_AMBIENT=: 0.15
GS_DIFFUSE=: 0.7
GS_SPECULAR=: 0.7
GS_ROTXYZ=: 294 360 287

paint=: 3 : 0
  gsinit GS_LIGHT
  gsdrawviewbox RED
  (0.05;YELLOW) gsmark 4{.   Q
  (0.05;CYAN  ) gsmark 2{.4}.Q
  gsdrawpolygon P0;(gsnormal P0);RED
  gsdrawpolygon P1;(gsnormal P1);BLUE
  gsdrawquadstrip Q;'';GREEN
  gsfini''
)

NB. ------------------------- TBD in jzopenglutil.ijs ---
gsnormal=: (% +/&.(*:"_))@(+/)
gsquadnormal=: (2,:4)&(gsnormal;._3)

gsdrawquadstrip=: 3 : 0 "2
  'v n c'=. y
  v=. gscol3 v
  if. 0=#n do. n=. gsquadnormal v end.
  if. #c do. gscolor c end.
  glBegin GL_QUAD_STRIP
  for_i. i.&.-: #v do.
    if. i~:2 do. glNormal (-:0>.i-2){n end.
    glVertex (i+i.2){v  end.
  glEnd''
)

gsmark=: 0.1&$: : (4 : 0)"1
  glPushMatrix ''
  glTranslate y
  gsdrawcube&>/ 2{.(boxopen x),<SKYBLUE
  glPopMatrix ''
)


--- Brian Schott <[EMAIL PROTECTED]> wrote:

> Oleg,
> 
>       I altered your script to show the flat sides more
> clearly. I added the following line to your paint verb
> below gsinit.
>   glShadeModel GL_FLAT

That's a good workaround, thought it's good to figure out
smooth normals too.

> This resulted in more distinct sides, but may not have been
> what you wanted. I think you can see the result by holding
> down the right-arrow or up-arrow key and watching the
> lighting change. I see the most dramatic changes with the
> right- or left-arrow key movements from the original
> position.

I think, the correct normals should glitter when the face
is orthogonal to view axis, as now is for caps.

>       I noticed a peculiar feature in the graphic that may
> be a reult of your model, or may be a "feature" of the J
> openGL. The feature is that the light shading changes
> dramatically as soon as you press any scene movement key,
> such as j, x, or arrow. Whereas initially the forward end of
> the cylinder is brightly lit, as soon as any key is pressed
> (while the graphic window is in focus), the same end is NOT
> lit any longer.

That's possibly because the subsequent repaint picks up 
the state of the previous scene, whereas first is default.

>       Btw, I ran your graphic by embedding it in the file
> /Users/brian/j601/system/examples/graphics/opengl/demo/glviews.ijs
> . This is done by replacing the 2 characters "XX" in the
> file by your code.

I do all the samples by replacing the whole scene in the
OpenGL Demo "View Definition". You can then make it "Stand Alone"
from the Options menu.

> (B=)
> 
> On Thu, 27 Jul 2006, Oleg Kobchenko wrote:
> 
> + Well, I don't see how OpenGL automatically creates
> + normals. In all examples with light and n-gons (strips, quads, etc.)
> + the normals are explicit. Thus, we can have the utility
> + verb to optionally automatically generate the normals,
> + as shown below. Though I don't like the result very much:
> + there's definitely some normals, but are they correct?
> +
> + P=: +. (4%:_1)*^:(<8) 1  NB. regular planar octagon
> + P0=: P,._1
> + P1=: P,. 1
> + Q=: _3]\,P0,.P1  NB. quad strip (last not added to look inside)
> +
> + GS_AMBIENT=: 0.15
> + GS_DIFFUSE=: 0.7
> + GS_SPECULAR=: 0.7
> + GS_ROTXYZ=: 25 40 0
> +
> + paint=: 3 : 0
> +   gsinit GS_LIGHT
> +   gsdrawviewbox RED
> +   gsdrawpolygon P0;'';RED
> +   gsdrawpolygon P1;'';BLUE
> +   gsdrawquadstrip Q;'';GREEN
> +   gsfini''
> + )
> +
> + NB. ========================= TBD in jzopenglutil.ijs ===
> + gsnormal=: (% +/&.(*:"_))@(+/)
> + gsquadnormal=: (2,:4)&(gsnormal;._3)
> +
> + gsdrawquadstrip=: 3 : 0 "2
> +   'v n c'=. y
> +   v=. gscol3 v
> +   if. 0=#n do. n=. gsquadnormal v end.
> +   if. #c do. gscolor c end.
> +   glBegin GL_QUAD_STRIP
> +   for_i. i.&.-: #v do.
> +     if. i>0 do. glNormal (-:i-2){n end.
> +     glVertex (i+i.2){v
> +   end.
> +   glEnd''
> + )
> +
> +
> + ----- Original Message ----
> + From: "Miller, Raul D" <[EMAIL PROTECTED]>
> + To: Programming forum <[email protected]>
> + Sent: Thursday, July 27, 2006 8:08:39 PM
> + Subject: RE: [Jprogramming] opengl geometry meshes?
> +
> +
> + Oleg Kobchenko wrote:
> + > Here's the simplest I could think of.
> + > But no triangles here: a polygon and a quad strip.
> +
> + Thanks.
> +
> + I'll try to look at it in more depth when I have the
> + chance to figure out jzopenglutil.
> +
> + > The problem here is light/normals: it looks like
> + > OpenGL cannot automatically figure out normals (?).
> +
> + That's odd.  Normally it does.
> +
> + And they're extremely simple to figure out --
> + take the (3d) cross product of the two vectors
> + leading out from any corner of a face, and the
> + result is normal to that face.  Divide by the
> + length and you have the normal.
> +
> + I was under the impression that opengl did
> + this by default unless you configured it
> + such that you're providing normals manually.
> +
> + --
> + Raul
> +
> 
> (B=) <----------my "sig"
> 
> Brian Schott
> Atlanta, GA, USA
> schott DOT bee are eye eh en AT gee em ae eye el DOT com
> http://schott.selfip.net/~brian/



__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to