4 |
|
|
5 |
class Scene: |
class Scene: |
6 |
"""A vertex program version of buoys for exploring |
"""A vertex program version of buoys for exploring |
7 |
1) vertex programs, 2) buoy geometry. |
1) vertex programs, 2) buoy geometry, 3) Cg. |
8 |
|
|
9 |
Not for real use. |
Not for real use. |
10 |
""" |
""" |
21 |
}; |
}; |
22 |
float4x4 pmat; |
float4x4 pmat; |
23 |
|
|
24 |
outs main( float4 orig : POSITION, |
float2 anchorPlace(float4 orig) { |
25 |
|
float4x4 pmat = glstate.matrix.program[0]; |
26 |
|
float div = dot(pmat[3], orig); |
27 |
|
return float2( |
28 |
|
dot(pmat[0], orig) / div, |
29 |
|
dot(pmat[1], orig) / div |
30 |
|
); |
31 |
|
} |
32 |
|
|
33 |
|
outs main( |
34 |
|
float4 orig : POSITION, |
35 |
float4 texcoord : TEXCOORD0, |
float4 texcoord : TEXCOORD0, |
36 |
float4 color : COLOR |
float4 color : COLOR, |
37 |
|
uniform float4 p : C0, |
38 |
|
uniform float4 origin : C1 |
39 |
) { |
) { |
40 |
float4 p = { 100, 350, 0, 0 }; |
outs o; |
41 |
float4 origin = { 500, 350, 0, 0}; |
float rad = 400; |
42 |
|
float2 anchor = anchorPlace(orig); |
43 |
|
|
44 |
|
float2 ap = anchor.xy - origin.xy; |
45 |
|
float aplen = length(ap); |
46 |
|
float2 apnor = ap / aplen; |
47 |
|
|
48 |
|
float2 opnor = normalize(origin.xy - p.xy); |
49 |
|
|
50 |
|
float4 buoy; |
51 |
|
buoy.xy = anchor + orig.z * (10 * opnor); |
52 |
|
buoy.z = 1-orig.z; |
53 |
|
buoy.w = 1; |
54 |
|
|
55 |
|
o.pos = mul(glstate.matrix.mvp, buoy); |
56 |
|
o.pointsize = float4(4. + 4. * orig.z, 0, 0, 0); |
57 |
|
o.color = color; |
58 |
|
return o; |
59 |
|
} |
60 |
|
|
61 |
|
outs foo( |
62 |
|
float4 orig : POSITION, |
63 |
|
float4 texcoord : TEXCOORD0, |
64 |
|
float4 color : COLOR, |
65 |
|
uniform float4 p : C0, |
66 |
|
uniform float4 origin : C1 |
67 |
|
) { |
68 |
|
// float4 p = { 100, 350, 0, 0 }; |
69 |
|
// float4 origin = { 500, 350, 0, 0}; |
70 |
float rad = 400; |
float rad = 400; |
71 |
|
|
72 |
outs o; |
outs o; |
80 |
float w = dot(pmat[3], orig); |
float w = dot(pmat[3], orig); |
81 |
anchor /= w; |
anchor /= w; |
82 |
|
|
83 |
|
|
84 |
float a2o = distance(anchor.xy, origin.xy) / rad; |
float a2o = distance(anchor.xy, origin.xy) / rad; |
85 |
float2 ap ; |
float2 ap ; |
86 |
ap.xy = anchor.xy - p.xy; |
ap.xy = anchor.xy - p.xy; |
87 |
float a2p = length(ap) / rad; |
float a2p = length(ap) / rad; |
88 |
|
|
89 |
|
// first coordinate |
90 |
|
float c1 = (a2o < 1 ? a2p / 2 : 0); |
91 |
|
|
92 |
|
// Two separate locations |
93 |
|
float s1 = .9 * (1-c1); |
94 |
|
float s2 = max(0, -1 + 10*c1); |
95 |
|
|
96 |
|
float ctrhat = max(0, 1-a2o); |
97 |
|
|
98 |
|
float shift = .4 * ctrhat / a2p; |
99 |
|
|
100 |
|
// the "default" position |
101 |
|
float2 defbuoy = anchor + ap * shift; |
102 |
|
|
103 |
|
float d2o = distance(defbuoy.xy, origin.xy) / rad; |
104 |
|
// float dir = 2.*( |
105 |
|
float dir = dot(defbuoy.xy - origin.xy, ap.xy) > 0 ? 1 : -1; |
106 |
|
// Push away |
107 |
|
shift = 0.6 * dir * ctrhat ; |
108 |
|
|
109 |
float4 buoy; |
float4 buoy; |
110 |
|
buoy.xy = anchor + orig.z * (ap * shift + .1 * (origin.xy - p.xy)); |
111 |
|
|
|
buoy.xy = anchor + orig.z * .5 * ap * max(0,1-a2o); |
|
112 |
buoy.z = 1-orig.z; |
buoy.z = 1-orig.z; |
113 |
buoy.w = 1; |
buoy.w = 1; |
114 |
|
|
115 |
o.pos = mul(glstate.matrix.mvp, buoy); |
o.pos = mul(glstate.matrix.mvp, buoy); |
116 |
o.color = float4(1-orig.z, a2o, a2p, color.w); |
o.color = float4(1-orig.z, dir, dir, color.w); |
117 |
o.pointsize = float4(4. + 4. * orig.z, 0, 0, 0); |
o.pointsize = float4(4. + 4. * orig.z, 0, 0, 0); |
118 |
|
|
119 |
return o; |
return o; |
297 |
Vertex %(x)s %(y)s 1 1 |
Vertex %(x)s %(y)s 1 1 |
298 |
""" % locals()) |
""" % locals()) |
299 |
else: |
else: |
300 |
for i in range(0,4000): |
for i in range(0,500): |
301 |
x, y = java.lang.Math.random(), java.lang.Math.random() |
x, y = [2*java.lang.Math.random()-1 for i in (0,1)] |
302 |
vert.append(""" |
vert.append(""" |
303 |
Color %(x)s .0 %(y)s .6 |
Color %(x)s .0 %(y)s .6 |
304 |
Vertex %(x)s %(y)s 0 1 |
Vertex %(x)s %(y)s 0 1 |
361 |
if self.showmapping: |
if self.showmapping: |
362 |
vs.put(GLRen.createSetMatrix("MATRIX0_ARB"), "M", 0, |
vs.put(GLRen.createSetMatrix("MATRIX0_ARB"), "M", 0, |
363 |
0, 350, 1, 1) |
0, 350, 1, 1) |
364 |
vs.put(self.linep, "G", 0, 0, 0, 1, 1) |
vs.map.put(self.linep, 0) |
365 |
else: |
else: |
366 |
vs.put(GLRen.createSetMatrix("MATRIX0_ARB"), "M", 0, |
cs = vs.orthoCS(0, "M", 0, |
367 |
-300+Math.random() * 300, -300+Math.random() * 300, |
-200+Math.random() * 200, -200+Math.random() * 200, |
368 |
1400 + Math.random() * 400, 1400 + Math.random() * 400, |
1200 + Math.random() * 600, 1200 + Math.random() * 600, |
369 |
) |
) |
370 |
|
cs = vs.orthoCS(cs, "F", 0, .5, .5, .5, .5) |
371 |
|
vs.map.put(GLRen.createSetMatrix("MATRIX0_ARB"), cs) |
372 |
|
|
373 |
vs.put(self.pointlist, "F", 0, 0, 0, 1, 1) |
putnoc(vs, getDListNocoords(""" |
374 |
|
ProgramLocalParameter VERTEX_PROGRAM_ARB 0 100 350 0 0 |
375 |
|
ProgramLocalParameter VERTEX_PROGRAM_ARB 1 500 350 0 0 |
376 |
|
""")) |
377 |
|
vs.map.put(self.pointlist, 0) |
378 |
|
putnoc(vs, getDListNocoords(""" |
379 |
|
ProgramLocalParameter VERTEX_PROGRAM_ARB 0 900 350 0 0 |
380 |
|
ProgramLocalParameter VERTEX_PROGRAM_ARB 1 500 350 0 0 |
381 |
|
""")) |
382 |
|
vs.map.put(self.pointlist, 0) |
383 |
|
|
384 |
putnoc(vs, getDListNocoords(""" |
putnoc(vs, getDListNocoords(""" |
385 |
BindProgram VERTEX_PROGRAM_ARB 0 |
BindProgram VERTEX_PROGRAM_ARB 0 |