示例#1
0
        void RT_RenderFrame()
        {
            #region LightDataTimingsAndMouse
            CalculateDeltaTime();
            lightPosition = new Vector3(1000f * (float)Math.Cos(tick), 50, 1000f * (float)Math.Sin(tick));

            tick += 0.01f * deltaTimeAdjusted;
            int MouseX = 0;
            int MouseY = 0;

            #endregion


            //   GL.Line3D(new Vector3(0, 0, 0), new Vector3(100, 100, 100), 30, 30, 30);

            #region CursorPosition
            if (CursorHook)
            {
                int cursorX = Cursor.Position.X;
                int cursorY = Cursor.Position.Y;

                int sourceX = 0;
                int sourceY = 0;

                this.Invoke((Action) delegate()
                {
                    sourceX = PointToScreen(Point.Empty).X + this.ClientSize.Width / 2;
                    sourceY = PointToScreen(Point.Empty).Y + this.ClientSize.Height / 2;
                });

                MouseX = cursorX - sourceX;
                MouseY = cursorY - sourceY;

                Cursor.Position = new Point(sourceX, sourceY);
                if (!requestHome)
                {
                    cameraRotation += new Vector3(0, MouseY / 8f, MouseX / 8f);
                }
            }
            else if (mmbdown & !requestHome)
            {
                int cursorX = Cursor.Position.X;
                int cursorY = Cursor.Position.Y;

                MouseX    = cursorX - MMBDeltaX;
                MouseY    = cursorY - MMBDeltaY;
                MMBDeltaX = cursorX; MMBDeltaY = cursorY;

                cameraPosition = renderX.Pan3D(cameraPosition, cameraRotation, MouseX / 8f, MouseY / 8f);
            }
            #endregion

            #region KeyboardDeltas
            if (rdown | ldown)
            {
                if (rdown)
                {
                    if (KeyDelta.x > 0)
                    {
                        KeyDelta.x = 0;
                    }
                    KeyDelta.x--;
                }
                else if (ldown)
                {
                    if (KeyDelta.x < 0)
                    {
                        KeyDelta.x = 0;
                    }
                    KeyDelta.x++;
                }
            }
            else
            {
                KeyDelta.x = 0;
            }

            if (udown | bdown)
            {
                if (udown)
                {
                    if (KeyDelta.y > 0)
                    {
                        KeyDelta.y = 0;
                    }
                    KeyDelta.y--;
                }
                else if (bdown)
                {
                    if (KeyDelta.y < 0)
                    {
                        KeyDelta.y = 0;
                    }
                    KeyDelta.y++;
                }
            }
            else
            {
                KeyDelta.y = 0;
            }
            #endregion

            #region CameraLerpingAndPosition
            if (!requestHome)
            {
                cameraPosition = renderX.Pan3D(cameraPosition, cameraRotation, (KeyDelta.x / 32f) * deltaTimeAdjusted, 0, (KeyDelta.y / 32f) * deltaTimeAdjusted);
            }
            else
            {
                cameraPosition = Vector3.Lerp(cameraPosition, TargetPosition, 0.1f * deltaTimeAdjusted);
                cameraRotation = Vector3.LerpAngle(cameraRotation, TargetRotation, 0.1f * deltaTimeAdjusted);

                if ((cameraPosition - TargetPosition).Abs() < 0.01f && (cameraRotation - TargetRotation).Abs().Repeat(360) < 0.01f)
                {
                    requestHome = false;
                }
            }

            GL.ForceCameraRotation(cameraRotation);
            GL.ForceCameraPosition(cameraPosition);
            #endregion

            #region MatrixInterpolation
            if (Math.Abs(CMatrix - TMatrix) > 0.001f)
            {
                CMatrix = renderX.Lerp(CMatrix, TMatrix, 0.1f * deltaTimeAdjusted);
            }
            else
            {
                CMatrix = TMatrix;
            }

            GL.SetMatrixData(90, 160, CMatrix);
            MiniGL.SetMatrixData(90, 350, CMatrix);

            #endregion

            #region BufferCaching
            bool y = cameraPosition.Equals(lcP) && cameraRotation.Equals(lcR) && Math.Abs(CurrentFOV - TargetFOV) < 0.01f && CMatrix == TMatrix;
            if (!y)
            {
                readyCache = false;
            }
            #endregion

            #region Indicator, Buffer Selection, Clearing and LightData
            PrepareLightningData();
            ProcessCameraIndicator();
            GL.Clear();
            //   GL.Clear(55, 155, 255);
            GL.ClearDepth();

            GL.SelectShader(DisplayTexture);
            GL.SelectBuffer(VertexBuffer);
            #endregion

            //GL.BlitInto

            if (y & !readyCache & FBCaching)
            {
                GL.CreateCopyOnDraw(cachedBuffer);
                GL.Draw();
                readyCache = true;
                y          = false;
            }

            sw.Start();
            if (readyCache)
            {
                GL.CopyFromCache(cachedBuffer, CopyMethod.SplitLoop);
            }
            else
            {
                GL.Draw();
            }
            sw.Stop();

            //   GL.Draw(LineBuffer, LineShader);
            //   GL.Draw(CubeVBO, cubeShader);

            //  GL.Clear(255);

            #region AxesIndicator
            GL.Line3D(new Vector3(0, 0, 0), new Vector3(1000000, 0, 0), 255, 0, 0);
            GL.Line3D(new Vector3(0, 0, 0), new Vector3(0, 1000000, 0), 0, 255, 0);
            GL.Line3D(new Vector3(0, 0, 0), new Vector3(0, 0, 1000000), 0, 0, 255);
            #endregion

            //  sw.Restart();
            //    GL.VignettePass();
            //  sw.Stop();

            MiniGL.BlitInto(GL, GL.RenderWidth - 130, GL.RenderHeight - 128, Color.FromArgb(255, 0, 0, 0));

            //   GL.BlitInto(infoBitmap, new Rectangle(0, 0, 200, 200));
            //   GL.BlitFrom(infoBitmap, new Rectangle(0, 0, 40, 40), 0, 0);
            DrawText();

            GL.Blit();

            //   this.Invoke((Action)delegate() { this.Text = (sw.Elapsed.TotalMilliseconds) + " ms"; });
            this.Invoke((Action) delegate() { this.Text = (1000f / deltaTime) + " FPS, DrawTime: " + sw.Elapsed.TotalMilliseconds + "ms"; });
            //   this.Invoke((Action)delegate() { this.Text = "pos: " + cameraPosition.ToString() + ", rot: " + cameraRotation.ToString(); });


            lcR = cameraRotation;
            lcP = cameraPosition;

            sw.Reset();
        }