public void DrawGoo() { float CurrTime = DXUtil.Timer(DirectXTimer.GetApplicationTime); float fTime = (float)(((CurrTime % 180.0f) / 180.0f) * (2 * Math.PI)); WorldMatrix = DirectX.Matrix.RotationYawPitchRoll((float)((CurrTime % 240) / 240 * Math.PI), 0, 0) * DirectX.Matrix.Translation(0, -45, -400); DirectX.Matrix WorldViewMatrix = WorldMatrix * ViewMatrix; DirectX.Matrix WorldViewProjMatrix = WorldMatrix * ViewMatrix * ProjectionMatrix; GooEffect.SetValue("fMixTime", fTime); GooEffect.SetValue("WorldView", WorldViewMatrix); GooEffect.SetValue("WorldViewProjection", WorldViewProjMatrix); GameDevice.RenderState.AlphaBlendEnable = false; int numPasses = GooEffect.Begin(0); for (int i = 0; i < numPasses; i++) { GooEffect.BeginPass(i); GooMesh.DrawSubset(0); GooEffect.EndPass(); } GooEffect.End(); // Restore alpha blend setting GameDevice.RenderState.AlphaBlendEnable = true; }
public Explosion(Direct3D.Device NewDevice, DirectX.Vector3 NewPosition) { this.CurrDevice = NewDevice; this.ExplosionTexture = Direct3D.TextureLoader.FromFile(CurrDevice, GameConfig.Files.ExplosionPoint); this.LightTexture = Direct3D.TextureLoader.FromFile(CurrDevice, GameConfig.Files.ExplosionLight); this.ExplosionPosition = NewPosition; this.Rand = new Random(); this.UniversalGravity = .50f; this.ParticleCount = 100; this.NeedsDelete = false; this.Particles = new ArrayList(); for (int i = 0; i < this.ParticleCount; i++) { Particles.Add(new Particle(this.UniversalGravity, ExplosionPosition, new DirectX.Vector3((float)(Rand.NextDouble() * 0.75f - 0.375f), (float)(Rand.NextDouble() * 0.5f - 0.1f), 0.0f), DXUtil.Timer(DirectXTimer.GetApplicationTime))); } ExplosionFlash = new Flash(ExplosionPosition, DXUtil.Timer(DirectXTimer.GetApplicationTime)); this.LastUpdateTime = DXUtil.Timer(DirectXTimer.GetApplicationTime); }
private void Draw() { float AppTime = DXUtil.Timer(DirectXTimer.GetApplicationTime); Vector3 campos = new Vector3(80f * (float)Math.Cos(AppTime), 38, 80f * (float)Math.Sin(AppTime)); if (camMode) { campos = new Vector3(0, 200, -30); } viewMatrix = Matrix.LookAtLH(campos, new Vector3(), new Vector3(0, 1, 0)); Matrix worldViewProj = viewMatrix * projMatrix; // Update the effect's variables effect.SetValue(handle1, ambient); effect.SetValue(handle2, worldViewProj); effect.SetValue(handle3, new float[] { Terrain.size *0.5f *(float)Math.Sin(AppTime), 80, Terrain.size * 0.5f * (float)Math.Cos(AppTime) }); // Begin rendering with the effect effect.Begin(0); // There's only one pass effect.BeginPass(0); t.Draw(); effect.EndPass(); effect.End(); }
// The GameClass constructor. Here we create, but not show, the GameSettings form. // The public GameClass(MainClass mainClass, Control owner) { gameState = GameStates.Loading; this.owner = owner; this.mainClass = mainClass; splash = new SplashScreen(this); splash.ShowDialog(); gameSettings = new SpaceWar.GameSettings(this); gameSettings.Location = new Point(owner.Bounds.Right, owner.Bounds.Top); gravity = gameSettings.Gravity; gameSpeed = gameSettings.GameSpeed; bounceBack = gameSettings.Bounce; inverseGravity = gameSettings.InverseGravity; blackHole = gameSettings.BlackHole; localDevice = new Microsoft.DirectX.DirectDraw.Device(); localDevice.SetCooperativeLevel(owner, Microsoft.DirectX.DirectDraw.CooperativeLevelFlags.Normal); DXUtil.Timer(DirectXTimer.Start); SpaceWar.RotatableShape.CreateShapes(); input = new InputClass(this.owner); soundHandler = new SoundHandler(this.owner); try { netPeer = new PlayClass(this); } catch (DirectXException e) { MessageBox.Show(owner, e.ToString()); } }
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) { if (device.Disposed) { return; } // Get elapsed time to calculate FPS ElapsedTime = DXUtil.Timer(DirectXTimer.GetElapsedTime); device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.CornflowerBlue, 1.0f, 0); device.BeginScene(); Draw(); // Drawing multiple lines of text on the same sprite is more efficient using (Sprite s = new Sprite(device)) { s.Begin(SpriteFlags.AlphaBlend); int y = 5; font.DrawText(s, string.Format("FPS: {0}", ((int)(1f / ElapsedTime)).ToString()), new Rectangle(4, y, 0, 0), DrawTextFormat.NoClip, Color.FromArgb(64, 255, 255, 255)); y += 22; font.DrawText(s, string.Format("Ambient light: {0}%", (int)(ambient * 100)), new Rectangle(4, y, 0, 0), DrawTextFormat.NoClip, Color.FromArgb(64, 255, 255, 255)); s.End(); } device.EndScene(); device.Present(); // The onPaint event must be called again this.Invalidate(); }
public XmlDataStore() { // First try to find the default XML Schema string mediaFolder = DXUtil.GetDXSDKMediaPath(); xmlDocumentLocation = mediaFolder + "dxmsgserver.xml"; xmlDom = new XmlDocument(); if (!System.IO.File.Exists(xmlDocumentLocation)) { // We need to create our default schema MessageBox.Show("The default XML data structure could not be found. We will create a new one.", "No default schema.", MessageBoxButtons.OK, MessageBoxIcon.Information); this.CreateDefaultSchema(); } try { // Well the file exists, try to load it, and throw an exception if you // don't like it xmlDom.Load(xmlDocumentLocation); if (xmlDom.ChildNodes.Count < 1) { throw new Exception(); } } catch { MessageBox.Show("There was an error trying to read the XML data. We will create a new schema.", "No default schema.", MessageBoxButtons.OK, MessageBoxIcon.Information); this.CreateDefaultSchema(); } // No one can be logged on now, make sure everyone is marked offline MarkEveryoneOffline(); }
internal void DiscardDeviceResources() { DXUtil.Dispose(ref _blur); DXUtil.Dispose(ref _warp); DXUtil.Dispose(ref _dxgiDevice); DXUtil.Dispose(ref _d2dContext); }
/// <summary> /// The device has been created. Resources that are not lost on /// Reset() can be created here -- resources in Pool.Managed, /// Pool.Scratch, or Pool.SystemMemory. Image surfaces created via /// CreateImageSurface are never lost and can be created here. Vertex /// shaders and pixel shaders can also be created here as they are not /// lost on Reset(). /// </summary> protected override void InitializeDeviceObjects() { // Initialize the drawingFont's internal textures drawingFont.InitializeDeviceObjects(device); ExtendedMaterial[] mtrl = null; string path = DXUtil.FindMediaFile(initialDirectory, meshFilename); try { systemMemoryMesh = Mesh.FromFile(path, MeshFlags.SystemMemory, device, out adjacency, out mtrl); } catch { // Hide the error so we display a blue screen return; } // Lock the vertex buffer, to generate a simple bounding sphere VertexBuffer vb = null; try { vb = systemMemoryMesh.VertexBuffer; GraphicsStream vbStream = vb.Lock(0, 0, 0); objectRadius = Geometry.ComputeBoundingSphere(vbStream, systemMemoryMesh.NumberVertices, systemMemoryMesh.VertexFormat, out objectCenter); } finally { // Make sure we unlock the buffer if we fail if (vb != null) { vb.Unlock(); } } meshMaterials = new Material[mtrl.Length]; meshTextures = new Texture[mtrl.Length]; for (int i = 0; i < mtrl.Length; i++) { meshMaterials[i] = mtrl[i].Material3D; if ((mtrl[i].TextureFilename != null) && ((mtrl[i].TextureFilename != string.Empty))) { meshTextures[i] = TextureLoader.FromFile(device, DXUtil.FindMediaFile(null, mtrl[i].TextureFilename)); } } // Make sure there are normals, which are required for the tesselation // enhancement if ((systemMemoryMesh.VertexFormat & VertexFormats.Normal) != VertexFormats.Normal) { Mesh tempMesh = systemMemoryMesh.Clone(systemMemoryMesh.Options.Value, systemMemoryMesh.VertexFormat | VertexFormats.Normal, device); tempMesh.ComputeNormals(); systemMemoryMesh.Dispose(); systemMemoryMesh = tempMesh; } }
public SplashScreen(string filename, int nDuration) { image = new Image(filename); m_StartTime = DXUtil.Timer(TIMER.GETABSOLUTETIME); m_EndTime = m_StartTime + nDuration; m_vb = new VertexBuffer(typeof(CustomVertex.TransformedTextured), 4, CGameEngine.Device3D, Usage.WriteOnly, CustomVertex.TransformedTextured.Format, Pool.Default); }
/// <summary> /// Clean up any resources being used. /// </summary> protected override void Dispose(bool disposing) { if (disposing) { DXUtil.Dispose(ref _effect); DXUtil.Dispose(ref _vertexBuffer); DXUtil.Dispose(ref _drawInfo); } base.Dispose(disposing); }
public AudioClass(Control owner) { BufferDescription desc = new BufferDescription(); localDevice = new Device(); localDevice.SetCooperativeLevel(owner, CooperativeLevel.Normal); localBuffer = new Buffer(DXUtil.FindMediaFile(null, "drumpad-bass_drum.wav"), desc, localDevice); audioPlayer = new Audio(DXUtil.FindMediaFile(null, "DirectX Theme.wma")); }
/// <summary> /// Helper function to create a texture. It checks the root path first, /// then tries the DXSDK media path (as specified in the system registry). /// </summary> public static Texture CreateTexture(Device device, string textureFilename, Format format) { // Get the path to the texture string path = DXUtil.FindMediaFile(null, textureFilename); // Create the texture using D3DX return(TextureLoader.FromFile(device, path, D3DX.Default, D3DX.Default, D3DX.Default, 0, format, Pool.Managed, Filter.Triangle | Filter.Mirror, Filter.Triangle | Filter.Mirror, 0)); }
void PrepareForNewImage() { if (_initialized) { DXUtil.Dispose(ref _imBmp); ClearSavedCopy(); _savedCopy = _bitmap.Transform(); UpdateTargetRect(); Invalidate(false); } }
//---------------------------------------------------------------------- #region ** overridden methods protected override void OnResize(EventArgs e) { if (_initialized) { DXUtil.Dispose(ref _targetBmp); if (_bitmap != null && _bitmap.HasImage) { UpdateTargetRect(); } } base.OnResize(e); }
public void Draw() { Particle tmpParticle; float CurrTime; float TimeDiff; if (this.Particles.Count < 1) { NeedsDelete = true; } CurrTime = DXUtil.Timer(DirectXTimer.GetApplicationTime); TimeDiff = CurrTime - LastUpdateTime; for (int i = 0; i < Particles.Count; i++) { tmpParticle = (Particle)Particles[i]; tmpParticle.Velocities.Y -= tmpParticle.Gravity * TimeDiff; tmpParticle.Positions.X += tmpParticle.Velocities.X * TimeDiff; tmpParticle.Positions.Y += tmpParticle.Velocities.Y * TimeDiff; tmpParticle.Positions.Z += tmpParticle.Velocities.Z * TimeDiff; if (CurrTime - tmpParticle.TimeCreated <= 1.5f) { tmpParticle.Height = 1.5f * (1.5f - (CurrTime - tmpParticle.TimeCreated)); tmpParticle.Width = 1.5f * (1.5f - (CurrTime - tmpParticle.TimeCreated)); tmpParticle.GenerateVerticies(); } this.CurrDevice.Transform.World = DirectX.Matrix.RotationYawPitchRoll(0, 0, 0) * DirectX.Matrix.Translation(tmpParticle.Positions.X, tmpParticle.Positions.Y, tmpParticle.Positions.Z) * SpaceAndTime.ScaleStandard; this.CurrDevice.SetTexture(0, ExplosionTexture); CurrDevice.DrawUserPrimitives(Direct3D.PrimitiveType.TriangleStrip, 2, tmpParticle.Verticies); if (tmpParticle.Positions.Y < -2.0f) { this.Particles.Remove(tmpParticle); } } if (CurrTime - ExplosionFlash.TimeCreated <= .25) { ExplosionFlash.Height = 256 * (CurrTime - ExplosionFlash.TimeCreated); ExplosionFlash.Width = 256 * (CurrTime - ExplosionFlash.TimeCreated); ExplosionFlash.GenerateVerticies(); } else { ExplosionFlash.Height = 0.0f; ExplosionFlash.Width = 0.0f; ExplosionFlash.GenerateVerticies(); } this.CurrDevice.Transform.World = DirectX.Matrix.RotationYawPitchRoll(0, 0, 0) * DirectX.Matrix.Translation(ExplosionFlash.Positions.X, ExplosionFlash.Positions.Y, ExplosionFlash.Positions.Z) * SpaceAndTime.ScaleStandard; this.CurrDevice.SetTexture(0, LightTexture); CurrDevice.DrawUserPrimitives(Direct3D.PrimitiveType.TriangleStrip, 2, ExplosionFlash.Verticies); this.LastUpdateTime = DXUtil.Timer(DirectXTimer.GetApplicationTime); }
/// <summary> /// Assembles and creates a file-based vertex shader /// </summary> public static VertexShader CreateVertexShader(Device device, string filename) { GraphicsStream code = null; string path = null; // Get the path to the vertex shader file path = DXUtil.FindMediaFile(null, filename); // Assemble the vertex shader file code = ShaderLoader.FromFile(path, null, 0); // Create the vertex shader return(new VertexShader(device, code)); }
void DiscardDeviceResources() { if (_d2dContext != null) { DXUtil.Dispose(ref _blur); DXUtil.Dispose(ref _warp); DXUtil.Dispose(ref _imBmp); DXUtil.Dispose(ref _targetBmp); _d2dDevice.Dispose(); _lineBrush.Dispose(); _d2dContext.Dispose(); _d2dContext = null; } }
/// <summary> /// The device has been created. Resources that are not lost on /// Reset() can be created here -- resources in Pool.Managed, /// Pool.Scratch, or Pool.SystemMemory. Image surfaces created via /// CreateImageSurface are never lost and can be created here. Vertex /// shaders and pixel shaders can also be created here as they are not /// lost on Reset(). /// </summary> protected override void InitializeDeviceObjects() { // Initialize the font's internal textures drawingFont.InitializeDeviceObjects(device); drawingFontSmall.InitializeDeviceObjects(device); // Load a sphere mesh ballMesh = Mesh.Sphere(device, 1.2f, 36, 36); // Load effect file string strPath = DXUtil.FindMediaFile(null, "MotionBlur.fx"); effect = Effect.FromFile(device, strPath, null, 0, null); }
/// <summary> /// Send a user specified message when the wait cursor count down has reached zero. /// </summary> public static void ElapsedEvent(int countDownMs, GUIMessage message) { _eventTarget = SendElapsedEventMessage; _eventParam = message; _countValue = countDownMs / 1000; _countDown = (countDownMs > 0); _startTime = DXUtil.timeGetTime(); _elapsedEventRunning = true; // The count label depends on font rendering. If the users callback involves reloading fonts then we need to reallocate // the labels resources to be sure everything calculates okay (e.g., the x,y position of the control). _countLabel.Dispose(); _countLabel.AllocResources(); Show(); }
/// <summary> /// Called once per frame, the call is the entry point for 3d rendering. This /// function sets up render states, clears the viewport, and renders the scene. /// </summary> protected override void Render() { input.GetInputState(); //Clear the backbuffer to a Blue color device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Gray, 1.0f, 0); //Begin the scene device.BeginScene(); device.Lights[0].Enabled = true; // Setup the world, view, and projection matrices Matrix m = new Matrix(); if (destination.Y != 0) { y += DXUtil.Timer(DirectXTimer.GetElapsedTime) * (destination.Y * 25); } if (destination.X != 0) { x += DXUtil.Timer(DirectXTimer.GetElapsedTime) * (destination.X * 25); } m = Matrix.Translation(0.0f, 0.75f, 0.0f); m *= Matrix.RotationY(y); m *= Matrix.RotationX(x); device.Transform.World = m; // Render the teapot. teapot.DrawSubset(0); m = new Matrix(); m = Matrix.Translation(0.0f, -0.75f, 0.0f); m *= Matrix.RotationY(y); m *= Matrix.RotationX(x); device.Transform.World = m; //render the box box.DrawSubset(0); device.Transform.View = Matrix.LookAtLH(new Vector3(0.0f, 3.0f, -5.0f), new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f, 1.0f, 0.0f)); device.Transform.Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4, 1.0f, 1.0f, 100.0f); device.EndScene(); }
/// <summary> /// Do all the processing for this quadro before we render it /// </summary> private void processaProximoQuadro() { // Get the current elapsed time tempoDecorrido = DXUtil.Timer(DirectXTimer.GetElapsedTime); // Set the world matrix Matrix worldMatrix = Matrix.Translation(objetoCentro); device.Transform.World = worldMatrix; if (quadroRaiz.AnimationController != null) { quadroRaiz.AnimationController.AdvanceTime(tempoDecorrido, null); } quadro_AtualizarMatrizes((QuadroDerivado)quadroRaiz.FrameHierarchy, worldMatrix); } // processaProximoQuadro().fim
/// <summary> /// Creates a new mesh /// </summary> /// <param name="device">The device used to create the mesh</param> /// <param name="filename">the file to load</param> public void Create(Device device, string filename) { string strPath = null; GraphicsStream adjacencyBuffer; ExtendedMaterial[] Mat; if (device != null) { device.DeviceLost += new System.EventHandler(this.InvalidateDeviceObjects); device.Disposing += new System.EventHandler(this.InvalidateDeviceObjects); device.DeviceReset += new System.EventHandler(this.RestoreDeviceObjects); } // Find the path for the file, and convert it to ANSI (for the D3DX API) strPath = DXUtil.FindMediaFile(null, filename); // Load the mesh systemMemoryMesh = Mesh.FromFile(strPath, MeshFlags.SystemMemory, device, out adjacencyBuffer, out Mat); // Optimize the mesh for performance systemMemoryMesh.OptimizeInPlace(MeshFlags.OptimizeCompact | MeshFlags.OptimizeAttrSort | MeshFlags.OptimizeVertexCache, adjacencyBuffer); textures = new Texture[Mat.Length]; materials = new Direct3D.Material[Mat.Length]; for (int i = 0; i < Mat.Length; i++) { materials[i] = Mat[i].Material3D; // Set the ambient color for the material (D3DX does not do this) materials[i].Ambient = materials[i].Diffuse; if (Mat[i].TextureFilename != null) { // Create the texture string texturefilename = DXUtil.FindMediaFile(null, Mat[i].TextureFilename); textures[i] = TextureLoader.FromFile(device, texturefilename); } } adjacencyBuffer.Close(); adjacencyBuffer = null; }
/// <summary> /// Create the animation hierarchy for this file /// </summary> private void carregarModeloAnimado(string file, PresentParameters presentParams) { // Create our allocate hierarchy derived class HierarquiaAlojamento alloc = new HierarquiaAlojamento(this); // Load our file quadroRaiz = Mesh.LoadHierarchyFromFile(file, MeshFlags.Managed, device, alloc, null); // Calculate the center and radius of a bounding sphere objetoRaio = Frame.CalculateBoundingSphere(quadroRaiz.FrameHierarchy, out objetoCentro); // Setup the matrices for animation ossos_ConfigurarMatrizes((QuadroDerivado)quadroRaiz.FrameHierarchy); // Start the timer DXUtil.Timer(DirectXTimer.Start); } // carregarModeloAnimado().fim
/// <summary> /// The device has been created. Resources that are not lost on /// Reset() can be created here -- resources in Pool.Managed, /// Pool.Scratch, or Pool.SystemMemory. Image surfaces created via /// CreateImageSurface are never lost and can be created here. Vertex /// shaders and pixel shaders can also be created here as they are not /// lost on Reset(). /// </summary> protected override void InitializeDeviceObjects() { // Initialize the font's internal textures drawingFont.InitializeDeviceObjects(device); drawingFontSmall.InitializeDeviceObjects(device); // Create teapot mesh and sphere mesh // Note: We don't need a declarator here since D3DXCreateSphere already // implicitly creates one for us, and it is set inside the DrawSubset call. teapotMesh = Mesh.Teapot(device); sphereMesh = Mesh.Sphere(device, 1.0f, 30, 30); // Load effect file string strPath = DXUtil.FindMediaFile(null, "ClipVolume.fx"); effect = Effect.FromFile(device, strPath, null, 0, null); }
public static void Render() { if (_showCount <= 0) { return; } GUIGraphicsContext.SetScalingResolution(0, 0, false); if (_countDown) { // Set the count label value and position in the center of the window. _timeElapsed = DXUtil.timeGetTime() - _startTime; if (_timeElapsed >= ONE_SECOND) { _startTime = DXUtil.timeGetTime(); _timeElapsed = 0.0f; _countValue--; if (_countValue < 0) { // Invoke the users callback method and disable the cursor. // The callback must be invoked in a separte thread otherwise it gets executed in the window render loop which // can cause conflicts (especially if the users callback method makes calls that may change the window rendering). guiWaitCursorThread = new Thread(GUIWaitCursorElapsedEventThread); guiWaitCursorThread.IsBackground = true; guiWaitCursorThread.Name = "WaitcursorElapsedEvent"; guiWaitCursorThread.Start(); Hide(); return; } } int offset = 5; int xPos = (GUIGraphicsContext.Width / 2) - 48; int yPos = (GUIGraphicsContext.Height / 2) - 48 + offset; _countLabel.SetPosition(xPos, yPos); _countLabel.Label = _countValue.ToString(); _countLabel.Render(GUIGraphicsContext.TimePassed); } _animation.Render(GUIGraphicsContext.TimePassed); }
protected override void RestoreDeviceObjects(object sender, System.EventArgs e) { // Now Create the VB if ((vertexBuffer == null) || (vertexBuffer.Disposed)) { vertexBuffer = new VertexBuffer(typeof(CustomVertex.PositionNormalTextured), 100, device, Usage.WriteOnly, CustomVertex.PositionNormalTextured.Format, Pool.Default); vertexBuffer.Created += new System.EventHandler(this.OnCreateVertexBuffer); this.OnCreateVertexBuffer(vertexBuffer, null); } device.RenderState.Ambient = System.Drawing.Color.White; // Turn off culling, so we see the front and back of the triangle device.RenderState.CullMode = Cull.None; // Turn off D3D lighting device.RenderState.Lighting = false; // Turn on the ZBuffer device.RenderState.ZBufferEnable = true; device.SamplerState[0].AddressU = TextureAddress.Clamp; device.SamplerState[0].AddressV = TextureAddress.Clamp; string path = DXUtil.FindMediaFile(null, "ruby.avi"); try { videoTexture = Video.FromFile(path); videoTexture.Ending += new System.EventHandler(this.MovieOver); videoTexture.TextureReadyToRender += new TextureRenderEventHandler(this.RenderIt); // Now start rendering to our texture videoTexture.RenderToTexture(device); } catch (Exception err) { MessageBox.Show(string.Format("An error has occurred that will not allow this sample to continue.\r\nException={0}", err.ToString()), "This sample must exit.", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); throw err; } }
DataStream GenerateMesh() { float offsetX = 1f / TesselationLevelsX; float offsetY = 1f / TesselationLevelsY; _numVertices = TesselationLevelsX * TesselationLevelsY * 6; var stream = new DataStream(DXUtil.SizeOf <Vector2>() * _numVertices, false, true); for (int i = 0; i < TesselationLevelsY; i++) { for (int j = TesselationLevelsX - 1; j >= 0; j--) { float x = offsetX * j; float y = offsetY * i; stream.Write(new Vector2(x, y)); stream.Write(new Vector2(x, y + offsetY)); stream.Write(new Vector2(x + offsetX, y)); stream.Write(new Vector2(x + offsetX, y)); stream.Write(new Vector2(x, y + offsetY)); stream.Write(new Vector2(x + offsetX, y + offsetY)); } } return(stream); }
public GameWorld(MainForm _mainform) { // // TODO: Add constructor logic here // mainform = _mainform; DXUtil.Timer(DirectXTimer.Start); peer = new NETPlayer(this); if (peer.InSession) { if (peer.IsHost) { timer.Tick += new EventHandler(TimerEvent); timer.Interval = 4500; timer.Start(); } } InitializeKeyboard(); }
/// <summary> /// The device exists, but may have just been Reset(). Resources in /// Pool.Default and any other device state that persists during /// rendering should be set here. Render states, matrices, textures, /// etc., that don't change during rendering can be set once here to /// avoid redundant state setting during Render() or FrameMove(). /// </summary> protected override void RestoreDeviceObjects(System.Object sender, System.EventArgs e) { // Setup render states device.RenderState.Lighting = false; device.RenderState.CullMode = Cull.None; // Create index buffer indexBuffer = new IndexBuffer(typeof(short), numberIndices, device, 0, Pool.Default); short[] indices = (short[])indexBuffer.Lock(0, 0); int count = 0; for (int y = 1; y < m_Size; y++) { for (int x = 1; x < m_Size; x++) { indices[count++] = (short)((y - 1) * m_Size + (x - 1)); indices[count++] = (short)((y - 0) * m_Size + (x - 1)); indices[count++] = (short)((y - 1) * m_Size + (x - 0)); indices[count++] = (short)((y - 1) * m_Size + (x - 0)); indices[count++] = (short)((y - 0) * m_Size + (x - 1)); indices[count++] = (short)((y - 0) * m_Size + (x - 0)); } } indexBuffer.Unlock(); // Create vertex buffer vertexBuffer = new VertexBuffer(typeof(Vector2), numberVertices, device, Usage.WriteOnly, 0, Pool.Default); Vector2[] vertices = (Vector2[])vertexBuffer.Lock(0, 0); count = 0; for (int y = 0; y < m_Size; y++) { for (int x = 0; x < m_Size; x++) { vertices[count++] = new Vector2(((float)x / (float)(m_Size - 1) - 0.5f) * (float)Math.PI, ((float)y / (float)(m_Size - 1) - 0.5f) * (float)Math.PI); } } vertexBuffer.Unlock(); // Create vertex shader string shaderPath = null; GraphicsStream code = null; // Create our declaration VertexElement[] decl = new VertexElement[] { new VertexElement(0, 0, DeclarationType.Float2, DeclarationMethod.Default, DeclarationUsage.Position, 0), VertexElement.VertexDeclarationEnd }; ourDeclaration = new VertexDeclaration(device, decl); // Find the vertex shader file shaderPath = DXUtil.FindMediaFile(null, "Ripple.vsh"); // Assemble the vertex shader from the file code = ShaderLoader.FromFile(shaderPath, null, 0); // Create the vertex shader ourShader = new VertexShader(device, code); code.Close(); // Set up the projection matrix float fAspectRatio = (float)device.PresentationParameters.BackBufferWidth / (float)device.PresentationParameters.BackBufferHeight; projectionMatrix = Matrix.PerspectiveFovRH(Geometry.DegreeToRadian(60.0f), fAspectRatio, 0.1f, 100.0f); device.Transform.Projection = projectionMatrix; }
void DiscardDeviceIndependentResources() { DXUtil.Dispose(ref _d2dFactory); DXUtil.Dispose(ref _wicFactory); }