Beispiel #1
0
        /// <summary>
        /// The primary rendering logic. Here, the current object is rendered using OpenGL.
        /// </summary>
        public void RenderFrame()
        {
            ThrowIfDisposed();

            lock (this.RenderTargetLock)
            {
                // Make sure the viewport is accurate for the current widget size on screen
                int widgetWidth  = this.ViewportWidget.AllocatedWidth;
                int widgetHeight = this.ViewportWidget.AllocatedHeight;
                GL.Viewport(0, 0, widgetWidth, widgetHeight);
                GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

                // Calculate the current relative movement of the camera
                if (this.WantsToMove)
                {
                    switch (this.RenderTarget.Projection)
                    {
                    case ProjectionType.Orthographic:
                    {
                        Calculate2DMovement();
                        break;
                    }

                    case ProjectionType.Perspective:
                    {
                        Calculate3DMovement();
                        break;
                    }
                    }
                }

                if (!this.HasRenderTarget)
                {
                    return;
                }

                // Render the current object
                // Tick the actor, advancing any time-dependent behaviour
                ITickingActor tickingRenderable = this.RenderTarget as ITickingActor;
                tickingRenderable?.Tick(this.DeltaTime);

                // Update the camera with new parameters
                this.Camera.ViewportHeight = widgetHeight;
                this.Camera.ViewportWidth  = widgetWidth;

                Matrix4 view       = this.Camera.GetViewMatrix();
                Matrix4 projection = this.Camera.GetProjectionMatrix();

                if (this.RenderTarget.Projection == ProjectionType.Perspective)
                {
                    this.Grid.Render(view, projection, this.Camera);
                }

                // Then render the visual component
                this.RenderTarget.Render(view, projection, this.Camera);
            }
        }
Beispiel #2
0
        /// <summary>
        /// The primary rendering logic. Here, the current object is rendered using OpenGL.
        /// </summary>
        public void RenderFrame()
        {
            lock (this.RenderTargetLock)
            {
                this.FrameWatch.Reset();
                this.FrameWatch.Start();

                // Make sure the viewport is accurate for the current widget size on screen
                int widgetWidth  = this.ViewportWidget.AllocatedWidth;
                int widgetHeight = this.ViewportWidget.AllocatedHeight;
                GL.Viewport(0, 0, widgetWidth, widgetHeight);
                GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

                if (this.RenderTarget != null)
                {
                    // Calculate the current relative movement of the camera
                    if (this.WantsToMove)
                    {
                        switch (this.RenderTarget.Projection)
                        {
                        case ProjectionType.Orthographic:
                        {
                            Calculate2DMovement();
                            break;
                        }

                        case ProjectionType.Perspective:
                        {
                            Calculate3DMovement();
                            break;
                        }
                        }
                    }

                    // Render the current object
                    // Tick the actor, advancing any time-dependent behaviour
                    ITickingActor tickingRenderable = this.RenderTarget as ITickingActor;
                    tickingRenderable?.Tick(this.DeltaTime);

                    // Update the camera with new parameters
                    this.Camera.ViewportHeight = widgetHeight;
                    this.Camera.ViewportWidth  = widgetWidth;

                    // Then render the visual component
                    Matrix4 view       = this.Camera.GetViewMatrix();
                    Matrix4 projection = this.Camera.GetProjectionMatrix();
                    this.RenderTarget.Render(view, projection, this.Camera);

                    GraphicsContext.CurrentContext.SwapBuffers();
                }

                this.FrameWatch.Stop();
                this.DeltaTime = (float)this.FrameWatch.Elapsed.TotalMilliseconds / 1000;
            }
        }
Beispiel #3
0
        /// <summary>
        /// The primary rendering logic. Here, the current object is rendered using OpenGL.
        /// </summary>
        public void RenderFrame()
        {
            lock (RenderTargetLock)
            {
                // Make sure the viewport is accurate for the current widget size on screen
                int widgetWidth  = this.ViewportWidget.AllocatedWidth;
                int widgetHeight = this.ViewportWidget.AllocatedHeight;
                GL.Viewport(0, 0, widgetWidth, widgetHeight);
                GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

                if (RenderTarget != null)
                {
                    Stopwatch sw = Stopwatch.StartNew();

                    // Calculate the current relative movement of the camera
                    if (WantsToMove)
                    {
                        int mouseX;
                        int mouseY;
                        this.ViewportWidget.GetPointer(out mouseX, out mouseY);

                        float deltaMouseX = MouseXLastFrame - mouseX;
                        float deltaMouseY = MouseYLastFrame - mouseY;

                        this.Movement.CalculateMovement(deltaMouseX, deltaMouseY, this.deltaTime, this.ForwardAxis, this.RightAxis, this.UpAxis);

                        MouseXLastFrame = mouseX;
                        MouseYLastFrame = mouseY;
                    }

                    // Render the current object
                    // Tick the actor, advancing any time-dependent behaviour
                    ITickingActor tickingRenderable = RenderTarget as ITickingActor;
                    if (tickingRenderable != null)
                    {
                        tickingRenderable.Tick(deltaTime);
                    }

                    // Then render the visual component
                    Matrix4 view       = this.Camera.GetViewMatrix();
                    Matrix4 projection = this.Camera.GetProjectionMatrix(this.RenderTarget.Projection, widgetWidth, widgetHeight);
                    RenderTarget.Render(view, projection);

                    GraphicsContext.CurrentContext.SwapBuffers();
                    sw.Stop();
                    deltaTime = (float)sw.Elapsed.TotalMilliseconds / 1000;
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// The primary rendering logic. Here, the current object is rendered using OpenGL.
        /// </summary>
        public void RenderFrame()
        {
            lock (this.RenderTargetLock)
            {
                this.FrameWatch.Reset();
                this.FrameWatch.Start();

                // Make sure the viewport is accurate for the current widget size on screen
                int widgetWidth  = this.ViewportWidget.AllocatedWidth;
                int widgetHeight = this.ViewportWidget.AllocatedHeight;
                GL.Viewport(0, 0, widgetWidth, widgetHeight);
                GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

                if (this.RenderTarget != null)
                {
                    // Calculate the current relative movement of the camera
                    if (this.WantsToMove)
                    {
                        int mouseX = Mouse.GetCursorState().X;
                        int mouseY = Mouse.GetCursorState().Y;

                        float deltaMouseX = this.InitialMouseX - mouseX;
                        float deltaMouseY = this.InitialMouseY - mouseY;

                        this.Movement.CalculateMovement(deltaMouseX, deltaMouseY, this.DeltaTime);

                        // Return the mouse to its original position
                        Mouse.SetPosition(this.InitialMouseX, this.InitialMouseY);
                    }

                    // Render the current object
                    // Tick the actor, advancing any time-dependent behaviour
                    ITickingActor tickingRenderable = this.RenderTarget as ITickingActor;
                    tickingRenderable?.Tick(this.DeltaTime);

                    // Then render the visual component
                    Matrix4 view       = this.Camera.GetViewMatrix();
                    Matrix4 projection = this.Camera.GetProjectionMatrix(this.RenderTarget.Projection, widgetWidth, widgetHeight);
                    this.Camera.RecalculateFrustum(projection);

                    this.RenderTarget.Render(view, projection, this.Camera);

                    GraphicsContext.CurrentContext.SwapBuffers();
                }

                this.FrameWatch.Stop();
                this.DeltaTime = (float)this.FrameWatch.Elapsed.TotalMilliseconds / 1000;
            }
        }