當前位置: 首頁>>代碼示例>>C#>>正文


C# Bounds.SqrDistance方法代碼示例

本文整理匯總了C#中UnityEngine.Bounds.SqrDistance方法的典型用法代碼示例。如果您正苦於以下問題:C# Bounds.SqrDistance方法的具體用法?C# Bounds.SqrDistance怎麽用?C# Bounds.SqrDistance使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在UnityEngine.Bounds的用法示例。


在下文中一共展示了Bounds.SqrDistance方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: CustomCull

        /// <summary>
        /// Checks to see if object is inside the view frustum of any of the LOS cameras.
        /// Ideally should be called in OnWillRenderObject, but it's to late to disable renderer..
        /// Early outs when visible to one camera.
        /// </summary>
        private static bool CustomCull(Bounds meshBounds, int layerMask)
        {
            //Get list of cube sources
            List<LOSSourceCube> losCubeSources = LOSManager.Instance.LOSSourcesCube;

            for (int i = 0; i < losCubeSources.Count; ++i)
            {
                LOSSourceCube losSourceCube = losCubeSources[i];
                Camera currentCamera = losSourceCube.SourceCamera;

                if (losSourceCube.IsVisible && currentCamera != null)
                {
                    float squaredDistance = currentCamera.farClipPlane * currentCamera.farClipPlane;
                    if (meshBounds.SqrDistance(losSourceCube.transform.position) <= squaredDistance)
                    {
                        if (CheckRayCast(currentCamera, meshBounds, layerMask))
                            return true;
                    }
                }
            }

            // Get list of sources.
            List<LOSSource> losSources = LOSManager.Instance.LOSSources;

            for (int i = 0; i < losSources.Count; ++i)
            {
                LOSSource losSource = losSources[i];
                Camera currentCamera = losSource.SourceCamera;

                if (losSource.IsVisible && currentCamera != null)
                {
                    Plane[] cameraPlanes = losSource.FrustumPlanes;

                    if (GeometryUtility.TestPlanesAABB(cameraPlanes, meshBounds))
                    {
                        if (CheckRayCast(currentCamera, meshBounds, layerMask))
                            return true;
                    }
                }
            }

            return false;
        }
開發者ID:riscvul,項目名稱:SCP_Game_Prototype,代碼行數:48,代碼來源:LOSCuller.cs

