コード例 #1
0
        public static RayTraceResult rayTrace(Vector3 startPos, Vector3 dir, RayTraceChunkManager rtm, float length)
        {
            DirInfo dirInfo       = new DirInfo(dir);
            Vector3 startPosInner = startPos;
            float   hitTime       = 0;
            float   startOffset   = 0;
            bool    bHitBounds    = true;//能击中总区域,或者在内部

            if (startPos.x >= 0 && startPos.x < rtm.getSizeX() && startPos.y >= 0 && startPos.y < rtm.getSizeY() && startPos.z >= 0 && startPos.z < rtm.getSizeZ())
            {
                bHitBounds = true;
            }
            else
            {
                bHitBounds = Misc.rayHitAABB(startPos, dir, new Vector3(0, 0, 0), rtm.getSize(), ref hitTime);
                if (hitTime > 0)
                {
                    startOffset = hitTime;
                }
                startPosInner = startPos + dir * startOffset - dir * 0.01f;
            }
            if (bHitBounds)
            {
                RayTraceResult rlt = rayTraceSmall(startPosInner, dirInfo, rtm, Face.FNI_Unknown, length - startOffset);
                rlt.hitLength += startOffset;
                return(rlt);
            }
            else
            {
                return(new RayTraceResult(false, 0, 0, 0, Face.FNI_Unknown, 0));
            }
        }