
# Direct 3D Startup Code for the NEBUKA TEKDEMOS
# Workaround since NLAUNCH accepts no additional arguments.
# nebula home has to be the current working dir
set     nomads_home    [/sys/share/assigns/home.gets]
set     home           $nomads_home
set     3ddevice      " Direct3D V7 HAL "

source  $home/data/tekdemos/tekdemos.tcl


#--------------------------------------------------------------------
#   tekdemos.tcl
#
#   upd.:   01-Apr-2000 floh    added fog.tcl and burningbanana.tcl
#
#   (C) 1999-2000 RADON LABS
#   Beyreuther, Weissflog, Flemming GbR
#
#--------------------------------------------------------------------

global nomads_home
set    demorunning  "none"

#--------------------------------------------------------------------
#
#   Shows the TCL source of the current running Nebula demo.
#   This is pure TK code.
#
#--------------------------------------------------------------------
proc viewsource { datei } {
    if ![winfo exists .code] {
       	toplevel    .code
	    frame       .code.frame
    	pack        .code.frame -expand yes -fill both -padx 1 -pady 1
    	text .code.text -height 20 -wrap word\
    	    -xscrollcommand ".code.xscroll set" \
    	    -yscrollcommand ".code.yscroll set" \
    	    -setgrid 1 -highlightthickness 0 -pady 2 -padx 3
    	scrollbar .code.xscroll -command ".code.text xview" -highlightthickness 0 -orient horizontal
    	scrollbar .code.yscroll -command ".code.text yview" -highlightthickness 0 -orient vertical

    	grid .code.text -in .code.frame -padx 1 -pady 1 -row 0 -column 0 -rowspan 1 -columnspan 1 -sticky news
    	grid .code.yscroll -in .code.frame -padx 1 -pady 1 -row 0 -column 1 -rowspan 1 -columnspan 1 -sticky news
    	grid rowconfig    .code.frame 0 -weight 1 -minsize 0
    	grid columnconfig .code.frame 0 -weight 1 -minsize 0
    }

    wm title     .code "Nebula Source: $datei"
    wm iconname  .code "Nebula Source: $datei"
    wm deiconify .code
    set id [ open $datei "r" ]
    .code.text delete 1.0 end
    .code.text insert 1.0 [read $id]
    .code.text mark set insert 1.0
    close $id
    
return
}

#--------------------------------------------------------------------
#   load_script
#   Laedt ein neues Tekdemo-Script. Vorher wird /usr/scene
#   aufgeraeumt. Nach dem Laden wird die Kamera neu positioniert.
#--------------------------------------------------------------------
proc load_script { script brightness } {
global nomads_home
global demorunning
global bg

    foreach job [after info] { after cancel $job }

    sel /
    delete /usr/scene
    new n3dnode /usr/scene

    # Eventuelle TK-Subfenster killen
    destroy .r
    destroy .ped
    update

    # Eventuellen TIMELOCK korrigieren
    /sys/servers/time.lockdeltat 0.0

    /sys/servers/gfx.setclearcolor $brightness $brightness $brightness $brightness
    set bg $brightness

    source $nomads_home/data/tekdemos/$script
    set    demorunning $nomads_home/data/tekdemos/$script

    # Standard-Kameraposition setzen
    orig
}

