def InitGraphics(self, handle): """Creates the Direct3D device which is used to render the scene. Pops up a message box and returns False on failure (returns True on success). """ params = Direct3D.PresentParameters() params.Windowed = True params.SwapEffect = Direct3D.SwapEffect.Discard params.EnableAutoDepthStencil = True params.AutoDepthStencilFormat = Direct3D.DepthFormat.D16 self.Device = Direct3D.Device( 0, Direct3D.DeviceType.Hardware, handle, Direct3D.CreateFlags.SoftwareVertexProcessing, params) self.Device.RenderState.ZBufferEnable = True self.Device.Transform.Projection = DirectX.Matrix.PerspectiveFovLH( System.Math.PI / 4.0, 1, 1, 100) self.Device.Transform.View = DirectX.Matrix.LookAtLH( DirectX.Vector3(0, 3, -5), DirectX.Vector3(0, 0, 0), DirectX.Vector3(0, 1, 0)) self.Device.RenderState.Ambient = Drawing.Color.White # ensure we are not paused self.Paused = False return True
def __init__(self, device, name, file): PositionableObject.__init__(self) RotatableObject.__init__(self) self.Name = name materials = Direct3D.MaterialList() self.Mesh = Direct3D.Mesh(device, file, Direct3D.MeshFlags.SystemMemory, None, materials, None) self.Materials = [] self.Textures = [] for i in range(materials.Count): # load material, set color material = materials[i].Material material.AmbientColor = material.DiffuseColor # load texture, if possible texture = None texFile = materials[i].TextureFileName if texFile is not None and texFile.Length: texture = Direct3D.Texture(device, texFile) # insert the material and texture into the lists self.Materials.append(material) self.Textures.append(texture)
def __init__(self, device, type, name, color, *params): SceneObject.__init__(self) if not callable(type): type = self.ObjectTypes[type] self.Name = name self.Mesh = type(device, *params) color = Direct3D.ColorValue.FromColor(color) material = Direct3D.Material() material.AmbientColor = color self.Materials = [material] self.Textures = []