public bool intersectRay(Ray pRay, ref float pMaxDist, bool pStopAtFirstHit, ModelIgnoreFlags ignoreFlags)
        {
            if (iModel == null)
            {
                return(false);
            }

            float time = pRay.intersectionTime(iBound);

            if (float.IsInfinity(time))
            {
                return(false);
            }

            // child bounds are defined in object space:
            Vector3 p        = iInvRot * (pRay.Origin - iPos) * iInvScale;
            Ray     modRay   = new Ray(p, iInvRot * pRay.Direction);
            float   distance = pMaxDist * iInvScale;
            bool    hit      = iModel.IntersectRay(modRay, ref distance, pStopAtFirstHit, ignoreFlags);

            if (hit)
            {
                distance *= iScale;
                pMaxDist  = distance;
            }
            return(hit);
        }
Exemple #2
0
        public bool IsInLineOfSight(Vector3 pos1, Vector3 pos2, ModelIgnoreFlags ignoreFlags)
        {
            float maxDist = (pos2 - pos1).magnitude();

            // return false if distance is over max float, in case of cheater teleporting to the end of the universe
            if (maxDist == float.MaxValue ||
                maxDist == float.PositiveInfinity)
            {
                return(false);
            }

            // valid map coords should *never ever* produce float overflow, but this would produce NaNs too
            Cypher.Assert(maxDist < float.MaxValue);
            // prevent NaN values which can cause BIH intersection to enter infinite loop
            if (maxDist < 1e-10f)
            {
                return(true);
            }
            // direction with length of 1
            Ray ray = new Ray(pos1, (pos2 - pos1) / maxDist);

            if (GetIntersectionTime(ray, ref maxDist, true, ignoreFlags))
            {
                return(false);
            }

            return(true);
        }
Exemple #3
0
        bool GetIntersectionTime(Ray pRay, ref float pMaxDist, bool pStopAtFirstHit, ModelIgnoreFlags ignoreFlags)
        {
            float          distance             = pMaxDist;
            MapRayCallback intersectionCallBack = new MapRayCallback(iTreeValues, ignoreFlags);

            iTree.IntersectRay(pRay, intersectionCallBack, ref distance, pStopAtFirstHit);
            if (intersectionCallBack.DidHit())
            {
                pMaxDist = distance;
            }
            return(intersectionCallBack.DidHit());
        }
Exemple #4
0
 public virtual bool IntersectRay(Ray ray, ref float distance, bool stopAtFirstHit, ModelIgnoreFlags ignoreFlags)
 {
     return(false);
 }
Exemple #5
0
 public virtual bool IntersectRay(Ray ray, ref float maxDist, bool stopAtFirstHit, PhaseShift phaseShift, ModelIgnoreFlags ignoreFlags)
 {
     return(false);
 }
        public override bool IntersectRay(Ray ray, ref float maxDist, bool stopAtFirstHit, PhaseShift phaseShift, ModelIgnoreFlags ignoreFlags)
        {
            if (!isCollisionEnabled() || !owner.IsSpawned())
            {
                return(false);
            }

            if (!owner.IsInPhase(phaseShift))
            {
                return(false);
            }

            float time = ray.intersectionTime(iBound);

            if (time == float.PositiveInfinity)
            {
                return(false);
            }

            // child bounds are defined in object space:
            Vector3 p        = iInvRot * (ray.Origin - iPos) * iInvScale;
            Ray     modRay   = new Ray(p, iInvRot * ray.Direction);
            float   distance = maxDist * iInvScale;
            bool    hit      = iModel.IntersectRay(modRay, ref distance, stopAtFirstHit, ignoreFlags);

            if (hit)
            {
                distance *= iScale;
                maxDist   = distance;
            }
            return(hit);
        }
Exemple #7
0
        public override bool IntersectRay(Ray ray, ref float distance, bool stopAtFirstHit, ModelIgnoreFlags ignoreFlags)
        {
            // If the caller asked us to ignore certain objects we should check flags
            if ((ignoreFlags & ModelIgnoreFlags.M2) != ModelIgnoreFlags.Nothing)
            {
                // M2 models are not taken into account for LoS calculation if caller requested their ignoring.
                if ((Flags & (uint)ModelFlags.M2) != 0)
                {
                    return(false);
                }
            }

            // small M2 workaround, maybe better make separate class with virtual intersection funcs
            // in any case, there's no need to use a bound tree if we only have one submodel
            if (groupModels.Count == 1)
            {
                return(groupModels[0].IntersectRay(ray, ref distance, stopAtFirstHit));
            }

            WModelRayCallBack isc = new WModelRayCallBack(groupModels);

            groupTree.IntersectRay(ray, isc, ref distance, stopAtFirstHit);
            return(isc.hit);
        }
Exemple #8
0
        public bool isInLineOfSight(uint mapId, float x1, float y1, float z1, float x2, float y2, float z2, ModelIgnoreFlags ignoreFlags)
        {
            if (!isLineOfSightCalcEnabled() || Global.DisableMgr.IsDisabledFor(DisableType.VMAP, mapId, null, DisableFlags.VmapLOS))
            {
                return(true);
            }

            var instanceTree = iInstanceMapTrees.LookupByKey(mapId);

            if (instanceTree != null)
            {
                Vector3 pos1 = convertPositionToInternalRep(x1, y1, z1);
                Vector3 pos2 = convertPositionToInternalRep(x2, y2, z2);
                if (pos1 != pos2)
                {
                    return(instanceTree.isInLineOfSight(pos1, pos2, ignoreFlags));
                }
            }

            return(true);
        }
Exemple #9
0
 public MapRayCallback(ModelInstance[] val, ModelIgnoreFlags ignoreFlags)
 {
     prims = val;
     hit   = false;
     flags = ignoreFlags;
 }