def renderAndPresent(self):
        self.device.setRenderTargetsDefault()
        self.device.setVertexBuffers([self.vertexBuffer])
        self.device.setInputLayout(self.inputLayout)
        self.device.setPrimitiveTopology(PRIMITIVE_TOPOLOGY_TRIANGLELIST)

        #View matrix.
        viewMatrix = d3d11.Matrix()
        viewMatrix.lookAt((0, 5, -15), (0, 5, 0), (0, 1, 0))

        #Projection matrix.
        screenDesc = self.device.getScreenDesc()
        fieldOfView = math.radians(60.0)
        aspectRatio = float(screenDesc.width) / screenDesc.height
        projMatrix = d3d11.Matrix()
        projMatrix.perspectiveFov(fieldOfView, aspectRatio, 0.1, 100.0)

        #World matrix.
        yRot = time.clock()
        worldMatrix = d3d11.Matrix()
        worldMatrix.rotate((0, yRot, 0))

        #Combined matrix.
        wordViewProj = worldMatrix * viewMatrix * projMatrix

        #Update effect variable(s).
        self.effect.set("worldViewProjection", wordViewProj)
        self.effect.apply(0, 0)

        #Draw all three vertices using the currently bound vertex buffer
        #and other settings (Effect, input layout, topology etc.).
        self.device.draw(len(self.vertexBuffer), 0)

        #Present our rendering.
        self.device.present(0)
    def onRender(self):
        viewMatrix = self.camera.getViewMatrix()
        projMatrix = self.createProjection(60, 0.1, 200)

        #Heightmap.
        self.heightmap.effect.set("lightAmbient", (0.5, 0.5, 0.5, 0))
        self.heightmap.render(d3d11.Matrix(), viewMatrix, projMatrix)

        #Then all sprites.
        self.device.setVertexBuffers([self.spriteBuffer])
        self.device.setPrimitiveTopology(PRIMITIVE_TOPOLOGY_POINTLIST)
        self.device.setInputLayout(self.spriteInputLayout)

        #Update effect variables.
        viewInverse = d3d11.Matrix(viewMatrix)
        viewInverse.invert()
        self.spriteEffect.set("viewInverse", viewInverse)
        self.spriteEffect.set("viewProjection", viewMatrix * projMatrix)
        self.spriteEffect.set("defaultTexture", self.spriteTexture)
        self.spriteEffect.apply(0, 0)

        #First shadow points. Use an offset. Note that they are rotated
        #towards the camera too which is not that great. As an excercise
        #you could make them align using the surface normal. Or use real shadows.
        self.device.draw(POINT_COUNT, POINT_COUNT)

        #Then colored and textured points.
        self.device.draw(POINT_COUNT, 0)
示例#3
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 onRender(self):
        lights = [((-10, 20, 0), (10, 10, 10, 0))]
        view = self.camera.getViewMatrix()
        projection = self.createProjection(45, 0.1, 500.0)

        #Skybox first.
        camPos = self.camera.pos
        skyWorld = d3d11.Matrix()
        skyWorld.translate(
            (camPos.x * 0.99, camPos.y - self.skybox.height / 2.0,
             camPos.z * 0.99))
        self.skybox.render(skyWorld, view, projection)

        #Then the height map.
        hmapWorld = d3d11.Matrix()
        self.heightmap.setLights(lights)
        self.heightmap.render(hmapWorld, view, projection)
示例#5
0
 def randomMatrix(self):
     m = d3d11.Matrix()
     for x in range(4):
         for y in range(4):  
             #Test both indexing styles.
             m[x][y] = random.random() * 103.1453
             self.assert_(m[x][y] == m[x,y])
     return m
    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)
示例#7
0
 def test_error(self):
     m = d3d11.Matrix()
     m[3][3] = 1
     m[3,3] = 1  
     
     self.failUnlessRaises(IndexError, m.__setitem__, (4, 3), 1)
     self.failUnlessRaises(IndexError, m.__setitem__, (3, 4), 1) 
     self.failUnlessRaises(IndexError, m.__getitem__, (4, 3))
     self.failUnlessRaises(IndexError, m.__getitem__, (3, 4)) 
示例#8
0
 def test_indexing(self):
     m = d3d11.Matrix()
     for x in range(4):
         for y in range(4):
             self.assertEqual(m[x][y], identity[x][y])
             m[x][y] = 1.0
         
     for x in range(4):
         for y in range(4):
             self.assertEqual(m[x][y], 1.0)
