;; Fu Jie Huang  , Feb 2003
;; testing the SoSelection object
;; draw two object. 
;; when clicked, the object will be highlighted with a bounding box

(libload "inventor/inventor")
(libload "inventor/inventorxt")

(setq mywindow (soxt_init "selection"))

(setq selectionroot (new soselection ()))
(==> selectionroot ref)
(==> (==> selectionroot getsf-policy) setvalue @SoSelection_SHIFT)

(setq mycamera  (new soperspectivecamera ()))
(setq mylight   (new sodirectionallight ()))
(==> selectionroot addChild :mycamera:p)
(==> selectionroot addChild :mylight:p)

(setq coneroot  (new soseparator ()))
(let ((mymaterial (new somaterial ()))
      (mytransform (new sotransform ()))
      (myshape (new socone ())))
  (==> (==> mymaterial getmf_diffusecolor) setvalue 1.0 0.0 0.0)
  (==> (==> mytransform getsf_translation) setvalue 2 0 0)
  (==> coneroot addChild :mymaterial:p)
  (==> coneroot addChild :mytransform:p)
  (==> coneroot addChild :myshape:p))

(setq sphereroot (new soseparator ()))
(let ((mymaterial  (new somaterial ()))
      (mytransform (new sotransform ()))
      (myshape     (new sosphere ())))
  (==> (==> mymaterial getmf_diffusecolor) setvalue 0.0 0.0 1.0)
  (==> (==> mytransform getsf_translation) setvalue -2 0 0)
  (==> sphereroot addChild :mymaterial:p)
  (==> sphereroot addChild :mytransform:p)
  (==> sphereroot addChild :myshape:p))

(==> selectionroot addChild :coneroot:p)
(==> selectionroot addChild :sphereroot:p)


(setq myarea (new soxtrenderarea mywindow "test" 1 1 1 ()))
(==> myarea  setscenegraph :selectionroot:p)

;; the trick.  RenderAction is "BoxHighLight", 
;; and "SelectionChange" triggers re-draw
(setq raction (new SoBoxHighlightRenderAction ()))
(==> myarea  setglrenderaction :raction:p)
(==> myarea  redrawOnSelectionChange  :selectionroot:p)

(==> mycamera viewall_node :selectionroot:p  (==> myarea getviewportregion)  2.0)
(==> myarea show)
(soxt_show mywindow)
