   f_[15] * rhs.f_[3];

    ret.f_[4] = f_[0] * rhs.f_[4] + f_[4] * rhs.f_[5] + f_[8] * rhs.f_[6] +
                f_[12] * rhs.f_[7];
    ret.f_[5] = f_[1] * rhs.f_[4] + f_[5] * rhs.f_[5] + f_[9] * rhs.f_[6] +
                f_[13] * rhs.f_[7];
    ret.f_[6] = f_[2] * rhs.f_[4] + f_[6] * rhs.f_[5] + f_[10] * rhs.f_[6] +
                f_[14] * rhs.f_[7];
    ret.f_[7] = f_[3] * rhs.f_[4] + f_[7] * rhs.f_[5] + f_[11] * rhs.f_[6] +
                f_[15] * rhs.f_[7];

    ret.f_[8] = f_[0] * rhs.f_[8] + f_[4] * rhs.f_[9] + f_[8] * rhs.f_[10] +
                f_[12] * rhs.f_[11];
    ret.f_[9] = f_[1] * rhs.f_[8] + f_[5] * rhs.f_[9] + f_[9] * rhs.f_[10] +
                f_[13] * rhs.f_[11];
    ret.f_[10] = f_[2] * rhs.f_[8] + f_[6] * rhs.f_[9] + f_[10] * rhs.f_[10] +
                 f_[14] * rhs.f_[11];
    ret.f_[11] = f_[3] * rhs.f_[8] + f_[7] * rhs.f_[9] + f_[11] * rhs.f_[10] +
                 f_[15] * rhs.f_[11];

    ret.f_[12] = f_[0] * rhs.f_[12] + f_[4] * rhs.f_[13] + f_[8] * rhs.f_[14] +
                 f_[12] * rhs.f_[15];
    ret.f_[13] = f_[1] * rhs.f_[12] + f_[5] * rhs.f_[13] + f_[9] * rhs.f_[14] +
                 f_[13] * rhs.f_[15];
    ret.f_[14] = f_[2] * rhs.f_[12] + f_[6] * rhs.f_[13] + f_[10] * rhs.f_[14] +
                 f_[14] * rhs.f_[15];
    ret.f_[15] = f_[3] * rhs.f_[12] + f_[7] * rhs.f_[13] + f_[11] * rhs.f_[14] +
                 f_[15] * rhs.f_[15];

    *this = ret;
    return *this;
  }

  Mat4 operator*(const float rhs) {
    Mat4 ret;
    for (int32_t i = 0; i < 16; ++i) {
      ret.f_[i] = f_[i] * rhs;
    }
    return ret;
  }

  Mat4& operator*=(const float rhs) {
    for (int32_t i = 0; i < 16; ++i) {
      f_[i] *= rhs;
    }
    return *this;
  }

  Mat4& operator=(const Mat4& rhs) {
    for (int32_t i = 0; i < 16; ++i) {
      f_[i] = rhs.f_[i];
    }
    return *this;
  }

  Mat4 Inverse();

  Mat4 Transpose() {
    Mat4 ret;
    ret.f_[0] = f_[0];
    ret.f_[1] = f_[4];
    ret.f_[2] = f_[8];
    ret.f_[3] = f_[12];
    ret.f_[4] = f_[1];
    ret.f_[5] = f_[5];
    ret.f_[6] = f_[9];
    ret.f_[7] = f_[13];
    ret.f_[8] = f_[2];
    ret.f_[9] = f_[6];
    ret.f_[10] = f_[10];
    ret.f_[11] = f_[14];
    ret.f_[12] = f_[3];
    ret.f_[13] = f_[7];
    ret.f_[14] = f_[11];
    ret.f_[15] = f_[15];
    *this = ret;
    return *this;
  }

  Mat4& PostTranslate(float tx, float ty, float tz) {
    f_[12] += (tx * f_[0]) + (ty * f_[4]) + (tz * f_[8]);
    f_[13] += (tx * f_[1]) + (ty * f_[5]) + (tz * f_[9]);
    f_[14] += (tx * f_[2]) + (ty * f_[6]) + (tz * f_[10]);
    f_[15] += (tx * f_[3]) + (ty * f_[7]) + (tz * f_[11]);
    return *this;
  }

  float* Ptr() { return f_; }

  //--------------------------------------------------------------------------------
  // Misc
  //--------------------------------------------------------------------------------
  static Mat4 Perspective(float width, float height, float nearPlane,
                          float farPlane);

  static Mat4 LookAt(const Vec3& vEye, const Vec3& vAt, const Vec3& vUp);

  static Mat4 Translation(const
# This code creates the ICEM CFD Manager.
#
# Copyright (c) 1993 - 1996 Pacific Marketing and Consulting, Inc,
#       and ICEM Systems, GmbH.  All rights reserved.
# Author:  Wayne A. Christopher, wayne@icemcfd.com

# This is a scrolled button box.

proc scroll_bbox {w name message options variable} {
    global $variable
    
    catch {destroy $w}
    
    set nopts [llength $options]
    if {!$nopts} {puts stderr "Empty options string!!"; return 0}
    
    set sb [expr {$nopts > 10}]
    
    toplevel $w
    wm title $w $name
    message $w.mess -text $message -aspect 400 -relief raised -borderwidth 2
    canvas $w.c -relief raised -borderwidth 2
    frame $w.buts -relief raised -borderwidth 2
    
    frame $w.c.win
    
    # Add all the checkbuttons.
    for {set i 0} {$i < $nopts} {incr i} {
	set opt [lindex $options $i]
	checkbutton $w.c.win.$i -text $opt -variable ${variable}($opt) -anchor nw
	pack append $w.c.win $w.c.win.$i {top fill expand}
    }

    wm withdraw $w
    update idletasks
    
    set width [winfo reqwidth $w.c.win]
    if $sb {
	set height [expr {[winfo reqheight $w.c.win.0] * 10}]
    } else {
	set height [winfo reqheight $w.c.win]
    }
    
    set fitem [$w.c create window 0 0 -window $w.c.win -anchor nw]
    $w.c configure -width $width -height $height \
	-scrollregion "0 0 [winfo reqwidth $w.c.win] [winfo reqheight $w.c.win]" \
	-scrollincrement [winfo reqheight $w.c.win.0]
    
    set donevar ${variable}_scroll_bbox_done
    global $donevar
    
    # Add the buttons.
    button $w.buts.done -text Done -command "set $donevar 1"
    button $w.buts.cancel -text Cancel -command "set $donevar 0"
    button $w.buts.all -text All -command \
	"foreach j \{[array names $variable]\} \{set [format %s(\$j) $variable] 1\}"
    button $w.buts.none -text None -command \
	"foreach j \{[array names $variable]\} \{set [format %s(\$j) $variable] 0\}"
    pack append $w.buts \
	$w.buts.done {left fill expand} \
	$w.buts.cancel {left fill expand} \
	$w.buts.all {left fill expand} \
	$w.buts.none {left fill expand}
	
    if $sb {
	scrollbar $w.scroll -command "$w.c yview"  -relief raised -borderwidth 2 \
	    -orient v
	$w.c configure -yscroll "$w.scroll set"
	pack append $w \
	    $w.mess {top fill} \
	    $w.buts {bottom fill} \
	    $w.c {left fill expand} \
	    $w.scroll {right fill}
    } else {
	pack append $w \
	    $w.mess {top fill} \
	    $w.buts {bottom fill} \
	    $w.c {left fill expand}
    }

    #putcenter $w
    update idletasks
    wm geometry $w +300+300
    update idletasks
    wm deiconify $w
    
    tkwait variable $donevar

    destroy $w
    
    return [set $donevar]
}

proc scroll_bbox_labels {w name message options labels extras colorcommands \
    variable centercommand} {
    global $variable
    
    catch {destroy $w}
    
    set nopts [llength $options]
    if {!$nopts} {puts stderr "Empty options string!!"; return 0}
    
    set sb [expr {$nopts > 12}]
    
    toplevel $w
    wm title $w $name
    message $w.mess -text $message -aspect 400 -relief raised -borderwidth 2
    canvas $w.c -relief raised -borderwidth 2
    frame $w.buts -relief raised -borderwidth 2
    
    frame $w.c.win
    frame $w.c.win.ch
    pack append $w.c.win $w.c.win.ch {left fill}
    
    # Add all the checkbuttons.
    for {set i 0} {$i < $nopts} {incr i} {
	set opt [lindex $options $i]
	set lab [lindex $labels $i]
	set ext [lindex $extras $i]
	eval checkbutton $w.c.win.ch.$i -text \"$lab\" \
	    -variable \"${variable}($opt)\" -anchor nw $ext
	
	pack append $w.c.win.ch $w.c.win.ch.$i {top fill expand}
    }
    
    # Add all the color commands.
    if {$colorcommands != ""} {
	frame $w.c.win.co
	pack append $w.c.win $w.c.win.co {left fill}
	for {set i 0} {$i < $nopts} {incr i} {
	    set com [lindex $colorcommands $i]
	    eval button $w.c.win.co.$i $com
	    
	    pack append $w.c.win.co $w.c.win.co.$i {top fill expand}
	}    
    }
    
    wm withdraw $w
    update idletasks
    
    set width [winfo reqwidth $w.c.win]
    if $sb {
	set height [expr {[winfo reqheight $w.c.win.ch.0] * 10}]
    } else {
	set height [winfo reqheight $w.c.win]
    }
    
    set fitem [$w.c create window 0 0 -window $w.c.win -anchor nw]
    $w.c configure -width $width -height $height \
	-scrollregion "0 0 [winfo reqwidth $w.c.win] [winfo reqheight $w.c.win]" \
	-scrollincrement [winfo reqheight $w.c.win.ch.0]
    
    set donevar ${variable}_scroll_bbox_done
    global $donevar
    
    # Add the buttons.
    button $w.buts.done -text Done -command "set $donevar 1"
    button $w.buts.cancel -text Cancel -command "set $donevar 0"
    button $w.buts.all -text All -command \
	"foreach j \{[array names $variable]\} \{set [format %s(\$j) $variable] 1\}"
    button $w.buts.none -text None -command \
	"foreach j \{[array names $variable]\} \{set [format %s(\$j) $variable] 0\}"
    pack append $w.buts \
	$w.buts.done {left fill expand} \
	$w.buts.cancel {left fill expand} \
	$w.buts.all {left fill expand} \
	$w.buts.none {left fill expand}
	
    if $sb {
	scrollbar $w.scroll -command "$w.c yview"  -relief raised -borderwidth 2 \
	    -orient v
	$w.c configure -yscroll "$w.scroll set"
	pack append $w \
	    $w.mess {top fill} \
	    $w.buts {bottom fill} \
	    $w.c {left fill expand} \
	    $w.scroll {right fill}
    } else {
	pack append $w \
	    $w.mess {top fill} \
	    $w.buts {bottom fill} \
	    $w.c {left fill expand}
    }

    eval $centercommand
    update idletasks
    wm deiconify $w
    
    tkwait variable $donevar

    destroy $w
    
    return [set $donevar]
}

proc scroll_radiobuttons {w name message options labels extras colorcommands \
    variable centercommand} {
    global $variable
    
    catch {destroy $w}
    
    set nopts [llength $options]
    if {!$nopts} {puts stderr "Empty options string!!"; return 0}
    
    set sb [expr {$nopts > 12}]
    
    toplevel $w
    wm title $w $name
    message $w.mess -text $message -aspect 400 -relief raised -borderwidth 2
    canvas $w.c -relief raised -borderwidth 2
    frame $w.buts -relief raised -borderwidth 2
    
    frame $w.c.win
    frame $w.c.win.ch
    pack append $w.c.win $w.c.win.ch {left fill}
    
    # Add all the checkbuttons.
    for {set i 0} {$i < $nopts} {incr i} {
	set opt [lindex $options $i]
	set lab [lindex $labels $i]
	set ext [lindex $extras $i]
	eval radiobutton $w.c.win.ch.$i -text \"$lab\" \
	    -variable $variable -value $opt -anchor nw $ext
	
	pack append $w.c.win.ch $w.c.win.ch.$i {top fill expand}
    }
    
    # Add all the color commands.
    if {$colorcommands != ""} {
	frame $w.c.win.co
	pack append $w.c.win $w.c.win.co {left fill}
	for {set i 0} {$i < $nopts} {incr i} {
	    set com [lindex $colorcommands $i]
	    if {$com != ""} {
		eval button $w.c.win.co.$i $com
	    }
	    
	    pack append $w.c.win.co $w.c.win.co.$i {top fill expand}
	}    
    }
    
    wm withdraw $w
    update idletasks
    
    set width [winfo reqwidth $w.c.win]
    if $sb {
	set height [expr {[winfo reqheight $w.c.win.ch.0] * 10}]
    } else {
	set height [winfo reqheight $w.c.win]
    }
    
    set fitem [$w.c create window 0 0 -window $w.c.win -anchor nw]
    $w.c configure -width $width -height $height \
	-scrollregion "0 0 [winfo reqwidth $w.c.win] [winfo reqheight $w.c.win]" \
	-scrollincrement [winfo reqheight $w.c.win.ch.0]
    
    set donevar ${variable}_scroll_bbox_done
    global $donevar
    
    # Add the buttons.
    button $w.buts.done -text Done -command "set $donevar 1"
    button $w.buts.cancel -text Cancel -command "set $donevar 0"
    pack append $w.buts \
	$w.buts.done {left fill expand} \
	$w.buts.cancel {left fill expand}
	
    if $sb {
	scrollbar $w.scroll -command "$w.c yview"  -relief raised -borderwidth 2 \
	    -orient v
	$w.c configure -yscroll "$w.scroll set"
	pack append $w \
	    $w.mess {top fill} \
	    $w.buts {bottom fill} \
	    $w.c {left fill expand} \
	    $w.scroll {right fill}
    } else {
	pack append $w \
	    $w.mess {top fill} \
	    $w.buts {bottom fill} \
	    $w.c {left fill expand}
    }

    eval $centercommand
    update idletasks
    wm deiconify $w
    
    tkwait variable $donevar

    destroy $w
    
    if [set $donevar] {
	return [set $variable]
    } else {
	return ""
    }
}
