Exemplo n.º 1
0
        protected bool GetInsertionPosition(out Vec3F result, Point clientPt)
        {
            var ray  = GetWorldRay(clientPt);
            var pick = Picking.RayPick(
                GameEngine.GetEngineDevice(), Adapter.SceneManager, Adapter.TechniqueContext,
                ray, Utils.AsCameraDesc(Camera), ClientSize, Picking.Flags.Terrain);

            if (pick != null && pick.Length > 0)
            {
                result = pick[0].hitPt;
                return(true);
            }

            // If the ray is off the terrain, find the intersection of the ray with Z=0 plane.
            float distance = ray.Origin.Z / -ray.Direction.Z;

            if (distance > 0.0f)
            {
                result = ray.Origin + distance * ray.Direction;
                return(true);
            }

            result = new Vec3F(0.0f, 0.0f, 0.0f);
            return(false);
        }
Exemplo n.º 2
0
        protected bool GetTerrainCollision(out Vec3F result, Point clientPt)
        {
            var pick = Picking.RayPick(
                GameEngine.GetEngineDevice(),
                Adapter.SceneManager, Adapter.TechniqueContext,
                GetWorldRay(clientPt), Utils.AsCameraDesc(Camera), ClientSize, Picking.Flags.Terrain);

            if (pick != null && pick.Length > 0)
            {
                result = pick[0].hitPt;
                return(true);
            }

            result = new Vec3F(0.0f, 0.0f, 0.0f);
            return(false);
        }
Exemplo n.º 3
0
        protected override IList <object> Pick(MouseEventArgs e)
        {
            bool          multiSelect = DragOverThreshold;
            List <object> paths       = new List <object>();

            Picking.HitRecord[] hits;

            if (multiSelect)
            {// frustum pick
                RectangleF rect    = MakeRect(FirstMousePoint, CurrentMousePoint);
                var        frustum = XLEBridgeUtils.Utils.MakeFrustumMatrix(Utils.AsCameraDesc(Camera), rect, ClientSize);
                hits = Picking.FrustumPick(
                    GameEngine.GetEngineDevice(),
                    Adapter.SceneManager, Adapter.TechniqueContext,
                    frustum, Utils.AsCameraDesc(Camera), ClientSize,
                    Picking.Flags.Objects | Picking.Flags.Helpers);
            }
            else
            {// ray pick
                Ray3F rayW = GetWorldRay(CurrentMousePoint);
                hits = Picking.RayPick(
                    GameEngine.GetEngineDevice(),
                    Adapter.SceneManager, Adapter.TechniqueContext,
                    rayW, Utils.AsCameraDesc(Camera), ClientSize,
                    Picking.Flags.Terrain | Picking.Flags.Objects | Picking.Flags.Helpers);
            }

            if (hits == null)
            {
                return(new List <object>());
            }

            // create unique list of hits
            HashSet <ulong> instanceSet = new HashSet <ulong>();
            var             uniqueHits  = new List <Picking.HitRecord>();

            // build 'path' objects for each hit record.
            foreach (var hit in hits)
            {
                bool added = instanceSet.Add(hit.instanceId);
                if (added)
                {
                    uniqueHits.Add(hit);
                }
            }

            var firstHit = new Picking.HitRecord();


            // build 'path' objects for each hit record.
            foreach (var hit in uniqueHits)
            {
                var nativeIdMapping = Globals.MEFContainer.GetExportedValue <INativeIdMapping>();
                var nobj            = nativeIdMapping.GetAdapter(hit.documentId, hit.instanceId).As <DomNodeAdapter>();
                if (nobj == null)
                {
                    continue;
                }

                DomNode dom     = nobj.DomNode;
                object  hitPath = Util.AdaptDomPath(dom);
                object  obj     = DesignView.PickFilter.Filter(hitPath, e);
                if (obj != null)
                {
                    if (paths.Count == 0)
                    {
                        firstHit = hit;
                    }
                    var newPath = obj as AdaptablePath <object> ?? Util.AdaptDomPath((DomNode)obj);
                    paths.Add(newPath);
                }
            }


            if (multiSelect == false && paths.Count > 0)
            {
                var path = paths[0];
                ISelectionContext selection = DesignView.Context.As <ISelectionContext>();
                ILinear           linear    = path.As <ILinear>();
                if (linear != null &&
                    Control.ModifierKeys == System.Windows.Forms.Keys.Shift &&
                    selection.SelectionContains(path))
                {
                    ITransactionContext trans = DesignView.Context.As <ITransactionContext>();
                    trans.DoTransaction(
                        delegate
                    {
                        linear.InsertPoint(firstHit.index, firstHit.hitPt.X, firstHit.hitPt.Y, firstHit.hitPt.Z);
                    }, "insert control point".Localize()
                        );
                }
            }
            return(paths);
        }
