コード例 #1
0
        public static bool Intersect(H1Ray InRay, H1Bound InBound, out float OutT0, out float OutT1)
        {
            float T0 = 0.0f;
            float T1 = float.MaxValue;

            H1Vector3 RayOrigin = InRay.Origin;

            for (Int32 SlabIndex = 0; SlabIndex < InBound.SafeSlabs.Count(); ++SlabIndex)
            {
                // curr slab
                H1Slab Slab = InBound.SafeSlabs[SlabIndex];

                // slab normal
                H1Vector3 SlabNormal = Slab.Normal;

                float NominatorPlane0 = Slab[0].Distance - H1Vector3.Dot(Slab[0].Normal, InRay.Origin);
                float NominatorPlane1 = Slab[1].Distance - H1Vector3.Dot(Slab[1].Normal, InRay.Origin);

                float Denominator = H1Vector3.Dot(InRay.Direction, SlabNormal);

                float CurrT0 = NominatorPlane0 / Denominator;
                float CurrT1 = NominatorPlane1 / Denominator;

                // check if we need to swap
                if (CurrT0 > CurrT1)
                {
                    float Temp = CurrT0;
                    CurrT0 = CurrT1;
                    CurrT1 = Temp;
                }

                // if we need to update T0 or T1, update it
                if (T0 < CurrT0)
                {
                    T0 = CurrT0;
                }

                if (T1 > CurrT1)
                {
                    T1 = CurrT1;
                }


                if (T0 > T1)
                {
                    OutT0 = float.MaxValue;
                    OutT1 = float.MinValue;
                    return(false);
                }
            }

            OutT0 = T0;
            OutT1 = T1;

            return(true);
        }
コード例 #2
0
        protected void CreateSlabs(EBoundType InBoundType, H1Vector3 InLocation, H1Vector3 InExtent)
        {
            // depending on bound type, define the number of slabs
            Int32 SlabNum = 0;

            // setting transform properties
            Position = InLocation;
            Extent   = InExtent;

            switch (InBoundType)
            {
            case EBoundType.Box:
            {
                // total 3 slabs needed (x, y, z)
                SlabNum = 3;

                Slabs = new H1Slab[SlabNum];

                // x-axis
                H1Vector3 DirectionX = new H1Vector3(1, 0, 0);
                float     ExtentX    = InExtent.X;

                Slabs[0] = new H1Slab(DirectionX, Position, ExtentX);

                // y-axis
                H1Vector3 DirectionY = new H1Vector3(0, 1, 0);
                float     ExtentY    = InExtent.Y;

                Slabs[1] = new H1Slab(DirectionY, Position, ExtentY);

                // z-axis
                H1Vector3 DirectionZ = new H1Vector3(0, 0, 1);
                float     ExtentZ    = InExtent.Z;

                Slabs[2] = new H1Slab(DirectionZ, Position, ExtentZ);

                break;
            }

            default:
                break;
            }
        }