private void Panel1_MouseMove(object sender, MouseEventArgs e) { if (!loaded) { return; } bool mouseWrapScreen = false; int camresult = 0; if (!eventcamera || animframe == -1) { System.Drawing.Rectangle mouseBounds = (mouseWrapScreen) ? Screen.GetBounds(ClientRectangle) : panel1.RectangleToScreen(panel1.Bounds); camresult = cam.UpdateCamera(new Point(Cursor.Position.X, Cursor.Position.Y), mouseBounds, lookKeyDown, zoomKeyDown, cameraKeyDown); } if (camresult >= 2 && selectedObject != null) { propertyGrid1.Refresh(); } if (camresult >= 1) { UpdateWeightedModels(); DrawEntireModel(); } }
public override void Update(GameTime gameTime) { while (TouchPanel.IsGestureAvailable) { GestureSample gesture = TouchPanel.ReadGesture(); if (gesture.GestureType == GestureType.FreeDrag) { Vector2 b = gesture.Position; // current finger position Vector2 a = b - gesture.Delta; // previous finger position Vector3d a3 = camera.GetUnitSphereIntersection(a.X, a.Y); Vector3d b3 = camera.GetUnitSphereIntersection(b.X, b.Y); if (a3 != null && b3 != null) { UpdateCameraRotation(a3, b3); } } else if (gesture.GestureType == GestureType.Pinch) { Vector2 b = gesture.Position; // current finger position Vector2 a = b - gesture.Delta; // previous finger position Vector2 d = gesture.Position2; // current finger position Vector2 c = d - gesture.Delta2; // previous finger position Vector3d a3 = camera.GetUnitSphereIntersection(a.X, a.Y); Vector3d b3 = camera.GetUnitSphereIntersection(b.X, b.Y); Vector3d c3 = camera.GetUnitSphereIntersection(c.X, c.Y); Vector3d d3 = camera.GetUnitSphereIntersection(d.X, d.Y); if (a3 != null && b3 != null && c3 != null && d3 != null) { // this is likely not 100% accurate pinch, but good enough for awhile Vector3d avg1 = camera.GetUnitSphereIntersection(a.X / 2 + c.X / 2, a.Y / 2 + c.Y / 2); Vector3d avg2 = camera.GetUnitSphereIntersection(b.X / 2 + d.X / 2, b.Y / 2 + d.Y / 2); if (avg1 != null && avg2 != null) { double cos1 = a3.Dot(c3); double sin1 = a3.Cross(c3).Length(); double cos2 = b3.Dot(d3); double sin2 = b3.Cross(d3).Length(); double angle1 = Math.Atan2(sin2, cos2); double angle2 = Math.Atan2(sin1, cos1); double scaleAmount; if (angle1 < 2 * angle2 && angle1 > 0.5 * angle2) // let's ignore division by zero and extreme zoom for now { scaleAmount = angle1 / angle2; } else { scaleAmount = 1; } camera.cameraZoom += Math.Log(scaleAmount, 2); UpdateCameraRotation(avg1, avg2); } } } else if (gesture.GestureType == GestureType.Tap) { Vector2 a = gesture.Position; // current finger position Vector3d a3 = camera.GetLatLongOfCoord(a.X, a.Y); // center on the click and zoom in if (a3 != null) { camera.cameraRotX = a3.X; camera.cameraRotY = a3.Y; camera.cameraZoom += 1; } } } camera.UpdateCamera(); }