Menu

[025cc2]: / Samples / SampleBlobs.py  Maximize  Restore  History

Download this file

96 lines (71 with data), 2.9 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
"""Blob, blob, blob."""
import math
import random
import d3d11
import d3d11x
import d3d11gui
from d3d11c import *
BLOB_COUNT = 4 #Don't change this.
class SampleBlobs(d3d11x.Frame):
def onCreate(self):
#Add a macro and replace the default effect with our own.
d3d11x.Mesh.effectMacros["BLOB_COUNT"] = str(BLOB_COUNT)
d3d11x.Mesh.effectName = "SampleBlobs.fx"
self.mesh = d3d11x.Mesh(self.device, d3d11x.getResourceDir("Mesh", "sphere.obj"))
#Blob data.
self.blobs = []
self.pos = [
d3d11.Vector(-1.5, 6.0, -4.0), d3d11.Vector(1.5, 0.0, -4.0),
d3d11.Vector(6.5, 7.0, -4.0), d3d11.Vector(-6.5, 7.0, -4.0)
]
#GUI stuff.
self.manager = d3d11gui.Manager(self.device, self.window)
main = d3d11gui.Window(self.manager, d3d11x.Rect(10, 50, 200, 120))
main.text = "Choose the technique:"
choice = d3d11gui.Choice(main, d3d11x.Rect(5, 30, 150, 25))
choice.onChoice = self.onChoiceTech
choice.add("Merge")
choice.add("Meta")
choice.add("Wobble")
choice.add("Avoid")
choice.add("No effect")
self.tech = 0
def onChoiceTech(self, event, i, text):
self.tech = i
def onMessage(self, msg):
return self.manager.onMessage(msg)
def onUpdate(self):
yBoost = 2 #Add some movement to y-axis.
sintime = math.sin(self.time)
costime = math.cos(self.time)
#Second blob.
p = self.pos[1]
p.x = sintime * 8
p.y = costime * yBoost + 6.0
#Third blob.
p = self.pos[2]
p.x = costime * 4 + 5
p.y = sintime * yBoost + 7.5
#Fourth blob.
p = self.pos[3]
p.x = -sintime * 4 - 7
p.y = costime * yBoost + 8.5
#Save blob positions.
self.blobs = []
for p in self.pos:
self.blobs.append((p.x, p.y, -4))
def onRender(self):
view = self.createLookAt((0, 7, -25), (0, 8, 0))
projection = self.createProjection(60, 0.1, 300.0)
self.mesh.effect.set("blobAction", self.tech)
self.mesh.effect.set("positions", self.blobs)
self.mesh.effect.set("time", self.time)
for i, blob in enumerate(self.blobs):
meshWorld = d3d11.Matrix()
meshWorld.translate(blob)
self.mesh.effect.set("self", i)
self.mesh.render(meshWorld, view, projection)
self.manager.render(self.frameTime)
if __name__ == "__main__":
sample = SampleBlobs("Blobs - DirectPython 11", __doc__)
sample.mainloop()
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.