Ejemplo n.º 1
0
        public static RayCastResult rayCast(Vector3 startPos, Vector3 dir, RayCastManager rtm, float length, RayCastBlockType mask)
        {
            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)
            {
                RayCastResult rlt = rayTraceSmall(startPosInner, dirInfo, rtm, Face.FNI_Unknown, length - startOffset, mask);
                rlt.hitLength += startOffset;
                return(rlt);
            }
            else
            {
                return(new RayCastResult(false, 0, 0, 0, Face.FNI_Unknown, 0));
            }
        }
Ejemplo n.º 2
0
        public RayCastRestult rayCast(Vector3 startPos, Vector3 dir, float length, RayCastBlockType mask)
        {
            RayCastRestult outResult;
            //求局部坐标,左下角为(0,0,0),单位长度为chunkSize
            Vector3       localStartPos = startPos - new Vector3(baseX, baseY, baseZ);
            RayCastResult rlt           = RayTrace.rayCast(localStartPos, dir, this, length, mask);//进行粗糙范围射线追踪

            outResult.bHit = rlt.bHit;
            if (rlt.hitLength > length)
            {
                outResult.bHit = false;
            }
            outResult.hitFaceIndex = (int)rlt.faceIndex;
            outResult.hitLength    = rlt.hitLength;
            return(outResult);
        }