############################################################################ # # Triangles - a simple SLIDE example # # This example shows how to do the following: # 1) Comment Code # 2) Specify Geometry # 3) Add Color # 4) Create Sliders with Tcl/Tk ############################################################################ # 1) Comment Code # # "#" - comments out a single line, like "//" in C++ (* "(* text *)" - comments out all text in between, like "/* */" in C++ *) ############################################################################ # 2) Specify Geometry # # 2a) First specify the primitive objects (spheres, cones, etc) and their parameters. # The complete SLIDE syntax is http://www.cs.berkeley.edu/~ug/slide/docs/slide/spec/ point pTri0 ( -1 0 0 ) endpoint point pTri1 ( 1 0 0 ) endpoint point pTri2 ( 0 {expr $triangle_higt} 0 ) endpoint face fTri ( pTri0 pTri1 pTri2 ) endface object oTri ( fTri ) endobject group gTriangles instance oTri scale ( {expr $triangle_size} {expr $triangle_size} {expr $triangle_size} ) surface sBlue shading SLF_WIRE endinstance instance oTri surface sRed translate ( 3 0 0 ) rotate ( 0 0 1 ) ( {expr 30.0*$SLF_TIME*$triangle_sped} ) endinstance endgroup # 2c) Finally we need to add the triangles to the World. group World instance gTriangles scale ( 0.1 0.1 0.1 ) endinstance endgroup ############################################################################ # 3) Add Color # # In the Triangle group we specified the surface color of each instance. # Now we need to define these surfaces. surface sBlue color (0.0 0.0 1.0) endsurface surface sRed color (1.0 0.0 0.0) endsurface ############################################################################ # 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 ### This is where the sliders are actually created ! ! ! ### variable name variable name slider text ### | | | ### V V V set higt [CreateScale $name $root higt "Height" 1 0.1 2 0.1 1 horizontal] set size [CreateScale $name $root size "Size" 1 1 5 0.1 1 horizontal] set sped [CreateScale $name $root sped "Speed" 1 1 5 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 $higt $size $sped -side top -fill x } ### This calls the procedure that creates the sliders CreateSliders $winName triangle } ######################################################################################## # 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