示例#1
0
        public void GetTriangleBoundingBox(int triangleIndex, ref BoundingBox boundingBox)
        {
            boundingBox = BoundingBox.CreateInvalid();
            Vector3 v1, v2, v3;

            GetVertex(Triangles[triangleIndex].I0, Triangles[triangleIndex].I1, Triangles[triangleIndex].I2, out v1, out v2, out v3);

            boundingBox.Include(
                v1,
                v2,
                v3);
        }
        public BoundingBox GetAABB()
        {
            BoundingBox     box     = BoundingBox.CreateInvalid();
            BoundingFrustum frustum = ConvertToFrustum();

            box.Include(ref frustum);
            return(box);
        }
示例#3
0
        internal static BoundingBox MakeAabbFromSpotlightCone(ref MySpotlightInfo spotlight, Vector3 position)
        {
            float ratio = (float)Math.Sqrt(1 - spotlight.ApertureCos * spotlight.ApertureCos) / spotlight.ApertureCos;
            float h     = ratio * spotlight.Range;
            var   bb    = BoundingBox.CreateInvalid();

            bb.Include(new Vector3(-h, -h, 0));
            bb.Include(new Vector3(h, h, -spotlight.Range));

            return(bb.Transform(Matrix.CreateLookAtInv(position, position + spotlight.Direction, spotlight.Up)));
        }
示例#4
0
        internal void UpdateBeforeDraw()
        {
            if (m_dirtyProxy)
            {
                RebuildProxies();
            }

            foreach (var val in m_materialGroups.Values)
            {
                var index = val.m_index;
                val.UpdateProxyVerticesNum(ref m_proxy.Proxies[index]);
            }

            if (m_dirtyPosition)
            {
                foreach (var val in m_materialGroups.Values)
                {
                    val.UpdateAll();
                }

                m_dirtyPosition = false;
            }

            if (m_dirtyTree)
            {
                BoundingBox bb = BoundingBox.CreateInvalid();

                foreach (var child in m_children)
                {
                    if (child.m_visible && child.GetRenderable() != null && !child.GetRenderable().IsRendered)
                    {
                        bb.Include(child.Aabb);
                    }
                }

                m_owner.Aabb = bb;

                if (m_materialGroups.Count > 0)
                {
                    if (m_btreeProxy == -1)
                    {
                        m_btreeProxy = MyScene.GroupsDBVH.AddProxy(ref m_owner.Aabb, m_proxy, 0);
                    }
                    else
                    {
                        MyScene.GroupsDBVH.MoveProxy(m_btreeProxy, ref m_owner.Aabb, Vector3.Zero);
                    }
                }

                m_dirtyTree = false;
            }
        }
示例#5
0
        internal void Construct()
        {
            m_components.Clear();

            m_visible          = true;
            m_renderProxyDirty = true;

            m_ID                = new MyIDTracker <MyActor>();
            m_localAabb         = null;
            m_relativeTransform = null;

            Aabb = BoundingBox.CreateInvalid();
        }
示例#6
0
        public BoundingBox GetAABB()
        {
            BoundingBox box = BoundingBox.CreateInvalid();

            foreach (Line line in this.UniqueLines)
            {
                Vector3 from = line.From;
                Vector3 to   = line.To;
                box = box.Include(ref from);
                box = box.Include(ref to);
            }
            return(box);
        }
示例#7
0
        public BoundingBox GetAABB()
        {
            BoundingBox aabb = BoundingBox.CreateInvalid();

            foreach (Line line in UniqueLines)
            {
                Vector3 from = line.From;
                Vector3 to   = line.To;
                aabb = aabb.Include(ref from);
                aabb = aabb.Include(ref to);
            }

            return(aabb);
        }
        public BoundingBox GetAABB()
        {
            if (m_cornersTmp == null)
            {
                m_cornersTmp = new Vector3[8];
            }
            this.GetCorners(m_cornersTmp, 0);
            BoundingBox box = BoundingBox.CreateInvalid();

            for (int i = 0; i < 8; i++)
            {
                box.Include(m_cornersTmp[i]);
            }
            return(box);
        }
示例#9
0
        //  IMPORTANT: This struct must be initialized using this constructor, or by filling all four fields. It's because
        //  some code may need length or distance, and if they aren't calculated, we can have problems.
        public Line(Vector3 from, Vector3 to, bool calculateBoundingBox = true)
        {
            From      = from;
            To        = to;
            Direction = to - from;
            Length    = Direction.Normalize();

            //  Calculate line's bounding box, but only if we know we will need it
            BoundingBox = BoundingBox.CreateInvalid();
            if (calculateBoundingBox == true)
            {
                //BoundingBoxHelper.AddLine(ref this, ref BoundingBox);
                BoundingBox = BoundingBox.Include(ref from);
                BoundingBox = BoundingBox.Include(ref to);
            }
        }