#--------------------------------------------------------------------
#   create_window
#   Erzeugt das Tk-Frontend.
#--------------------------------------------------------------------
proc create_window { } {
global 3ddevice
global nomads_home
global bg

    set platform [get_platform]

    wm title     .     "Nebula Tekdemos" 
    wm geometry  .     214x394+580+1
    wm resizable .     0 0

    frame .f0 -relief sunken -borderwidth 1
    pack  .f0 -side top -expand 1

    # D3D/OpenGL-Switcher
    menubutton .f0.mb -width 213   -text $3ddevice -textvariable 3ddevice -indicatoron 1 -menu .f0.mb.m1 -relief raised -direction below
    menu .f0.mb.m1 -tearoff 0               

    if {($platform=="win9x") || ($platform=="win2k")} {
        .f0.mb.m1 add radiobutton -label " Direct3D V6 " -variable 3ddevice -command { tod3d6 
            /sys/servers/gfx.setclearcolor $bg $bg $bg $bg }
        .f0.mb.m1 add radiobutton -label " Direct3D V7 HAL " -variable 3ddevice -command { tod3d7hal 
            /sys/servers/gfx.setclearcolor $bg $bg $bg $bg }
        .f0.mb.m1 add radiobutton -label " Direct3D V7 EMU " -variable 3ddevice -command { tod3d7emu 
            /sys/servers/gfx.setclearcolor $bg $bg $bg $bg }
    }
    .f0.mb.m1 add radiobutton -label " OpenGL " -variable 3ddevice -command { togl 
                /sys/servers/gfx.setclearcolor $bg $bg $bg $bg 
    }
    pack .f0.mb -side top -fill x

    button   .f0.ba   -height 1  -text "Current Source"  -command { viewsource $demorunning }
    pack     .f0.ba  -side right -fill x -expand 1

    button   .f0.bb   -text "Toggle Console"   -command { /sys/servers/console.toggle }
    pack     .f0.bb  -side right -fill x -expand 1

    frame     .f1 -bd 2  -relief sunken 
    pack      .f1 -expand yes -fill both 

    button   .f1.b1   -text "Mesh Interpolation"  -command     { load_script meshanim.tcl   0.5 }
    pack     .f1.b1  -side top -fill x

    button   .f1.b2   -text "Skin Deformation"    -command     { load_script boneanim.tcl   0.5 }
    pack     .f1.b2  -side top -fill x

    button   .f1.b3   -text "Hierarchical Animation"  -command { load_script newplanets.tcl 0   }
    pack     .f1.b3  -side top -fill x

    button   .f1.b4   -text "Animation Blending"      -command { load_script weightdemo.tcl 0.5 }
    pack     .f1.b4  -side top -fill x

    button   .f1.b5   -text "MipMapping"              -command { load_script mipmap.tcl     0.5 }
    pack     .f1.b5  -side top -fill x

    button   .f1.b6   -text "Texture Animation"       -command { load_script textureanim.tcl 0  }
    pack     .f1.b6  -side top -fill x

    button   .f1.b7   -text "Animated Light"          -command { load_script lightanim.tcl   0  }
    pack     .f1.b7  -side top -fill x

    button   .f1.b8   -text "Material Editor"          -command { load_script materialed.tcl 0  }
    pack     .f1.b8  -side top -fill x

    button   .f1.b9   -text "Billboards + Sprites"     -command { load_script billboards.tcl 0.1  
                                                             /usr/lookat.txyz   0    0    0
                                                             /usr/lookat.rxyz  -5   25   0
                                                             /usr/camera.tz     25
                                                            }
    pack     .f1.b9  -side top -fill x

    button   .f1.ba   -text "Particle"     -command { load_script particle.tcl 0.1  
                                                             /usr/lookat.txyz   0   5    0
                                                             /usr/lookat.rxyz  -5   25   0
                                                             /usr/camera.tz     15
                                                            }

    pack     .f1.ba  -side top -fill x

    button   .f1.bb   -text "Exponential Fog"  -command { load_script fog.tcl 0.5  
                                                        /usr/lookat.txyz   0   5   0
                                                        /usr/lookat.rxyz   0   0   0
                                                        /usr/camera.tz     0
                                                        }

    pack     .f1.bb  -side top -fill x

    button   .f1.bc   -text "Burning Banana"  -command { load_script burningbanana.tcl 0.0  
                                                        /usr/lookat.txyz   0   5   0
                                                        /usr/lookat.rxyz   0   0   0
                                                        /usr/camera.tz     20
                                                        }

    pack     .f1.bc  -side top -fill x

}

#--------------------------------------------------------------------
#   main
#   HIER GEHTS LOS
#--------------------------------------------------------------------

if  [ catch { set test $3ddevice } err ] {
    set 3ddevice " OpenGL "
}    

# NomadsHome setzen
set     nomads_home    [/sys/share/assigns/home.gets]
set     home           $nomads_home

# Libs laden
source $nomads_home/bin/nsh.tcl
source $nomads_home/bin/observerlib.tcl 
source $nomads_home/bin/loadtk.tcl
cd $nomads_home/data/tekdemos

# observer-Objekt initialisieren
init_observer

# Window erzeugen
create_window

# Default Demo
load_script meshanim.tcl 0.5

# und los....
/observer.setsleep 0.02
/observer.setgrid  false
/observer.start

#--------------------------------------------------------------------
#   EOF
#--------------------------------------------------------------------

