Click here to Skip to main content
15,906,816 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i try to move multiple object open on Helix viewport 3D. so curtly mutiple object are open succesfuly. but problem in when i try to move any specific model at that time object move mouse opposit position like when i move on Right side at time object is goes to left side same as all axis. so i past here mouse move click event hrer, please provide a solution.

Number of query -

multiple object open at time i need to select particular object and move it. curntly all model are move in oposite axix.

Mouse move time object move opposite direction.


What I have tried:

Object load Event :

C#
private void loadbtn_Click(object sender, RoutedEventArgs e)
{
            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();

            dlg.DefaultExt = ".stl";
            dlg.Filter = "STL Files|*.stl;";
            Nullable<bool> result = dlg.ShowDialog();
            if (result == true)
            {
                string filename = dlg.FileName;
                openfile = filename;
               // txt1.Text = dlg.FileName;
            }
            ModelVisual3D device3D = new ModelVisual3D();
            device3D.Content = Display3d(openfile);
            // viewPort3d.Children.Add(device3D);

            var reader = new StLReader();
            _modelGroup = reader.Read(openfile);
   
            var modelVisual = new ModelVisual3D();
            modelVisual.Content = _modelGroup;

            // Apply the TranslateTransform3D to your STL object
            _modelGroup.Transform = _translate;

            // Add the ModelVisual3D to the Children property of the HelixViewport3D
            viewPort3d.Children.Add(modelVisual); 
}

Mouse Down event is as per below.

C#
private void viewPort3d_MouseDown(object sender, MouseButtonEventArgs e)
      {
         //*** MOVE ***
          var position = e.GetPosition(viewPort3d);
          var origin = new Point3D(position.X, position.Y, 0);
          Point originPoint = new Point(origin.X, origin.Y);
          var transformedOrigin = Viewport3DHelper.UnProject(ConvertToViewport3D(viewPort3d),           originPoint);
          _lastPosition = position;
          viewPort3d.MouseMove += viewPort3d_MouseMove;
          viewPort3d.MouseUp += viewPort3d_MouseUp;
      }

C#
private Viewport3D ConvertToViewport3D(HelixViewport3D helixViewport)
        {
            Viewport3D viewport = new Viewport3D();
            viewport.Camera = helixViewport.Camera;
            foreach (var child in helixViewport.Children)
            {
                if (child is ModelVisual3D modelVisual)
                {
                    if (modelVisual.Content is Model3D model)
                    {
                        ModelVisual3D newChild = new ModelVisual3D();
                        newChild.Content = model;
                        viewport.Children.Add(newChild);
                    }
                    else
                    {
                        // handle other types of modelVisual.Content if necessary
                    }
                }
                else
                {
                    // handle other types of Visual3D objects if necessary
                }
            }
            return viewport;
        }


Mouse Move event is as per below.

C#
private void viewPort3d_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
{
            System.Windows.Point position = e.GetPosition(this); // this = viewPort3D
            double pX = position.X;
            double pY = position.Y;

            _translate.OffsetX -=pX;
            _translate.OffsetY += pY;

            _lastPosition = position;
}


Mouse Up event is as per below.

C#
private void viewPort3d_MouseUp(object sender, MouseButtonEventArgs e)
        {
            //_isDragging = false;
            viewPort3d.MouseMove -= viewPort3d_MouseMove;
            viewPort3d.MouseUp -= viewPort3d_MouseUp;
            //ReleaseMouseCapture();

        }
Posted
Comments
[no name] 10-Feb-23 12:43pm    
If something moves consistently in the wrong direction, I would negate it (-) to get the right direction ... until I understood why.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900