### Split_4Link.slf
### two snap-together halves of the parameterized 4-ring
### using the rhombic profile plug
### CHS 2007-11-09


tclinit {
  set winName .slfWindow
  
  source SLIDEUI.tcl
  source MATH.tcl
  
  proc CreateSliders { parent name } {
    set subname "slf_[subst $name]"
    
    if { $parent == {} } {
	set root .$subname
    } elseif { $parent == "." } {
	set root .$subname
    } else {
	set root $parent.$subname
    }
    
    toplevel $root
    
    set oct  [CreateScale $name $root oct  "xoctagonalization"   0.354   0.25   0.5  0.001 1 horizontal]
                                                              ## 0.354 to make an octagonal hole

    set sc  [CreateScale $name $root sc  "plug scale"          0.17    0.1   5.0   0.1   1 horizontal]
    set tx  [CreateScale $name $root tx  "plug x-shift"        0.75   -1     1     0.01  1 horizontal]
    set ty  [CreateScale $name $root ty  "plug y-shift"        0.2    -1     1     0.01  1 horizontal]

    set rot [CreateScale $name $root rot "rot view (y)"        0       0    90     1     1 horizontal]
    
#    pack   $oct   $sc  $tx $ty   $rot     -side top -fill x  ## for individual plug use
    pack   $oct     $rot     -side top -fill x

  }
    CreateSliders $winName slider
}

include "snaplockNEW.slf"


########### Parameterized 4-ring ############

point r2 ( 1 -1 0) endpoint
point r3 ( 0 -1 0) endpoint
point r4 ( -1 -1 0) endpoint
point r6 ( -1 1 0) endpoint
point r8 ( 1 1 0) endpoint
point r1 ( 1 0 0) endpoint
point r5 ( -1 0 0) endpoint
point m1 ( 0.5 0 0) endpoint
point m2 ( {expr $slider_oct} {expr -$slider_oct} 0) endpoint
point m3 ( 0 -0.5 0) endpoint
point m4 ( {expr -$slider_oct} {expr -$slider_oct} 0) endpoint
point m5 ( -0.5 0 0) endpoint
point t1 ( {expr  1-$slider_oct} 0 {expr  $slider_oct}) endpoint
point t2 ( 0.5 -0.5 0.5) endpoint
point t3 ( 0 {expr -1+$slider_oct} {expr  $slider_oct}) endpoint
point t4 ( -0.5 -0.5 0.5) endpoint
point t5 ( {expr -1+$slider_oct} 0 {expr  $slider_oct}) endpoint
point b1 ( {expr 1-$slider_oct} 0 {expr -$slider_oct}) endpoint
point b2 ( 0.5 -0.5 -0.5) endpoint
point b3 ( 0 {expr -1+$slider_oct} {expr -$slider_oct} ) endpoint 
point b4 ( -0.5 -0.5 -0.5) endpoint
point b5 ( {expr -1+$slider_oct} 0 {expr -$slider_oct}) endpoint

face F0R (r2 t2 t3 r3) surface Y endface
face F0L (r3 t3 t4 r4) surface Y endface
face F1R (r3 b3 b2 r2)  surface Y endface
face F1L (r4 b4 b3 r3)  surface Y endface

 face F2 (r4 t4 t5 r5)  surface Y endface
 face F3 (r5 b5 b4 r4)  surface Y endface
 face F4 (r1 t1 t2 r2)  surface Y endface
 face F5 (r2 b2 b1 r1)  surface Y endface
 face F6 (m1 m2 t2 t1)  surface G endface
 face F7 (b1 b2 m2 m1)  surface G endface

face F8 (m2 m3 t3 t2)  surface C endface
face F9 (b2 b3 m3 m2)  surface C endface
face F10 (m3 m4 t4 t3)  surface C endface
face F11 (b3 b4 m4 m3)  surface C endface

 face F12 (m4 m5 t5 t4)  surface G endface
 face F13 (b4 b5 m5 m4)  surface G endface
 face F14 (r1 b1 m1 t1)  surface M endface
 face F15 (r5 t5 m5 b5)  surface M endface

object halfring (F0R F0L F1R F1L  F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 F13 F14 F15 )endobject



group assembly 
  instance halfring  translate(0 {expr -$sli_ty} 0) endinstance
  instance halfring  rotate(0 0 1)(180)  translate(0 {expr $sli_ty} 0) endinstance

  instance plugassembly  endinstance   ### imported from  "snaplockNEW.slf"

(* 
## for adding the plugs individually ...
  instance plug surface R     
    scale( {expr $slider_sc} {expr $slider_sc} {expr $slider_sc} )  
    rotate(1 0 0)(-90)  translate({expr $slider_tx} {expr -$slider_ty} 0)
  endinstance
  instance mirhole surface G
    scale( {expr $slider_sc} {expr $slider_sc} {expr $slider_sc} )
    rotate(1 0 0)(-90)  translate({expr $slider_tx} {expr $slider_ty} 0)
  endinstance

  instance plug surface R  
    scale( {expr $slider_sc} {expr $slider_sc} {expr $slider_sc} )
    rotate(1 0 0)(90)  translate({expr -$slider_tx} {expr $slider_ty} 0)
  endinstance
  instance mirhole surface G
    scale( {expr $slider_sc} {expr $slider_sc} {expr $slider_sc} )
    rotate(1 0 0)(90)  translate({expr -$slider_tx} {expr -$slider_ty} 0)
  endinstance
*)
endgroup


surface W color (1.0 1.0 1.0) endsurface
surface R color (1.0 0.0 0.0) endsurface
surface O color (1.0 0.8 0.5) endsurface
surface Y color (0.9 0.8 0.0) endsurface
surface G color (0.0 0.6 0.2) endsurface
surface C color (0.0 0.7 1.0) endsurface
surface B color (0.0 0.0 1.0) endsurface
surface M color (1.0 0.0 0.7) endsurface
surface D color (0.2 0.2 0.2) endsurface
surface K color (0.5 0.5 0.3) endsurface

# A generic setup for viewing SLF objects
##########################################

light amb
  type SLF_AMBIENT
  color (0.3 0.3 0.3)
endlight

light sun
  type SLF_DIRECTIONAL
  color (0.9 0.9 0.9)
endlight

group world
  instance assembly   
    scale (0.075 0.075 0.075)
    rotate(0 1 0)({expr $slider_rot})
    translate (0 0 0.8)
  endinstance

  instance amb
    id main_amb
  endinstance
  instance sun
    id left_sun
    rotate (0 1 0) (-45)
    rotate (0 0 1) (-60)
  endinstance
endgroup

camera cam
   projection SLF_PERSPECTIVE
  frustum ( -0.2 -0.2 -4 ) ( 0.2 0.2 -0.01 )
endcamera

group gCam
  instance cam
    id iCam
    translate ( 0.0 0.0 1.75 )
  endinstance
endgroup

window Window
  background (1 1 1)
endwindow

viewport vp Window
endviewport

render vp gCam.iCam.cam world  
  light world.left_sun.sun
  light world.main_amb.amb
endrender