Exemplo n.º 1
0
        void renderScene(IDeviceContext ic, ITextureView swapChainRgb, ITextureView swapChainDepthStencil)
        {
            // ConsoleLogger.logDebug( "SpinningTeapot.render" );

            ic.SetRenderTarget(swapChainRgb, swapChainDepthStencil, ResourceStateTransitionMode.Transition);

            // Clear the back buffer
            ic.ClearRenderTarget(swapChainRgb, clearColor);
            ic.ClearDepthStencil(swapChainDepthStencil, ClearDepthStencilFlags.DepthFlag, 1.0f, 0, ResourceStateTransitionMode.Transition);

            if (resources.haveMesh)
            {
                Matrix4x4 world     = teapotWorld * Matrix4x4.CreateFromQuaternion(extraRotation * motion.rotation);
                Matrix4x4 view      = Matrix4x4.CreateTranslation(0, 0, 5);
                Vector3   cameraPos = new Vector3(0, -3, 0);
                view      = DiligentMatrices.createLookAt(cameraPos, Vector3.Zero, Vector3.UnitZ);
                worldView = world * view;

                float NearPlane = 0.1f;
                float FarPlane  = 100;
                // Projection matrix differs between DX and OpenGL
                Matrix4x4 projection = DiligentMatrices.createPerspectiveFieldOfView(0.25f * MathF.PI * motion.zoomFactor, context.aspectRatio, NearPlane, FarPlane, isOpenGlDevice);

                resources.draw(ic, ref worldView, ref projection);
            }
        }
Exemplo n.º 2
0
        void iDeltaTimeUpdate.tick(float elapsedSeconds)
        {
            angle.rotate(velocity, elapsedSeconds);

            // Set cube world view matrix
            Matrix4x4 CubeWorldView = Matrix4x4.CreateRotationY(angle)
                                      * Matrix4x4.CreateRotationX(MathF.PI * -0.1f)
                                      * Matrix4x4.CreateTranslation(0, 0, 5);

            float NearPlane = 0.1f;
            float FarPlane  = 100;
            // Projection matrix differs between DX and OpenGL
            Matrix4x4 Proj = DiligentMatrices.createPerspectiveFieldOfView(0.25f * MathF.PI, context.aspectRatio, NearPlane, FarPlane, isOpenGlDevice);

            worldViewProjMatrix = CubeWorldView * Proj;
        }