Ejemplo n.º 1
0
        private IClickable3D GetClosestObject(Ray pointer)
        {
            IClickable3D closestClickable = null;
            float        closest          = float.PositiveInfinity;

            foreach (var o in objects)
            {
                if (o is IClickable3D)
                {
                    var   clickable = o as IClickable3D;
                    float distance  = clickable.DistanceToObject(pointer);
                    if (distance < closest)
                    {
                        closestClickable = clickable;
                        closest          = distance;
                    }
                }
            }

            if (FilterSelectable(closestClickable))
            {
                closestClickable.MouseHover(); // TODO: find a better way to handle hover indication...
                return(closestClickable);
            }
            return(viewport as IClickable3D);
        }
Ejemplo n.º 2
0
        void HandleMouseDown(object sender, MouseEventArgs e)
        {
            if (clickedObject != null)
            {
                // If something's already clicked, don't allow selecting other items.
                // This will force a mouse up in the client area.
                return;
            }

            mouseDownLocation = e.Location;

            Ray pointer = viewport.GetPointerRay(e.Location);

            clickedObject = GetClosestObject(pointer);

            if (e.Button == System.Windows.Forms.MouseButtons.Right)
            {
                mouseRDown = true;
                viewport.BeginRotate();
                return;
            }
            else if (e.Button != System.Windows.Forms.MouseButtons.Left)
            {
                return;
            }



            clickedObject.MouseDown(pointer);

            this.Invalidate();
        }
Ejemplo n.º 3
0
 void HandleMouseMove(object sender, MouseEventArgs e)
 {
     hoveredObject = null;
     if (mouseRDown)
     {
         Point mouseDelta = new Point(e.Location.X - mouseDownLocation.X, e.Location.Y - mouseDownLocation.Y);
         viewport.ViewportRotate(mouseDelta.X, mouseDelta.Y);
     }
     else
     {
         Ray pointer = viewport.GetPointerRay(e.Location);
         if (clickedObject != null)
         {
             clickedObject.MouseMove(pointer);
         }
         else
         {
             IClickable3D hovered = GetClosestObject(pointer);
             if (hovered != null)
             {
                 hoveredObject = hovered;
             }
         }
     }
     this.Invalidate();
 }
Ejemplo n.º 4
0
        void HandleMouseUp(object sender, MouseEventArgs e)
        {
            // Display a context menu?
            if (mouseRDown)
            {
                if (mouseDownLocation == e.Location)
                {
                    if (clickedObject != null && clickedObject is TriangleMeshGUI)
                    {
                        System.Windows.Forms.ContextMenu menu = new ContextMenu();
                        var item = new MenuItem("Delete", new EventHandler(objectDeleteClicked));
                        item.Tag = clickedObject;
                        menu.MenuItems.Add(item);
                        menu.Show(this, e.Location);
                    }
                }
            }

            mouseRDown = false;
            if (clickedObject != null)
            {
                Ray pointer = viewport.GetPointerRay(e.Location);
                clickedObject.MouseUp(pointer);
                clickedObject = null;
            }
        }
Ejemplo n.º 5
0
        private void objectSetAsBottomFaceClicked(object sender, EventArgs e)
        {
            var item = sender as MenuItem;

            if (item != null)
            {
                IClickable3D toModify     = item.Tag as IClickable3D;
                var          triangleMesh = item.Tag as TriangleMeshGUI;
                if (triangleMesh != null)
                {
                    Ray pointer = viewport.GetPointerRay(mouseDownLocation);

                    // If we rotate the object, tabs will become invalid.
                    foreach (var tab in triangleMesh.Tabs)
                    {
                        objects.Remove(tab);
                    }

                    triangleMesh.SetClickedFaceAsBottom(pointer);

                    foreach (var tab in triangleMesh.Tabs)
                    {
                        objects.Add(tab);
                    }
                }
            }
        }
Ejemplo n.º 6
0
 internal void DeleteSelectedObjected()
 {
     if (clickedObject != null)
     {
         objects.RemoveAll(c => c == clickedObject);
     }
     clickedObject = null;
 }
Ejemplo n.º 7
0
        void objectDeleteClicked(object sender, EventArgs e)
        {
            var item = sender as MenuItem;

            if (item != null)
            {
                IClickable3D toRemove = item.Tag as IClickable3D;
                if (toRemove != null)
                {
                    if (toRemove is TriangleMeshGUI)
                    {
                        foreach (var tab in (toRemove as TriangleMeshGUI).Tabs)
                        {
                            objects.RemoveAll(o => o == tab);
                        }
                    }
                    objects.RemoveAll(o => o == toRemove);
                }
            }
        }
