private void pictureBox1_MouseUp(object sender, MouseEventArgs e) { _mouseDownOn = MouseDownOn.Nothing; pictureBox1.PanMouseButton = MouseButtons.Left; // this might have been disabled in mouse down if (_triangle1 != null) { _triangle1.OnMouseUp(); } if (_triangle2 != null) { _triangle2.OnMouseUp(); } if (_polygon1 != null) { _polygon1.OnMouseUp(); } if (_polygon2 != null) { _polygon2.OnMouseUp(); } }
private void pictureBox1_MouseDown(object sender, MouseEventArgs e) { const double VELOCITYCLICKDISTANCE = 35; MyVector clickPoint = pictureBox1.GetPositionViewToWorld(new MyVector(e.X, e.Y, 0)); if (e.Button == MouseButtons.Left) { if (radBallBall.Checked || radSolidBallSolidBall.Checked || radSphereSphere.Checked) { #region Balls if (_ball1 != null && Utility3D.GetDistance3D(clickPoint, GetVelocityEnd(_ball1)) <= VELOCITYCLICKDISTANCE) { _mouseDownOn = MouseDownOn.Ball1Velocity; _offset = _ball1.Velocity - clickPoint; } else if (_ball2 != null && Utility3D.GetDistance3D(clickPoint, GetVelocityEnd(_ball2)) <= VELOCITYCLICKDISTANCE) { _mouseDownOn = MouseDownOn.Ball2Velocity; _offset = _ball2.Velocity - clickPoint; } else if (_ball1 != null && Utility3D.GetDistance3D(clickPoint, _ball1.Position) <= _ball1.Radius) { _mouseDownOn = MouseDownOn.Ball1; _offset = _ball1.Position - clickPoint; } else if (_ball2 != null && Utility3D.GetDistance3D(clickPoint, _ball2.Position) <= _ball2.Radius) { _mouseDownOn = MouseDownOn.Ball2; _offset = _ball2.Position - clickPoint; } else { return; } #endregion } else if (radLineTriangle.Checked || radSphereTriangle.Checked) { #region 1 Triangle if (_ball1 != null && Utility3D.GetDistance3D(clickPoint, GetVelocityEnd(_ball1)) <= VELOCITYCLICKDISTANCE) { _mouseDownOn = MouseDownOn.Ball1Velocity; _offset = _ball1.Velocity - clickPoint; } else if (_ball1 != null && Utility3D.GetDistance3D(clickPoint, _ball1.Position) <= _ball1.Radius) { _mouseDownOn = MouseDownOn.Ball1; _offset = _ball1.Position - clickPoint; } else if (_triangle1 != null && _triangle1.OnMouseDown(clickPoint)) { _mouseDownOn = MouseDownOn.Triangle1; // no need to set the offset. the triangle takes care of everything internally } else { return; } #endregion } else if (radTriangleTriangle.Checked) { #region Triangles if (_triangle1 != null && _triangle1.OnMouseDown(clickPoint)) { _mouseDownOn = MouseDownOn.Triangle1; // no need to set the offset. the triangle takes care of everything internally } else if (_triangle2 != null && _triangle2.OnMouseDown(clickPoint)) { _mouseDownOn = MouseDownOn.Triangle2; // no need to set the offset. the triangle takes care of everything internally } else { return; } #endregion } else if (radSpherePolygon.Checked) { #region 1 Polygon if (_ball1 != null && Utility3D.GetDistance3D(clickPoint, _ball1.Position) <= _ball1.Radius) { _mouseDownOn = MouseDownOn.Ball1; _offset = _ball1.Position - clickPoint; } else if (_polygon1 != null && _polygon1.OnMouseDown(clickPoint)) { _mouseDownOn = MouseDownOn.Polygon1; // no need to set the offset. the polygon takes care of everything internally } else { return; } #endregion } else if (radPolygonPolygon.Checked) { #region Polygons if (_polygon1 != null && _polygon1.OnMouseDown(clickPoint)) { _mouseDownOn = MouseDownOn.Polygon1; // no need to set the offset. the polygon takes care of everything internally } else if (_polygon2 != null && _polygon2.OnMouseDown(clickPoint)) { _mouseDownOn = MouseDownOn.Polygon2; // no need to set the offset. the polygon takes care of everything internally } else { return; } #endregion } } _mouseDownPoint = clickPoint; _curMousePoint = clickPoint.Clone(); // If they are dragging something, then don't pan (gets reset on mouse up) if (_mouseDownOn != MouseDownOn.Nothing) { pictureBox1.PanMouseButton = MouseButtons.None; } }