"""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()