Ejemplo n.º 8
0
        public void MouseMove(Vector2 screen_location)
        {
            p = ComputeMouseTarget(screen_location);
            if (isMouseRDown)
            {
                //wasMouseDragged = true;
                // Rotate Scene

                // Rotate about the point in the center of the screen



                // location is mouse position on the screen
                // Screen is 45 degrees up/down
                Rectangle r = parent.ClientRectangle;
                if (r.Height == 0)
                {
                    r.Height = 1;
                }

                Vector2 center = new Vector2(r.Width / 2, r.Height / 2);

                viewMatrix = mouseDownMatrix;
                Vector3 point = this.ComputeMouseTarget(center);

                float y = -screen_location.Y / (float)r.Height + 0.5f;
                float x = screen_location.X / (float)r.Width - 0.5f;


                Vector2 l2 = mouseDownLocation * 1000;
                float   y2 = -l2.Y / (float)r.Height + 0.5f;
                float   x2 = l2.X / (float)r.Width - 0.5f;

                float aspect = AspectRatio;

                //Console.WriteLine("pos = {0}, {1}", (x2 - x) * aspect, y2 - y);

                x = (x2 - x) * aspect;
                y = (y2 - y);
                x = x * 4;
                y = y * 4;

                viewMatrix = Matrix4.Mult(Matrix4.CreateTranslation(point), mouseDownMatrix);
                viewMatrix = Matrix4.Mult(Matrix4.CreateRotationZ(-x), viewMatrix);
                Matrix4 m = viewMatrix;
                m.Invert();
                Vector3 left = new Vector3(m.Row0.X, m.Row0.Y, m.Row0.Z);
                viewMatrix = Matrix4.Mult(Matrix4.CreateFromAxisAngle(left, y), viewMatrix);
                viewMatrix = Matrix4.Mult(Matrix4.CreateTranslation(-point), viewMatrix);
            }
            else if (isMouseLDown)
            {
            }
            else
            {
                // Some hacky stuff to pass the mouse location to sub-objects
                foreach (Object o in this.objects)
                {
                    if (o is IClickable3D)
                    {
                        Vector3 location = this.CameraPosition;

                        Vector3 t         = ComputeMouseTarget(screen_location);
                        Vector3 direction = t - location;
                        //Console.WriteLine("Camera Forward {0}, Pos = {1}", direction, location);
                        direction.Normalize();

                        IClickable3D c = o as IClickable3D;
                        //Vector3 target = this.ComputeMouseTarget(screen_location);
                        //Vector2 t = new Vector2 (target.X, target.Y) * 1000;
                        c.IsPointOnObject(location * 1000, direction);
                    }
                }
            }
            //Console.WriteLine("Mouse Position = {0}", p);
        }
Ejemplo n.º 9
0
        void HandleMouseUp(object sender, MouseEventArgs e)
        {
            // Display a context menu?
            if (mouseRDown)
            {
                if (mouseDownLocation == e.Location)
                {
                    if (clickedObject != null && clickedObject is TriangleMeshGUI)
                    {
                        System.Windows.Forms.ContextMenu menu = new ContextMenu();
                        var item = new MenuItem("Delete", new EventHandler(objectDeleteClicked));
                        item.Tag = clickedObject;
                        menu.MenuItems.Add(item);
                        menu.Show(this, e.Location);
                    }
                }
            }

            mouseRDown = false;
            if (clickedObject != null)
            {
                Ray pointer = viewport.GetPointerRay(e.Location);
                clickedObject.MouseUp(pointer);
                clickedObject = null;
            }
        }
Ejemplo n.º 10
0
 void HandleMouseMove(object sender, MouseEventArgs e)
 {
     hoveredObject = null;
     if (mouseRDown)
     {
         Point mouseDelta = new Point(e.Location.X - mouseDownLocation.X, e.Location.Y - mouseDownLocation.Y);
         viewport.ViewportRotate(mouseDelta.X, mouseDelta.Y);
     }
     else
     {
         Ray pointer = viewport.GetPointerRay(e.Location);
         if (clickedObject != null)
         {
             clickedObject.MouseMove(pointer);
         }
         else
         {
             IClickable3D hovered = GetClosestObject(pointer);
             if (hovered != null)
             {
                 hoveredObject = hovered;
             }
         }
     }
     this.Invalidate();
 }
Ejemplo n.º 11
0
        void HandleMouseDown(object sender, MouseEventArgs e)
        {
            if (clickedObject != null)
            {
                // If something's already clicked, don't allow selecting other items.
                // This will force a mouse up in the client area.
                return;
            }

            mouseDownLocation = e.Location;

            Ray pointer = viewport.GetPointerRay(e.Location);
            clickedObject = GetClosestObject(pointer);

            if (e.Button == System.Windows.Forms.MouseButtons.Right)
            {
                mouseRDown = true;
                viewport.BeginRotate();
                return;
            }
            else if (e.Button != System.Windows.Forms.MouseButtons.Left)
            {
                return;
            }

            clickedObject.MouseDown(pointer);

            this.Invalidate();
        }
Ejemplo n.º 12
0
 internal void DeleteSelectedObjected()
 {
     if (clickedObject != null)
     {
         objects.RemoveAll(c => c == clickedObject);
     }
     clickedObject = null;
 }