!S0-AppF2.f95  Group ID: #12    Dodecahedron - the 12-face Platonic Solid.
!                               SA2-hVecMath16Mod.f95 computes the geometry.
!2025.05.24.1840cdt- Application F2

!            Author- Jeffrey M. Setterholm, Lakeville,MN 55044 USA
!         IP Status- Free source code (e.g.: post copyright)
!
!          Computer- "T3"/Dell Precision T3500/Intel i5 E5520/Win10Pro-21H2
!                     ^name ^Mfgr.Id           ^chipset       ^OS 
!                    /Absoft Pro Fortran 21.0.2/GeForce GTX 1050/f90gl~Glut3.7
!                     ^compiler ~Fortran 95     ^graphics card   ^graphics

!    f90gl bindings- public domain; see "https://math.nist.gov/f90gl/"

!Disclaimer:
! ***************************************************************
! **********   Individual cognition is always flawed,  **********
! **********         including yours and mine.         **********
! **********                 - So: -                   **********
! **********       Use this code at your own risk.     **********
! ***************************************************************

!Table of Contents: ...use to search...
!Subroutine S12AppF2
!Subroutine PLabelView(A3,P3L,iCol,WidthOfLine)
!---------------------------------------------------------------------------7 9

Subroutine S12AppF2
!2025.04.20.1520cdt JMS- Dodecahedron - the 12-face Platonic Solid.
 use TaskDef   ,only: Analyst,Phone,Street,CityStateZip,IPSummary
 use ioDef     ,only: Up,Ut,iTeapot
 use ScreenDef ,only: yWindowFull,xyWindowRatio,PixelsPerCM,MagFactor
 use MouseDef  ,only: MChan
 use AppsDef   ,only: AppBanner,AppInFile
 use ViewDef   ,only: ThreePhase,V,jVG,Key
 use ModelDef  ,only: M7Init,M7,nM7L,Nnutate
 use SimDef    ,only: RunTimer,IterTotal
 use S2Callback,only: CheckGL
 use OpenGLRec,only:    glPolygonMode,GL_FRONT,GL_LINE,GL_BACK        &
                       ,glLineWidth,glShadeModel,GL_SMOOTH            &
                       ,glBegin,GL_Quads,GL_LINES,glVertex3fv,glEnd   &
                       ,glGetIntegerv,glMatrixMode,GL_MATRIX_MODE     &
                       ,GL_MODELVIEW,glPushMatrix,glPopMatrix,glFlush &
                       ,glMultMatrixd,glLoadIdentity                  &
                       ,glFloat,GL_LINE_STRIP,GL_POINTS,GL_LIGHTING   &
                       ,glVertex3f,glVertex3d,glVertex3dv             &
                       ,glPointSize,glDisable,GL_FLAT

 use TubeDef

 use DodecIO 
     !^ Note: all the reals in DodecIO are quad precision! Use dble() here.
 implicit none
 !-----                                                               Arguments
  integer(4)::iP
 !-----                                                               Internals
  integer(4)::Init,i

  real(8)   ::Angle     !Yaw angle- real(8)
  real(8)   ::Angledv(3)!                  - vector form

  real(4)   ::Anglef    !         - real(4)
  real(4)   ::Anglefv(3)!                  - vector form

  real(8)   ::sY,cY     !         - cosine, sine
  real(8)   ::vTemp(4)  !         - cosine, sine
  integer(4)::iDone,nPoint
  real(8)   ::P1(4)

  !-- Graphics-use
  character::chn*80
  real(8)   ::vTemph(4)  !,vMag,vMag1
  integer(4)::MtxMode(1)
  integer(4)::nRow,nCol

  real(8)   ::XYZRPYwC(7) !(X,Y,Z,Roll,Pitch,Yaw,height of Character)
  real(4)   ::LineWidth = 2
  real(4)   ::LHeight   = 2
  character(len= 3)::A3
  character(len=80)::PText

 !--EndDefs-----------------------------------------------
