30 |
|
|
31 |
from vob.fillet import light3d |
from vob.fillet import light3d |
32 |
from vob.putil.demowindow import w |
from vob.putil.demowindow import w |
33 |
|
from org.nongnu.libvob.input import RelativeAxisListener |
34 |
from random import Random |
from random import Random |
35 |
|
import math |
36 |
|
|
37 |
|
def quatmul(a, b): |
38 |
|
return ( |
39 |
|
a[3] * b[0] + a[0] * b[3] + a[1] * b[2] - a[2] * b[1], |
40 |
|
a[3] * b[1] - a[0] * b[2] + a[1] * b[3] + a[2] * b[0], |
41 |
|
a[3] * b[2] + a[0] * b[1] - a[1] * b[0] + a[2] * b[3], |
42 |
|
a[3] * b[3] - a[0] * b[0] - a[1] * b[1] - a[2] * b[2], |
43 |
|
) |
44 |
|
|
45 |
|
|
46 |
class Scene: |
class Scene: |
47 |
"Random graph" |
"Random graph" |
48 |
def __init__(self): |
def __init__(self): |
49 |
|
self.rot = (0, 0, 0, 1) |
50 |
|
def rotX(a): self.rot = quatmul((0,-math.sin(.005*a),0,math.cos(.005*a)), self.rot) |
51 |
|
def rotY(a): self.rot = quatmul((-math.sin(.005*a), 0, 0, math.cos(.005*a)), self.rot) |
52 |
|
|
53 |
self.key = KeyPresses( |
self.key = KeyPresses( |
54 |
self, |
self, |
55 |
SlideLin("x", 200, 20, "x", "Left", "Right"), |
SlideLin("x", 200, 20, "x", "Left", "Right"), |
56 |
SlideLin("y", 300, 20, "y", "Up", "Down"), |
SlideLin("y", 300, 20, "y", "Up", "Down"), |
57 |
SlideLin("ang", 0, 3, "Rotation angle", "Prior", "Next"), |
Action("Rotate Left", "Left", lambda *x: rotX(10)), |
58 |
SlideLin("ang2", 0, 3, "Rotation angle 2", "Home", "End"), |
Action("Rotate Right", "Right", lambda *x: rotX(-10)), |
59 |
|
Action("Rotate Up", "Up", lambda *x: rotY(-10)), |
60 |
|
Action("Rotate Down", "Down", lambda *x: rotY(10)), |
61 |
Action("Use display list", "D", self.compile, noAnimation=1), |
Action("Use display list", "D", self.compile, noAnimation=1), |
62 |
*light3d.commonkeys |
*light3d.commonkeys |
63 |
) |
) |
64 |
self.list = None |
self.list = None |
65 |
|
|
66 |
|
class Listener(RelativeAxisListener): |
67 |
|
def __init__(self, changed): |
68 |
|
self.changed = changed |
69 |
|
|
70 |
|
def changedRelative(self, x): |
71 |
|
self.changed(x) |
72 |
|
vob.AbstractUpdateManager.setNoAnimation() |
73 |
|
vob.AbstractUpdateManager.chg() |
74 |
|
|
75 |
|
if 0: |
76 |
|
self.ps2 = vob.input.impl.PS2MouseDevice("/dev/input/mouse1", "main", |
77 |
|
vob.input.impl.PS2MouseDevice.IMPS_PROTO) |
78 |
|
self.naxes = len(self.ps2.getAxes()) |
79 |
|
self.ps2.getAxes()[0].setMainListener(Listener(rotX)) |
80 |
|
self.ps2.getAxes()[1].setMainListener(Listener(rotY)) |
81 |
|
|
82 |
def compile(self, *args): |
def compile(self, *args): |
83 |
if self.list: |
if self.list: |
84 |
self.list = None |
self.list = None |
142 |
0.5 * size.height, |
0.5 * size.height, |
143 |
0.5 * box); |
0.5 * box); |
144 |
|
|
145 |
cs = vs.coords.rotateXYZ(cs, 0, 1, 0, self.ang); |
cs = vs.coords.rotateQuaternion(cs, *self.rot) |
146 |
vs.matcher.add(cs, "Rot") |
vs.matcher.add(cs, "Rot") |
|
cs = vs.coords.rotateXYZ(cs, 1, 0, 0, self.ang2); |
|
|
vs.matcher.add(cs, "Rot2") |
|
147 |
|
|
148 |
if self.list: |
if self.list: |
149 |
vs.put(self.list, cs) |
vs.put(self.list, cs) |