コード例 #1
0
ファイル: BoundingBox.cs プロジェクト: ezequias2d/Ez
 /// <summary>
 /// Returns the <see cref="ContainmentType"/> between this and another <see cref="IBoundingVolume"/>.
 /// </summary>
 /// <param name="bounding">The other <see cref="IBoundingVolume"/> to compare.</param>
 /// <returns>
 /// <see cref="ContainmentType.Disjoint"/>, if there is no overlap between the bounding volumes.<br/>
 /// <see cref="ContainmentType.Contains"/>, if the instance fully contains the volume of <see cref="IBoundingVolume"/>.<br/>
 /// <see cref="ContainmentType.Intersects"/>, if only part of the instance contains at least part of
 /// <paramref name="bounding"/> volume.</returns>
 public ContainmentType Contains(IBoundingVolume bounding)
 {
     if (bounding is BoundingBox boundingBox)
     {
         Contains(boundingBox);
     }
     return(ContainmentType.Disjoint);
 }
コード例 #2
0
 public static dynamic GetTSObject(IBoundingVolume dynObject)
 {
     if (dynObject is null)
     {
         return(null);
     }
     return(dynObject.teklaObject);
 }
コード例 #3
0
 /// <summary>
 /// Create vertex arrays representing the <see cref="IBoundingVolume"/>, using lines delimiting the box volume.
 /// </summary>
 /// <param name="bbox"></param>
 /// <returns></returns>
 private static VertexArrays CreateBoundingVolumeArrays(IBoundingVolume bbox)
 {
     if (bbox.GetType() == typeof(BoundingBox))
     {
         return(CreateBoundingBoxArrays());
     }
     else
     {
         throw new NotImplementedException();
     }
 }
コード例 #4
0
ファイル: SceneGraph.cs プロジェクト: vipyami/OpenGL.Net
 private VertexArrayObject CreateBBoxVertexArray(IBoundingVolume bbox)
 {
     if (bbox.GetType() == typeof(BoundingBox))
     {
         return(_BoundingBoxArray);
     }
     else
     {
         throw new NotImplementedException();
     }
 }
コード例 #5
0
    public bool IntersectsWith(IBoundingVolume anotherBoundingVolume)
    {
        if (anotherBoundingVolume != null)
        {
            if (anotherBoundingVolume is BoundingRectangle)
            {
                return(IntersectsWith((BoundingRectangle)anotherBoundingVolume));
            }
        }

        return(false);
    }
コード例 #6
0
    public bool Contains(IBoundingVolume anotherBoundingVolume)
    {
        if (anotherBoundingVolume != null)
        {
            if (anotherBoundingVolume is BoundingRectangle)
            {
                return(Contains((BoundingRectangle)anotherBoundingVolume));
            }
        }

        return(false);
    }
コード例 #7
0
        /// <summary>
        /// Get all geometries compositing this SceneObjectGeometry, filtering them using view-frustum.
        /// </summary>
        /// <param name="currentState">
        /// A <see cref="State.GraphicsStateSet"/> that specifies the current graphics state to be merged with
        /// each returned geometry.
        /// </param>
        /// <param name="clippingPlanes">
        ///
        /// </param>
        /// <param name="viewModel">
        ///
        /// </param>
        /// <returns>
        /// It returns a <see cref="IEnumerable{SceneObjectBatch}"/>.
        /// </returns>
        private IEnumerable <SceneObjectBatch> GetGeometriesViewFrustum(SceneGraphContext ctxScene)
        {
            GraphicsStateSet currentState       = ctxScene.GraphicsStateStack.Current.Push();
            TransformState   sceneGeometryModel = (TransformState)currentState[TransformState.StateSetIndex];
            Matrix4x4f       viewModel          = sceneGeometryModel.ModelView;

            if (_GeometryInstances.Count > 0)
            {
                foreach (Geometry sceneObjectBatch in _GeometryInstances)
                {
                    IBoundingVolume instanceVolume = sceneObjectBatch.BoundingVolume ?? _BoundingVolume;

                    if (instanceVolume != null && instanceVolume.IsClipped(ctxScene.ViewFrustumPlanes, viewModel))
                    {
                        continue;
                    }

                    GraphicsStateSet geometryState;

                    if (sceneObjectBatch.State != null)
                    {
                        geometryState = currentState.Push();
                        geometryState.Merge(sceneObjectBatch.State);
                    }
                    else
                    {
                        geometryState = currentState;
                    }

                    yield return(new SceneObjectBatch(
                                     sceneObjectBatch.VertexArray ?? VertexArray,
                                     geometryState,
                                     sceneObjectBatch.Program ?? Program
                                     ));
                }
            }
            else
            {
                if (_BoundingVolume != null && _BoundingVolume.IsClipped(ctxScene.ViewFrustumPlanes, viewModel))
                {
                    yield break;
                }

                if (VertexArray == null)
                {
                    yield break;
                }

                yield return(new SceneObjectBatch(VertexArray, currentState, Program));
            }
        }
