Ejemplo n.º 1
0
    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
Ejemplo n.º 2
0
    def test_ctor(self):
        v = d3d11.Vector()
        self.assert_(v.x == 0.0 and v.y == 0.0 and v.z == 0.0 and v.w == 0.0)
        self.assert_(self.equal(v, d3d11.Vector()))

        v = d3d11.Vector(1, 2, 3)
        v2 = d3d11.Vector(v)
        self.assert_(self.equal(v, v2))
        self.assert_(self.equal(v, d3d11.Vector((1, 2, 3))))
Ejemplo n.º 3
0
 def randomVector(self):
     v = d3d11.Vector(*[random.random() * 142.325 for x in range(3)])
     self.assert_(v.x == v[0] and v.y == v[1] and v.z == v[2])
     self.assert_(len(v) == 3)
     self.assert_(self.equal(v, v))
     t = tuple(v)
     return v
Ejemplo n.º 4
0
    def test_mul(self):
        C = 5.34
        a = self.randomVector()
        b = a * C

        v = d3d11.Vector(a)
        v *= C
        self.assert_(self.equal(b, v))
Ejemplo n.º 5
0
	def onCreate(self):
		#self.device = d3d11.Device(self.window, DRIVER_TYPE_WARP)
		self.camera = d3d11x.Camera()

		self.cubeMarker = marker.CubeMarker()
		self.cubeMarker.position = d3d11.Vector(40, 40, 40)
		marker.mgr.addMarker(self.cubeMarker)

		gridplane.createPlanes()

		self.panel = Panel(self.device, self.window)
		self.scene = scene.FbxScene('assets/box_only.fbx')
		self.scene.load()
Ejemplo n.º 6
0
    def __init__(self, effect=None):
        self.effecName = effect
        self.vertexBuffer = None
        self.indexBuffer = None
        self.effect = None
        self.position = d3d11.Vector(0, 0, 0)
        self.yaw = 0
        self.pitch = 0
        self.roll = 0
        self.scale = (1, 1, 1)

        self.rotationMatrix = d3d11.Matrix()
        self.translationMatrix = d3d11.Matrix()
        self.scaleMatrix = d3d11.Matrix()
        self.world = d3d11.Matrix()
        self.build()
    def renderScene(self):
        #This renders the scene into the current render target.
        eyePoint = d3d11.Vector(0, 5, -10)
        viewMatrix = self.createLookAt(eyePoint, (0, 0, 0))
        projMatrix = self.createProjection(60, 0.1, 300)

        #Render the skybox.
        skyMatrix = d3d11.Matrix()
        skyMatrix.translate(
            (0, eyePoint.y - self.skyBox.height / 2.0, eyePoint.z))
        self.skyBox.render(skyMatrix, viewMatrix, projMatrix)

        meshMatrix = d3d11.Matrix()
        meshMatrix.rotate((self.time, 0, self.time))
        #Add a red light and render the mesh.
        self.mesh.setLights([((0, 10, 10), (1, 0, 0, 0))])
        self.mesh.render(meshMatrix, viewMatrix, projMatrix)
Ejemplo n.º 8
0
 def createLights(self):
     #Add 7 lights (maximum defined in 'Shared.fx').
     lights = []
     for i in range(1, 8):
         #Each light is little farther than the previous one.
         distance = i * 5
         lightTime = self.time * (i * 0.5)
         #Use sin() and cos() to create a nice little movement pattern.
         x = math.sin(lightTime) * distance
         z = math.cos(lightTime) * distance
         y = self.heightmap.getHeight(x, z)
         pos = d3d11.Vector(x, y + 1, z)
         #Set color (RGBA) (from 0.0 to 1.0). 30.0 is just a magic value which looks good.
         red = i / 30.0
         green = (7 - i) / 30.0
         color = (red, green, 0, 0)
         lights.append((pos, color))
     return lights
Ejemplo n.º 9
0
    def __init__(self, effect=None):
        self.effecName = effect
        self.vertexBuffer = None
        self.indexBuffer = None
        self.effect = None
        self.position = d3d11.Vector(0, 0, 0)
        self.yaw = 0
        self.pitch = 0
        self.roll = 0
        self.scale = (1, 1, 1)

        self.width = 100
        self.height = 100
        self.gridsize = 10.0
        self.gridx = int(self.width / self.gridsize)
        self.gridy = int(self.height / self.gridsize)

        self.rotationMatrix = d3d11.Matrix()
        self.translationMatrix = d3d11.Matrix()
        self.scaleMatrix = d3d11.Matrix()
        self.world = d3d11.Matrix()
        self.build()
Ejemplo n.º 10
0
 def addPlane(self, plane, coord):
     plane.position = d3d11.Vector(coord[0] * plane.width, 0,
                                   coord[1] * plane.height)
     self.planes[coord] = plane
Ejemplo n.º 11
0
 def newSprite(self, i):
     pos = d3d11.Vector(0, POINT_SIZE + random.random(), 0)
     #Boost the .y axis slightly.
     direction = d3d11.Vector(0.5 - random.random(), 0.5 + random.random(),
                              0.5 - random.random())
     return Sprite3D(pos, direction.normalize() * 0.25, i)
Ejemplo n.º 12
0
particle simulations on the GPU. You can use 
the mouse and keyboard to control the camera.
"""

import math
import random
import time

import d3d11
import d3d11x
from d3d11c import *

POINT_SIZE = 0.5
POINT_COUNT = 150
GROUND_LEVEL = 0.0
GRAVITY = d3d11.Vector(0, -0.005, 0)

spriteLayoutDesc = [
    ("POSITION", 0, FORMAT_R32G32B32_FLOAT),
    ("COLOR", 0, FORMAT_R32G32B32A32_FLOAT),
    ("PSIZE", 0, FORMAT_R32_FLOAT),
]


class Sprite3D:
    def __init__(self, pos, direction, index):
        self.position = pos
        self.direction = direction
        self.index = index + 1

    def toShadowVertex(self):