I am trying to check the possibilities of DirectPython by converting the
DirectX tutorials to Python.
Can you tell me what's wrong with the following example ?
The sprite rotates but the triangle stays in place.
I have downloaded the source-code but could not find a way to compile it.
Am I missing some makefiles or is there a trick to compile the sources ?
Regards,
Gert
----
import math
import array
import d3d
import d3dx
from d3dc import *
use_framework = False
vertices = (
( 150, 50 , 0.5, 1, 0xffffff00 ),
( 250, 250, 0.5, 1, 0xffff00ff ),
( 50, 250, 0.5, 1, 0xff00ff00 )
)
class CreateDevice( d3dx.Frame ):
def __init__(self, *args, **kwargs):
d3dx.Frame.__init__(self, *args, **kwargs)
self.angle = 0
def onCreate( self ):
self.vbuffer = d3d.VertexBuffer( FVF.XYZRHW | FVF.DIFFUSE, len(
vertices ) )
self.vbuffer.extend( vertices )
def setupMatrices( self ):
self.angle += 0.01
matrix = array.array("f", (
math.cos(self.angle), 0.0, -math.sin(self.angle), 0.0,
0.0, 1.0, 0.0, 0.0,
math.sin(self.angle), 0.0, math.cos(self.angle), 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0))
d3d.setMatrix(matrix, MATRIX.WORLD)
d3d.setView( ( 0.0, 3.0, -5.0 ), ( 0.0, 1.0, 0.0 ), 100, math.pi
/ 4 )
def onRender( self ):
d3d.clear( 0x00000000 )
self.setupMatrices()
d3d.setState( RS.FVF, FVF.XYZRHW | FVF.DIFFUSE )
d3d.drawVertices( TYPE.TRIANGLELIST, self.vbuffer )
def mainloop():
#Create a windowed device. This sample does not
#support real fullscreen mode, see the other samples
#and d3dx.Frame if you want fullscreen.
window = ( 200, 200, 800, 600 )
title = u"D3D Tutorial 1: CreateDevice"
d3d.createDevice( title, u'', window[2], window[3], False,
CREATE.HARDWARE | CREATE.NOVSYNC )
vbuffer = d3d.VertexBuffer( FVF.XYZRHW | FVF.DIFFUSE, len( vertices ) )
vbuffer.extend( vertices )
texture = d3d.Texture("textures/tree.dds")
d3d.setWindow( *window )
angle = 0
while True:
#Handle messages. This very basic sample
#only checks for QUIT or escape key being pressed
for m in d3d.getMessages():
if m[0] == WM.QUIT:
return
if m[0] == WM.KEY:
if m[1] == 27: # 'Escape key'
return
#Clear the buffer and begin the scene.
d3d.clear( 0x00ff0000 ) # 0xAARRGGBB
d3d.beginScene()
matrix = array.array("f", (
math.cos(angle), math.sin(angle), 0.0, 0.0,
-math.sin(angle), math.cos(angle), 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0,
))
angle += 0.01
d3d.setState( RS.FVF, FVF.XYZRHW | FVF.DIFFUSE )
d3d.setMatrix(matrix, MATRIX.WORLD)
d3d.drawVertices( TYPE.TRIANGLELIST, vbuffer )
d3d.setMatrix(matrix, MATRIX.SPRITE)
d3d.drawSprites(texture, [(-50, -50, 0.5, -1, -1, -1, -1,
0x80ffffff)])
#End the scene and present the drawing.
d3d.endScene()
d3d.present()
if __name__ == "__main__":
if use_framework:
frm = CreateDevice( u'D3D Tutorial 2: Vertices' )
frm.mainloop()
else:
mainloop()
|