void timer_Tick(object sender, EventArgs e) { GL.Clear(0, 0, 0); GL.ClearDepth(); GL.SelectBuffer(vertexBuffer); GL.SelectShader(cubeShader); GL.Draw(); GL.Blit(); objectRotation = new Vector3(0, 0, rotAngle++); oSin = GetSin(objectRotation); oCos = GetCos(objectRotation); cameraPosition.y = 10f * (float)Math.Sin(rotAngle / 25.1f); GL.ForceCameraPosition(cameraPosition); }
private void Form1_Load(object sender, EventArgs e) { this.ClientSize = new System.Drawing.Size(800, 600); GL = new renderX(800, 600, this.Handle); GL.Clear(); vertexBuffer = new GLBuffer(renderX.PrimitiveTypes.Cube(), 5, MemoryLocation.Heap); cubeShader = new Shader(CubeVS, CubeFS, GLRenderMode.Triangle); cameraPosition = new Vector3(0, 0, -100); cameraRotation = new Vector3(0, 0, 0); GL.SetMatrixData(90, 160, 0); GL.ForceCameraPosition(cameraPosition); GL.ForceCameraRotation(cameraRotation); GL.SetFaceCulling(true, false); texture2d = new GLTexture("container2.png", MemoryLocation.Heap, DuringLoad.Flip); TEXTURE_ADDR = (int *)texture2d.GetAddress(); textureHeight = texture2d.Height; textureWidthMinusOne = texture2d.Width - 1; textureHeightMinusOne = texture2d.Height - 1; Timer timer = new Timer(); timer.Interval = 15; timer.Tick += timer_Tick; timer.Start(); }
void ProcessCameraIndicator() { int FI; int YI; bool BS = false; bool GS = false; bool RS = false; bool RS1 = false; bool GS1 = false; bool BS1 = false; bool OS = false; if (requestClick && MiniGL.GetClickBufferData(130 - (GL.RenderWidth - rcX), 128 - (GL.RenderHeight - (this.ClientSize.Height - rcY)), out FI, out YI)) { if (YI == 1) //BLUE { TargetPosition = new Vector3(0, 0, DistanceCenter) + ModelCenter; TargetRotation = new Vector3(0, 0, 180); } else if (YI == 2) //RED { TargetPosition = new Vector3(DistanceCenter, 0, 0) + ModelCenter; TargetRotation = new Vector3(0, 0, -90); } else if (YI == 3) //GREEN { TargetPosition = new Vector3(0, DistanceCenter, 0) + ModelCenter; TargetRotation = new Vector3(0, 90, 0); } else if (YI == 4) //WHITE { if (TMatrix == 1f) { TMatrix = 0f; } else { TMatrix = 1f; } } else if (YI == 5) //BLUE1 { TargetPosition = new Vector3(0, 0, -DistanceCenter) + ModelCenter; TargetRotation = new Vector3(0, 0, 0); } else if (YI == 6) //GREEN1 { TargetPosition = new Vector3(0, -DistanceCenter, 0) + ModelCenter; TargetRotation = new Vector3(0, -90, 0); } else if (YI == 7) //RED1 { TargetPosition = new Vector3(-DistanceCenter, 0, 0) + ModelCenter; TargetRotation = new Vector3(0, 0, 90); } if (YI != 4) { requestHome = true; } requestClick = false; } int sourceX = 0; int sourceY = 0; this.Invoke((Action) delegate(){ sourceX = this.PointToClient(Cursor.Position).X; sourceY = this.PointToClient(Cursor.Position).Y; }); if (MiniGL.GetClickBufferData(130 - (GL.RenderWidth - sourceX), 128 - (GL.RenderHeight - (this.ClientSize.Height - sourceY)), out FI, out YI)) { BS = YI == 1; RS = YI == 2; GS = YI == 3; OS = YI == 4; BS1 = YI == 5; GS1 = YI == 6; RS1 = YI == 7; } MiniGL.Clear(); MiniGL.ClearClickBuffer(); MiniGL.ClearDepth(); //DRAW CENTER AXIS INDICATOR PIECE MiniGL.SetClickBufferInt(4); MiniGL.SelectBuffer(CICVertex); CI_RAngle = new Vector3(0, 0, 0); CI_Color = new Vector3(1f, 1f, 1f); if (OS) { CI_Color = CI_Color * 0.5f; } SMPLT = true; MiniGL.Draw(); SMPLT = false; MiniGL.SelectBuffer(CIPVertex); //DRAW BLUE AXIS INDICATOR MiniGL.SetClickBufferInt(1); CI_Color = new Vector3(1, 0.69f, 0.14f); if (BS) { CI_Color = CI_Color * 0.5f; } CI_RAngle = new Vector3(0, 0, 180); MiniGL.Draw(); //DRAW RED AXIS INDICATOR MiniGL.SetClickBufferInt(2); CI_Color = new Vector3(0, 0, 1); if (RS) { CI_Color = CI_Color * 0.5f; } CI_RAngle = new Vector3(0, 0, 90); MiniGL.Draw(); MiniGL.SetClickBufferInt(7); CI_Color = new Vector3(1, 1, 1); if (RS1) { CI_Color = CI_Color * 0.5f; } CI_RAngle = new Vector3(0, 0, 270); MiniGL.Draw(); MiniGL.SetClickBufferInt(5); CI_Color = new Vector3(1, 1, 1); if (BS1) { CI_Color = CI_Color * 0.5f; } CI_RAngle = new Vector3(0, 0, 0); MiniGL.Draw(); MiniGL.SetClickBufferInt(3); CI_Color = new Vector3(0, 1, 0); if (GS) { CI_Color = CI_Color * 0.5f; } CI_RAngle = new Vector3(0, -90, 0); MiniGL.Draw(); MiniGL.SetClickBufferInt(6); CI_Color = new Vector3(1, 1, 1); if (GS1) { CI_Color = CI_Color * 0.5f; } CI_RAngle = new Vector3(0, 90, 0); MiniGL.Draw(); }
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(); }