示例#9
0
文件: Tutorial2.py 项目: konlil/mypy
def mainloop():
    while 1:
        #Check all new messages.
        for msg in window.getMessages():
            if msg.code == WM_DESTROY:
                #Close the application.
                return

        #Set default render targets.
        device.setRenderTargetsDefault()

        #Set vertex buffer, input layout and topology.
        device.setVertexBuffers([vertexBuffer])
        device.setInputLayout(inputLayout)
        device.setPrimitiveTopology(PRIMITIVE_TOPOLOGY_TRIANGLESTRIP)

        #Projection matrix.
        screenDesc = device.getScreenDesc()
        fieldOfView = math.radians(60.0)  #60 degrees.
        aspectRatio = float(screenDesc.width) / screenDesc.height
        projMatrix = d3d11.Matrix()
        projMatrix.perspectiveFov(fieldOfView, aspectRatio, 0.1, 100.0)

        #The world matrix. Rotate the triangle (in radians) based
        #on the value returned by clock().
        yRot = time.clock()
        worldMatrix = d3d11.Matrix()
        worldMatrix.rotate((0, yRot, 0))

        #Combine matrices into one matrix by multiplying them.
        wordViewProj = worldMatrix * viewMatrix * projMatrix

        #Update effect variable(s).
        effect.set("worldViewProjection", wordViewProj)
        #Apply technique number 0 and it's pass 0.
        effect.apply(0, 0)

        #Draw all three vertices using the currently bound vertex buffer
        #and other settings (Effect, input layout, topology etc.).
        device.draw(len(vertexBuffer), 0)

        #Present our rendering. Wait for vsync.
        device.present(1)
示例#10
0
	def getNodeWorldMatrix(self, node):
		worldMat = d3d11.Matrix()
		worldTrans = node.EvaluateGlobalTransform()
		#lTranslation = node.LclTranslation;
		#lRotation    = node.LclRotation;
		#lScaling     = node.LclScaling;
		#print type(worldMat), dir(worldMat)
		for i in xrange(4):
			for j in xrange(4):
				worldMat[i][j] = worldTrans.Get(i, j)
		return worldMat
示例#11
0
文件: gridplane.py 项目: konlil/mypy
    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()
示例#12
0
    def onRender(self):
        #World matrix, rotate the model.
        world = d3d11.Matrix()
        world.rotate((self.time, 0, self.time))

        view = self.createLookAt((0, 5, -5), (0, 0, 0))
        projection = self.createProjection(60, 0.1, 100.0)

        #Set one yellow light.
        self.mesh.setLights([((10, 0, 0), (0.5, 0.5, 0, 0))])

        #Update the effect and render the mesh.
        self.mesh.effect.set("lightAmbient", (0.5, 0.5, 0.5, 0))
        self.mesh.render(world, view, projection)
    def onRender(self):
        #View- and projectionmatrix.
        view = self.createLookAt((-50, 25, -50), (0, 0, 0))
        projection = self.createProjection(45, 0.1, 300.0)

        lights = self.createLights()

        #First the heightmap.
        self.heightmap.setLights(lights)
        #Add some ambient lightning so that it is not so dark.
        self.heightmap.effect.set("lightAmbient", (0.5, 0.5, 0.5, 0))
        self.heightmap.render(d3d11.Matrix(), view, projection)

        #Then our "light spheres".
        self.sphere.setLights(lights)
        for light in lights:
            #World matrix.
            meshWorld = d3d11.Matrix()
            lightPos = light[0]
            #Add little to y to lift the sphere off the ground.
            meshWorld.translate((lightPos.x, lightPos.y + 1, lightPos.z))
            #Set ambient to light color.
            self.sphere.effect.set("lightAmbient", light[1])
            self.sphere.render(meshWorld, view, projection)
示例#14
0
    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)
示例#15
0
 def test_ctor(self):
     a = self.randomMatrix() 
     b = d3d11.Matrix(a)
     self.assert_(self.equal(a, b))
     self.assert_(self.equal(d3d11.Matrix(), d3d11.Matrix()))
     
     i = d3d11.Matrix()
     i2 = d3d11.Matrix(identity)
     self.assert_(self.equal(i, i2))
     
     x = self.randomMatrix()
     self.assert_(self.equal(x, d3d11.Matrix(x.toList())))
示例#16
0
 def test_multiply2(self):
     a = self.randomMatrix() 
     b = d3d11.Matrix(a) 
     m = self.randomMatrix() 
     a *= m
     self.assert_(self.equal(a, b * m))
示例#17
0
文件: Tutorial2.py 项目: konlil/mypy
vertices = []
for p in cdata.Box:
    vertices.append((p[0], p[1], p[2], 1, 1, 1, 1))

#Effect for rendering. The file contains trivial vertex- and pixel-shader.
effect = d3d11.Effect(d3d11x.getResourceDir("Effects", "simple.fx"))

#Input layout for the effect. Valid when technique index == 0 and it's pass index == 0 or
#the pass's input signature is compatible with that combination.
inputLayout = d3d11.InputLayout(vertexDesc, effect, 0, 0)

#Create a hardware buffer to hold our triangle.
vertexBuffer = d3d11.Buffer(vertexDesc, vertices, BIND_VERTEX_BUFFER)

#Precalculate view matrix. Eye position is (0, 5, -15) and it is looking at (0, 5, 0). (0, 1, 0) points up.
viewMatrix = d3d11.Matrix()
viewMatrix.lookAt((0, 5, -15), (0, 5, 0), (0, 1, 0))


def mainloop():
    while 1:
        #Check all new messages.
        for msg in window.getMessages():
            if msg.code == WM_DESTROY:
                #Close the application.
                return

        #Set default render targets.
        device.setRenderTargetsDefault()

        #Set vertex buffer, input layout and topology.
示例#18
0
 def test_multiply(self):
     a = d3d11.Matrix() 
     b = d3d11.Matrix() 
     self.assert_(self.equal(a, b))
     self.assert_(self.equal(a * b, b * a))