Exemplo n.º 4
0
        protected override IEnumerable <object> Pick(MouseEventArgs e)
        {
            bool multiSelect = DragOverThreshold;

            Picking.HitRecord[] hits;
            if (multiSelect)
            {
                RectangleF rect    = MakeRect(FirstMousePoint, CurrentMousePoint);
                var        frustum = XLEBridgeUtils.Utils.MakeFrustumMatrix(Utils.AsCameraDesc(Camera), rect, ClientSize);
                hits = Picking.FrustumPick(
                    GameEngine.GetEngineDevice(),
                    Adapter.SceneManager, Adapter.TechniqueContext,
                    frustum, Utils.AsCameraDesc(Camera), ClientSize,
                    Picking.Flags.Objects | Picking.Flags.Helpers);
            }
            else
            {
                Ray3F rayW = GetWorldRay(CurrentMousePoint);
                hits = Picking.RayPick(
                    GameEngine.GetEngineDevice(),
                    Adapter.SceneManager, Adapter.TechniqueContext,
                    rayW, Utils.AsCameraDesc(Camera), ClientSize,
                    Picking.Flags.Terrain | Picking.Flags.Objects | Picking.Flags.Helpers);
            }

            if (hits == null)
            {
                return(new List <object>());
            }

            // create unique list of hits
            var uniqueHits = new List <DomNode>();

            var             nativeIdMapping = Globals.MEFContainer.GetExportedValue <INativeIdMapping>();
            HashSet <ulong> instanceSet     = new HashSet <ulong>();

            foreach (var hit in hits)
            {
                if (instanceSet.Add(hit.instanceId))
                {
                    var nobj = nativeIdMapping.GetAdapter(hit.documentId, hit.instanceId).As <DomNodeAdapter>();
                    if (nobj != null && nobj.DomNode != null)
                    {
                        uniqueHits.Add(nobj.DomNode);
                    }
                }
            }

            // build 'path' objects for each hit record.
            var paths = new List <AdaptablePath <object> >();

            foreach (var node in uniqueHits)
            {
                var hitPath = Util.AdaptDomPath(node);
                var obj     = DesignView.PickFilter.Filter(hitPath, e);
                if (obj != null)
                {
                    var path = obj as AdaptablePath <object> ?? Util.AdaptDomPath((DomNode)obj);
                    // Prevent the same object from being added multiple times...
                    if (paths.Where(x => x.Last == path.Last).FirstOrDefault() == null)
                    {
                        paths.Add(path);
                    }
                }
            }

            #if false
            if (multiSelect == false && paths.Count > 0 && firstHit != null)
            {
                var path = paths[0];
                ISelectionContext selection = DesignView.Context.As <ISelectionContext>();
                ILinear           linear    = path.As <ILinear>();
                if (linear != null &&
                    Control.ModifierKeys == System.Windows.Forms.Keys.Shift &&
                    selection.SelectionContains(path))
                {
                    ITransactionContext trans = DesignView.Context.As <ITransactionContext>();
                    trans.DoTransaction(
                        delegate
                    {
                        linear.InsertPoint(firstHit.index, firstHit.hitPt.X, firstHit.hitPt.Y, firstHit.hitPt.Z);
                    }, "insert control point".Localize()
                        );
                }
            }
            #endif

            return(paths);
        }