コード例 #8
0
        /// <summary>
        /// Search for elements within the volume defined by the bounding volume.
        /// </summary>
        public IEnumerable <T> FindInsideBoundingVolume(IBoundingVolume bv)
        {
            if (!bv.Intersect(this.Tree.InternalBounds))
            {
                yield break;
            }

            // Init search
            Stack <KdNode <T> > s = new Stack <KdNode <T> >();

            s.Push(this.Tree);
            int found = 0;

            // Run
            while (s.Count > 0 && found < this.CountLimit)
            {
                KdNode <T> n = s.Pop();
                if (n.Leaf)
                {
                    // Once we encounter a leaf an exhaustive search is performed for all elements inside
                    // the bounding volume up to the adjusted limit.
                    List <T> elements = this.ExhaustiveSearchLeaf(n, ref found, delegate(T obj) { return(bv.Inside(obj)); });
                    foreach (T t in elements)
                    {
                        yield return(t);
                    }
                }
                else // Intermediate node
                // Classify against split plane
                {
                    EPlanePosition pos = bv.ClassifyPlane(n.SplitDimension, n.SplitLocation);
                    if (pos == EPlanePosition.LeftOfBV)
                    {
                        s.Push(n.Right);
                    }
                    else if (pos == EPlanePosition.RightOfBV)
                    {
                        s.Push(n.Left);
                    }
                    else // Intersecting
                    {
                        s.Push(n.Right);
                        s.Push(n.Left);
                    }
                }
            }
        }
コード例 #9
0
    public QuadTreeNode(IBoundingVolume bounds)
    {
        Capacity =
            DefaultCapacity;
        Bounds =
            bounds;

        centerOfMass =
            bounds.Center;
        Mass =
            0.0f;

        Nodes =
            new QuadTreeNode [4];
        Planets =
            new List <PlanetController> (Capacity);
    }
コード例 #10
0
ファイル: SceneGraph.cs プロジェクト: vipyami/OpenGL.Net
        private GraphicsStateSet CreateBBoxState(IBoundingVolume bbox)
        {
            GraphicsStateSet bboxState;

            if (bbox.GetType() == typeof(BoundingBox))
            {
                bboxState = CreateBBoxState((BoundingBox)bbox);
            }
            else
            {
                throw new NotImplementedException();
            }

            // No blending
            bboxState.DefineState(new BlendState());

            return(bboxState);
        }
