private void UpdateModelFromMouse(Vector mousePositionDelta) { if (this.cameraElement == null || !(this.cameraElement is ProjectionCameraElement)) { return; } if (this.mouseMovementMode == CameraOrbitToolBehavior.MovementMode.Rotate) { this.totalAzimuthDelta += -mousePositionDelta.X / 2.0; this.totalElevationDelta += -mousePositionDelta.Y / 2.0; double angle1 = this.totalAzimuthDelta; if (this.IsShiftDown) { angle1 = CameraOrbitToolBehavior.shiftSnapAngle * Math.Round(angle1 / CameraOrbitToolBehavior.shiftSnapAngle); } RotateTransform3D rotateTransform3D1 = new RotateTransform3D(Vector3D.DotProduct((Vector3D)this.cameraElement.GetComputedValue(ProjectionCameraElement.UpDirectionProperty), this.cameraInitialUp) >= 0.0 ? (Rotation3D) new AxisAngleRotation3D(this.cameraInitialUp, angle1) : (Rotation3D) new AxisAngleRotation3D(-this.cameraInitialUp, angle1), this.cameraInitialLookAt); Point3D point = rotateTransform3D1.Transform(this.cameraInitialPosition); Vector3D vector3D1 = rotateTransform3D1.Transform(this.cameraInitialUp); Vector3D axis = Vector3D.CrossProduct(this.cameraInitialLookAt - point, vector3D1); double angle2 = this.totalElevationDelta; if (this.IsShiftDown) { angle2 = CameraOrbitToolBehavior.shiftSnapAngle * Math.Round(angle2 / CameraOrbitToolBehavior.shiftSnapAngle); } if (axis.LengthSquared == 0.0) { return; } RotateTransform3D rotateTransform3D2 = new RotateTransform3D((Rotation3D) new AxisAngleRotation3D(axis, angle2), this.cameraInitialLookAt); Point3D point3D1 = rotateTransform3D2.Transform(point); Vector3D vector3D2 = rotateTransform3D2.Transform(vector3D1); Point3D point3D2 = RoundingHelper.RoundPosition(point3D1); Vector3D vector3D3 = RoundingHelper.RoundDirection(vector3D2); Vector3D vector3D4 = RoundingHelper.RoundDirection(this.cameraInitialLookAt - point3D2); this.cameraElement.SetValue(ProjectionCameraElement.PositionProperty, (object)point3D2); this.cameraElement.SetValue(ProjectionCameraElement.UpDirectionProperty, (object)vector3D3); this.cameraElement.SetValue(ProjectionCameraElement.LookDirectionProperty, (object)vector3D4); } else { Matrix3D matrix3D = Helper3D.CameraRotationMatrix((Camera)this.cameraElement.ViewObject.PlatformSpecificObject); if (this.mouseMovementMode == CameraOrbitToolBehavior.MovementMode.TranslateXY) { Vector3D vector3D1 = new Vector3D(matrix3D.M11, matrix3D.M21, matrix3D.M31); Vector3D vector3D2 = new Vector3D(matrix3D.M12, matrix3D.M22, matrix3D.M32); this.cameraInitialPosition += this.scale * (-mousePositionDelta.X * vector3D1 + mousePositionDelta.Y * vector3D2); } else { Vector3D vector3D1 = new Vector3D(matrix3D.M13, matrix3D.M23, matrix3D.M33); this.cameraInitialPosition += this.scale * mousePositionDelta.Y * vector3D1; Vector3D vector3D2 = RoundingHelper.RoundDirection(this.cameraInitialLookAt - this.cameraInitialPosition); this.cameraElement.SetValue(ProjectionCameraElement.LookDirectionProperty, (object)vector3D2); } this.cameraInitialPosition = RoundingHelper.RoundPosition(this.cameraInitialPosition); this.cameraElement.SetValue(ProjectionCameraElement.PositionProperty, (object)this.cameraInitialPosition); } }
protected override void UpdateModelFromMouse(Base3DElement selected3DElement, Vector mousePositionDelta) { Camera camera = (Camera)selected3DElement.Viewport.Camera.ViewObject.PlatformSpecificObject; Matrix3D matrix3D1 = Helper3D.CameraRotationMatrix(camera); Matrix3D matrix3D2 = camera.Transform.Value; if (matrix3D2.HasInverse) { matrix3D2.Invert(); matrix3D1 *= matrix3D2; } Vector3D vector1 = new Vector3D(matrix3D1.M11, matrix3D1.M21, matrix3D1.M31); Vector3D vector2_1 = new Vector3D(matrix3D1.M12, matrix3D1.M22, matrix3D1.M32); Vector3D vector2_2 = new Vector3D(matrix3D1.M13, matrix3D1.M23, matrix3D1.M33); Base3DElement base3Delement = selected3DElement.Parent as Base3DElement; Matrix3D matrix3D3 = Matrix3D.Identity; if (base3Delement != null) { matrix3D3 = base3Delement.GetComputedTransformFromRoot3DElementToElement(); matrix3D3.Invert(); } if (this.mouseMovementMode == ObjectRotateTranslateBehavior.MovementMode.Rotate) { mousePositionDelta /= 2.0; Vector3D axisOfRotation = Vector3D.CrossProduct(new Vector3D(-mousePositionDelta.X, mousePositionDelta.Y, 0.0), vector2_2); double length = axisOfRotation.Length; if (length <= 0.0) { return; } Vector3D vector3D = Helper3D.EulerAnglesFromQuaternion(new Quaternion(axisOfRotation, length) * Helper3D.QuaternionFromEulerAngles(selected3DElement.CanonicalRotationAngles)); vector3D = new Vector3D(RoundingHelper.RoundAngle(vector3D.X), RoundingHelper.RoundAngle(vector3D.Y), RoundingHelper.RoundAngle(vector3D.Z)); selected3DElement.CanonicalRotationAngles = vector3D; } else { Vector3D vector3D1 = new Vector3D(selected3DElement.CanonicalTranslationX, selected3DElement.CanonicalTranslationY, selected3DElement.CanonicalTranslationZ); Point lastMousePosition = this.LastMousePosition; Point endPoint = lastMousePosition + mousePositionDelta; Vector3D vector3D2; if (this.mouseMovementMode == ObjectRotateTranslateBehavior.MovementMode.TranslateXY) { Plane3D plane = new Plane3D(Vector3D.CrossProduct(vector1, vector2_1), this.hitPoint); Vector3D vector = Helper3D.VectorBetweenPointsOnPlane((Viewport3D)selected3DElement.Viewport.ViewObject.PlatformSpecificObject, plane, lastMousePosition, endPoint); Vector3D vector3D3 = matrix3D3.Transform(vector); vector3D2 = vector3D1 + vector3D3; } else { double scale = this.Scale; vector3D2 = vector3D1 + scale * -mousePositionDelta.Y * vector2_2; } selected3DElement.CanonicalTranslationX = RoundingHelper.RoundLength(vector3D2.X); selected3DElement.CanonicalTranslationY = RoundingHelper.RoundLength(vector3D2.Y); selected3DElement.CanonicalTranslationZ = RoundingHelper.RoundLength(vector3D2.Z); } }