!  AppNumber    = 2
   iP = Ut
   if(Init.eq.0) then
    !--Establish screen default 7DoF, if desired:
     AppBanner(   2) ='S12AppF2: Dodecahedron Visualization'
     AppInFile(   2) = char(0)
     Analyst(     2) = '    Jeff Setterholm'
     Street(      2) = '    8095 230th St.E.'
     CityStateZip(2) = 'Lakeville, MN 55044 USA'
     Phone(       2) = '     (nnn)-nnn-nnn'
     IPsummary(   2) = '         Free'
                                                  !a35
  !----- Dodecahedron initilization - Jeff Setterholm's algorithm:
     Dd%iFaceSee(0:12)=(/0,1,0,0,0,0,1,0,0,0,1,1,1/) !Face#1,#6,#10,#11,& #12
     Dd%iFaceSee(0:12)=(/0,1,1,0,0,1,1,0,0,0,1,1,1/)
     Dd%iFaceSee(0)   =1 !=0 !=-1
     Dd%iEdgeSee(0)   =0 !=-1
     Dd%iVertexSee(0) =0 !=-1

     if(iP>5)write(iP,"(/'Subroutine S12AppF2 calling DodecModel16() @L103:')")
     call DodecModel16(iP)   !(This will compute the dodecahedron geometry
     call SaveOutFile

     iTeapot        =0  !Turns off the teapot
    !Setting up the default modelview matrix:
     M7(0)%DoF      = (/ 0.d0, 0.d0, 0.d0,   0.d0, 0.d0,  0.d0, 5.d0 /)
    !M7(0)%ioe(1)   = 7 !Immediate control- mag   by  vertical  mouse motion.
     M7(0)%ioe(1)   = 5 !                 - pitch by  vertical  mouse motion.
     M7(0)%ioe(2)   = 6 !                 - yaw   by horizontal mouse motion.
     M7Init           = 0
     call Motion7(0,0,6)  !X  Y  Z  R  P  Y MAG
    !M7(0)%Locked   = (/0, 1, 1, 1, 1, 1, 1, 0  /) !On screen "L"'s Mag moves
     M7(0)%Locked   = (/0, 0, 0, 0, 0, 0, 0, 0  /) !On screen "L"'s Unlocked
     M7(0)%DoFReset = M7(0)%DoF

     Key%VuMode      = 1  !Perspective
     Key%SplitScreen = 0  !Screen not split
     nNutate = 1          !Nutate the modelview matrix
     Init=1
   endif !Init=0

   select case(ThreePhase)
    case(1)  !Background number crunching, if any:
                                                          call CheckGL(+120108)
     !--Establish screen default 7DoF, if desired:

     if(Up>5) then !This section of code only runs when you request a printout.
       !--As a novice, call your numeric subroutine in case(1).
       !   & press "p" for a live DOS screen printout
       !        or "P" for printout to a file (e.g. when you set Up = 13).
       write(Up,"('F2:TP',i1,'Up',i2)") ThreePhase,Up
       write(uP,"(/'S12AppF2:')")
       write(uP,"(  f20.12,' = RunTimer')") RunTimer

     endif!uP>5
                                                          call CheckGL(-120119)

   !~~~~~~~~~~~~~~~
    case(2)  !Update variables & 2D screen info: Superceded by split screen(s)

    case(3)  !Draw/redraw app. 2D & 3D graphics:   (ThreePhase==3)
                                                          call CheckGL(+120125)
!!!if(1>0) return
   !--- Recurring visualization
   call glGetIntegerv(GL_MATRIX_MODE,MtxMode)

   !--- Insert your 2-D code here:
   call glMatrixMode(GL_MODELVIEW)  ;call glPushMatrix;  call glLoadIdentity
                                   nRow = 3;                   nCol = 2
       write(Ptext, "('SA2-hVecMath16Mod.f95/DodecModel16()')")
                              nRow=nRow+1; call PrntOrtho(nRow,nCol,1, 0,PText)
       write(Ptext, "('   computes the geometry.')")
                              nRow=nRow+1; call PrntOrtho(nRow,nCol,1, 0,PText)

   call glMatrixMode(GL_MODELVIEW)  ;call glPopMatrix

   !--- Insert your 3-D code here:
   call glMatrixMode(GL_MODELVIEW)  ;call glPushMatrix

   !-- Draw arcs:
   call glShadeModel(GL_SMOOTH)
 ! call glLineWidth(3._glfloat)
   call glLineWidth(LineWidth)
   call Colors3D(2)

  !call glBegin(GL_LINE_LOOP)         
  !Draw a unit circle in the X-Y plane:
   call glBegin(GL_LINE_strip) !;call Colors3D(8)         
            call glvertex3d( 0.d0,0.d0,0.d0 )
     do i=-90,90 ;Angle=i

       call glvertex3d( dcosd(Angle) ,dsind(Angle) ,0.d0 )

   enddo!i
   call glend ;call glFlush                              ;call CheckGL(-120148)

  !Draw an arc in the X-Z plane:
   call Colors3D(2)  
   call glBegin(GL_LINE_strip)
     do i=-90,90 ;Angle=i
       call glvertex3d( dcosd(Angle),0.d0,-dsind(Angle) )        
     enddo!i
       call glvertex3d( 0.d0,0.d0,-0.79465447229d0 )
   call glend ;call glFlush

  !Draw an arc inscribing the five vertices of face#11:
   vTemph=(/  0.60706199821d0, 0.d0, -0.79465447229d0, 1.d0 /)
   call Colors3D(2)
   call glBegin(GL_LINE_strip)        
     do i=-108,108 ;Angle=i ;cY=vTemph(1)*dcosd(Angle)
                             sY=vTemph(1)*dsind(Angle)
          call glvertex3d(cY,sY,vTemph(3))
     enddo!i
   call glend ;call glFlush

   !--- Visualize vertex & face-center points:
   call Colors3D( 1)
   call glShadeModel(GL_SMOOTH)
  !call glLineWidth(4._glfloat)
   call glPointSize(6._glfloat)
  !call Colors3D(15)
  !call Colors3D(15)
   call glBegin(GL_POINTS)
     do i=1,20 ;if(Dd%iVertexSee(i).eq.0) cycle
       call glvertex3dv(dble(Dd%Vertex(1:3,i)))
     enddo!i
   call glend ;call glFlush

  !call Colors3D(1)                             !13->1
   call glBegin(GL_POINTS)
     do i=1,12 ;if(Dd%iFaceSee(i).eq.0) cycle
       call glvertex3dv(dble(Dd%vNormal(1:3,i)))
     enddo!i
   call glend ;call glFlush

   !--- For each selected face:
      !if(iP.gt.5) write(iP,"('Face drawing:')")                   !Diagnostics
   do i=1,12 ;if(Dd%iFaceSee(i).eq.0) cycle
     !Number the face:
     write(chn(1:3),"(i2,1x)") i
     if(Dd%iFaceSee(0).gt.-1)  &
     call PLabelView(chn(1:3),dble(Dd%vNormal(1:3,i)), 1,3.)

     !Draw the outward normal:
     if(Dd%iFaceSee(0).le.-2)  exit
     call glShadeModel(GL_SMOOTH) ;call glLineWidth(2._glfloat)
     call Colors3D(15)
     call glBegin(GL_LINES)
                               vTemp(1:3  )=Dd%vNormal(1:3,i)*.75d0 
       call glvertex3dv(       vTemp(1:3  ) ) !0.d0,0.d0,0.d0) 
       call glvertex3dv(dble(Dd%vNormal(1:3,i)))
      !if(iP.gt.5) write(iP,"(i2,3f20.10)") i,Dd%vNormal(1:3,i)       !Diagnostics
     call glend ;call glFlush
   enddo!i
   !--- For each selected vertex:
   do i=1,20 ;if(Dd%iVertexSee(i).eq.0) cycle
     !Number the vertices:
     if(Dd%iVertexSee(0).le.-1) exit
      write(chn(1:3),"(i2,1x)") i
       if(Dd%iVertexSee(0).ge.0) &
       call PLabelView(chn(1:3),dble(Dd%Vertex(1:3,i)),12,3.)
   enddo!j
   !--- For each selected edge:
   do i=1,30 ;if(Dd%iEdgeSee(i).eq.0) cycle   
     !Draw the edges:
     if(Dd%iEdgeSee(0).le.-2) exit
     call glShadeModel(GL_SMOOTH) ;call glLineWidth(2._glfloat)
     call Colors3D(13) !(mod(i,10)+6) !
     call glBegin(GL_LINES)        
       call glvertex3dv(dble(Dd%Vertex(1:3,Dd%iEdge(1,i)))) 
       call glvertex3dv(dble(Dd%Vertex(1:3,Dd%iEdge(2,i)))) 
     call glend ;call glFlush

    !The solid edge tubes are drawn here.
     call Colors3D(1)
     iDone=-2
     P1=(Dd%Vertex(1:4,Dd%iEdge(1,i)))
     call Sphere(.02d0,P1)
     call Tubes(iDone,nPoint,P1,.02d0,0)
     P1=(Dd%Vertex(1:4,Dd%iEdge(2,i)))
     call Sphere(.02d0,P1)
     call Tubes(iDone,nPoint,P1,.02d0,0)
    
     !Number the edges:
     call glDisable(GL_LIGHTING)
     if(Dd%iEdgeSee(0).le.-1) cycle
     vTemph=( Dd%Vertex(1:4,Dd%iEdge(1,i)) + Dd%Vertex(1:4,Dd%iEdge(2,i)) )/2.d0
     write(chn(1:3),"(i2,1x)") i
     call PLabelView(chn(1:3),vTemph(1:3),13,2.)
   enddo!i

