I think I have discovered how to make my approach
work with the subcomponent system based on openGL "display
lists." For me the breakthrough was understanding that with
the cover scripts provided by J via jzopengl.ijs , every
object must ultimately be embedded in a display list
**after** any coloring, rotations, and translations, etc.
Somehow I thought that the coloring, rotations, and
translations, etc. could be applied to the display list
after it was generated. What a mistake that was.

        In the system I am designing for simulating
contra dancers, most features of the dancers remains
constant throughout a simulation, but often
their position and heading changes and periodically their
color changes to indicated the regrouping of foursomes and
(less often) the redirection of progress of couples reaching
the end of the contra line or set. So the building blocks
approach is appealing especially for the more static
features.

        For anyone interested in the resulting code, I am
attaching a short test case script demonstrating a 3-layer
system with the following three layers.


       display list (atoms)                display lists
   __________________________          __________________
3  LTurtle0       LTurtle1         <---These are in LISTS
2  Turtle0        Turtle1          <---These are in PARTS
1  Head0 Nose0    Head1 Nose1      <---These are in PARTS

        Look in the verb "run" for the two command sequences
backetted by "glNewList LTurtleX , GL_COMPILE" ...
"glEndList ''" for the pieces I had to add.

(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/
NB. turtlemove.ijs
NB. standalone version

require 'opengl'
coinsert 'jgl3 jzopengl '

turtle =: monad define
  glPushMatrix ''
  glPushAttrib GL_CURRENT_BIT
  glEnable GL_NORMALIZE
  glScale SCALE * SIZE
  glClipPlane  GL_CLIP_PLANE0, 0 0 1 0
  glEnable     GL_CLIP_PLANE0
  gluSphere  LQuad, 1 30 30
  glCallList ".'LHead',":y.
  glDisable     GL_CLIP_PLANE0
  glPopAttrib ''
  glPopMatrix ''
)

turtlehead =: monad define
  glPushMatrix ''
  glTranslate 0 1 0
  glColor HCOLOR
  gluSphere LQuad, TURTLE_HEAD_RELATIVE , 30 30
  glCallList ".'LNose',":y.
  glPopMatrix ''
)

turtlenose =: monad define
  glPushMatrix ''
  glTranslate 0 0.25 0
  glColor NCOLOR
  gluSphere LQuad, TURTLE_HEAD_RELATIVE , 30 30
  glPopMatrix ''
)

ROTturtle =: 30 0 0 1
TURTLE_HEAD_RELATIVE =: 0.3 NB. head size relative to body
PARTS =: i. 0
PARTSSTART =: 2000

run =: verb define
  gldefault''
  glinit''
  stdlistlight''
  LQuad =: gluNewQuadric''
  gluQuadricDrawStyle LQuad,GLU_FILL
  gluQuadricNormals   LQuad,GLU_SMOOTH
  genlist 'LTurtle0 LTurtle1'
  genpartslist 'Turtle0 Turtle1 LHead0 LNose0 LHead1 LNose1'
  HCOLOR =: 1 0 1 1
  NCOLOR =: 0 1 0 1
  turtlenose makelist LNose0 ''
  turtlehead makelist LHead0 0
  turtle makelist Turtle0 0
  HCOLOR =: 0 1 0 1
  NCOLOR =: 1 0 1 1
  turtlenose makelist LNose1 ''
  turtlehead makelist LHead1 1
  turtle makelist Turtle1 1 

  glNewList LTurtle0 , GL_COMPILE
  COLOR =: 0 0 1 1
  POSITION =: _1 0 0
  glPushMatrix ''
  glColor COLOR
  glTranslate  POSITION
  glCallList Turtle0
  glPopMatrix ''
  glEndList ''

  glNewList LTurtle1 , GL_COMPILE
  COLOR =: 1 0 0 1
  POSITION =: 1 0 0
  glPushMatrix ''
  glColor COLOR
  glTranslate  POSITION
  glCallList Turtle1
  glPopMatrix ''
  glEndList ''

  stdpaintx ''
)

NB. patterned after genlist in jzopengl
genpartslist=: 3 : 0
  bgn=. >:>./PARTS,PARTSSTART
  if. 2 = 3!:0 y. do.
    nms=. ;: y.
    r=. bgn + i.#nms
    (nms)=: r
  else.
    r=. bgn + i.y.
  end.
  PARTS=: PARTS,r 
  r
)
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to