public SimulationVisualMovable3D(IMovableObjectInfo moveableObject) : base(moveableObject) { // Store object _moveableObject = moveableObject; // Calculate height if (this is SimulationVisualPod3D) { _height = _moveableObject.GetInfoRadius() * 4; } else if (this is SimulationVisualBot3D) { _height = _moveableObject.GetInfoRadius() * 0.9; } else { throw new ArgumentException("Unknown visual: " + this.GetType().ToString()); } // Add transforms Transform3DGroup tg = new Transform3DGroup(); tg.Children.Add(new TranslateTransform3D( _moveableObject.GetInfoCurrentTier().GetInfoTLX() + _moveableObject.GetInfoCenterX(), _moveableObject.GetInfoCurrentTier().GetInfoTLY() + _moveableObject.GetInfoCenterY(), _moveableObject.GetInfoCurrentTier().GetInfoZ() + GetZ())); tg.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 0, 1), moveableObject.GetInfoOrientation() / (2 * Math.PI) * 360))); Transform = tg; }
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(); }