示例#10
0
        void IPrimitiveManagerBase.GetPrimitiveBox(int prim_index, out AABB primbox)
        {
            BoundingBox bbox = BoundingBox.CreateInvalid();
            Vector3     v1   = GetVertex(Triangles[prim_index].I0);
            Vector3     v2   = GetVertex(Triangles[prim_index].I1);
            Vector3     v3   = GetVertex(Triangles[prim_index].I2);

            bbox.Include(
                ref v1,
                ref v2,
                ref v3);

            primbox = new AABB()
            {
                m_min = bbox.Min.ToBullet(), m_max = bbox.Max.ToBullet()
            };
        }
        static void SendOutputMessages()
        {
            foreach (var q in m_cullQuery.FrustumQuery)
            {
                foreach (var proxy in q.List)
                {
                    // all should have same parent
                    MyRenderProxy.VisibleObjectsWrite.Add(proxy.Proxies[0].Parent.m_owner.ID);
                }
            }

            // TODO: just for now
            foreach (var h in MyComponentFactory <MyGroupRootComponent> .GetAll())
            {
                if (true)
                {
                    BoundingBox bb = BoundingBox.CreateInvalid();

                    foreach (var child in h.m_children)
                    {
                        if (child.m_visible)
                        {
                            bb.Include(child.Aabb);
                        }
                    }

                    if (MyEnvironment.ViewFrustum.Contains(bb) != VRageMath.ContainmentType.Disjoint)
                    {
                        MyRenderProxy.VisibleObjectsWrite.Add(h.m_owner.ID);
                    }
                }
            }

            foreach (var id in MyClipmapFactory.ClipmapByID.Keys)
            {
                MyRenderProxy.VisibleObjectsWrite.Add(id);
            }
        }
示例#12
0
        //internal static void BeginQuadRendering()
        //{
        //    var context = MyRender.Context;

        //    context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
        //    context.Rasterizer.SetViewport(0, 0, MyRender.ViewportResolution.X, MyRender.ViewportResolution.Y);
        //    context.OutputMerger.SetTargets(null as DepthStencilView, MyRender.Backbuffer.RenderTarget);
        //    context.OutputMerger.BlendState = null;
        //}

        //internal static void DrawQuad()
        //{

        //}

        internal static void DrawHierarchyDebug()
        {
            var worldToClip   = MyEnvironment.ViewProjection;
            var displayString = new StringBuilder();

            var batch = MyLinesRenderer.CreateBatch();

            if (MyRender11.Settings.DisplayIDs)
            {
                foreach (var actor in MyActorFactory.GetAll())
                {
                    var h = actor.GetGroupLeaf();
                    var r = actor.GetRenderable();

                    Vector3 position;
                    uint    ID;

                    if (r != null)
                    {
                        position = r.m_owner.WorldMatrix.Translation;
                        ID       = r.m_owner.ID;
                    }
                    else if (h != null)
                    {
                        position = h.m_owner.WorldMatrix.Translation;
                        ID       = h.m_owner.ID;
                    }
                    else
                    {
                        continue;
                    }

                    var clipPosition = Vector3.Transform(position, ref worldToClip);
                    clipPosition.X = clipPosition.X * 0.5f + 0.5f;
                    clipPosition.Y = clipPosition.Y * -0.5f + 0.5f;

                    if (clipPosition.Z > 0 && clipPosition.Z < 1)
                    {
                        displayString.AppendFormat("{0}", ID);
                        MySpritesRenderer.DrawText(new Vector2(clipPosition.X, clipPosition.Y) * MyRender11.ViewportResolution,
                                                   displayString, Color.DarkCyan, 0.5f);
                    }

                    displayString.Clear();
                }
            }

            if (MyRender11.Settings.DisplayAabbs)
            {
                //foreach (var h in MyComponentFactory<MyHierarchyComponent>.GetAll())
                //{
                //    if (h.IsParent)
                //    {
                //        batch.AddBoundingBox(h.m_owner.Aabb, Color.Red);
                //    }
                //    else
                //    {
                //        batch.AddBoundingBox(h.m_owner.Aabb, Color.Orange);
                //    }
                //}

                foreach (var actor in MyActorFactory.GetAll())
                {
                    var h = actor.GetGroupRoot();
                    var r = actor.GetRenderable();

                    if (h != null)
                    {
                        BoundingBox bb = BoundingBox.CreateInvalid();

                        foreach (var child in h.m_children)
                        {
                            if (child.m_visible)
                            {
                                bb.Include(child.Aabb);
                            }
                        }

                        batch.AddBoundingBox(bb, Color.Red);
                        MyPrimitivesRenderer.Draw6FacedConvex(bb.GetCorners(), Color.Red, 0.1f);
                    }
                    else if (r != null && actor.GetGroupLeaf() == null)
                    {
                        batch.AddBoundingBox(r.m_owner.Aabb, Color.Green);
                    }
                }
            }

            batch.Commit();
        }