Exemple #1
0
        static public CullingResult Cull(ref WorldBounds bounds, ref Frustum f)
        {
            int mall = 0;

            for (int i = 0; i < f.PlanesCount; i++)
            {
                float4 plane = f.GetPlane(i);
                int    m     = IsCulled(bounds.c000, plane) ? 1 : 0;
                m |= IsCulled(bounds.c001, plane) ? 2 : 0;
                m |= IsCulled(bounds.c010, plane) ? 4 : 0;
                m |= IsCulled(bounds.c011, plane) ? 8 : 0;
                m |= IsCulled(bounds.c100, plane) ? 16 : 0;
                m |= IsCulled(bounds.c101, plane) ? 32 : 0;
                m |= IsCulled(bounds.c110, plane) ? 64 : 0;
                m |= IsCulled(bounds.c111, plane) ? 128 : 0;
                if (m == 255)
                {
                    return(CullingResult.Outside);          // all points outside one plane
                }
                mall |= m;
            }
            if (mall == 0)
            {
                return(CullingResult.Inside);           // all points inside all planes
            }
            return(CullingResult.Intersects);
        }
Exemple #2
0
        static public void WorldBoundsToAxisAligned(ref WorldBounds wBounds, out AABB aab)
        {
            float3 bbMin = wBounds.c000;
            float3 bbMax = wBounds.c000;

            GrowBounds(ref bbMin, ref bbMax, in wBounds);
            aab.Center  = (bbMax + bbMin) * .5f;
            aab.Extents = (bbMax - bbMin) * .5f;
        }
Exemple #3
0
        static public bool PointInBounds(ref WorldBounds bounds, float3 p)
        {
            float4 pfront = PlaneFromTri(bounds.c000, bounds.c001, bounds.c011);

            if (IsCulled(p, pfront))
            {
                return(false);
            }
            float4 pback = PlaneFromTri(bounds.c100, bounds.c111, bounds.c101);

            if (IsCulled(p, pback))
            {
                return(false);
            }
            // etc TODO
            Assert.IsTrue(false);

            return(true);
        }
Exemple #4
0
        static public bool IsCulled(ref WorldBounds bounds, ref Frustum f)
        {
            // if all vertices are completely outside of one culling plane, the object is culled
            for (int i = 0; i < f.PlanesCount; i++)
            {
                float4 plane = f.GetPlane(i);
                if (IsCulled8(bounds.c000, bounds.c001, bounds.c011, bounds.c010,
                              bounds.c100, bounds.c101, bounds.c111, bounds.c110, plane))
                {
                    return(true);
                }
            }
            return(false);

            /* reference
             * bool r = false;
             * bgfx.dbg_text_clear(0, false);
             * for (int i = 0; i < 6; i++) {
             *  float4 plane = f.GetPlane(i);
             *  int m = IsCulled(bounds.c000, plane) ? 1 : 0;
             *  m |= IsCulled(bounds.c001, plane) ? 2 : 0;
             *  m |= IsCulled(bounds.c010, plane) ? 4 : 0;
             *  m |= IsCulled(bounds.c011, plane) ? 8 : 0;
             *  m |= IsCulled(bounds.c100, plane) ? 16 : 0;
             *  m |= IsCulled(bounds.c101, plane) ? 32 : 0;
             *  m |= IsCulled(bounds.c110, plane) ? 64 : 0;
             *  m |= IsCulled(bounds.c111, plane) ? 128 : 0;
             *  if (m == 255) r = true;
             *
             *  string s = StringFormatter.Format("{0}: {1} {2}   ", i, m, plane);
             *  bgfx.dbg_text_printf(0, (ushort)i, 0xf0, s, null);
             *
             *  //if (IsCulled8(bounds.c000, bounds.c001, bounds.c011, bounds.c010,
             *  //              bounds.c100, bounds.c101, bounds.c111, bounds.c110, plane))
             *  //    return true;
             * }
             * bgfx.set_debug((uint)bgfx.DebugFlags.Text);
             * return r;
             */
        }
Exemple #5
0
 // modifies bounds1 with results
 static public void MergeBounds(ref WorldBounds bounds1, ref WorldBounds bounds2)
 {
     // TODO
     Assert.IsTrue(false);
 }
Exemple #6
0
        static public void AxisAlignedToWorldBounds(ref float4x4 tx, ref AABB aaBounds, out WorldBounds wBounds)
        {
            float3 o  = math.mul(tx, new float4(aaBounds.Min, 1)).xyz;
            float3 dx = math.mul(tx, new float4(aaBounds.Size.x, 0, 0, 0)).xyz;
            float3 dy = math.mul(tx, new float4(0, aaBounds.Size.y, 0, 0)).xyz;
            float3 dz = math.mul(tx, new float4(0, 0, aaBounds.Size.z, 0)).xyz;

            wBounds.c000 = o;
            wBounds.c001 = o + dx;
            wBounds.c011 = o + dx + dy;
            wBounds.c010 = o + dy;
            wBounds.c100 = o + dz;
            wBounds.c101 = o + dz + dx;
            wBounds.c111 = o + dz + dx + dy;
            wBounds.c110 = o + dz + dy;
        }