comparison src/scheme/view3d.scm @ 0:bf79fb79ee13

Initial Mercurial check in.
author samer
date Tue, 17 Jan 2012 17:50:20 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:bf79fb79ee13
1 (import "samer.j3d.*")
2 (import "samer.j3d.Util")
3
4
5 (define (xform . nodes)
6 (define tg (javax.media.j3d.TransformGroup.))
7 (for-each (lambda (node) (.addChild tg node)) nodes)
8 tg)
9
10 (define (branch . nodes)
11 (define bg (javax.media.j3d.BranchGroup.))
12 (for-each (lambda (node) (.addChild bg node)) nodes)
13 bg)
14
15 (define (root3d . nodes)
16 (define r (Root.))
17 (for-each (lambda (node) (.addChild r node)) nodes)
18 r)
19
20 (define shape javax.media.j3d.Shape3D.)
21 (define (appearance shape app) (.setAppearance shape app) shape)
22
23 (define (manipulate tg)
24 (Util.mouseRotate tg)
25 ; (Util.mouseTranslate tg)
26 (Util.mouseZoom tg)
27 tg)
28
29 (define (rotating period) (lambda (x) (Util.addRotator period x)))
30
31 (put "lookfrom" "(10 20 64)")
32
33 (define c3f javax.vecmath.Color3f.)
34 (define (white) (c3f 1f 1f 1f))
35 (define (green) (c3f 0.1f 1f 0.2f))
36
37
38 (define (view3d vec points container mk-view)
39 (node (.getNode vec)
40 (node "3d"
41 (define view (mk-view))
42 (define VG (ViewGroup.))
43 (define root
44 (root3d
45 (container (xform (manipulate (xform
46 (appearance (Axes.) (Util.color (green) (Util.alpha 0.5 (Util.wireframe))))
47 (shape
48 (Points3DAlpha. points vec)
49 ;(Points4D. points vec)
50 (Util.alpha 0 (Util.points)))
51 ))))
52 VG
53 )
54 )
55 (.attachView VG view)
56 (addtask view)
57 (.compile root)
58 (.activate root)
59 )
60 )
61 )
62
63 ;;; immediate mode viewer:
64 ; get root
65 ; add viewer
66 ; get renderer
67 ; set geometry and appearance
68
69 (define (view-patches x)
70 (define patches (Matrix. "PatchesMatrix" 512 6))
71 (put "stereo" #f)
72 (put "linewidth" 1)
73 ;(addtask (.getTask (samer.j3d.J3DViewer. patches x)))
74 ;(model (PatchArrayAlpha. points vec) (flat (alpha 0.0 (patches))))
75 )
76
77 ; Optional background colour
78 ; (Util.addBackground root
79 ; (javax.media.j3d.Background
80 ; (Color3f. 0.26f 0.23f 0.35f)));
81
82 ;;; appearance bundles
83 '(
84 (define (pointy1) (alpha 0.8 (color '(0.8 0.6 1) (points))))
85 (define (pointy3) (color '(0.8 0.6 1) (points)))
86 (define (wireframe1) (color '(0.6 0.4 0.5) (transparent 0.4 (wireframe))))
87 (define (wireframe2) (color '(0.8 0.6 1) (transparent 0.7 (wireframe))))
88 (define (wireframe3)
89 (define col (c3f 0.6 0.5 0.7))
90 (Util.material col col 48 (wireframe)))
91 )
92
93