Beispiel #1
0
        private void SelectionRequested(SelectionFrustum obj)
        {
            if (_pos == null)
            {
                return;
            }

            // The user has interactively edited the constrained sections -> propagate the information to the simulation core
            List <int>     indices = new List <int>();
            List <Double3> pos     = _pos.GetList();

            Double4x4 trafo = _gl.SceneGraph.AbsoluteTransformation;
            //trafo.Invert();


            Double3 center = Double3.Zero;

            for (int i = 0; i < pos.Count; ++i)
            {
                double d;
                if (obj.IsPointInside(trafo.TransformPoint(pos[i]), out d))
                {
                    indices.Add(i);
                    center += pos[i];
                }
            }

            if (indices.Count > 0)
            {
                center /= indices.Count;

                SceneNode n = new SceneNode();
                n.RelativeTranslation = center;

                CoordinateSystemSceneNode cs = new CoordinateSystemSceneNode();
                //cs.RelativeTranslation = center;

                cs.Call <SceneNode>(m => m.Overlay = true);

                n.Add(cs);


                _gl.SceneGraph.Add(n);


                _sim.AddConstraint(new ConstrainedSection(cs, indices));
                _sim.UpdateConstraintConfiguration();
            }
        }
Beispiel #2
0
        public void Select(Double2 rangeStart, Double2 rangeEnd)
        {
            Double2 min = new Double2(Math.Min(rangeStart.X, rangeEnd.X), Math.Min(rangeStart.Y, rangeEnd.Y));
            Double2 max = new Double2(Math.Max(rangeStart.X, rangeEnd.X), Math.Max(rangeStart.Y, rangeEnd.Y));

            Double3 originA;
            Double3 dirA = _camera.GetRayDirection(min, out originA);

            Double3 originB;
            Double3 dirB = _camera.GetRayDirection(new Double2(min.X, max.Y), out originB);

            Double3 originC;
            Double3 dirC = _camera.GetRayDirection(max, out originC);

            Double3 originD;
            Double3 dirD = _camera.GetRayDirection(new Double2(max.X, min.Y), out originD);


            SelectionFrustum frustum = new SelectionFrustum(new FrustumPlane(_camera.LookAt, _camera.Position),
                                                            new FrustumPlane(originA, originB, originB + dirB), new FrustumPlane(originC, originD, originD + dirD),
                                                            new FrustumPlane(originB, originC, originC + dirC), new FrustumPlane(originD, originA, originA + dirA));

            OnSelectionRequested(frustum);
        }
Beispiel #3
0
 protected virtual void OnSelectionRequested(SelectionFrustum frustum)
 {
     SelectionRequested?.Invoke(frustum);
 }