gzz-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gzz-commits] gzz/gfx/demo vpbuoy.py


From: Tuomas J. Lukka
Subject: [Gzz-commits] gzz/gfx/demo vpbuoy.py
Date: Tue, 17 Dec 2002 09:11:19 -0500

CVSROOT:        /cvsroot/gzz
Module name:    gzz
Changes by:     Tuomas J. Lukka <address@hidden>        02/12/17 09:11:18

Modified files:
        gfx/demo       : vpbuoy.py 

Log message:
        vpbuoy updates

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/demo/vpbuoy.py.diff?tr1=1.8&tr2=1.9&r1=text&r2=text

Patches:
Index: gzz/gfx/demo/vpbuoy.py
diff -u gzz/gfx/demo/vpbuoy.py:1.8 gzz/gfx/demo/vpbuoy.py:1.9
--- gzz/gfx/demo/vpbuoy.py:1.8  Mon Dec 16 10:51:25 2002
+++ gzz/gfx/demo/vpbuoy.py      Tue Dec 17 09:11:18 2002
@@ -1,5 +1,6 @@
 from gfx.util.misc import *
 from gfx.util import vparb, cg
+from java.lang import Math
 
 
 class Scene:
@@ -9,6 +10,14 @@
     Not for real use.
     """
     def __init__(self):
+
+       self.vs = None
+
+       self.x = 500
+       self.y = 350
+       self.w = 500
+       self.h = 350
+
        rad = 400.0
        recrad = 1/400.0
 
@@ -30,6 +39,23 @@
                );
            }
 
+           float2 project2circle(float2 pt, float2 p, float2 ctr, float rad) {
+               float2 ao = pt - ctr;
+               float2 ap = pt - p;
+
+               float a = dot(ap, ap);
+               float b = 2*dot(ap, ao);
+               float c = dot(ao, ao) - rad * rad;
+
+               float det = b*b - 4*a*c;
+
+
+               float ans = (det > 0 ? (-b + sqrt(det)) / (2*a) : 0);
+
+               return pt + ans * ap;
+
+           }
+
            outs main(
                    float4 orig : POSITION, 
                    float4 texcoord : TEXCOORD0,
@@ -43,34 +69,41 @@
 
                float2 ap = anchor.xy - p.xy;
                float2 ao = anchor.xy - origin.xy;
+
                float aplen = length(ap);
                float aolen = length(ao);
                float2 apnor = ap / aplen;
+               float2 opnor = normalize(origin.xy - p.xy);
 
-               float vrad = rad * (1 - .5 * (1 - aolen/rad));
+               float outside = smoothstep(.9, 1, aolen /rad);
+               // float outside = 1;
 
-               float2 opnor = normalize(origin.xy - p.xy);
+               // component of a..origin perpendicular to
+               // origin--p
 
-               float a = dot(ap, ap);
-               float b = 2*dot(ap, ao);
-               float c = dot(ao, ao) - vrad * vrad;
+               float2 yperp = ao - dot(ao,opnor) * opnor;
 
-               float det = b*b - 4*a*c;
+               // float vrad = rad * (1 - .25 * (2 - aplen/rad));
+               float vrad = rad + .1 * outside * aolen; // rad;
+
+
+
+               float2 projected = project2circle(anchor.xy, 
+                       p.xy + outside * yperp, origin.xy + outside * yperp, 
vrad);
 
-               bool outside = aolen > rad;
 
-               float ans = (det > 0 ? (-b + sqrt(det)) / (2*a) : 0);
 
 
                float4 buoy;
-               buoy.xy = anchor + 
-                   ( outside ? orig.z * opnor * 20 
-                             : orig.z * ((ans) * ap));
+               buoy.xy = (orig.z > 0 ? 
+                       projected
+                       // lerp(anchor + opnor * 20 , projected, 1-outside)
+                           : anchor);
                buoy.z = 1-orig.z;
                buoy.w = 1;
 
                o.pos = mul(glstate.matrix.mvp, buoy);
-               o.pointsize = float4(3. + 20. * orig.z * max(1-aolen/rad, 0), 
0, 0, 0);
+               o.pointsize = float4(3. + 60. * orig.z * max(1-aolen/rad, 0), 
0, 0, 0);
                o.color = color;
                return o;
            }
@@ -357,6 +390,30 @@
        if k == "m":
            self.showmapping = 1-self.showmapping
            AbstractUpdateManager.setNoAnimation()
+       if k == " ":
+           self.x, self.y, self.w, self.h = (
+               400+Math.random() * 200, 300+Math.random() * 200,
+               600 + Math.random() * 300, 600 + Math.random() * 300,
+               )
+       self.vs = None
+    def mouse(self, ev):
+       if ev.getID() == ev.MOUSE_DRAGGED:
+           if self.but == ev.BUTTON3_MASK:
+               self.h = self.pwh[1] * math.exp(
+                       (self.press[1] - ev.getY())/150.0)
+               self.w = self.pwh[0] * math.exp(
+                       (self.press[0] - ev.getX())/150.0)
+           elif self.but == ev.BUTTON1_MASK:
+               self.x = self.pxy[0] + (ev.getX() - self.press[0])
+               self.y = self.pxy[1] + (ev.getY() - self.press[1])
+           AbstractUpdateManager.chg()
+           replaceNewScene(self.vs)
+           self.setZoomPan()
+       elif ev.getID() == ev.MOUSE_PRESSED:
+           self.press = (ev.getX(), ev.getY())
+           self.pxy = self.x, self.y
+           self.pwh = self.w, self.h
+           self.but = ev.getModifiers()
     def scene(self, vs):
        vs.map.put(background((.2,.4,.1)))
 
@@ -373,18 +430,14 @@
                Enable BLEND
        """ % self.prog.getProgId()));
 