コード例 #11
0
        internal IEnumerable <SceneObjectBatch> GetBoundingVolumes(SceneGraphContext ctxScene)
        {
            GraphicsStateSet currentState       = ctxScene.GraphicsStateStack.Current.Push();
            TransformState   sceneGeometryModel = (TransformState)currentState[TransformState.StateSetIndex];
            Matrix4x4f       viewModel          = sceneGeometryModel.ModelView;

            if (_GeometryInstances.Count > 0)
            {
                foreach (Geometry sceneObjectBatch in _GeometryInstances)
                {
                    IBoundingVolume instanceVolume = sceneObjectBatch.BoundingVolume ?? _BoundingVolume;

                    if (instanceVolume != null && instanceVolume.IsClipped(ctxScene.ViewFrustumPlanes, viewModel))
                    {
                        continue;
                    }

                    GraphicsStateSet volumeState = currentState.Push();

                    SetBoundingVolumeState(instanceVolume, volumeState);

                    yield return(new SceneObjectBatch(
                                     _BoundingVolumeArray,
                                     volumeState,
                                     _BoundingVolumeProgram
                                     ));
                }
            }
            else
            {
                if (_BoundingVolume == null || _BoundingVolume.IsClipped(ctxScene.ViewFrustumPlanes, viewModel))
                {
                    yield break;
                }

                GraphicsStateSet volumeState = currentState.Push();

                SetBoundingVolumeState(_BoundingVolume, volumeState);

                yield return(new SceneObjectBatch(_BoundingVolumeArray, volumeState, _BoundingVolumeProgram));
            }
        }
コード例 #12
0
        internal IEnumerable <SceneObjectBatch> GetGeometries(State.GraphicsStateSet currentState, IEnumerable <Plane> clippingPlanes, IMatrix4x4 viewModel)
        {
            if (_GeometryInstances.Count > 0)
            {
                foreach (Geometry sceneObjectBatch in _GeometryInstances)
                {
                    IBoundingVolume instanceVolume = sceneObjectBatch.BoundingVolume ?? _BoundingVolume;

                    if (instanceVolume != null && instanceVolume.IsClipped(clippingPlanes, viewModel))
                    {
                        continue;
                    }

                    State.GraphicsStateSet geometryState;

                    if (sceneObjectBatch.State != null)
                    {
                        geometryState = currentState.Push();
                        geometryState.Merge(sceneObjectBatch.State);
                    }
                    else
                    {
                        geometryState = currentState;
                    }

                    yield return(new SceneObjectBatch(
                                     sceneObjectBatch.VertexArray ?? VertexArray,
                                     geometryState,
                                     sceneObjectBatch.Program ?? Program
                                     ));
                }
            }
            else
            {
                if (_BoundingVolume != null && _BoundingVolume.IsClipped(clippingPlanes, viewModel))
                {
                    yield break;
                }

                yield return(new SceneObjectBatch(VertexArray, currentState, Program));
            }
        }
コード例 #13
0
        private static void SetBoundingVolumeState(IBoundingVolume boundingVolume, GraphicsStateSet volumeState)
        {
            if (boundingVolume == null)
            {
                throw new ArgumentNullException("boundingVolume");
            }
            if (volumeState == null)
            {
                throw new ArgumentNullException("volumeState");
            }

            if (boundingVolume.GetType() == typeof(BoundingBox))
            {
                SetBoundingVolumeState((BoundingBox)boundingVolume, volumeState);
            }
            else
            {
                throw new NotImplementedException();
            }
        }
コード例 #14
0
    public         IBoundingVolume [] Subdivide()
    {
        var result =
            new IBoundingVolume [4];

        float halfWidth =
            Width * 0.5f;
        float halfHeight =
            Height * 0.5f;

        int i = 0;

        for (int y = 0; y < 2; ++y)
        {
            for (int x = 0; x < 2; ++x)
            {
                var quadrant =
                    new BoundingRectangle(this);

                quadrant.Minimum +=
                    new Vector2(
                        x * halfWidth,
                        y * halfHeight
                        );

                quadrant.Width =
                    halfWidth;
                quadrant.Height =
                    halfHeight;

                result [i++] =
                    new BoundingRectangle(quadrant);
            }
        }

        return(result);
    }
コード例 #15
0
 public static double GetCost(IBoundingVolume parent)
 {
     return(parent.GetSurfaceArea());
     //return volume.GetVolume();
 }