Here's the simplest I could think of.
But no triangles here: a polygon and a quad strip.
The problem here is light/normals: it looks like
OpenGL cannot automatically figure out normals (?).
P=: +. (4%:_1)*^:(<8) 1 NB. regular planar octagon
P0=: P,._1
P1=: P,. 1
Q=: (, 2&{.) _3]\,P0,.P1 NB. quad strip
GS_ROTXYZ=: 25 40 0
paint=: 3 : 0
gsinit ''
gsdrawviewbox RED
gsdrawpolygon P0;'';RED
gsdrawpolygon P1;'';BLUE
gsdrawquadstrip Q;'';GREEN
gsfini''
)
gsdrawquadstrip=: 3 : 0 "2 NB. TBD in jzopenglutil.ijs
'v n c'=. y
v=. gscol3 v
if. #n do. glNormal n end.
if. #c do. gscolor c end.
glBegin GL_QUAD_STRIP
glVertex v
glEnd''
)
----- Original Message ----
From: "Miller, Raul D" <[EMAIL PROTECTED]>
To: Programming forum <[email protected]>
Sent: Tuesday, July 25, 2006 3:32:23 PM
Subject: [Jprogramming] opengl geometry meshes?
Describing geometry for opengl can be interesting. Opengl
provides several different ways of describing 3d geometry, the
simplest of which is probably as a set of triangles in three
space.
But, how do you express the meshes which correspond to
solid forms (pythogorean solids, "cylinders", etc.)?
In the J examples I've seen, this issue has been dealt
with one of two ways -- either explicitly provide
the mesh data, or delegate the issue to some other
chunk of software (like NURBS).
It seems like there ought to be some relatively straight
forward algorithms to describe these meshes, at least
for simple geometries. But I've yet to find anything
that seems worthwhile.
Suggestions?
For example, let's say that I want to create an
octagonal cylinder, with corners at
I=:0-.~i:
D=:#~ ~:/@|:@:|
,/(D>,{;~I 2),"1 0/I 1
What's a good (algorithmic) way of expressing a
set of outward facing triangles to represent this
solid? (Feel free to introduce additional points on
any of the surfaces if that makes the algorithm simpler,
and I'm fine with a special-case algorithm -- I'm not
sure it's possible to be "fully general" for all convex
geometry).
Alternatively, if that particular shape is particularly
obnoxious, feel free to illustrate concepts using some
different shape.
Thanks,
--
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm