Пример #1
0
        public static LineGeometry3D CreateOctreeLineModel(this IOctree tree)
        {
            var builder = new LineBuilder();

            CreateOctreeLineModel(tree, builder);
            return(builder.ToLineGeometry3D());
        }
Пример #2
0
 public NeighbourCoordsResult(bool sameTree, Coords coordsResult, IOctree tree)
 {
     Assert.IsNotNull(tree, "Cannot have a null tree for a neighbour Coords result, return null instead");
     this.sameTree     = sameTree;
     this.coordsResult = coordsResult;
     this.tree         = tree;
 }
Пример #3
0
	public NeighbourCoordsResult(bool sameTree, Coords coordsResult, IOctree tree)
	{
		Assert.IsNotNull(tree, "Cannot have a null tree for a neighbour Coords result, return null instead");
		this.sameTree = sameTree;
		this.coordsResult = coordsResult;
		this.tree = tree;
	}
Пример #4
0
 private void TransferOctantDictionary(IOctree source, ref Dictionary <Guid, IOctree> dictionary)
 {
     if (source == this)
     {
         return;
     }
     this.OctantDictionary = dictionary;
     dictionary            = null;
 }
Пример #5
0
        private void RemoveFromRootDictionary(IOctree node, Guid guid)
        {
            node = FindRoot(node);
            var root = node as BoundableNodeOctree;

            if (root.OctantDictionary.ContainsKey(guid))
            {
                root.OctantDictionary.Remove(guid);
            }
        }
Пример #6
0
 public RayIntersectionResult(bool hit)
 {
     this.hit      = hit;
     node          = null;
     _coords       = new Coords();
     entryDistance = 0;
     position      = new Vector3();
     normal        = new Vector3();
     neighbourSide = NeighbourSide.Invalid;
     tree          = null;
 }
Пример #7
0
 public RayIntersectionResult(bool hit)
 {
     this.hit = hit;
     node = null;
     _coords = new Coords();
     entryDistance = 0;
     position = new Vector3();
     normal = new Vector3();
     neighbourSide = NeighbourSide.Invalid;
     tree = null;
 }
Пример #8
0
 public SceneSnapshot(IAppWindow win, IManagerChangeNotify notifier,
                      IViewport viewport,
                      IOctree octree, InputSnapshot isnapshot, TimeSpan time)
 {
     Viewport      = viewport;
     Notifier      = notifier;
     InputSnapshot = isnapshot;
     FrameRateTime = time;
     Window        = win;
     Lights        = new LightState[LightStructBuffer.MaxCount];
     Octree        = octree;
 }
Пример #9
0
 public bool RemoveByBound(SceneNode item, ref BoundingBox bound, IOctree root)
 {
     if (base.RemoveByBound(item, ref bound))
     {
         RemoveFromRootDictionary(root, item.GUID);
         return(true);
     }
     else
     {
         return(false);
     }
 }
Пример #10
0
 public bool RemoveSafe(SceneNode item, IOctree root)
 {
     if (base.RemoveSafe(item))
     {
         RemoveFromRootDictionary(root, item.GUID);
         return(true);
     }
     else
     {
         return(false);
     }
 }
Пример #11
0
        public bool RemoveAt(int index, IOctree root)
        {
            var id = this.Objects[index].GUID;

            if (base.RemoveAt(index))
            {
                RemoveFromRootDictionary(root, id);
                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #12
0
        public override bool PushExistingToChild(int index, out IOctree octant)
        {
            var item = Objects[index];

            if (base.PushExistingToChild(index, out octant))
            {
                var root = FindRoot(this) as BoundableNodeOctree;
                root.OctantDictionary[item.GUID] = octant;
                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #13
0
 public RayIntersectionResult(IOctree tree,
                              INode node,
                              Coords coords,
                              float entryDistance,
                              Vector3 position,
                              Vector3 normal, NeighbourSide neighbourSide)
 {
     hit                = true;
     this.tree          = tree;
     this.node          = node;
     _coords            = coords;
     this.entryDistance = entryDistance;
     this.position      = position;
     this.normal        = normal;
     this.neighbourSide = neighbourSide;
 }
Пример #14
0
    public RayIntersectionResult(IOctree tree, 
		INode node,
		Coords coords,
		float entryDistance,
		Vector3 position,
		Vector3 normal, NeighbourSide neighbourSide)
    {
        hit = true;
        this.tree = tree;
        this.node = node;
        _coords = coords;
        this.entryDistance = entryDistance;
        this.position = position;
        this.normal = normal;
        this.neighbourSide = neighbourSide;
    }
Пример #15
0
 public override bool Add(SceneNode item, out IOctree octant)
 {
     if (base.Add(item, out octant))
     {
         if (octant == null)
         {
             throw new Exception("Output octant is null");
         }
         ;
         var root = FindRoot(this) as BoundableNodeOctree;
         root.OctantDictionary.Add(item.GUID, octant);
         return(true);
     }
     else
     {
         return(false);
     }
 }
Пример #16
0
        public static void CreateOctreeLineModel(this IOctree tree, LineBuilder builder)
        {
            if (tree == null)
            {
                return;
            }
            var box = tree.Bound;

            Vector3[] verts = new Vector3[8];
            verts[0] = box.Minimum;
            verts[1] = new Vector3(box.Minimum.X, box.Minimum.Y, box.Maximum.Z); //Z
            verts[2] = new Vector3(box.Minimum.X, box.Maximum.Y, box.Minimum.Z); //Y
            verts[3] = new Vector3(box.Maximum.X, box.Minimum.Y, box.Minimum.Z); //X

            verts[7] = box.Maximum;
            verts[4] = new Vector3(box.Maximum.X, box.Maximum.Y, box.Minimum.Z); //Z
            verts[5] = new Vector3(box.Maximum.X, box.Minimum.Y, box.Maximum.Z); //Y
            verts[6] = new Vector3(box.Minimum.X, box.Maximum.Y, box.Maximum.Z); //X
            builder.AddLine(verts[0], verts[1]);
            builder.AddLine(verts[0], verts[2]);
            builder.AddLine(verts[0], verts[3]);
            builder.AddLine(verts[7], verts[4]);
            builder.AddLine(verts[7], verts[5]);
            builder.AddLine(verts[7], verts[6]);

            builder.AddLine(verts[1], verts[6]);
            builder.AddLine(verts[1], verts[5]);
            builder.AddLine(verts[4], verts[2]);
            builder.AddLine(verts[4], verts[3]);
            builder.AddLine(verts[2], verts[6]);
            builder.AddLine(verts[3], verts[5]);

            if (tree.HasChildren)
            {
                foreach (IOctree child in tree.ChildNodes)
                {
                    if (child != null)
                    {
                        CreateOctreeLineModel(child, builder);
                    }
                }
            }
        }
Пример #17
0
    public RayIntersection(Transform transform, IOctree octree, Ray r, bool intersectMultiple, int? wantedDepth = null,
		bool debug = false)
        : this(transform, octree, r, intersectMultiple, wantedDepth, null, debug)
    {
    }
Пример #18
0
 public void SetOctree(IOctree o)
 {
     Octree = o;
     notificator.Subscribe(Octree);
 }
Пример #19
0
 protected BoundableNodeOctree(BoundingBox bound, List <SceneNode> objList, IOctree parent, OctreeBuildParameter paramter, Stack <KeyValuePair <int, IOctree[]> > queueCache)
     : base(ref bound, objList, parent, paramter, queueCache)
 {
 }
Пример #20
0
 /// <summary>
 /// Initializes a new instance of the <see cref="OctreeArgs"/> class.
 /// </summary>
 /// <param name="octree">The octree.</param>
 public OctreeArgs(IOctree octree)
 {
     Octree = octree;
 }
Пример #21
0
 public RayIntersection(Transform transform, IOctree octree, Ray r, bool intersectMultiple, int?wantedDepth = null,
                        bool debug = false) : this(transform, octree, r, intersectMultiple, wantedDepth, null, debug)
 {
 }
Пример #22
0
    public RayIntersection(Transform transform, IOctree octree, Ray r, bool intersectMultiple, int?wantedDepth,
                           Filter filter, bool debug = false)
    {
        _filter = filter;

        _debug    = debug;
        _tree     = octree;
        _rootNode = octree.GetRoot();
        if (_rootNode == null)
        {
            //we had a good run guys, time to call it a day
            return;
        }

        _transform          = transform;
        _ray                = r;
        _intersectMultiple  = intersectMultiple;
        _dimensionFlipFlags = 0;


        var rootBounds = _rootNode.GetBounds();

        if (_debug)
        {
            DrawBounds(rootBounds, Color.gray);
        }

        var rootCenter = rootBounds.center;

        var ro = transform.InverseTransformPoint(r.origin) - rootCenter;
        var rd = transform.InverseTransformDirection(r.direction);

        var rox = ro.x;
        var roy = ro.y;
        var roz = ro.z;

        var rdx = rd.x;
        var rdy = rd.y;
        var rdz = rd.z;

        var ocMin = rootBounds.min - rootCenter;
        var ocMax = rootBounds.max - rootCenter;

        if (rdx < 0.0f)
        {
            rox = -rox;
            rdx = -rdx;
            _dimensionFlipFlags |= 1;
        }

        if (rdy < 0.0f)
        {
            roy = -roy;
            rdy = -rdy;
            _dimensionFlipFlags |= 2;
        }

        if (rdz < 0.0f)
        {
            roz = -roz;
            rdz = -rdz;
            _dimensionFlipFlags |= 4;
        }

        float tx0, tx1, ty0, ty1, tz0, tz1;

        if (!Mathf.Approximately(rdx, 0.0f))
        {
            tx0 = (ocMin.x - rox) / rdx;
            tx1 = (ocMax.x - rox) / rdx;
        }
        else
        {
            tx0 = 99999.9f;
            tx1 = 99999.9f;
        }

        if (!Mathf.Approximately(rdy, 0.0f))
        {
            ty0 = (ocMin.y - roy) / rdy;
            ty1 = (ocMax.y - roy) / rdy;
        }
        else
        {
            ty0 = 99999.9f;
            ty1 = 99999.9f;
        }

        if (!Mathf.Approximately(rdz, 0.0f))
        {
            tz0 = (ocMin.z - roz) / rdz;
            tz1 = (ocMax.z - roz) / rdz;
        }
        else
        {
            tz0 = 99999.9f;
            tz1 = 99999.9f;
        }

        if (_debug)
        {
            Debug.DrawLine(_ray.origin, _ray.GetPoint(5000), Color.yellow);
        }

        if (Mathf.Max(tx0, ty0, tz0) < Mathf.Min(tx1, ty1, tz1))
        {
            ProcSubtree(tx0, ty0, tz0, tx1, ty1, tz1, _rootNode, _rootNode.IsSolid(), 0, wantedDepth,
                        _rootNode.GetCoords());
        }
    }
Пример #23
0
 protected override IOctree CreateNodeWithParent(ref BoundingBox bound, List <SceneNode> objList, IOctree parent)
 {
     return(new BoundableNodeOctree(bound, objList, parent, parent.Parameter, this.stack));
 }
Пример #24
0
    public RayIntersection(Transform transform, IOctree octree, Ray r, bool intersectMultiple, int? wantedDepth,
		Filter filter, bool debug = false)
    {
        _filter = filter;

        _debug = debug;
        _tree = octree;
        _rootNode = octree.GetRoot();
        if (_rootNode == null) {
            //we had a good run guys, time to call it a day
            return;
        }

        _transform = transform;
        _ray = r;
        _intersectMultiple = intersectMultiple;
        _dimensionFlipFlags = 0;

        var rootBounds = _rootNode.GetBounds();
        if (_debug) {
            DrawBounds(rootBounds, Color.gray);
        }

        var rootCenter = rootBounds.center;

        var ro = transform.InverseTransformPoint(r.origin) - rootCenter;
        var rd = transform.InverseTransformDirection(r.direction);

        var rox = ro.x;
        var roy = ro.y;
        var roz = ro.z;

        var rdx = rd.x;
        var rdy = rd.y;
        var rdz = rd.z;

        var ocMin = rootBounds.min - rootCenter;
        var ocMax = rootBounds.max - rootCenter;

        if (rdx < 0.0f) {
            rox = -rox;
            rdx = -rdx;
            _dimensionFlipFlags |= 1;
        }

        if (rdy < 0.0f) {
            roy = -roy;
            rdy = -rdy;
            _dimensionFlipFlags |= 2;
        }

        if (rdz < 0.0f) {
            roz = -roz;
            rdz = -rdz;
            _dimensionFlipFlags |= 4;
        }

        float tx0, tx1, ty0, ty1, tz0, tz1;

        if (!Mathf.Approximately(rdx, 0.0f)) {
            tx0 = (ocMin.x - rox) / rdx;
            tx1 = (ocMax.x - rox) / rdx;
        } else {
            tx0 = 99999.9f;
            tx1 = 99999.9f;
        }

        if (!Mathf.Approximately(rdy, 0.0f)) {
            ty0 = (ocMin.y - roy) / rdy;
            ty1 = (ocMax.y - roy) / rdy;
        } else {
            ty0 = 99999.9f;
            ty1 = 99999.9f;
        }

        if (!Mathf.Approximately(rdz, 0.0f)) {
            tz0 = (ocMin.z - roz) / rdz;
            tz1 = (ocMax.z - roz) / rdz;
        } else {
            tz0 = 99999.9f;
            tz1 = 99999.9f;
        }

        if (_debug) {
            Debug.DrawLine(_ray.origin, _ray.GetPoint(5000), Color.yellow);
        }

        if (Mathf.Max(tx0, ty0, tz0) < Mathf.Min(tx1, ty1, tz1)) {
            ProcSubtree(tx0, ty0, tz0, tx1, ty1, tz1, _rootNode, _rootNode.IsSolid(), 0, wantedDepth,
                _rootNode.GetCoords());
        }
    }