11 |
def ds(): |
def ds(): |
12 |
return rng.nextDouble() * 2 - 1 |
return rng.nextDouble() * 2 - 1 |
13 |
|
|
|
linecon = GZZGL.createLineConnector(0, 0) |
|
14 |
|
|
15 |
# Prototype: project to a semicircle |
execfile("gfx/libutil/effects.py") |
|
# from a point. |
|
|
class NadirCircleFloater(Buoy3Floater): |
|
|
def __init__(self, vs, center, radius, p, nadir): |
|
|
self.vs, self.c, self.r, self.p, self.nadir = vs, center, radius, p, nadir |
|
|
def addBuoy(self, anchorX, anchorY, importance, key, buoy, w, h): |
|
|
size = importance |
|
|
|
|
|
# 1. find the projected buoy point |
|
|
|
|
|
# Vector from center to projection point |
|
|
AmC = (self.p[0] - self.c[0], self.p[1] - self.c[1]) |
|
|
|
|
|
# Vector from anchor to projection point |
|
|
v = (anchorX - self.p[0], anchorY - self.p[1]) |
|
|
|
|
|
# Coefficients of the 2nd degree eq |
|
|
a = v[0]*v[0] + v[1]*v[1] |
|
|
b = 2*(v[0]*AmC[0] + v[1]*AmC[1]) |
|
|
c = AmC[0]*AmC[0] + AmC[1]+AmC[1] - self.r**2 |
|
|
|
|
|
print "S: ",v,AmC,self.r, a,b,c |
|
|
|
|
|
# Determinant |
|
|
det = b**2 - 4*a*c |
|
|
if det <= 0: |
|
|
# For now, ignore |
|
|
print "Ignoring ",key |
|
|
return |
|
|
|
|
|
ans = (-b + math.sqrt(det)) / (2*a) |
|
|
print "DA: ",det,ans |
|
|
|
|
|
b = (self.p[0] + ans * v[0], self.p[1] + ans * v[1]) |
|
|
print "Buoy: (%s,%s): (%s,%s)\n"%( |
|
|
anchorX, anchorY, b[0], b[1]) |
|
|
|
|
|
# Create the coordinate system |
|
|
|
|
|
vs = self.vs |
|
|
transaffine(vs, str(key)+"_1", b[0], b[1], size, 0, 0, size) |
|
|
rotate(vs, str(key)+"_2", 360 * self.nadir.getAngleRad(b[0], b[1]) / |
|
|
(2 * math.pi), 0, 0, 1) |
|
|
buoy.run() |
|
|
poptrans(vs, str(key)+"_2") |
|
|
poptrans(vs, str(key)+"_1") |
|
|
|
|
|
ac = vs.coords.coordsys(0, str(key)+"_5", 10, anchorX, anchorY, 0, 0) |
|
|
bc = vs.coords.coordsys(0, str(key)+"_6", 10, b[0], b[1], 0, 0) |
|
|
vs.map.put(linecon, ac, bc) |
|
16 |
|
|
17 |
class BScene: |
class BScene: |
18 |
def __init__(self): |
def __init__(self): |
49 |
poptrans(vs, key+"_1") |
poptrans(vs, key+"_1") |
50 |
|
|
51 |
def scene(self, vs): |
def scene(self, vs): |
52 |
|
# GZZGL.reallyClearStencilBuffer(1024, 768); |
53 |
putnoc(vs, background((0.1,0.4,0.5))) |
putnoc(vs, background((0.1,0.4,0.5))) |
54 |
self.nadir = NadirAngler(800, self.nadiry[0]) |
self.nadir = NadirAngler(800, self.nadiry[0]) |
55 |
|
|
77 |
else: |
else: |
78 |
f = NadirCircleFloater(vs, (ctrx, ctry), rad, |
f = NadirCircleFloater(vs, (ctrx, ctry), rad, |
79 |
(ctrx+1.5*rad, ctry), self.nadir) |
(ctrx+1.5*rad, ctry), self.nadir) |
80 |
|
putnoc(vs, getDListNocoords(""" |
81 |
|
Disable TEXTURE_2D |
82 |
|
""")) |
83 |
class R(Runnable): |
class R(Runnable): |
84 |
def run(rself): |
def run(rself): |
85 |
vs.put(self.q[self.i], "XXX", 10, -20, -20, 40, 40) |
vs.put(self.q[self.i], "XXX", 10, -20, -20, 40, 40) |