!--Draw colored axes:
   call glLineWidth(2.)
  !--
   call Colors3D(11) !Green
   call glBegin(GL_LINES)
     call glVertex3f(0.,0.,0.); call glVertex3f(1.,0.,0.)
   call glEnd
  !--
   call Colors3D( 9) !Yellow
   call glBegin(GL_LINES)
     call glVertex3f(0.,0.,0.); call glVertex3f(0.,1.,0.)
   call glEnd
  !--
   call Colors3D( 7) !Red
   call glBegin(GL_LINES)
     call glVertex3f(0.,0.,0.); call glVertex3f(0.,0.,1.)
   call glEnd; call glFlush
  !--
   
  !if(nCol>0) then
    !--Axis labels:
    !              XYZRPYwC=(/   X ,   Y  , Z   , Roll, Pitch, Yaw,width Ch/)   
                   XYZRPYwC=(/ .8d0, .0d0,-.02d0, 0.d0,  0.d0,  0.d0 ,.1d0 /)
    !call VecFont7(XYZRPYwC,LineWidth,iCol,Label)
     PText="+X" ; call VecFont7(XYZRPYwC,LineWidth, 11 ,PText) !Green
     
                   XYZRPYwC=(/ .0d0, .8d0,-.02d0, 0.d0,  0.d0, 90.d0 ,.1d0 /)             
     PText="+Y" ; call VecFont7(XYZRPYwC,LineWidth,  9 ,PText) !Yellow
     
                   XYZRPYwC=(/ .0d0, .02d0, .8d0, 0.d0,-90.d0,  0.d0 ,.1d0 /)          
     PText="+Z" ; call VecFont7(XYZRPYwC,LineWidth,  7 ,PText) !Red
                                                          call CheckGL(-120266)
   !---
   call glMatrixMode(GL_MODELVIEW ) ;call glPopMatrix
   call glMatrixMode(MtxMode(1))
   call glFlush                                          ;call CheckGL(-120280)
   end select!ThreePhase

   return
