private void Form1_MouseClick(object sender, MouseEventArgs e) { Boolean found = false; if (draw) { if ((e.X >= 200 && e.X <= 600) && (e.Y >= 100 && e.Y <= 400))//çizim alanında mı { for (int i = 0; i < pointList.Count; i++) { if (pointList[i].getRectangle().Contains(e.X, e.Y)) { found = true; break; } } if (!found) { Nokta n = new Nokta(e.X, e.Y); pointList.Add(n); Invalidate(); } } } else if (delete) { if ((e.X >= 200 && e.X <= 600) && (e.Y >= 100 && e.Y <= 400))//çizim alanında mı { for (int i = 0; i < pointList.Count; i++) { if(pointList[i].getRectangle().Contains(e.X,e.Y)) { pointList.RemoveAt(i); Invalidate(); } } } } }
private void Form1_MouseUp(object sender, MouseEventArgs e) { if (translateStart) { Nokta n = new Nokta(e.X, e.Y); n.setColor(translatedColor); pointList.Add(n); translateStart = false; Invalidate(); } }
/// <summary> /// This callback function will be called at the end of every frame to perform all the /// rendering calls for the scene, and it will also be called if the window needs to be /// repainted. After this function has returned, the sample framework will call /// Device.Present to display the contents of the next buffer in the swap chain /// </summary> public void OnFrameRender(Device device, double appTime, float elapsedTime) { bool beginSceneCalled = false; // Clear the render target and the zbuffer device.Clear(ClearFlags.ZBuffer | ClearFlags.Target, MyClearColor, 1.0f, 0); SiradakiVerts = 0; //reset draw query KoseNoktaAdet = 3; PrimCOunt = (int)(KoseNoktaAdet / 3); //sender tarafýndan hesaplanacak if (KoseNoktaAdet == 0) { return; //köþe nokta yoksa çýk } try { device.BeginScene(); beginSceneCalled = true; SetupMatrices(); vertexBuffer = new VertexBuffer(typeof(CustomVertex.PositionNormalColored), KoseNoktaAdet, device, Usage.None, CustomVertex.PositionNormalColored.Format, Pool.SystemMemory); CustomVertex.PositionNormalColored[] verts = (CustomVertex.PositionNormalColored[])vertexBuffer.Lock(0, 0); //objects rendering Nokta[] MyN = new Nokta[3]; System.Drawing.Color MyColor = System.Drawing.Color.White; MyN[0] = new Nokta(0, 0, 100); MyN[1] = new Nokta(0, 1, -100); MyN[2] = new Nokta(1, 1, 0); int UpVector = 1; float[] X = new float[3]; float[] Y = new float[3]; float[] Z = new float[3]; for (int t = 0; t < 2; t++) { X[t] = MyN[t].X; Y[t] = MyN[t].Y; Z[t] = MyN[t].Z; } //1.üçgen verts[SiradakiVerts].X = X[0]; verts[SiradakiVerts].Y = Y[0]; verts[SiradakiVerts].Z = Z[0]; verts[SiradakiVerts].Nx = X[0]; verts[SiradakiVerts].Ny = Y[0]; verts[SiradakiVerts].Nz = Z[0] + UpVector; verts[SiradakiVerts].Color = MyColor.ToArgb(); SiradakiVerts++; verts[SiradakiVerts].X = X[2]; verts[SiradakiVerts].Y = Y[2]; verts[SiradakiVerts].Z = Z[2]; verts[SiradakiVerts].Nx = X[2]; verts[SiradakiVerts].Ny = Y[2]; verts[SiradakiVerts].Nz = Z[2] + UpVector; verts[SiradakiVerts].Color = MyColor.ToArgb(); SiradakiVerts++; verts[SiradakiVerts].X = X[1]; verts[SiradakiVerts].Y = Y[1]; verts[SiradakiVerts].Z = Z[1]; verts[SiradakiVerts].Nx = X[1]; verts[SiradakiVerts].Ny = Y[1]; verts[SiradakiVerts].Nz = Z[1] + UpVector; verts[SiradakiVerts].Color = MyColor.ToArgb(); SiradakiVerts++; //if (verts!=null) DrawUcgen(MyN, System.Drawing.Color.Blue) //objects reindering vertexBuffer.Unlock(); // Rendering of scene objects can happen here device.SetStreamSource(0, vertexBuffer, 0); device.VertexFormat = CustomVertex.PositionNormalColored.Format; device.DrawPrimitives(PrimitiveType.TriangleStrip, 0, PrimCOunt); //End the scene //Update the effect's variables. Instead of using strings, it would //be more efficient to cache a handle to the parameter by calling //Effect.GetParameter //effect.SetValue("worldViewProjection", camera.WorldMatrix * viewMatrix * camera.ProjectionMatrix); //effect.SetValue("worldMatrix", camera.WorldMatrix); //effect.Technique = "RenderScene"; // Render the mesh //int passes = effect.Begin(0); //Mesh localMesh = mesh.LocalMesh; //for (int pass = 0; pass < passes; pass++) //{ // effect.BeginPass(pass); //for(int i = 0; i < mesh.NumberMaterials; i++) //{ // effect.SetValue("sceneTexture", mesh.GetTexture(i)); //effect.CommitChanges(); //localMesh.DrawSubset(i); //} //effect.EndPass(); //} //effect.End(); // Show frame rate RenderText(); // Show UI hud.OnRender(elapsedTime); //sampleUi.OnRender(elapsedTime); //device.EndScene(); //device.Present(); } finally { if (beginSceneCalled) { device.EndScene(); } device.Present(); //remden arýndýr verts = null; vertexBuffer.Dispose(); GC.Collect(); } }