public Viewer3D() { InitializeComponent(); DataContextChanged += Viewer3D_DataContextChanged; //if(Tag.ToString() == "Z") //{ // return; //} // Setta to XY Vector3D faceNormal = new Vector3D(0, 0, 1); Vector3D faceUp = new Vector3D(0, 1, 0); var camera = view.Viewport.Camera as ProjectionCamera; Point3D target = camera.Position + camera.LookDirection; double dist = camera.LookDirection.Length; Vector3D lookdir = -faceNormal; lookdir.Normalize(); lookdir = lookdir * dist; Point3D pos = target - lookdir; Vector3D updir = faceUp; updir.Normalize(); CameraHelper.AnimateTo(camera, pos, lookdir, updir, 500); //view.Orthographic = true; //view.Camera.NearPlaneDistance = 0; //view.Camera.FarPlaneDistance = 10000; }
public void UpdateTransformation(bool overrideUpdate) { if (_moveableObject.GetInfoChanged() || overrideUpdate) { // Fetch necessary information ITierInfo tier = _moveableObject.GetInfoCurrentTier(); if (tier != null) { // Get position double xOffset = tier.GetInfoTLX() + _moveableObject.GetInfoCenterX(); double yOffset = tier.GetInfoTLY() + _moveableObject.GetInfoCenterY(); double zOffset = tier.GetInfoZ() + GetZ(); double orientationInDegrees = _moveableObject.GetInfoOrientation() / (2 * Math.PI) * 360; //// Fetch transformers // TODO is it really necessary to "new" the transformer objects? //Transform3DGroup tg = (Transform3DGroup)Transform; //TranslateTransform3D positionTransform = (TranslateTransform3D)tg.Children.First(); //RotateTransform3D rotationTransform = (RotateTransform3D)tg.Children.Last(); //// Set new information //positionTransform.OffsetX = xOffset; //positionTransform.OffsetY = yOffset; //positionTransform.OffsetZ = zOffset; // Update visual object itself Transform3DGroup tg = new Transform3DGroup(); tg.Children.Add(new TranslateTransform3D(xOffset, yOffset, zOffset)); tg.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 0, 1), _moveableObject.GetInfoOrientation() / (2 * Math.PI) * 360), new Point3D(xOffset, yOffset, zOffset))); Transform = tg; // Update onboard camera, if attached if (_onboardCameraAttached) { double angle = _moveableObject.GetInfoOrientation() + 0.5 * Math.PI; CameraHelper.AnimateTo( _camera, // The camera to adjust new Point3D(xOffset, yOffset, tier.GetInfoZ() + _height + 0.05), // The position of the camera new Vector3D(Math.Sin(angle), -Math.Cos(angle), 0), // The direction the camera is facing new Vector3D(0, 0, 1), // The roll of the camera - just keep it upright 0); // The animation time } } } // Update meta info UpdateMetaInfo(); }
/// <summary> /// Handles left clicks on the view cube. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The event arguments. /// </param> private void FaceMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { if (!this.IsEnabled) { return; } var faceNormal = this.faceNormals[sender]; var faceUp = this.faceUpVectors[sender]; var lookDirection = -faceNormal; var upDirection = faceUp; lookDirection.Normalize(); upDirection.Normalize(); // Double-click reverses the look direction if (e.ClickCount == 2) { lookDirection *= -1; if (upDirection != this.ModelUpDirection) { upDirection *= -1; } } if (this.Viewport != null) { if (this.Viewport.Camera is ProjectionCamera camera) { var target = camera.Position + camera.LookDirection; double distance = camera.LookDirection.Length; lookDirection *= distance; var newPosition = target - lookDirection; CameraHelper.AnimateTo(camera, newPosition, lookDirection, upDirection, 500); } } e.Handled = true; this.OnClicked(lookDirection, upDirection); }