include "spike-lib.slf" include "sWave.slf" group World instance Statue translate(0.0 0.0 0.0) scale (0.2 0.2 0.2) endinstance endgroup # 3) Add Color # colors added in above files ############################################################################ # 4) Create Sliders with Tcl/Tk # # The following Tcl/Tk code shows how to create the sliders and variables # that we referenced above. # Make a Tcl initialization block tclinit { set winName .slfWINDOW ### include some tcl libraries source SLIDEUI.tcl source MATH.tcl ### This defines a procedure called CreateSliders proc CreateSliders { parent name } { ### Don't worry about this stuff ... set subname "slf_[subst $name]" if { $parent == {} } { set root .$subname } elseif { $parent == "." } { set root .$subname } else { set root $parent.$subname } toplevel $root ############### change all "var" to correct variable and "file" to file name. ### This is where the sliders are actually created ! ! ! ### variable name variable name slider text ### | | | ### V V V set size [CreateScale $name $root size "Size" 1.0 0.01 3.0 0.01 1 horizontal] set red1 [CreateScale $name $root red1 "Primary Red" 0.0 0.0 1.0 0.01 1 horizontal] set green1 [CreateScale $name $root green1 "Primary Green" 1.0 0.0 1.0 0.01 1 horizontal] set blue1 [CreateScale $name $root blue1 "Primary Blue" 0.0 0.0 1.0 0.01 1 horizontal] ### ^ ^ ^ ^ ### | | | | ### initial slider value---' | | | ### minimum slider value------' | | ### maximum slider value----------' `- slider step value ### This line is important too. This tells the window to display the sliders. pack $size $red1 $green1 $blue1 -side top -fill x } ### This defines a procedure called CreateFadeSliders proc CreateFadeSliders { parent name } { ### Don't worry about this stuff ... set subname "slf_[subst $name]" if { $parent == {} } { set root .$subname } elseif { $parent == "." } { set root .$subname } else { set root $parent.$subname } toplevel $root ############### change all "var" to correct variable and "file" to file name. ### This is where the sliders are actually created ! ! ! ### variable name variable name slider text ### | | | ### V V V set type [CreateScale $name $root type "Fade: 0)No 1) Simple 2) Periodic" 0 0 2 1 1 horizontal] set ang [CreateScale $name $root ang "Fade Angle (Simple)" 180.0 0.0 358.0 2.0 1 horizontal] set period [CreateScale $name $root period "Fade Period" 1 1 180 1 1 horizontal] set red2 [CreateScale $name $root red2 "Secondary Red" 0.0 0.0 1.0 0.01 1 horizontal] set green2 [CreateScale $name $root green2 "Secondary Green" 0.0 0.0 1.0 0.01 1 horizontal] set blue2 [CreateScale $name $root blue2 "Secondary Blue" 0.0 0.0 1.0 0.01 1 horizontal] ### ^ ^ ^ ^ ### | | | | ### initial slider value---' | | | ### minimum slider value------' | | ### maximum slider value----------' `- slider step value ### This line is important too. This tells the window to display the sliders. pack $type $ang $period $red2 $green2 $blue2 -side top -fill x } proc CreateRotSliders { parent name } { ### Don't worry about this stuff ... set subname "slf_[subst $name]" if { $parent == {} } { set root .$subname } elseif { $parent == "." } { set root .$subname } else { set root $parent.$subname } toplevel $root ############### change all "var" to correct variable and "file" to file name. ### This is where the sliders are actually created ! ! ! ### variable name variable name slider text ### | | | ### V V V set ang [CreateScale $name $root ang "Sweep Angle" 0 0 358 2 1 horizontal] set res [CreateScale $name $root res "Resolution" 1 1 6 1 1 horizontal] set ptch [CreateScale $name $root ptch "Pitch" 0.0 -24.0 24.0 1.0 1 horizontal] set xAxis [CreateScale $name $root xAxis "X Axis" 0.0 0.0 1.0 0.1 1 horizontal] set yAxis [CreateScale $name $root yAxis "Y Axis" 1.0 0.0 1.0 0.1 1 horizontal] set zAxis [CreateScale $name $root zAxis "Z Axis" 0.0 0.0 1.0 0.1 1 horizontal] set x [CreateScale $name $root x "Rotate X" 0.0 0.0 1.0 0.1 1 horizontal] set y [CreateScale $name $root y "Rotate Y" 0.0 0.0 1.0 0.1 1 horizontal] set z [CreateScale $name $root z "Rotate Z" 1.0 0.0 1.0 0.1 1 horizontal] ### ^ ^ ^ ^ ### | | | | ### initial slider value---' | | | ### minimum slider value------' | | ### maximum slider value----------' `- slider step value ### This line is important too. This tells the window to display the sliders. pack $ang $res $ptch $xAxis $yAxis $zAxis -side top -fill x } proc CreatePathSliders { parent name } { ### Don't worry about this stuff ... set subname "slf_[subst $name]" if { $parent == {} } { set root .$subname } elseif { $parent == "." } { set root .$subname } else { set root $parent.$subname } toplevel $root ############### change all "var" to correct variable and "file" to file name. ### This is where the sliders are actually created ! ! ! ### variable name variable name slider text ### | | | ### V V V set xPath [CreateScale $name $root xPath "X path: 0)No 1)Cos 2)Sin " 0 0 2 1 1 horizontal] set yPath [CreateScale $name $root yPath "Y path: 0)No 1)Cos 2)Sin " 0 0 2 1 1 horizontal] set zPath [CreateScale $name $root zPath "Z path: 0)No 1)Cos 2)Sin " 0 0 2 1 1 horizontal] set amp [CreateScale $name $root amp "Amplitude" 0.5 0.0 5.0 0.1 1 horizontal] set period [CreateScale $name $root period "Period" 0.0 0.0 10.0 1 1 horizontal] ### ^ ^ ^ ^ ### | | | | ### initial slider value---' | | | ### minimum slider value------' | | ### maximum slider value----------' `- slider step value ### This line is important too. This tells the window to display the sliders. pack $xPath $yPath $zPath $amp $period -side top -fill x } proc CreateSpikeSliders { parent name } { ### Don't worry about this stuff ... set subname "slf_[subst $name]" if { $parent == {} } { set root .$subname } elseif { $parent == "." } { set root .$subname } else { set root $parent.$subname } toplevel $root ############### change all "var" to correct variable and "file" to file name. ### This is where the sliders are actually created ! ! ! ### variable name variable name slider text ### | | | ### V V V set tip [CreateScale $name $root tip "Tip" 0.3 0.01 2.0 0.01 1 horizontal] set tail [CreateScale $name $root tail "Tail" 0.3 0.01 2.0 0.01 1 horizontal] set start [CreateScale $name $root start "Spike Position" 0.7 0.01 1.0 0.01 1 horizontal] set rot [CreateScale $name $root rot "Spike Rotation" 60 0 120 1 1 horizontal] ### ^ ^ ^ ^ ### | | | | ### initial slider value---' | | | ### minimum slider value------' | | ### maximum slider value----------' `- slider step value ### This line is important too. This tells the window to display the sliders. pack $tip $tail $start $rot -side top -fill x } ### This calls the procedure that creates the sliders CreateSliders $winName stat CreateRotSliders $winName rot CreateFadeSliders $winName fade CreatePathSliders $winName path CreateSpikeSliders $winName spike ### a procedure that resizes each TETRA and allows sweeping proc ScaleProc { angle } { global stat_size global rot_ang global rot_res if { $angle > $rot_ang } { return 0.0000001 } elseif { [expr $angle % (2*$rot_res)] == 0 } { return [expr $stat_size] } else { return 0.0000001 } } proc RotXAxis {angle} { global rot_xAxis return $rot_xAxis } proc RotYAxis {angle} { global rot_yAxis return $rot_yAxis } proc RotZAxis {angle} { global rot_zAxis return $rot_zAxis } proc AxisAng {angle} { global rot_ptch return [expr $rot_ptch*$angle/3.0] } proc CosPath {angle period amp} { global SLF_PI return [expr $amp * cos($angle * $SLF_PI * $period / 180.0)] } proc SinPath {angle period amp} { global SLF_PI return [expr $amp * sin($angle * $SLF_PI * $period / 180.0)] } proc ChoosePath {path defaultPath angle period amp} { if {$path == 1} { return [CosPath $angle $period $amp] } elseif {$path == 2} { return [SinPath $angle $period $amp] } else { return $defaultPath } } proc TransX {angle} { global path_amp global path_period global path_xPath return [ChoosePath $path_xPath 1.0 $angle $path_period $path_amp] } proc TransY {angle} { global path_amp global path_period global path_yPath return [ChoosePath $path_yPath 0.0 $angle $path_period $path_amp] } proc TransZ {angle} { global path_amp global path_period global path_zPath return [ChoosePath $path_zPath 0.0 $angle $path_period $path_amp] } proc RotX {angle} { global rot_x return $rot_x } proc RotY {angle} { global rot_y return $rot_y } proc RotZ {angle} { global rot_z return $rot_z } proc RotAng {angle} { return $angle } proc Interp { a b t} { return [expr $a*(1.0 - $t) + $b*$t] } proc FadeToAndBack {color1 color2 angle halfway} { if {$angle < $halfway} { return [Interp $color1 $color2 [expr ( 2.0 * $angle / $halfway) / 2.0 ]] } else { return [Interp $color2 $color1 [expr (2.0 * $angle / $halfway) / 2.0 - 1.0]] } } proc SimpleFade { color1 color2 angle maxAngle } { if {$angle < $maxAngle} { return [Interp $color1 $color2 [expr ( 2.0 * $angle / $maxAngle) / 2.0 ]] } else { return [expr $color2] } } proc Fade { color1 color2 angle } { global fade_type global fade_ang global fade_period if {$fade_type == 0 } { return [expr $color1] } elseif {$fade_type == 1} { return [SimpleFade $color1 $color2 $angle $fade_ang] } else { return [FadeToAndBack $color1 $color2 [expr $angle % (360 / $fade_period)] [expr 180.0/$fade_period]] } } proc RedProc { angle} { global stat_red1 global fade_red2 return [Fade $stat_red1 $fade_red2 $angle] } proc GreenProc { angle} { global stat_green1 global fade_green2 return [Fade $stat_green1 $fade_green2 $angle] } proc BlueProc { angle} { global stat_blue1 global fade_blue2 return [Fade $stat_blue1 $fade_blue2 $angle] } proc Tip {} { global spike_tip return $spike_tip } proc Tail {} { global spike_tail return $spike_tail } proc MoveSpike {} { global spike_start return $spike_start } proc RotateSpike {} { global spike_rot return $spike_rot } } ######################################################################################## # The code below this line specifies the camera, lighting, and rendering. # Don't worry too much about this for now. #################### # CAMERA #################### camera cam projection SLF_PERSPECTIVE frustum ( -0.5 -0.5 -2 ) ( 0.5 0.5 -0.2 ) endcamera group gCamera instance cam id instCam translate ( 0.0 0.0 1.0 ) endinstance endgroup #################### # LIGHTS #################### light lAmbient type SLF_AMBIENT color ( 0.2 0.2 0.2 ) endlight light lTop type SLF_DIRECTIONAL color ( 1.0 1.0 1.0 ) endlight group gLight instance lTop id iTop lookat eye ( 0 0 0 ) target ( -1 -1 -1 ) up ( 0 1 0 ) endlookat translate ( 1 1 1 ) endinstance endgroup #################### # RENDER #################### window WINDOW # background ( 0.25 0.60 1.0 ) endwindow viewport VIEWPORT WINDOW endviewport render VIEWPORT gCamera.instCam.cam World light lAmbient light gLight.iTop.lTop endrender