private void ApplyVelocity() { double msPerUpdate = 1000.0 / updatesPerSecond; if (currentVelocityPerMs.LengthSquared > 0) { if (TrackBallController.CurrentTrackingType == TrackBallController.MouseDownType.None) { Vector2 center = LocalBounds.Center; TrackBallController.OnMouseDown(center, Matrix4X4.Identity, TrackBallController.MouseDownType.Rotation); TrackBallController.OnMouseMove(center + currentVelocityPerMs * msPerUpdate); TrackBallController.OnMouseUp(); Invalidate(); currentVelocityPerMs *= .85; if (currentVelocityPerMs.LengthSquared < .01 / msPerUpdate) { currentVelocityPerMs = Vector2.Zero; } if (currentVelocityPerMs.LengthSquared > 0) { UiThread.RunOnIdle(ApplyVelocity, 1.0 / updatesPerSecond); } } } }
private void ApplyVelocity() { if (HasBeenClosed || currentVelocityPerMs.LengthSquared <= 0) { UiThread.ClearInterval(runningInterval); } double msPerUpdate = 1000.0 / updatesPerSecond; if (currentVelocityPerMs.LengthSquared > 0) { if (TrackBallController.CurrentTrackingType == TrackBallTransformType.None) { Vector2 center = LocalBounds.Center; TrackBallController.OnMouseDown(center, Matrix4X4.Identity, TrackBallTransformType.Rotation); TrackBallController.OnMouseMove(center + currentVelocityPerMs * msPerUpdate); TrackBallController.OnMouseUp(); Invalidate(); currentVelocityPerMs *= .85; if (currentVelocityPerMs.LengthSquared < .01 / msPerUpdate) { currentVelocityPerMs = Vector2.Zero; } } } }
public TrackballTumbleWidget(WorldView world, GuiWidget sourceWidget) { AnchorAll(); TrackBallController = new TrackBallController(world); this.world = world; this.sourceWidget = sourceWidget; }
public override void OnMouseMove(MouseEventArgs mouseEvent) { // find the ray for this control // check what face it hits // mark that face to draw a highlight base.OnMouseMove(mouseEvent); // rotate the view if (MouseDownOnWidget) { var movePosition = mouseEvent.Position; Quaternion activeRotationQuaternion = TrackBallController.GetRotationForMove(new Vector2(Width / 2, Height / 2), world, Width, lastMovePosition, movePosition, false); if (activeRotationQuaternion != Quaternion.Identity) { lastMovePosition = movePosition; interactionLayer.World.RotationMatrix = interactionLayer.World.RotationMatrix * Matrix4X4.CreateRotation(activeRotationQuaternion); interactionLayer.Invalidate(); } } else if (world != null && cubeTraceData != null) // Make sure we don't use the trace data before it is ready { Ray ray = world.GetRayForLocalBounds(mouseEvent.Position); IntersectInfo info = cubeTraceData.GetClosestIntersection(ray); if (info != null) { var uV = ((TriangleShapeUv)info.closestHitObject).GetUv(info); } } }
public void DoRotateAroundOrigin(Vector2 mousePosition) { if (isRotating) { Quaternion activeRotationQuaternion; if (TurntableEnabled) { var delta = mousePosition - rotationStartPosition; // scale it to device units delta /= TrackBallController.TrackBallRadius / 2; var zRotation = Matrix4X4.CreateFromAxisAngle(Vector3.UnitZ.Transform(world.RotationMatrix), delta.X); var screenXRotation = Matrix4X4.CreateFromAxisAngle(Vector3.UnitX, -delta.Y); activeRotationQuaternion = new Quaternion(zRotation * screenXRotation); } else { activeRotationQuaternion = TrackBallController.GetRotationForMove(TrackBallController.ScreenCenter, TrackBallController.TrackBallRadius, rotationStartPosition, mousePosition, false); } rotationStartPosition = mousePosition; world.RotateAroundPosition(mouseDownWorldPosition, activeRotationQuaternion); Invalidate(); } }
public override void OnMouseWheel(MouseEventArgs mouseEvent) { if (!LockTrackBall) { TrackBallController.OnMouseWheel(mouseEvent.WheelDelta); Invalidate(); } base.OnMouseWheel(mouseEvent); }
public override void OnBoundsChanged(EventArgs e) { scene.camera = new Camera((int)Width, (int)Height, MathHelper.DegreesToRadians(40)); trackBallController = new TrackBallController(new Vector2(Width / 2, Height / 2), Math.Min(Width * .45, Height * .45)); OrientCamera(); NeedRedraw = true; base.OnBoundsChanged(e); }
public TrackballTumbleWidgetExtended(WorldView world, GuiWidget sourceWidget, Object3DControlsLayer Object3DControlLayer, ThemeConfig theme) { AnchorAll(); TrackBallController = new TrackBallController(world); this.theme = theme; this.world = world; this.sourceWidget = sourceWidget; this.Object3DControlLayer = Object3DControlLayer; }
public override void OnResize() { SetupScene((int)Width, (int)Height); trackBallController = new TrackBallController(new Vector2(Width / 2, Height / 2), Math.Min(Width * .45, Height * .45)); rayTraceScene(); base.OnResize(); }
public override void OnMouseWheel(MouseEventArgs mouseEvent) { if (!LockTrackBall && ContainsFirstUnderMouseRecursive()) { TrackBallController.OnMouseWheel(mouseEvent.WheelDelta); Invalidate(); } base.OnMouseWheel(mouseEvent); }
public override void OnMouseMove(MouseEventArgs mouseEvent) { base.OnMouseMove(mouseEvent); Vector2 currentMousePosition; if (mouseEvent.NumPositions == 1) { currentMousePosition.x = mouseEvent.X; currentMousePosition.y = mouseEvent.Y; if (MouseCaptured && TransformState == TrackBallController.MouseDownType.Rotation) { DrawRotationHelperCircle = true; } else { DrawRotationHelperCircle = false; } } else { Vector2 centerPosition = (mouseEvent.GetPosition(1) + mouseEvent.GetPosition(0)) / 2; currentMousePosition = centerPosition; DrawRotationHelperCircle = false; } motionQueue.AddMoveToMotionQueue(currentMousePosition, UiThread.CurrentTimerMs); if (!LockTrackBall && TrackBallController.CurrentTrackingType != TrackBallController.MouseDownType.None) { TrackBallController.OnMouseMove(currentMousePosition); Invalidate(); } // check if we should do some scaling or rotation if (TransformState != TrackBallController.MouseDownType.None && mouseEvent.NumPositions > 1 && startDistanceBetweenPoints > 0) { Vector2 position0 = mouseEvent.GetPosition(0); Vector2 position1 = mouseEvent.GetPosition(1); double curDistanceBetweenPoints = (position1 - position0).Length; double scaleAmount = pinchStartScale * curDistanceBetweenPoints / startDistanceBetweenPoints; TrackBallController.Scale = scaleAmount; double angle = Math.Atan2(position1.y - position0.y, position1.x - position0.x); } }
public override void OnResize() { Vector2 screenCenter = new Vector2(Width / 2, Height / 2); double trackingRadius = Math.Min(Width * .45, Height * .45); if (mainTrackBallController == null) { mainTrackBallController = new TrackBallController(screenCenter, trackingRadius); mainTrackBallController.Scale = .1; } else { mainTrackBallController.ScreenCenter = screenCenter; mainTrackBallController.TrackBallRadius = trackingRadius; } base.OnResize(); }
public override void OnMouseMove(MouseEventArgs mouseEvent) { mouseOver = false; // find the ray for this control // check what face it hits // mark that face to draw a highlight base.OnMouseMove(mouseEvent); // rotate the view if (MouseDownOnWidget) { var movePosition = mouseEvent.Position; Quaternion activeRotationQuaternion = TrackBallController.GetRotationForMove(new Vector2(Width / 2, Height / 2), Width, lastMovePosition, movePosition, false); if (activeRotationQuaternion != Quaternion.Identity) { lastMovePosition = movePosition; object3DControlLayer.World.RotationMatrix = object3DControlLayer.World.RotationMatrix * Matrix4X4.CreateRotation(activeRotationQuaternion); object3DControlLayer.Invalidate(); } } else if (world != null && cubeTraceData != null) // Make sure we don't use the trace data before it is ready { Ray ray = world.GetRayForLocalBounds(mouseEvent.Position); IntersectInfo info = cubeTraceData.GetClosestIntersection(ray); if (info != null) { mouseOver = true; DrawMouseHover(GetHitData(info.HitPosition)); } else { ResetTextures(); } } }
public override void OnMouseUp(MouseEventArgs mouseEvent) { if (!LockTrackBall && TrackBallController.CurrentTrackingType != TrackBallController.MouseDownType.None) { if (TrackBallController.CurrentTrackingType == TrackBallController.MouseDownType.Rotation && TrackBallController.LastMoveInsideRadius) { // try and preserve some of the velocity motionQueue.AddMoveToMotionQueue(mouseEvent.Position, UiThread.CurrentTimerMs); currentVelocityPerMs = motionQueue.GetVelocityPixelsPerMs(); if (currentVelocityPerMs.LengthSquared > 0) { UiThread.RunOnIdle(ApplyVelocity); } } TrackBallController.OnMouseUp(); } base.OnMouseUp(mouseEvent); }
public override void OnMouseMove(MouseEventArgs mouseEvent) { base.OnMouseMove(mouseEvent); Vector2 currentMousePosition; if (mouseEvent.NumPositions == 1) { currentMousePosition.X = mouseEvent.X; currentMousePosition.Y = mouseEvent.Y; } else { currentMousePosition = (mouseEvent.GetPosition(1) + mouseEvent.GetPosition(0)) / 2; } motionQueue.AddMoveToMotionQueue(currentMousePosition, UiThread.CurrentTimerMs); if (!LockTrackBall && TrackBallController.CurrentTrackingType != TrackBallTransformType.None) { TrackBallController.OnMouseMove(currentMousePosition); Invalidate(); } // check if we should do some scaling or rotation if (TransformState != TrackBallTransformType.None && mouseEvent.NumPositions > 1 && startDistanceBetweenPoints > 0) { Vector2 position0 = mouseEvent.GetPosition(0); Vector2 position1 = mouseEvent.GetPosition(1); double curDistanceBetweenPoints = (position1 - position0).Length; double scaleAmount = pinchStartScale * curDistanceBetweenPoints / startDistanceBetweenPoints; this.world.Scale = scaleAmount; double angle = Math.Atan2(position1.Y - position0.Y, position1.X - position0.X); } }
public override void OnMouseUp(MouseEventArgs mouseEvent) { if (!LockTrackBall && TrackBallController.CurrentTrackingType != TrackBallTransformType.None) { if (TrackBallController.CurrentTrackingType == TrackBallTransformType.Rotation) { // try and preserve some of the velocity motionQueue.AddMoveToMotionQueue(mouseEvent.Position, UiThread.CurrentTimerMs); if (!Keyboard.IsKeyDown(Keys.ShiftKey)) { currentVelocityPerMs = motionQueue.GetVelocityPixelsPerMs(); if (currentVelocityPerMs.LengthSquared > 0) { runningInterval = UiThread.SetInterval(ApplyVelocity, 1.0 / updatesPerSecond); } } } TrackBallController.OnMouseUp(); } base.OnMouseUp(mouseEvent); }
public override void OnMouseDown(MouseEventArgs mouseEvent) { base.OnMouseDown(mouseEvent); if (!LockTrackBall && MouseCaptured) { Vector2 currentMousePosition; if (mouseEvent.NumPositions == 1) { currentMousePosition.X = mouseEvent.X; currentMousePosition.Y = mouseEvent.Y; } else { currentMousePosition = (mouseEvent.GetPosition(1) + mouseEvent.GetPosition(0)) / 2; } currentVelocityPerMs = Vector2.Zero; motionQueue.Clear(); motionQueue.AddMoveToMotionQueue(currentMousePosition, UiThread.CurrentTimerMs); if (mouseEvent.NumPositions > 1) { Vector2 position0 = mouseEvent.GetPosition(0); Vector2 position1 = mouseEvent.GetPosition(1); startDistanceBetweenPoints = (position1 - position0).Length; pinchStartScale = world.Scale; if (TransformState != TrackBallTransformType.None) { if (!LockTrackBall && TrackBallController.CurrentTrackingType != TrackBallTransformType.None) { TrackBallController.OnMouseUp(); } TrackBallController.OnMouseDown(currentMousePosition, Matrix4X4.Identity, TrackBallTransformType.Translation); } } if (mouseEvent.Button == MouseButtons.Left) { if (TrackBallController.CurrentTrackingType == TrackBallTransformType.None) { switch (TransformState) { case TrackBallTransformType.Rotation: TrackBallController.OnMouseDown(currentMousePosition, Matrix4X4.Identity, TrackBallTransformType.Rotation); break; case TrackBallTransformType.Translation: TrackBallController.OnMouseDown(currentMousePosition, Matrix4X4.Identity, TrackBallTransformType.Translation); break; case TrackBallTransformType.Scale: TrackBallController.OnMouseDown(currentMousePosition, Matrix4X4.Identity, TrackBallTransformType.Scale); break; } } } else if (mouseEvent.Button == MouseButtons.Middle) { if (TrackBallController.CurrentTrackingType == TrackBallTransformType.None) { TrackBallController.OnMouseDown(currentMousePosition, Matrix4X4.Identity, TrackBallTransformType.Translation); } } else if (mouseEvent.Button == MouseButtons.Right) { if (TrackBallController.CurrentTrackingType == TrackBallTransformType.None) { TrackBallController.OnMouseDown(currentMousePosition, Matrix4X4.Identity, TrackBallTransformType.Rotation); } } } }
public void CalculateModelviewMatrix() { modelviewMatrix = Matrix4X4.CreateTranslation(0, 0, -7); modelviewMatrix = TrackBallController.GetTransform4X4() * modelviewMatrix; inverseModelviewMatrix = Matrix4X4.Invert(modelviewMatrix); }