!End Subroutine DodecViz
End Subroutine S12AppF2
!---------------------------------------------------------------------------7 9

Subroutine PLabelView(A3,P3L,iCol,WidthOfLine)
!2025.04,17.1220cdt JMS
!2013.10.15.0640cdt JMS- PLabelView(+WidthOfLine)->public
 !-----
 implicit none                                                       !arguments
  real(8)   ::P3L(3)
  integer(4)::iCol
  real(4)   ::WidthOfLine
 !---                                                                !internals
  character ::chn*80
  integer(4)::j
  real(8)   ::rA(3),xA(3)

  real(8)   ::XYZRPYwC(7) !(X,Y,Z,Roll,Pitch,Yaw,height of Character)
  character(len= 3)::A3
  character(len=80)::PText

  !----------
   xA(1)=P3L(1) ;rA(1)=  0.d0 != 90.d0
   xA(2)=P3L(2) ;rA(2)=  0.d0 !=-90.d0
   xA(3)=P3L(3) ;rA(3)= 90.d0 !=  0.d0
!! call glLineWidth(WidthOfLine)       !-- This doesn't appear to work yet
   do j=1,3
     select case(j)
      case(1);write(chn,"(     4x     ,f5.2    ,a1)")   P3L(1),char(0)
              xA(2)=P3L(2)+.03d0+.20d0
      case(2);write(chn,"(a3,a1)") A3,char(0)
              xA(2)=P3L(2)+.03d0
       XYZRPYwC=(/ xA(1),xA(2),xA(3),rA(1),rA(2),rA(3),.04d0 /)     !2025.04.15
                      ! VecFont7(XYZRPYwC,  LineWidth,iCol,Label)
       PText=chn ; call VecFont7(XYZRPYwC,WidthOfLine,iCol,PText)

      case(3);write(chn,"(     4x     ,f5.2    ,a1)")   P3L(3),char(0)
              xA(2)=P3L(2)+.03d0-.20d0
     end select!j
   enddo!j
   return
End Subroutine PLabelView
!---------------------------------------------------------------------------7 9
