private void CallUpdate() { Transform3DGroup tra1 = new Transform3DGroup(); Transform3DGroup tra2 = new Transform3DGroup(); Transform3DGroup tra3 = new Transform3DGroup(); Transform3DGroup tra4 = new Transform3DGroup(); Transform3DGroup tra5 = new Transform3DGroup(); Transform3DGroup tra6 = new Transform3DGroup(); //set position of models translate = new TranslateTransform3D(0, -4, 0); rotate = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 0, 1), baserotation), new Point3D(0, -4.5, 0)); tra1.Children.Add(translate); tra1.Children.Add(rotate); translate = new TranslateTransform3D(3, -4, -1); rotate = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 1, 0), -90), new Point3D(0, 0, 0)); rotate2 = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(1, 0, 0), elbow0rot), new Point3D(5, 0, 3)); tra2.Children.Add(translate); tra2.Children.Add(rotate); tra2.Children.Add(rotate2); tra2.Children.Add(tra1); translate = new TranslateTransform3D(4, 3, 0); rotate = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 0, 1), elbow1rot), new Point3D(0, 30, 0)); tra3.Children.Add(translate); tra3.Children.Add(rotate); tra3.Children.Add(tra2); translate = new TranslateTransform3D(2, -1.8, 0); rotate = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 0, 1), elbow2rot), new Point3D(-4.05, 39.2, 0)); tra4.Children.Add(translate); tra4.Children.Add(rotate); tra4.Children.Add(tra3); translate = new TranslateTransform3D(1, 0, 0); rotate = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(1, 0, 0), gripper0rot), new Point3D(0, 41, 0.86)); tra5.Children.Add(translate); tra5.Children.Add(rotate); tra5.Children.Add(tra4); baseHolder.Transform = tra1; elbow0.Transform = tra2; elbow1.Transform = tra3; elbow2.Transform = tra4; griper.Transform = tra5; tra6.Children.Add(new TranslateTransform3D(25.4931449890137, -39.7999992370605, 2.23200511932373)); tra6.Children.Add(new TranslateTransform3D(Global.point)); test.Transform = tra6; //Console.WriteLine(elbow2.Bounds.Location); //Console.WriteLine(test.Bounds.Location); }
public override void Create() { Matrix3D m = new RotateTransform3D(new AxisAngleRotation3D(Axis, Angle)).Value; foreach (Node n in Children) { Shapes.AddRange(n.Shapes.Select(a => a.Copy().ApplyTransform(m))); } }
private void OnLoaded(object sender, RoutedEventArgs e) { // Trackball setup _trackball = new Trackball(); _trackball.Attach(this); _trackball.Slaves.Add(_viewport3D); _trackball.Enabled = true; if (this.ItemsSource is ChartPlanes) { _planes = this.ItemsSource as ChartPlanes; } else { return; } // Add 3D model Content _viewport3D.Children.Clear(); _modelGroup = new Model3DGroup(); ScaleTransform3D GroupScaleTransform = new ScaleTransform3D(new Vector3D(0.74, 1, 1)); RotateTransform3D GroupRotateTransform = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 1, 0), 0), new Point3D(0, 0, 0)); TranslateTransform3D GroupTranslateTransform = new TranslateTransform3D(new Vector3D(0, 0, 0)); Transform3DCollection tcollection = new Transform3DCollection(); tcollection.Add(GroupScaleTransform); tcollection.Add(GroupRotateTransform); tcollection.Add(GroupTranslateTransform); Transform3DGroup tGroupDefault = new Transform3DGroup(); tGroupDefault.Children = tcollection; _modelGroup.Transform = tGroupDefault; Model3DGroup submodelGroup = new Model3DGroup(); submodelGroup.Children.Add(new AmbientLight(Colors.White)); _modelGroup.Children.Add(submodelGroup); ModelVisual3D mv3d = new ModelVisual3D(); GroupScaleTransform = new ScaleTransform3D(new Vector3D(1, 1, 1)); GroupRotateTransform = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 1, 0), 0), new Point3D(0, 0, 0)); GroupTranslateTransform = new TranslateTransform3D(new Vector3D(0, 0, 0)); tcollection = new Transform3DCollection(); tcollection.Add(GroupScaleTransform); tcollection.Add(GroupRotateTransform); tcollection.Add(GroupTranslateTransform); tGroupDefault = new Transform3DGroup(); tGroupDefault.Children = tcollection; mv3d.Transform = tGroupDefault; mv3d.Content = _modelGroup; _viewport3D.Children.Add(mv3d); }
private void sliderRotate_ValueChanged(object sender, RoutedPropertyChangedEventArgs <double> e) { RotateTransform3D rottrans = new RotateTransform3D(); AxisAngleRotation3D axisRot = new AxisAngleRotation3D(new Vector3D(1, 1, 1), sliderRotate.Value); rottrans.Rotation = axisRot; cubeRightModel3D.Transform = rottrans; }
private void RootRotationMem_ValueChanged(object sender, object value) { Application.Current.Dispatcher.Invoke(() => { System.Windows.Media.Media3D.Quaternion rot = this.RootRotation.ToMedia3DQuaternion(); RotateTransform3D trans = new RotateTransform3D(new QuaternionRotation3D(rot)); this.Root.Transform = trans; }); }
private void RotateLeft_Click(object sender, RoutedEventArgs e) { _rotateValue -= 5f; //viewport.Camera.Transform = cameraFoval; Transform3D cameraRotation = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 1, 0), _rotateValue)); viewport.Camera.Transform = cameraRotation; }
private Model3DGroup Initialize_Environment(string model1, string model2, string model3, string model4, double deg1, double deg2, double deg3) { try { viewPort3d.RotateGesture = new MouseGesture(MouseAction.LeftClick); ModelImporter import = new ModelImporter(); link1 = import.Load(model1); link2 = import.Load(model2); link3 = import.Load(model3); link4 = import.Load(model4); Transform3DGroup F1 = new Transform3DGroup(); Transform3DGroup F2 = new Transform3DGroup(); Transform3DGroup F3 = new Transform3DGroup(); Transform3DGroup F4 = new Transform3DGroup(); R = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 1, 0), deg1), new Point3D(0, 0, 0)); F1.Children.Add(R); T = new TranslateTransform3D(0, 100, 0); R = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(1, 0, 0), deg2), new Point3D(0, 100, 0)); F2.Children.Add(T); F2.Children.Add(R); F2.Children.Add(F1); T = new TranslateTransform3D(0, 550, 0); R = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 0, 1), deg3), new Point3D(0, 550, 0)); F3.Children.Add(T); F3.Children.Add(R); F3.Children.Add(F2); T = new TranslateTransform3D(0, 450, 0); R = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 1, 0), 0), new Point3D(0, 450, 0)); F4.Children.Add(T); F4.Children.Add(R); F4.Children.Add(F3); link1.Transform = F1; link2.Transform = F2; link3.Transform = F3; link4.Transform = F4; RA.Children.Add(link1); RA.Children.Add(link2); RA.Children.Add(link3); RA.Children.Add(link4); } catch (Exception e) { MessageBox.Show("Exception Error: " + e.StackTrace); } return(RA); }
private void RenderSomeModels() { myViewport.Name = "myViewport"; //Set camera viewpoint and properties. myPCamera.FarPlaneDistance = 20; myPCamera.NearPlaneDistance = 1; myPCamera.FieldOfView = 45; myPCamera.Position = new Point3D(-5, 2, 3); myPCamera.LookDirection = new Vector3D(5, -2, -3); myPCamera.UpDirection = new Vector3D(0, 1, 0); //Add light sources to the scene. myDirLight.Color = Colors.White; myDirLight.Direction = new Vector3D(-3, -4, -5); teapotModel.Geometry = (MeshGeometry3D)Application.Current.Resources["myTeapot"]; //Define DiffuseMaterial and apply to the mesh geometries. DiffuseMaterial teapotMaterial = new DiffuseMaterial(new SolidColorBrush(Colors.Blue)); //<SnippetAnimate3DRotationCode3DN1> //<SnippetAnimate3DRotationCode3DN2> //Define a transformation RotateTransform3D myRotateTransform = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 2, 0), 1)); //</SnippetAnimate3DRotationCode3DN2> //<SnippetAnimate3DRotationCode3DN3> //Define an animation for the transformation DoubleAnimation myAnimation = new DoubleAnimation(); myAnimation.From = 1; myAnimation.To = 361; myAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(5000)); myAnimation.RepeatBehavior = RepeatBehavior.Forever; //</SnippetAnimate3DRotationCode3DN3> //Add animation to the transformation myRotateTransform.Rotation.BeginAnimation(AxisAngleRotation3D.AngleProperty, myAnimation); //<SnippetAnimate3DRotationCode3DN4> //Add transformation to the model teapotModel.Transform = myRotateTransform; //</SnippetAnimate3DRotationCode3DN4> //</SnippetAnimate3DRotationCode3DN1> teapotModel.Material = teapotMaterial; //Add the model to the model group collection modelGroup.Children.Add(teapotModel); modelGroup.Children.Add(myDirLight); myViewport.Camera = myPCamera; myModelVisual3D.Content = modelGroup; myViewport.Children.Add(myModelVisual3D); //add the Viewport3D to the window mainWindow.Content = myViewport; }
// Define the model. private void DefineModel(Model3DGroup group) { // Make a cube. CubeMesh = MakeCubeMesh(0, 0, 0, 2); Material material = new DiffuseMaterial(Brushes.LightBlue); GeometryModel3D model = new GeometryModel3D(CubeMesh, material); group.Children.Add(model); // Rotate around the Y axis. CubeMesh.ApplyTransformation( D3.Rotate(new Vector3D(0, 1, 0), new Point3D(0, 0, 0), 45)); // Rotate around the X axis. double angle = Math.Atan2(Math.Sqrt(2), 1); angle = angle * 180 / Math.PI; CubeMesh.ApplyTransformation( D3.Rotate(new Vector3D(1, 0, 0), new Point3D(0, 0, 0), angle)); // Make a transformation to rotate the cube // 5 degrees around the Y axis. CubeRotator = D3.Rotate( new Vector3D(0, 1, 0), new Point3D(0, 0, 0), 5); #if SHOW_AXES const double thickness = 0.1; const double length = 3; // X axis. MeshGeometry3D xmesh = MakeCubeMesh(0, 0, 0, 1); xmesh.ApplyTransformation(new ScaleTransform3D(length, thickness, thickness)); xmesh.ApplyTransformation(new TranslateTransform3D(length / 2, 0, 0)); Material xmaterial = new DiffuseMaterial(Brushes.Red); GeometryModel3D xmodel = new GeometryModel3D(xmesh, xmaterial); group.Children.Add(xmodel); // Y axis cube. MeshGeometry3D ymesh = MakeCubeMesh(0, 0, 0, 1); ymesh.ApplyTransformation(new ScaleTransform3D(thickness, length, thickness)); ymesh.ApplyTransformation(new TranslateTransform3D(0, length / 2, 0)); Material ymaterial = new DiffuseMaterial(Brushes.Green); GeometryModel3D ymodel = new GeometryModel3D(ymesh, ymaterial); group.Children.Add(ymodel); // Z axis cube. MeshGeometry3D zmesh = MakeCubeMesh(0, 0, 0, 1); Transform3DGroup zgroup = new Transform3DGroup(); zgroup.Children.Add(new ScaleTransform3D(thickness, thickness, length)); zgroup.Children.Add(new TranslateTransform3D(0, 0, length / 2)); zmesh.ApplyTransformation(zgroup); Material zmaterial = new DiffuseMaterial(Brushes.Blue); GeometryModel3D zmodel = new GeometryModel3D(zmesh, zmaterial); group.Children.Add(zmodel); #endif }
public ModelRotatorSample() { InitializeComponent(); _normalMaterial = new DiffuseMaterial(Brushes.Silver); _selectedMaterial = new DiffuseMaterial(new SolidColorBrush(Color.FromArgb(150, 192, 192, 192))); // semi-transparent Silver _eventManager = new Ab3d.Utilities.EventManager3D(MainViewport); _eventManager.CustomEventsSourceElement = ViewportBorder; // IMPORTANT !!! // When ModelMoverVisual3D is used with EventManager3D // we need to call SubscribeWithEventManager3D to use EventManager3D for mouse events processing SelectedModelRotator.SubscribeWithEventManager3D(_eventManager); // Setup events on ModelRotatorVisual3D SelectedModelRotator.ModelRotateStarted += delegate(object sender, ModelRotatedEventArgs args) { if (_selectedBoxModel == null) { return; } // When a new rotation is started, we create a new AxisAngleRotation3D with the used Axis or rotation // During the rotation we will adjust the angle (inside ModelRotated event handler) _axisAngleRotation3D = new AxisAngleRotation3D(args.RotationAxis, 0); // Insert the new rotate transform before the last translate transform that positions the box var rotateTransform3D = new RotateTransform3D(_axisAngleRotation3D); AddRotateTransform(_selectedBoxModel, rotateTransform3D); }; SelectedModelRotator.ModelRotated += delegate(object sender, ModelRotatedEventArgs args) { if (_selectedBoxModel == null) { return; } _axisAngleRotation3D.Angle = args.RotationAngle; }; SelectedModelRotator.ModelRotateEnded += delegate(object sender, ModelRotatedEventArgs args) { // Nothing to do here in this sample // The event handler is here only for description purposes }; CreateRandomScene(); // IMPORTANT: // It is very important to call Dispose method on DXSceneView after the control is not used any more (see help file for more info) this.Unloaded += (sender, args) => MainDXViewportView.Dispose(); }
private void Rotate(Rotation rot) { var trans = new RotateTransform3D(rot); Up = trans.Transform(Up); Up.Normalize(); Forward = trans.Transform(Forward); Forward.Normalize(); }
public void ChangeTransformAxis() { RotateTransform3D Rotation = new RotateTransform3D(); AxisAngleRotation3D RAxis = new AxisAngleRotation3D(); RAxis.Axis = new Vector3D(0, 1, 0); RAxis.Angle = slider.Value; Rotation.Rotation = RAxis; v2dv3d.Transform = Rotation; }
/// <summary> /// Rotation of a vector around an axis according to a given angle. /// </summary> /// <param name="source">Source vector.</param> /// <param name="angle">Rotation angle (in degree).</param> /// <param name="axis">Axis vector.</param> /// <returns>A new Vector3D object corresponding to the rotation</returns> public static Vector3D RotateVector(Vector3D source, double angle, Vector3D axis) { AxisAngleRotation3D rotation = new AxisAngleRotation3D(); rotation.Angle = angle; rotation.Axis = axis; RotateTransform3D transform = new RotateTransform3D(rotation); return(transform.Transform(source)); }
public MainWindow() { InitializeComponent(); Loaded += MainWindow_Loaded; DataContext = this; RotateTransform = new RotateTransform3D(Rotation); }
/// <summary> /// Method for Model relocation /// </summary> /// <param name="New X coordinate"></param> /// <param name="New Y coordinate"></param> /// <param name="New Z coordinate"></param> public void Move(double offsetX, double offsetY, double offsetZ) { Transform3DGroup transform = new Transform3DGroup(); RotateTransform3D rotateTrans = new RotateTransform3D(); TranslateTransform3D translateTrans = new TranslateTransform3D(offsetX, offsetY, offsetZ); transform.Children.Add(rotateTrans); transform.Children.Add(translateTrans); this.Transform = transform; }
public Trackball(double rotationFactor = 4.0, double zoomFacfor = 1.0) { _rotationFactor = rotationFactor; _zoomFactor = zoomFacfor; _transform = new Transform3DGroup(); _transform.Children.Add(_scale); _rotateTransform = new RotateTransform3D(_rotation); _transform.Children.Add(_rotateTransform); _transform.Children.Add(_translate); }
/// <summary> /// /// </summary> public void Initialise(ILayer baseLayer) { #region Construct View Port , Add Transforms, Scale Viewport3D viewport = ViewPort; _transform = new Transform3DGroup(); _transform.Children.Add(_scale); _rotationTranform = new RotateTransform3D(_rotation); _transform.Children.Add(_rotationTranform); AmbientLight _ambLight = new AmbientLight(System.Windows.Media.Brushes.White.Color); var visuald = new ModelVisual3D(); Model3DGroup M3dG = new Model3DGroup(); M3dG.Children.Add(_ambLight); visuald.Content = M3dG; viewport.Children.Add(visuald); #endregion BaseLayer = baseLayer; this.RootTile = new GlobeTile(0, 0, 0, visuald); var root = this.RootTile; this.RootTile.zoomIn(); //Map Viewport as Event Source to Map Event Handlers. EventSource = viewport; //Add All Necessary Transforms to view port Camera. viewport.Camera.Transform = _transform; #region Populate Initial Layer [Based on MS Bing Map] var initialKey = "032010110132012031";//initial key for (var i = 0; i < initialKey.Length; i++) { root.Children[int.Parse(initialKey.Substring(i, 1))].zoomIn(); } #endregion #region Map Events to Handelers viewport.MouseDown += viewport_MouseDown; viewport.MouseUp += viewport_MouseUp; viewport.MouseMove += viewport_MouseMove; viewport.MouseWheel += viewport_MouseWheel; viewport.SizeChanged += viewport_SizeChanged; #endregion RedrawSphere(); }
public Creature(Point3D position, Creature mother, Creature father) { Mother = mother; Father = father; Gender = randomizer.Next(2) == 0 ? Gender.Male : Gender.Female; Position = position; Heading = 0; Speed = 0; AngularSpeed = 0; Acceleration = 0; BirthTime = GetRandom(5, 3); ChildhoodDuration = GetRandom(20, 10); LifeTime = GetRandom(90, 30); PrivacyDist = 2.5; double bmiMean = 25; double maxSpeedMean = 3; double heightMean = 1.75; if (mother != null) { heightMean = (Mother.GrownupHeight + Father.GrownupHeight) / 2; bmiMean = (Mother.BMI + Father.BMI) / 2; maxSpeedMean = (Mother.MaxSpeed + Father.MaxSpeed) / 2; } BMI = GetRandom(bmiMean, bmiMean / 2); GrownupHeight = GetRandom(heightMean, 0.5); MaxSpeed = Gender == Gender.Male ? GetRandom(maxSpeedMean + 2, 1) : GetRandom(maxSpeedMean, 1); Agility = GetRandom(15, 10); Fitness = GetRandom(1, 0.5); Energy = 1; model = new GeometryModel3D(); translation = new TranslateTransform3D(); scale = new ScaleTransform3D(); var rotationT = new RotateTransform3D(); rotation = new AxisAngleRotation3D(new Vector3D(0, 0, 1), 0); rotationT.Rotation = rotation; scale.ScaleX = 1; scale.ScaleY = 1; scale.ScaleZ = 1; var tg = new Transform3DGroup(); tg.Children.Add(scale); tg.Children.Add(rotationT); tg.Children.Add(translation); model.Transform = tg; Content = model; }
public WpfScene(TextureProvider<BitmapSource> textureProvider, MeshViewSettingsViewModel settingsViewModel) { _viewPort = new Viewport3D(); _rendererCamera = new WpfRendererCamera(_viewPort, Vector3.Zero); _textureProvider = textureProvider; var lightGroup = new Model3DGroup(); var light = new PointLight(Colors.Cornsilk, _rendererCamera.Position.AsPoint3D()); CameraLight = new WpfLight(light); lightGroup.Children.Add(light); _viewPort.Children.Add(new ModelVisual3D {Content = lightGroup}); _meshModelGroup = new Model3DGroup(); _wireFrameModelGroup = new Model3DGroup(); _allModelGroup = new Model3DGroup(); _allModelGroup.Children.Add(_meshModelGroup); _allModelGroup.Children.Add(_wireFrameModelGroup); var rotation = new RotateTransform3D(); _quaternionRotation = new QuaternionRotation3D(); rotation.Rotation = _quaternionRotation; _allModelGroup.Transform = rotation; var visual = new ModelVisual3D {Content = _allModelGroup}; _viewPort.Children.Add(visual); var border = new Border{Background = Brushes.Black}; border.Child = _viewPort; Visual = border; MouseInput = new WpfMouseInput(border); settingsViewModel.WhenAnyValue(s => s.MeshEnabled, s => s.WireFrameEnabled).Subscribe(_ => { ToggleMesh(settingsViewModel.MeshEnabled); ToggleWireFrame(settingsViewModel.WireFrameEnabled); }); settingsViewModel.WhenAnyValue( s => s.YRotation, s => s.XRotation, s => s.ZRotation).Subscribe(_ => { SetRootRotation( new Quaternion(new Vector3D(1, 0, 0), settingsViewModel.XRotation) * new Quaternion(new Vector3D(0, 1, 0), settingsViewModel.YRotation) * new Quaternion(new Vector3D(0, 0, 1), settingsViewModel.ZRotation)); }); }
//绕X轴旋转 private void createx360() { rtf3Dx = new RotateTransform3D(); aax = new AxisAngleRotation3D(); this.RegisterName("myAngleRotationx", aax); aax.Angle = 180; aax.Axis = new Vector3D(3, 0, 0); rtf3Dx.Rotation = aax; myModel3DGroup.Transform = rtf3Dx; myPCamera.Transform = rtf3Dx; }
//绕Y轴旋转模型 private void create360() { rtf3D = new RotateTransform3D(); aar = new AxisAngleRotation3D(); this.RegisterName("myAngleRotation", aar); aar.Angle = 0; aar.Axis = new Vector3D(0, 3, 0); rtf3D.Rotation = aar; myModel3DGroup.Transform = rtf3D; myPCamera.Transform = rtf3D; }
private void update_models() { Transform3DGroup transform_joint1 = new Transform3DGroup(); Transform3DGroup transform_joint2 = new Transform3DGroup(); Transform3DGroup transform_joint3 = new Transform3DGroup(); Transform3DGroup transform_position1 = new Transform3DGroup(); Transform3DGroup transform_position2 = new Transform3DGroup(); Translation = new TranslateTransform3D(Convert.ToDouble(coordinate_x.Text) - 40, Convert.ToDouble(coordinate_y.Text) - 30, Convert.ToDouble(coordinate_z.Text) - 10); transform_position1.Children.Add(Translation); Translation = new TranslateTransform3D(Convert.ToDouble(coordinate_end_x.Text) - 40, Convert.ToDouble(coordinate_end_y.Text) - 30, Convert.ToDouble(coordinate_end_z.Text) - 10); transform_position2.Children.Add(Translation); Rotation = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 0, 1), 90), new Point3D(0, 0, 0)); transform_position1.Children.Add(Rotation); transform_position2.Children.Add(Rotation); Rotation = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(1, 0, 0), 90), new Point3D(0, 0, 0)); transform_joint1.Children.Add(Rotation); Rotation = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 0, 1), joint1), new Point3D(17.5, -30, 0)); transform_joint1.Children.Add(Rotation); Translation = new TranslateTransform3D(0, 182.5, 0); transform_joint2.Children.Add(Translation); Rotation = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 1, 0), 90), new Point3D(0, 0, 0)); transform_joint2.Children.Add(Rotation); Rotation = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(1, 0, 0), joint2), new Point3D(0, 200, 0)); transform_joint2.Children.Add(Rotation); transform_joint2.Children.Add(transform_joint1); Translation = new TranslateTransform3D(100, 0, 0); transform_joint3.Children.Add(Translation); Rotation = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 0, 1), 0), new Point3D(0, 0, 0)); transform_joint3.Children.Add(Rotation); Rotation = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 0, 1), joint3), new Point3D(100, 17.5, 0)); transform_joint3.Children.Add(Rotation); transform_joint3.Children.Add(transform_joint2); positionmodel.Transform = transform_position1; positionmodel2.Transform = transform_position2; arm_link1.Transform = transform_joint1; arm_link2.Transform = transform_joint2; arm_link3.Transform = transform_joint3; }
internal static void Start(ModelVisual3D VP3D, RotateTransform3D _rotxform) { ssl = new ScreenSpaceLines3D(); rotxform = _rotxform; UpdateLocation(); ssl.Thickness = 2; ssl.Color = Color.FromRgb(255, 0, 0); VP3D.Children.Add(ssl); }
public Cube(Viewport3D myViewport3D, float obesity) { this.up = ((PerspectiveCamera)myViewport3D.Camera).UpDirection; this.trans = new Transform3DGroup(); this.scale = new ScaleTransform3D(); this.translation = new TranslateTransform3D(); this.rotation = new RotateTransform3D(); this.axis = new AxisAngleRotation3D(); this.obesity = obesity; this.cube = new Model3DGroup(); Point3D p0 = new Point3D(-1, -1, -1); Point3D p1 = new Point3D(1, -1, -1); Point3D p2 = new Point3D(1, -1, 1); Point3D p3 = new Point3D(-1, -1, 1); Point3D p4 = new Point3D(-1, 0, -1); Point3D p5 = new Point3D(1, 0, -1); Point3D p6 = new Point3D(1, 0, 1); Point3D p7 = new Point3D(-1, 0, 1); //front side triangles cube.Children.Add(CreateTriangleModel(p3, p2, p6)); cube.Children.Add(CreateTriangleModel(p3, p6, p7)); //right side triangles cube.Children.Add(CreateTriangleModel(p2, p1, p5)); cube.Children.Add(CreateTriangleModel(p2, p5, p6)); //back side triangles cube.Children.Add(CreateTriangleModel(p1, p0, p4)); cube.Children.Add(CreateTriangleModel(p1, p4, p5)); //left side triangles cube.Children.Add(CreateTriangleModel(p0, p3, p7)); cube.Children.Add(CreateTriangleModel(p0, p7, p4)); //top side triangles cube.Children.Add(CreateTriangleModel(p7, p6, p5)); cube.Children.Add(CreateTriangleModel(p7, p5, p4)); //bottom side triangles cube.Children.Add(CreateTriangleModel(p2, p3, p0)); cube.Children.Add(CreateTriangleModel(p2, p0, p1)); this.model = new ModelVisual3D(); this.model.Content = cube; this.myDirectionalLight = new DirectionalLight(); this.myDirectionalLight.Color = Colors.Green; this.myDirectionalLight.Direction = new Vector3D(-2, -3, 1); this.cube.Children.Add(myDirectionalLight); myViewport3D.Children.Add(model); trans.Children.Add(scale); trans.Children.Add(rotation); trans.Children.Add(translation); this.cube.Transform = trans; }
public ThrustLine(Viewport3D viewport, SharedVisuals sharedVisuals, Vector3D forceDirection, Vector3D localOffset) { this.Viewport = viewport; _forceDirection = forceDirection; _forceStrength = forceDirection.Length; // this way they don't have to set this if they don't want this.BodyOffset = new TranslateTransform3D(localOffset); // just setting it to something so it's not null #region Create Visual // I'll create the visual, but won't add it until they fire the thruster // Material MaterialGroup materials = new MaterialGroup(); materials.Children.Add(new DiffuseMaterial(Brushes.Coral)); materials.Children.Add(new SpecularMaterial(Brushes.Gold, 100d)); // Geometry Model // Create a skinny 3D rectangle along the x axis GeometryModel3D geometry = new GeometryModel3D(); geometry.Material = materials; geometry.BackMaterial = materials; geometry.Geometry = sharedVisuals.ThrustLineMesh; // Figure out how much to rotate the cube to be along the opposite of the force line. I do the opposite, because // thruster flames shoot in the opposite direction that they're pushing Vector3D flameLine = forceDirection; flameLine.Negate(); Quaternion rotation = Math3D.GetRotation(new Vector3D(1, 0, 0), flameLine); if (rotation.IsIdentity) { _initialRotate = null; } else { _initialRotate = new RotateTransform3D(new QuaternionRotation3D(rotation)); } //// Transform //Transform3DGroup transform = new Transform3DGroup(); // rotate needs to be added before translate //transform.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(axis, Math3D.RadiansToDegrees(radians)))); //transform.Children.Add(new TranslateTransform3D(from)); // Model Visual _model = new ModelVisual3D(); _model.Content = geometry; _model.Transform = new TranslateTransform3D(); // I won't do anything with this right now #endregion }
protected override void Calculate() { var mat = FirstOperand.WrappedItem; var axis = SecondOperand.WrappedItem; var angle = ThirdOperand.WrappedItem; var rotation = new RotateTransform3D(new AxisAngleRotation3D(axis, angle)); var result = rotation.Value; ResultOperand.WrappedItem = mat * result; }
/*Поворачивает изображение вокруг указанной оси на указанный угол*/ public static void RotateImage(string input, string output, Vector3D axis, int angle) { var myRotateTransform3D = new RotateTransform3D(); var myAxisAngleRotation3d = new AxisAngleRotation3D(); myAxisAngleRotation3d.Axis = axis; myAxisAngleRotation3d.Angle = angle; myRotateTransform3D.Rotation = myAxisAngleRotation3d; ImageTransformer.ApplyTransform(input, output, myRotateTransform3D.Value); }
/// <summary> /// This isn't a good way of manipulating the camera /// </summary> private void RotateCameraUsingTransform(double dx, double dy) { // Turn the mouse movement into 3D rotation Quaternion quat = GetSphericalMovement(dx, dy); Transform3DGroup transform = _camera1.Transform as Transform3DGroup; RotateTransform3D rotation = new RotateTransform3D(new AxisAngleRotation3D(quat.Axis, quat.Angle * -1d)); transform.Children.Add(rotation); }
private void MakeObjects(out MeshGeometry3D cameraMesh, out MeshGeometry3D boxMesh, out MeshGeometry3D edgeMesh, out Point3D cameraCenter) { // Make a "camera." cameraMesh = new MeshGeometry3D(); cameraMesh.AddBox(new Point3D(-0.6, -0.5, -0.2), D3.XVector(1.2), D3.YVector(1), D3.ZVector(0.4)); Point3D[] points = G3.MakePolygonPoints(20, new Point3D(0, 0, -0.7), D3.XVector(0.3), D3.YVector(0.3)); cameraMesh.AddCylinder(points, D3.ZVector(0.7), true); points = G3.MakePolygonPoints(20, new Point3D(0, 0, -0.8), D3.XVector(0.4), D3.YVector(0.4)); cameraMesh.AddCylinder(points, D3.ZVector(0.2), true); cameraMesh.AddBox(new Point3D(0.3, 0.5, -0.1), D3.XVector(0.2), D3.YVector(0.2), D3.ZVector(0.2)); MainGroup.Children.Add(cameraMesh.MakeModel(Brushes.LightBlue)); // Transform the camera and vector. Transform3DGroup trans = new Transform3DGroup(); RotateTransform3D r1 = D3.Rotate(D3.XVector(), D3.Origin, -45); trans.Children.Add(r1); RotateTransform3D r2 = D3.Rotate(D3.YVector(), D3.Origin, -45); trans.Children.Add(r2); // See where we need to translate to make the camera point at the origin. Point3D lookAtPoint = new Point3D(0, 0, -3.5); lookAtPoint = trans.Transform(lookAtPoint); TranslateTransform3D t1 = new TranslateTransform3D( -lookAtPoint.X, -lookAtPoint.Y, -lookAtPoint.Z); trans.Children.Add(t1); cameraMesh.ApplyTransformation(trans); cameraCenter = trans.Transform(D3.Origin); // Make a target box. boxMesh = new MeshGeometry3D(); boxMesh.AddBox(new Point3D(-0.75, -0.75, -0.75), D3.XVector(1.5), D3.YVector(1.5), D3.ZVector(1.5)); MainGroup.Children.Add(boxMesh.MakeModel(Brushes.LightGreen)); // Make the box's edges. edgeMesh = new MeshGeometry3D(); HashSet <Edge> edges = new HashSet <Edge>(); edgeMesh.AddBox(new Point3D(-0.75, -0.75, -0.75), D3.XVector(1.5), D3.YVector(1.5), D3.ZVector(1.5), edges: edges); MainGroup.Children.Add(edgeMesh.MakeModel(Brushes.Black)); }
//model transforms /// <summary> /// during adjustments, the sliders change the displayed mesh's rotation. Completing the dragging and letting go of the mouse saves the rotation directly to the mesh and reset's the slider's value /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void Slider_ValueChanged(object sender, RoutedEventArgs e) { if (bolus == null) { return; } //used to ensure that when we change slider values, it doesn't affect anything else if (disableUpdates) { return; } //if the tuhmb on the slider isn't being used if (!tempTransforms) { Slider_SetTransforms(sender); return; } //load the slider that issued the event and determine which axis it is Slider slider = sender as Slider; double angle = slider.Value; Vector3D axis = new Vector3D(0, 0, 0); switch (slider.Name) { case "XAxisSlider": axis = new Vector3D(1, 0, 0); break; case "YAxisSlider": axis = new Vector3D(0, 1, 0); break; case "ZAxisSlider": axis = new Vector3D(0, 0, 1); break; } //apply the rotation based on which slider was used to the displayed model AxisAngleRotation3D rotation = new AxisAngleRotation3D(axis, angle); RotateTransform3D rotationTransform = new RotateTransform3D(rotation); MeshView.Transform = rotationTransform; airholes.Clear(); //remove the added tubes based on position fo the mold //Show models DisplayModels(axis, angle); }
void TagCloud_Loaded(object sender, RoutedEventArgs e) { if (!isLoaded) { if (tags != null) FillTags(); rotateTransform = new RotateTransform3D { Rotation = new AxisAngleRotation3D(new Vector3D(1.0, 0.0, 0.0), 0) }; CompositionTarget.Rendering += CompositionTarget_Rendering; isLoaded = true; } }