public void Paste(Scene scene, Vector3 translation, ViewportOrientation viewport) { if (viewport == ViewportOrientation.Top) { translation.Y = copiedElemCenter.y; } else if (viewport == ViewportOrientation.Front) { translation.Z = copiedElemCenter.z; } else if (viewport == ViewportOrientation.Side) { translation.X = copiedElemCenter.x; } scene.AddPreparedElement(copyBuffer, translation); }
public void Paste(Scene scene, Vector3 translation, ViewportOrientation viewport) { if (viewport == ViewportOrientation.Top) { translation.Y = copiedElemCenter.y; } else if (viewport == ViewportOrientation.Front) { translation.Z = copiedElemCenter.z; } else if (viewport == ViewportOrientation.Side) { translation.X = copiedElemCenter.x; } scene.AddPreparedElement(copyBuffer, translation); }
public static ClipPlaneType SelectClippingPlane(Vertex[] clipVertices, int[] clipIndices, ViewportType viewportType, Point pos, Point size, Vector2 orthoSize, Vector3 orthoPos, Vector3 orthoLookAt, ViewportOrientation viewport) { if (viewportType == ViewportType.Perspective) return ClipPlaneType.NONE; Vector3 outCamPos = new Vector3(), outSurfPos = new Vector3(); CalcOrthoCoords(pos, size, orthoSize, orthoPos, orthoLookAt, out outCamPos, out outSurfPos); // Indeksy trójkątów które trzeba odrzucić, aby można było wybrać // właściwą płaszczyznę obcinającą. int minRejectIdx, maxRejectIdx; switch (viewport) { case ViewportOrientation.Front: minRejectIdx = 144/3; maxRejectIdx = 216/3-1; break; case ViewportOrientation.Side: minRejectIdx = 72/3; maxRejectIdx = 144/3-1; break; case ViewportOrientation.Top: minRejectIdx = 0/3; maxRejectIdx = 72/3-1; break; default: minRejectIdx = 0; maxRejectIdx = 0; break; } Vector3[] shiftDist = new Vector3[6]; for(int i = 0; i < 6; ++i) { shiftDist[i] = (clipVertices[8 * i].Position - clipVertices[8 * i + 4].Position) * 2; } for(int i = 0; i < 6; ++i) { for(int j = 0; j < 8; ++j) { if(j < 4) { clipVertices[i * 8 + j].Position += shiftDist[i]; } else { clipVertices[i * 8 + j].Position -= shiftDist[i]; } } } List<Triang> clipPlaneTriangs = new List<Triang>(); for (int i = 0; i < clipIndices.Length; i += 3) { clipPlaneTriangs.Add(new Triang(clipVertices[clipIndices[i]].Position, clipVertices[clipIndices[i + 1]].Position, clipVertices[clipIndices[i + 2]].Position)); } for(int i = 0; i < 6; ++i) { for(int j = 0; j < 8; ++j) { if(j < 4) { clipVertices[i * 8 + j].Position -= shiftDist[i]; } else { clipVertices[i * 8 + j].Position += shiftDist[i]; } } } Vector3 rayDir = Vector3.Normalize(outSurfPos - outCamPos); Ray ray = new Ray(outCamPos + 0.01f*rayDir, rayDir); float dist = float.PositiveInfinity; float tmpDist; int minIdx = -1; for (int i = 0; i < clipPlaneTriangs.Count; ++i) { if (i < minRejectIdx || i > maxRejectIdx) { if (Ray.Intersects(ray, clipPlaneTriangs[i].p1, clipPlaneTriangs[i].p2, clipPlaneTriangs[i].p3, out tmpDist)) { if (tmpDist < dist) { dist = tmpDist; minIdx = i; } } } } return (ClipPlaneType) (minIdx == -1 ? -1 : minIdx/12); }
private void contextViewport(object sender, System.EventArgs e) { if (maxViewport == ViewportOrientation.None) { ViewportOrientation rect = GetViewportType(mRCx, mRCy); if (rect != ViewportOrientation.None) { maxViewport = rect; contextMenu.MenuItems[4].Text = "Zmniejsz widok"; RenderViews(); } } else { maxViewport = ViewportOrientation.None; contextMenu.MenuItems[4].Text = "Powiększ widok"; RenderViews(); } }
private void Views_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) { Views.Focus(); mouseDownHandled = false; if (!GetShiftPressed() && e.Button == MouseButtons.Left) { if (currScene.selCams.Count > 0 || currScene.selLights.Count > 0 || currScene.selTriangles.Count > 0) { System.Windows.DataObject dataObject = new System.Windows.DataObject(); ViewportInfo coords = GetViewCoords(tabWidok.SelectedIndex); undo.Save(currScene); ViewportOrientation viewport = GetViewportType(e.X, e.Y); switch(viewport) { case ViewportOrientation.Front: dataObject.SetData("Viewport", "front"); break; case ViewportOrientation.Side: dataObject.SetData("Viewport", "side"); break; case ViewportOrientation.Top: dataObject.SetData("Viewport", "top"); break; case ViewportOrientation.Perspective: dataObject.SetData("Viewport", "perspective"); break; default: break; } if (currScene.selLights.Count == 1) { dataObject.SetData("Light", currScene.lights[currScene.selLights[0]]); dataObject.SetData("LightPrevious", new Light_(currScene.lights[currScene.selLights[0]])); } dragX = (float)e.X + xOffset; dragY = (float)e.Y + yOffset; if (contextMenu.MenuItems[1].Checked == true) { directionX = 0; directionY = 0; angle = undefined; int rect = (int)viewport; ViewportInfo views = GetViewCoords(tabWidok.SelectedIndex); dragX = (int)(views.posX[rect] + views.sizeX[rect] / 2.0f) + xOffset; dragY = (int)(views.posY[rect] + views.sizeY[rect] / 2.0f) + yOffset; } DragDrop.DoDragDrop(this, dataObject, System.Windows.DragDropEffects.Move); currScene.selectedHierObj = null; RenderViews(); } //else //{ // ViewportInfo views = GetViewCoords(tabWidok.SelectedIndex); // int x = (int)e.X; // int y = (int)e.Y; // ViewportOrientation viewport = GetViewportType(x, y); // if(viewport != ViewportOrientation.None) // { // ViewportType viewportType = viewport == ViewportOrientation.Perspective ? ViewportType.Perspective : ViewportType.Orto; // int rect = (int)viewport; // int orthoRect = rect == 3 ? 0 : rect; // SelectingElems.SelectElems(currScene, renderer.GetCamsPoints(), renderer.GetLightsPoints(), viewportType, new System.Drawing.Point(x - views.posX[rect], y - views.posY[rect]), // new System.Drawing.Point(views.sizeX[rect], views.sizeY[rect]), new Vector2(renderer.OrthoWidth[orthoRect], (float)views.sizeY[rect] / views.sizeX[rect] * renderer.OrthoWidth[orthoRect]), // renderer.OrthoPos[orthoRect], renderer.OrthoLookAt[orthoRect], false); // } // for (int i = 0; i < currScene.parts.Count; i++) // { // foreach (HierarchyMesh obj in currScene.selTriangles) // if (currScene.parts[i].triangles.Contains((int)obj.triangles[0])) // { // System.Windows.DataObject dataObject = new System.Windows.DataObject(); // Material_ material = null; // foreach (Material_ m in currScene.materials) // { // if (m.name == currScene.materialAssign[i]) // { // material = new Material_(m); // material.colorR = material.colorR * 255; // material.colorG = material.colorG * 255; // material.colorB = material.colorB * 255; // } // } // dataObject.SetData("Object", material); // currScene.selTriangles.Clear(); // DragDrop.DoDragDrop(this, dataObject, System.Windows.DragDropEffects.Move); // i = Int32.MaxValue - 1; // break; // } // } // currScene.ClearSelectedTriangles(); //} } //Console.WriteLine(e.Button + " " + GetShiftPressed()); else if(e.Button == MouseButtons.Middle || (e.Button == MouseButtons.Left && GetShiftPressed())) { ViewportInfo views = GetViewCoords(tabWidok.SelectedIndex); int x = (int)e.X; int y = (int)e.Y; ViewportOrientation viewport = GetViewportType(x, y); if(shiftingViewport == ViewportOrientation.None && viewport != ViewportOrientation.None && viewport != ViewportOrientation.Perspective) { shiftingViewport = viewport; } if(shiftingViewport != ViewportOrientation.None) { renderer.MoveOrtho((int)shiftingViewport, (int)-(e.X - mousePos.X), (int)-(e.Y - mousePos.Y), views.sizeX[(int)shiftingViewport], views.sizeY[(int)shiftingViewport]); RenderViews(); } } else { shiftingViewport = ViewportOrientation.None; } mousePos.X = e.X; mousePos.Y = e.Y; }
//private void ViewsBezier_MouseClick(object sender, System.Windows.Forms.MouseEventArgs e) //{ // ViewportInfo views = GetViewCoords(); // int x = (int)e.X; // int y = (int)e.Y; // ViewportOrientation viewport = GetViewportType(x, y); // if (viewport != ViewportOrientation.None) // { // ViewportType viewportType = viewport == ViewportOrientation.Perspective ? ViewportType.Perspective : ViewportType.Orto; // int rect = (int)viewport; // int orthoRect = rect == 3 ? 0 : rect; // SelectingElems.SelectBezierControlPoint(bezierSurface, renderer.bezierCam, viewportType, new System.Drawing.Point(x - views.posX[rect], y - views.posY[rect]), // new System.Drawing.Point(views.sizeX[rect], views.sizeY[rect]), new Vector2(renderer.BezierOrthoWidth[orthoRect], // (float)views.sizeY[rect] / views.sizeX[rect] * renderer.BezierOrthoWidth[orthoRect]), // renderer.BezierOrthoPos[orthoRect], renderer.BezierOrthoLookAt[orthoRect]); // RenderBezier(); // } //} private void ViewsBezier_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) { ViewsBezier.Focus(); if (e.Button == MouseButtons.Left && !GetShiftPressed()) { if (bezierSurface.selectedPointIdx != -1) { System.Windows.DataObject dataObject = new System.Windows.DataObject(); ViewportInfo coords = GetViewCoords(tabWidok.SelectedIndex); undo.Save(currScene); ViewportOrientation viewport = GetViewportType(e.X, e.Y); switch (viewport) { case ViewportOrientation.Front: dataObject.SetData("Viewport", "front"); break; case ViewportOrientation.Side: dataObject.SetData("Viewport", "side"); break; case ViewportOrientation.Top: dataObject.SetData("Viewport", "top"); break; case ViewportOrientation.Perspective: dataObject.SetData("Viewport", "perspective"); break; default: break; } dragX = (float)e.X + xOffset; dragY = (float)e.Y + yOffset; DragDrop.DoDragDrop(this, dataObject, System.Windows.DragDropEffects.Move); } } else if (e.Button == MouseButtons.Middle || e.Button == MouseButtons.Left && GetShiftPressed()) { ViewportInfo views = GetViewCoords(tabWidok.SelectedIndex); int x = (int)e.X; int y = (int)e.Y; ViewportOrientation viewport = GetViewportType(x, y); if (shiftingViewport == ViewportOrientation.None && viewport != ViewportOrientation.None && viewport != ViewportOrientation.Perspective) { shiftingViewport = viewport; } if (shiftingViewport != ViewportOrientation.None) { renderer.MoveBezierOrtho((int)shiftingViewport, (int)-(e.X - mousePos.X), (int)-(e.Y - mousePos.Y), views.sizeX[(int)shiftingViewport], views.sizeY[(int)shiftingViewport]); RenderBezier(); } } else { shiftingViewport = ViewportOrientation.None; } mousePos.X = e.X; mousePos.Y = e.Y; }
public MainWindow() { try { InitializeComponent(); } catch (Exception e) { } bezierSurface = new BezierSurface("new surface", ""); bezierSurface.Triangulate(0.5f); renderer = new Renderer(Views.Handle, ViewsBezier.Handle); maxViewport = ViewportOrientation.None; mouseDownHandled = false; shiftingViewport = ViewportOrientation.None; shiftingBezierViewport = ViewportOrientation.None; //currScene = Scene.GetExampleScene(); currScene = new Scene(); // Tworzenie kolekcji obiektów i dodawanie jej do kontrolki ItemsControl // galerii ksztaltow. _shapesGallery = new ShapeGallery(); // Wczytywanie powierzchni beziera ksztalty_ListView.ItemsSource = _shapesGallery; // Tworzenie kolekcji gotowych obiektów i dodawanie jej do kontrolki ItemsControl // galerii gotowych obiektów. _elementsGallery = new PreparedObjectsGallery(); gotowe_ListView.ItemsSource = _elementsGallery; _surfaceGallery = new SurfaceGallery(); materialy_ListView.ItemsSource = _surfaceGallery; _lightGallery = new LightGallery(); swiatla_ListView.ItemsSource = _lightGallery; //Menu kontekstowe contextMenu = new System.Windows.Forms.ContextMenu(); contextMenu.MenuItems.Add("Przenieś", contextMenuClick); contextMenu.MenuItems.Add("Obróć", contextMenuClick); contextMenu.MenuItems.Add("Skaluj", contextMenuClick); contextMenu.MenuItems.Add("Skaluj wzdłuż osi", contextMenuClick); contextMenu.MenuItems.Add("Powiększ widok", contextViewport); contextMenu.MenuItems.Add("Zapisz gotowy element", contextSave); System.Windows.Forms.MenuItem[] subMenu = new System.Windows.Forms.MenuItem[4]; System.Windows.Forms.MenuItem subLeft = new System.Windows.Forms.MenuItem("Lewej", subLeftClick); System.Windows.Forms.MenuItem subRight = new System.Windows.Forms.MenuItem("Prawej", subRightClick); System.Windows.Forms.MenuItem subUp = new System.Windows.Forms.MenuItem("Góry", subUpClick); System.Windows.Forms.MenuItem subDown = new System.Windows.Forms.MenuItem("Dołu", subDownClick); subMenu[0] = subLeft; subMenu[1] = subRight; subMenu[2] = subUp; subMenu[3] = subDown; contextMenu.MenuItems.Add("Dosuń do", subMenu); contextMenu.MenuItems.Add("Kopiuj", contextCopy); contextMenu.MenuItems.Add("Wklej", contextPaste); contextMenu.MenuItems.Add("Usuń", contextDelete); contextMenu.MenuItems[0].Checked = true; Views.ContextMenu = contextMenu; //Menu kontekstowe dla płatów beziera bezierContextMenu = new ContextMenu(); bezierContextMenu.MenuItems.Add("Zresetuj punkty", bezierContextMenuClick); bezierContextMenu.MenuItems.Add("Nowa powierzchnia", bezierContextMenuNewSurface); ViewsBezier.ContextMenu = bezierContextMenu; copyPaste = new CopyPaste.CopyPaste(); }
public static ClipPlaneType SelectClippingPlane(Vertex[] clipVertices, int[] clipIndices, ViewportType viewportType, Point pos, Point size, Vector2 orthoSize, Vector3 orthoPos, Vector3 orthoLookAt, ViewportOrientation viewport) { if (viewportType == ViewportType.Perspective) { return(ClipPlaneType.NONE); } Vector3 outCamPos = new Vector3(), outSurfPos = new Vector3(); CalcOrthoCoords(pos, size, orthoSize, orthoPos, orthoLookAt, out outCamPos, out outSurfPos); // Indeksy trójkątów które trzeba odrzucić, aby można było wybrać // właściwą płaszczyznę obcinającą. int minRejectIdx, maxRejectIdx; switch (viewport) { case ViewportOrientation.Front: minRejectIdx = 144 / 3; maxRejectIdx = 216 / 3 - 1; break; case ViewportOrientation.Side: minRejectIdx = 72 / 3; maxRejectIdx = 144 / 3 - 1; break; case ViewportOrientation.Top: minRejectIdx = 0 / 3; maxRejectIdx = 72 / 3 - 1; break; default: minRejectIdx = 0; maxRejectIdx = 0; break; } Vector3[] shiftDist = new Vector3[6]; for (int i = 0; i < 6; ++i) { shiftDist[i] = (clipVertices[8 * i].Position - clipVertices[8 * i + 4].Position) * 2; } for (int i = 0; i < 6; ++i) { for (int j = 0; j < 8; ++j) { if (j < 4) { clipVertices[i * 8 + j].Position += shiftDist[i]; } else { clipVertices[i * 8 + j].Position -= shiftDist[i]; } } } List <Triang> clipPlaneTriangs = new List <Triang>(); for (int i = 0; i < clipIndices.Length; i += 3) { clipPlaneTriangs.Add(new Triang(clipVertices[clipIndices[i]].Position, clipVertices[clipIndices[i + 1]].Position, clipVertices[clipIndices[i + 2]].Position)); } for (int i = 0; i < 6; ++i) { for (int j = 0; j < 8; ++j) { if (j < 4) { clipVertices[i * 8 + j].Position -= shiftDist[i]; } else { clipVertices[i * 8 + j].Position += shiftDist[i]; } } } Vector3 rayDir = Vector3.Normalize(outSurfPos - outCamPos); Ray ray = new Ray(outCamPos + 0.01f * rayDir, rayDir); float dist = float.PositiveInfinity; float tmpDist; int minIdx = -1; for (int i = 0; i < clipPlaneTriangs.Count; ++i) { if (i < minRejectIdx || i > maxRejectIdx) { if (Ray.Intersects(ray, clipPlaneTriangs[i].p1, clipPlaneTriangs[i].p2, clipPlaneTriangs[i].p3, out tmpDist)) { if (tmpDist < dist) { dist = tmpDist; minIdx = i; } } } } return((ClipPlaneType)(minIdx == -1 ? -1 : minIdx / 12)); }