! Copyright (C) 2008 Jeff Bigot ! See http://factorcode.org/license.txt for BSD license. USING: kernel namespaces accessors assocs make math math.functions math.trig math.parser hashtables sequences combinators continuations colors colors.constants prettyprint vars quotations io io.directories io.pathnames help.markup io.files ui.gadgets.panes ui ui.gadgets ui.traverse ui.gadgets.borders ui.gadgets.frames ui.gadgets.tracks ui.gadgets.labels ui.gadgets.labeled ui.gadgets.lists ui.gadgets.buttons ui.gadgets.packs ui.gadgets.grids ui.gadgets.corners ui.gestures ui.gadgets.scrollers splitting vectors math.vectors values 4DNav.turtle 4DNav.window3D 4DNav.deep 4DNav.space-file-decoder models fry adsoda adsoda.tools ; QUALIFIED-WITH: ui.pens.solid s QUALIFIED-WITH: ui.gadgets.wrappers w IN: 4DNav VALUE: selected-file VALUE: translation-step VALUE: rotation-step 3 \ translation-step set-value 5 \ rotation-step set-value VAR: selected-file-model VAR: observer3d VAR: view1 VAR: view2 VAR: view3 VAR: view4 VAR: present-space ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! namespace utilities : closed-quot ( quot -- quot ) namestack swap '[ namestack [ _ set-namestack @ ] dip set-namestack ] ; ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! waiting for deep-cleave-quots : 4D-Rxy ( angle -- Rx ) deg>rad [ 1.0 , 0.0 , 0.0 , 0.0 , 0.0 , 1.0 , 0.0 , 0.0 , 0.0 , 0.0 , dup cos , dup sin neg , 0.0 , 0.0 , dup sin , dup cos , ] 4 make-matrix nip ; : 4D-Rxz ( angle -- Ry ) deg>rad [ 1.0 , 0.0 , 0.0 , 0.0 , 0.0 , dup cos , 0.0 , dup sin neg , 0.0 , 0.0 , 1.0 , 0.0 , 0.0 , dup sin , 0.0 , dup cos , ] 4 make-matrix nip ; : 4D-Rxw ( angle -- Rz ) deg>rad [ 1.0 , 0.0 , 0.0 , 0.0 , 0.0 , dup cos , dup sin neg , 0.0 , 0.0 , dup sin , dup cos , 0.0 , 0.0 , 0.0 , 0.0 , 1.0 , ] 4 make-matrix nip ; : 4D-Ryz ( angle -- Rx ) deg>rad [ dup cos , 0.0 , 0.0 , dup sin neg , 0.0 , 1.0 , 0.0 , 0.0 , 0.0 , 0.0 , 1.0 , 0.0 , dup sin , 0.0 , 0.0 , dup cos , ] 4 make-matrix nip ; : 4D-Ryw ( angle -- Ry ) deg>rad [ dup cos , 0.0 , dup sin neg , 0.0 , 0.0 , 1.0 , 0.0 , 0.0 , dup sin , 0.0 , dup cos , 0.0 , 0.0 , 0.0 , 0.0 , 1.0 , ] 4 make-matrix nip ; : 4D-Rzw ( angle -- Rz ) deg>rad [ dup cos , dup sin neg , 0.0 , 0.0 , dup sin , dup cos , 0.0 , 0.0 , 0.0 , 0.0 , 1.0 , 0.0 , 0.0 , 0.0 , 0.0 , 1.0 , ] 4 make-matrix nip ; ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! UI ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! : button* ( string quot -- button ) closed-quot ; ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! : model-projection-chooser ( -- gadget ) observer3d> projection-mode>> { { 1 "perspective" } { 0 "orthogonal" } } ; : collision-detection-chooser ( -- gadget ) observer3d> collision-mode>> { { t "on" } { f "off" } } ; : model-projection ( x -- space ) present-space> swap space-project ; : update-observer-projections ( -- ) view1> relayout-1 view2> relayout-1 view3> relayout-1 view4> relayout-1 ; : update-model-projections ( -- ) 0 model-projection view1> model<< 1 model-projection view2> model<< 2 model-projection view3> model<< 3 model-projection view4> model<< ; : camera-action ( quot -- quot ) '[ drop _ observer3d> with-self update-observer-projections ] closed-quot ; : win3D ( text gadget -- ) "navigateur 4D : " rot append open-window ; ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! 4D object manipulation ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! : (mvt-4D) ( quot -- ) present-space> swap call space-ensure-solids >present-space update-model-projections update-observer-projections ; inline : rotation-4D ( m -- ) '[ _ [ [ middle-of-space dup vneg ] keep swap space-translate ] dip space-transform swap space-translate ] (mvt-4D) ; : translation-4D ( v -- ) '[ _ space-translate ] (mvt-4D) ; ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! menu ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! : menu-rotations-4D ( -- gadget ) 3 3 { 1 1 } >>filled-cell 1 >>fill "XY +" [ drop rotation-step 4D-Rxy rotation-4D ] button* add-gadget "XY -" [ drop rotation-step neg 4D-Rxy rotation-4D ] button* add-gadget @top-left grid-add 1 >>fill "XZ +" [ drop rotation-step 4D-Rxz rotation-4D ] button* add-gadget "XZ -" [ drop rotation-step neg 4D-Rxz rotation-4D ] button* add-gadget @top grid-add 1 >>fill "YZ +" [ drop rotation-step 4D-Ryz rotation-4D ] button* add-gadget "YZ -" [ drop rotation-step neg 4D-Ryz rotation-4D ] button* add-gadget @center grid-add 1 >>fill "XW +" [ drop rotation-step 4D-Rxw rotation-4D ] button* add-gadget "XW -" [ drop rotation-step neg 4D-Rxw rotation-4D ] button* add-gadget @top-right grid-add 1 >>fill "YW +" [ drop rotation-step 4D-Ryw rotation-4D ] button* add-gadget "YW -" [ drop rotation-step neg 4D-Ryw rotation-4D ] button* add-gadget @right grid-add 1 >>fill "ZW +" [ drop rotation-step 4D-Rzw rotation-4D ] button* add-gadget "ZW -" [ drop rotation-step neg 4D-Rzw rotation-4D ] button* add-gadget @bottom-right grid-add ; : menu-translations-4D ( -- gadget ) 3 3 { 1 1 } >>filled-cell 1 >>fill 1 >>fill "X+" [ drop { 1 0 0 0 } translation-step v*n translation-4D ] button* add-gadget "X-" [ drop { -1 0 0 0 } translation-step v*n translation-4D ] button* add-gadget add-gadget "YZW"