Ejemplo n.º 1
0
        /// <summary>
        /// Function called when the application goes into an idle state.
        /// </summary>
        /// <returns><b>true</b> to continue executing, <b>false</b> to stop.</returns>
        private static bool Idle()
        {
            _tileSize = new DX.Size2((int)(_screen.Width / _snowTile.ScaledSize.Width), (int)(_screen.Height / _snowTile.ScaledSize.Height));

            _screen.RenderTargetView.Clear(GorgonColor.White);
            _depthBuffer.Clear(1.0f, 0);

            // We have to pass in a state that allows depth writing and testing. Otherwise the depth buffer won't be used.
            _renderer.Begin(Gorgon2DBatchState.DepthEnabled);

            DrawBackground();

            // Note that the order that we draw here is not important since the depth buffer will sort on our behalf.
            // As mentioned in the description for the example, alpha blending doesn't work all that well with this
            // trick. You'll notice this when the guy walks behind the icicle as the icicle completely obscures the
            // guy even though the icicle has alpha translucency.
            DrawIcicle();

            DrawGuy();

            _renderer.End();

            GorgonExample.DrawStatsAndLogo(_renderer);

            _controller.Update();

            AnimationTransition();

            _screen.Present(1);
            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Function to handle idle time for the application.
        /// </summary>
        /// <returns><b>true</b> to continue processing, <b>false</b> to stop.</returns>
        private static bool Idle()
        {
            // Animate the ball.
            UpdateBall();

            // Clear to our gray color and clear out the depth buffer.
            _swap.RenderTargetView.Clear(Color.FromArgb(173, 173, 173));
            //_depthBuffer.Clear(0.0f, 0);
            _depthBuffer.Clear(0.0f, 0);

            // Render the back and floor planes.
            // ReSharper disable once ForCanBeConvertedToForeach
            for (int i = 0; i < _planes.Length; ++i)
            {
                RenderModel(_planes[i]);
            }

            // Render the ball.
            _sphere.Material.Diffuse = GorgonColor.White;
            RenderModel(_sphere);

            // Remember the position and rotation so we can restore them later.
            DX.Vector3 spherePosition = _sphere.Position;
            DX.Vector3 sphereRotation = _sphere.Rotation;

            // Offset the position of the ball so we can fake a shadow under the ball.
            _sphere.Position = new DX.Vector3(spherePosition.X + 0.25f, spherePosition.Y - 0.125f, spherePosition.Z + 0.5f);
            // Scale on the z-axis so the ball "shadow" has no real depth, and on the x & y to make it look slightly bigger.
            _sphere.Scale = new DX.Vector3(1.155f, 1.155f, 0.001f);
            // Reset the rotation so we don't rotate our flattened ball "shadow" (it'd look real weird if it rotated).
            _sphere.Rotation = DX.Vector3.Zero;
            // Render as black with alpha of 0.5 to simulate a shadow.
            _sphere.Material.Diffuse = new GorgonColor(0, 0, 0, 0.5f);

            // Render the shadow.
            RenderModel(_sphere);

            // Restore our original positioning so we can render the ball in the correct place on the next frame.
            _sphere.Position = spherePosition;
            // Reset scale on the z-axis so the ball so it'll be normal for the next frame.
            _sphere.Scale = DX.Vector3.One;
            // Reset the rotation so it'll be in the correct place on the next frame.
            _sphere.Rotation = sphereRotation;

            // Draw our text.
            // Use this to show how incredibly slow and terrible my 3D code is.
            GorgonExample.DrawStatsAndLogo(_2D);

            // Now we flip our buffers.
            // We need to this or we won't see anything.
            _swap.Present(1);

            return(true);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Main application loop.
        /// </summary>
        /// <returns><b>true</b> to continue processing, <b>false</b> to stop.</returns>
        private static bool Idle()
        {
            ProcessKeys();

            _swapChain.RenderTargetView.Clear(Color.CornflowerBlue);
            _depthBuffer.Clear(1.0f, 0);

            _cloudRotation += 2.0f * GorgonTiming.Delta;
            _objRotation   += 50.0f * GorgonTiming.Delta;

            if (_cloudRotation > 359.9f)
            {
                _cloudRotation -= 359.9f;
            }

            if (_objRotation > 359.9f)
            {
                _objRotation -= 359.9f;
            }

            _triangle.Material.TextureOffset = new DX.Vector2(0, _triangle.Material.TextureOffset.Y - (0.125f * GorgonTiming.Delta));

            if (_triangle.Material.TextureOffset.Y < 0.0f)
            {
                _triangle.Material.TextureOffset = new DX.Vector2(0, 1.0f + _triangle.Material.TextureOffset.Y);
            }

            _plane.Material.TextureOffset = _triangle.Material.TextureOffset;

            _icoSphere.Rotation = new DX.Vector3(0, _icoSphere.Rotation.Y + (4.0f * GorgonTiming.Delta), 0);
            _cube.Rotation      = new DX.Vector3(_objRotation, _objRotation, _objRotation);
            _sphere.Position    = new DX.Vector3(-2.0f, (_objRotation.ToRadians().Sin().Abs() * 2.0f) - 1.10f, 0.75f);
            _sphere.Rotation    = new DX.Vector3(_objRotation, _objRotation, 0);
            _clouds.Rotation    = new DX.Vector3(0, _cloudRotation, 0);

            _renderer.Render();

            _2DRenderer.Begin();
            _textSprite.Text = $@"FPS: {GorgonTiming.FPS:0.0}, Delta: {(GorgonTiming.Delta * 1000):0.000} msec. " +
                               $@"Tris: {
		                               ((_triangle.TriangleCount) + (_plane.TriangleCount) + (_cube.TriangleCount) + (_sphere.TriangleCount) + (_icoSphere.TriangleCount) +
		                                (_clouds.TriangleCount))
		                           :0} "         +
                               $@"CamRot: {_cameraRotation} Mouse: {_mouse?.Position.X:0}x{_mouse?.Position.Y:0} Sensitivity: {_sensitivity:0.0##}";
            _2DRenderer.DrawTextSprite(_textSprite);
            _2DRenderer.End();

            GorgonExample.DrawStatsAndLogo(_2DRenderer);

            _swapChain.Present();

            return(true);
        }