-       from java.lang import Math
 
        if self.showmapping: 
            vs.put(GLRen.createSetMatrix("MATRIX0_ARB"), "M", 0,
                0, 350, 1, 1)
            vs.map.put(self.linep, 0)
        else:
-           cs = vs.orthoCS(0, "M", 0,
-               -200+Math.random() * 200, -200+Math.random() * 200,
-               1200 + Math.random() * 600, 1200 + Math.random() * 600,
-               )
-           cs = vs.orthoCS(cs, "F", 0, .5, .5, .5, .5)
+           cs = vs.orthoCS(0, "M", 0, 0, 0, 0, 0)
+           self.cs = cs
            vs.map.put(GLRen.createSetMatrix("MATRIX0_ARB"), cs)
 
            putnoc(vs, getDListNocoords("""
@@ -392,15 +445,22 @@
                ProgramLocalParameter VERTEX_PROGRAM_ARB 1 500 350 0 0
            """))
            vs.map.put(self.pointlist, 0)
-           putnoc(vs, getDListNocoords("""
-               ProgramLocalParameter VERTEX_PROGRAM_ARB 0 900 350 0 0
-               ProgramLocalParameter VERTEX_PROGRAM_ARB 1 500 350 0 0
-           """))
-           vs.map.put(self.pointlist, 0)
+           if 0:
+               putnoc(vs, getDListNocoords("""
+                   ProgramLocalParameter VERTEX_PROGRAM_ARB 0 900 350 0 0
+                   ProgramLocalParameter VERTEX_PROGRAM_ARB 1 500 350 0 0
+               """))
+               vs.map.put(self.pointlist, 0)
 
        putnoc(vs, getDListNocoords("""
                BindProgram VERTEX_PROGRAM_ARB 0
                Disable VERTEX_PROGRAM_ARB
        """));
+       self.vs = vs
+       self.setZoomPan()
+
+    def setZoomPan(self):
+       self.vs.coords.setOrthoParams(self.cs, 0, self.x, self.y, self.w, 
self.h)
+
 
 currentScene = Scene()



reply via email to

[Prev in Thread] Current Thread [Next in Thread]