private void GetBone(ModelPanel panel, MouseEventArgs e, float depth, ModelPanelViewport v) { if (!_boneSelection.IsMoving() && depth < 1.0f) { IBoneNode o = null; Vector3 point = v.UnProject(e.X, e.Y, depth); bool doScale = v._renderAttrib._scaleBones; //Find orb near chosen point if (EditingAll) { foreach (IModel m in _targetModels) { foreach (IBoneNode b in m.RootBones) { if (CompareBoneDistanceRecursive(b, point, ref o, v, doScale)) { break; } } } } else if (_targetModel != null) { foreach (IBoneNode b in _targetModel.RootBones) { if (CompareBoneDistanceRecursive(b, point, ref o, v, doScale)) { break; } } } bool update = false; if (_hiBone != null && _hiBone != SelectedBone && (update = _hiBone.NodeColor != Color.Transparent)) { _hiBone.NodeColor = Color.Transparent; } if ((_hiBone = o) != null) { _hiBone.NodeColor = Color.FromArgb(255, 128, 0); panel.Cursor = Cursors.Hand; update = true; } if (update) { panel.Invalidate(); } } else if (_hiBone != null) { if (_hiBone != SelectedBone) { _hiBone.NodeColor = Color.Transparent; panel.Invalidate(); } _hiBone = null; } }
private void GetVertex(ModelPanel panel, MouseEventArgs e, float depth, ModelPanelViewport v) { //Try targeting a vertex if (RenderVertices) { if (panel.CurrentViewport.Selecting) { if (NotCtrlAlt) { ClearSelectedVertices(); } bool selected = false; if (TargetModel != null) { if (TargetModel.SelectedObjectIndex < 0) { foreach (IObject o in TargetModel.Objects) { if (o.IsRendering) { SelectVertices(o, panel); selected = true; } } } else { IObject w = TargetModel.Objects[TargetModel.SelectedObjectIndex]; if (w.IsRendering) { SelectVertices(w, panel); selected = true; } else { foreach (IObject h in TargetModel.Objects) { if (h.IsRendering) { SelectVertices(h, panel); selected = true; } } } } } else if (_targetModels != null) { foreach (IModel m in _targetModels) { if (m.SelectedObjectIndex < 0) { foreach (IObject o in m.Objects) { if (o.IsRendering) { SelectVertices(o, panel); selected = true; } } } else { IObject w = m.Objects[m.SelectedObjectIndex]; if (w.IsRendering) { SelectVertices(w, panel); selected = true; } else { foreach (IObject h in m.Objects) { if (h.IsRendering) { SelectVertices(h, panel); selected = true; } } } } } } if (selected) { OnSelectedVerticesChanged(); } } else { if (depth < 1.0f && _targetModel != null) { Vector3 point = v.UnProject(e.X, e.Y, depth); Vertex3 vertex = CompareVertexDistance(point); bool update = false; if (_hiVertex != null && !_hiVertex._selected) { update = true; _hiVertex._highlightColor = Color.Transparent; ModelPanel.CurrentViewport.AllowSelection = true; } if ((_hiVertex = vertex) != null) { update = true; _hiVertex._highlightColor = Color.Orange; panel.Cursor = Cursors.Cross; ModelPanel.CurrentViewport.AllowSelection = false; } if (update) { panel.Invalidate(); } } else if (_hiVertex != null) { if (!_hiVertex._selected) { _hiVertex._highlightColor = Color.Transparent; ModelPanel.CurrentViewport.AllowSelection = true; panel.Invalidate(); } _hiVertex = null; } } } }
/// <summary> /// Gets world-point of specified mouse point projected onto the selected bone's local space if rotating or in world space if translating or scaling. /// Intersects the projected ray with the appropriate plane using the snap flags. /// </summary> public bool GetTransformPoint( Vector2 mousePoint, out Vector3 point, ModelPanelViewport panel, Matrix localTransform, SelectionParams selection) { Vector3 lineStart = panel.UnProject(mousePoint._x, mousePoint._y, 0.0f); Vector3 lineEnd = panel.UnProject(mousePoint._x, mousePoint._y, 1.0f); Vector3 center = localTransform.GetPoint(); Vector3 camera = panel.Camera.GetPoint(); Vector3 normal = new Vector3(); bool axisSnap = selection._snapX || selection._snapY || selection._snapZ; CoordinateType coord = _coordinateTypes[(int)ControlType]; switch (ControlType) { case TransformType.Rotation: float radius = CamDistance(center, ModelPanel.CurrentViewport); if (axisSnap) { switch (coord) { case CoordinateType.Screen: if (selection._snapX || selection._snapY || selection._snapZ) { normal = camera.Normalize(center); } break; case CoordinateType.Local: normal = (localTransform * new Vector3( selection._snapX ? 1.0f : 0.0f, selection._snapY ? 1.0f : 0.0f, selection._snapZ ? 1.0f : 0.0f)).Normalize(center); break; case CoordinateType.World: normal = new Vector3( selection._snapX ? 1.0f : 0.0f, selection._snapY ? 1.0f : 0.0f, selection._snapZ ? 1.0f : 0.0f); break; } } else if (selection._snapCirc) { radius *= _circOrbScale; normal = camera.Normalize(center); } else if (Maths.LineSphereIntersect(lineStart, lineEnd, center, radius, out point)) { return(true); } else { normal = camera.Normalize(center); } if (Maths.LinePlaneIntersect(lineStart, lineEnd, center, normal, out point)) { point = Maths.PointAtLineDistance(center, point, radius); return(true); } break; case TransformType.Translation: case TransformType.Scale: if (axisSnap) { if (selection._snapX && selection._snapY && selection._snapZ) { normal = Vector3.UnitZ * Matrix.RotationMatrix(panel.Camera._rotation); } else { switch (coord) { case CoordinateType.Screen: normal = Vector3.UnitZ * Matrix.RotationMatrix(panel.Camera._rotation); break; case CoordinateType.Local: case CoordinateType.World: //Remove local rotation if (coord == CoordinateType.World) { localTransform = Matrix.TranslationMatrix(center) * Matrix.ScaleMatrix(localTransform.GetScale()); } if (selection._snapX && selection._snapY) { normal = (localTransform * Vector3.UnitZ).Normalize(center); } else if (selection._snapX && selection._snapZ) { normal = (localTransform * Vector3.UnitY).Normalize(center); } else if (selection._snapY && selection._snapZ) { normal = (localTransform * Vector3.UnitX).Normalize(center); } else //One of the snaps { Vector3 unitSnapAxis = new Vector3( selection._snapX ? 1.0f : 0.0f, selection._snapY ? 1.0f : 0.0f, selection._snapZ ? 1.0f : 0.0f); float camDist = camera.TrueDistance(center); Vector3 camVec = camera.Normalize(center); float ratio = camVec.Dot(unitSnapAxis) / (camVec.TrueDistance() * unitSnapAxis.TrueDistance()); float lineDist = camDist * ratio; Vector3 endPoint = localTransform * (unitSnapAxis * lineDist); normal = camera.Normalize(endPoint); } break; } } } else { normal = Vector3.UnitZ * Matrix.RotationMatrix(panel.Camera._rotation); } break; } return(Maths.LinePlaneIntersect(lineStart, lineEnd, center, normal, out point)); }