示例2: AvoideVessel

        public static bool AvoideVessel(VesselWrapper vsl, Vector3d dir, float dist, Vector3d dV, 
		                                float r2, Bounds exhaust2, Transform refT2,
		                                out Vector3d maneuver, float threshold = -1)
        {
            maneuver = Vector3d.zero;
            //filter vessels on non-collision courses
            var dVn = dV.normalized;
            var cosA = Mathf.Clamp(Vector3.Dot(dir, dVn), -1, 1);
            var collision_dist = threshold.Equals(0)?
                2*dist-vsl.Geometry.DistToBounds(vsl.Physics.wCoM+dir*dist)-
                Mathf.Sqrt(exhaust2.SqrDistance(refT2.InverseTransformPoint(vsl.Physics.wCoM))) :
                Mathf.Max(vsl.Geometry.R, dist-vsl.Geometry.DistToBounds(vsl.Physics.wCoM+dir*dist)) +
                Mathf.Max(r2, dist-Mathf.Sqrt(exhaust2.SqrDistance(refT2.InverseTransformPoint(vsl.Physics.wCoM))));
            //			vsl.Log("R {}, R2 {}; r {}, r2 {}", vsl.Geometry.R, r2,
            //			        dist-vsl.DistToBounds(vsl.wCoM+dir*dist),
            //			        dist-Mathf.Sqrt(exhaust2.SqrDistance(refT2.InverseTransformPoint(vsl.wCoM))));//debug
            //			Utils.Log("{}: cosA: {}, threshold {}", vsl.vessel.vesselName, cosA, threshold);//debug
            if(cosA <= 0) goto check_distance;
            if(threshold < 0) threshold = CPS.MinDistance;
            var sinA = Mathf.Sqrt(1-cosA*cosA);
            var min_separation = dist*sinA;
            var sep_threshold = collision_dist+threshold;
            //			Utils.Log("{}: min_sep > sep_thresh: {} > {}, threshold {}",
            //			          vsl.vessel.vesselName, min_separation, sep_threshold, threshold);//debug
            if(min_separation > sep_threshold) goto check_distance;
            //calculate time to collision
            var vDist = 0f;
            var alpha = Mathf.Acos(cosA);
            var dVm   = dV.magnitude;
            if(sinA <= 0) vDist = dist-sep_threshold;
            else if(dist > sep_threshold) vDist = sep_threshold*Mathf.Sin(Mathf.Asin(min_separation/sep_threshold)-alpha)/sinA;
            var vTime = Utils.ClampL(vDist, 0.1f)/dVm;
            //				Utils.Log("{}: vTime > SafeTime: {} > {}",
            //				          vsl.vessel.vesselName, vTime, CPS.SafeTime/Utils.Clamp(Mathf.Abs(Vector3.Dot(vsl.wMaxAngularA, dVn)), 0.01f, 1f));//debug
            if(vTime > SafeTime(vsl, dVn)) goto check_distance;
            //calculate maneuver
            Vector3d side;
            if(cosA < 0.9) side = (dVn*cosA-dir).normalized;
            else if(Math.Abs(Vector3d.Dot(dVn, vsl.Physics.Up)) < 0.9)
                side = Vector3d.Cross(dVn, vsl.Physics.Up).normalized;
            else side = Vector3d.Cross(dVn, vsl.OnPlanetParams.Fwd).normalized;
            //			if(dist > sep_threshold)
            //			{
            //				var beta = Mathf.Asin(sep_threshold/dist)-alpha;
            //				maneuver = (Mathf.Sin(beta)*side + dVn*(Mathf.Cos(beta)-1)).normalized;
            //			}
            //			else
            maneuver  = side;
            maneuver += vsl.Physics.Up*Mathf.Sign(Vector3.Dot(dir, vsl.Physics.Up))*(min_separation/sep_threshold-1);
            maneuver *= (sep_threshold-min_separation) / Math.Sqrt(vTime);
            //			maneuver = (-vsl.Up*Mathf.Sign(Vector3.Dot(dir, vsl.Up))*(1-min_separation/sep_threshold) +
            //			            (dVn*cosA-dir).normalized).normalized * (sep_threshold-min_separation) / vTime;
            //			vsl.Log("\ndist {}\ndV {}\nmaneuver: {}\n" +
            //			        "vTime {}, vDist {}, min sep {}, sep_thresh {}",
            //			        dir*dist, dV, maneuver, vTime, vDist, min_separation, sep_threshold);//debug
            #if DEBUG
            Collided |= dist < collision_dist;
            #endif
            //if distance is not safe, correct course anyway
            check_distance:
            var collision = !maneuver.IsZero();
            dist -= collision_dist;
            if(dist < threshold)
            {
                var dist_to_safe = Utils.ClampH(dist-threshold, -0.01f);
                var dc = dir*dist_to_safe;
                if(vsl.HorizontalSpeed.NeededVector.sqrMagnitude > CPS.LatAvoidMinVelSqr)
                {
                    var lat_avoid = Vector3d.Cross(vsl.Physics.Up, vsl.HorizontalSpeed.NeededVector.normalized);
                    dc = Vector3d.Dot(dc, lat_avoid) >= 0?
                        lat_avoid*dist_to_safe :
                        lat_avoid*-dist_to_safe;
                }
                if(dc.sqrMagnitude > 0.25) maneuver += dc/CPS.SafeTime*2;
            //				vsl.Log("adding safe distance correction: {}", dc/CPS.SafeTime*2);//debug
            }
            //			#if DEBUG
            //			Dir = dir*dist;
            //			DeltaV = dV;
            //			Maneuver = maneuver;
            //			#endif
            return collision;
        }
開發者ID:Kerbas-ad-astra,項目名稱:ThrottleControlledAvionics,代碼行數:83,代碼來源:CollisionPreventionSystem.cs

示例3: MinDistanceToAABB

    public static float MinDistanceToAABB(Vector3 vec, Vector3 pMin, Vector3 pMax)
    {
        var b = new Bounds();
        b.SetMinMax(pMin, pMax);

        // inside?
        if (b.Contains(vec)) return 0f;
        else return Mathf.Sqrt(b.SqrDistance(vec));
    }
開發者ID:hagish,項目名稱:tektix,代碼行數:9,代碼來源:UKMathHelper.cs


注:本文中的UnityEngine.Bounds.SqrDistance方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。