Exemplo n.º 1
0
        /// <summary></summary>
        public static bool Collide(MeshCollider m1, MeshCollider m2)
        {
            Sphere s1 = new Sphere(m1.transform.position, 0);
            Sphere s2 = new Sphere(m2.transform.position, 0);

            foreach (Point pt in m1.GetVertices())
            {
                float d = DistanceUtil.Dist(pt, s1.position);
                if (d > s1.radius)
                {
                    s1.radius = d;
                }
            }
            foreach (Point pt in m2.GetVertices())
            {
                float d = DistanceUtil.Dist(pt, s2.position);
                if (d > s2.radius)
                {
                    s2.radius = d;
                }
            }
            if (!Collide(s1, s2))
            {
                return(false);
            }
            return(DistanceUtil.Dist(m1, m2) <= 0);
        }
Exemplo n.º 2
0
 static public int constructor(IntPtr l)
 {
     try {
         int argc = LuaDLL.lua_gettop(l);
         UnityEngine.BoundingSphere o;
         if (argc == 3)
         {
             UnityEngine.Vector3 a1;
             checkType(l, 2, out a1);
             System.Single a2;
             checkType(l, 3, out a2);
             o = new UnityEngine.BoundingSphere(a1, a2);
             pushValue(l, true);
             pushValue(l, o);
             return(2);
         }
         else if (argc == 2)
         {
             UnityEngine.Vector4 a1;
             checkType(l, 2, out a1);
             o = new UnityEngine.BoundingSphere(a1);
             pushValue(l, true);
             pushValue(l, o);
             return(2);
         }
         return(error(l, "New object failed."));
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
 public static int constructor(IntPtr l)
 {
     try {
         int argc = LuaDLL.lua_gettop(l);
         UnityEngine.BoundingSphere o;
         if(argc==3){
             UnityEngine.Vector3 a1;
             checkType(l,2,out a1);
             System.Single a2;
             checkType(l,3,out a2);
             o=new UnityEngine.BoundingSphere(a1,a2);
             pushValue(l,true);
             pushValue(l,o);
             return 2;
         }
         else if(argc==2){
             UnityEngine.Vector4 a1;
             checkType(l,2,out a1);
             o=new UnityEngine.BoundingSphere(a1);
             pushValue(l,true);
             pushValue(l,o);
             return 2;
         }
         return error(l,"New object failed.");
     }
     catch(Exception e) {
         return error(l,e);
     }
 }
 static public int constructor(IntPtr l)
 {
     try {
                     #if DEBUG
         var    method     = System.Reflection.MethodBase.GetCurrentMethod();
         string methodName = GetMethodName(method);
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.BeginSample(methodName);
                     #else
         Profiler.BeginSample(methodName);
                     #endif
                     #endif
         int argc = LuaDLL.lua_gettop(l);
         UnityEngine.BoundingSphere o;
         if (argc == 3)
         {
             UnityEngine.Vector3 a1;
             checkType(l, 2, out a1);
             System.Single a2;
             checkType(l, 3, out a2);
             o = new UnityEngine.BoundingSphere(a1, a2);
             pushValue(l, true);
             pushValue(l, o);
             return(2);
         }
         else if (argc == 2)
         {
             UnityEngine.Vector4 a1;
             checkType(l, 2, out a1);
             o = new UnityEngine.BoundingSphere(a1);
             pushValue(l, true);
             pushValue(l, o);
             return(2);
         }
         else if (argc == 0)
         {
             o = new UnityEngine.BoundingSphere();
             pushValue(l, true);
             pushObject(l, o);
             return(2);
         }
         return(error(l, "New object failed."));
     }
     catch (Exception e) {
         return(error(l, e));
     }
             #if DEBUG
     finally {
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.EndSample();
                     #else
         Profiler.EndSample();
                     #endif
     }
             #endif
 }
Exemplo n.º 5
0
 static public int ctor_s(IntPtr l)
 {
     try {
         UnityEngine.BoundingSphere o;
         o = new UnityEngine.BoundingSphere();
         pushValue(l, true);
         pushValue(l, o);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Exemplo n.º 6
0
	void SetupCullinggroup()
	{
		// culling groupの初期化
		cullingGroup = new CullingGroup ();
		cullingGroup.targetCamera = Camera.main;

		// 敵を生成する座標の登録
		BoundingSphere[] bounds = new BoundingSphere[targetPositions.Length];
		for (int i = 0; i < targetPositions.Length; i++) {
			bounds [i].position = targetPositions [i].position;
			bounds [i].radius = 1;
		}
		cullingGroup.SetBoundingSpheres (bounds);
		cullingGroup.SetBoundingSphereCount (targetPositions.Length);
	}
Exemplo n.º 7
0
 static public int ctor__Vector4_s(IntPtr l)
 {
     try {
         UnityEngine.BoundingSphere o;
         UnityEngine.Vector4        a1;
         checkType(l, 1, out a1);
         o = new UnityEngine.BoundingSphere(a1);
         pushValue(l, true);
         pushValue(l, o);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Exemplo n.º 8
0
// fields
    static void BoundingSphere_position(JSVCall vc)
    {
        if (vc.bGet)
        {
            UnityEngine.BoundingSphere _this = (UnityEngine.BoundingSphere)vc.csObj;
            var result = _this.position;
            JSApi.setVector3S((int)JSApi.SetType.Rval, result);
        }
        else
        {
            UnityEngine.Vector3        arg0  = (UnityEngine.Vector3)JSApi.getVector3S((int)JSApi.GetType.Arg);
            UnityEngine.BoundingSphere _this = (UnityEngine.BoundingSphere)vc.csObj;
            _this.position = arg0;
            JSMgr.changeJSObj(vc.jsObjID, _this);
        }
    }
Exemplo n.º 9
0
 static void BoundingSphere_radius(JSVCall vc)
 {
     if (vc.bGet)
     {
         UnityEngine.BoundingSphere _this = (UnityEngine.BoundingSphere)vc.csObj;
         var result = _this.radius;
         JSApi.setSingle((int)JSApi.SetType.Rval, (System.Single)(result));
     }
     else
     {
         System.Single arg0 = (System.Single)JSApi.getSingle((int)JSApi.GetType.Arg);
         UnityEngine.BoundingSphere _this = (UnityEngine.BoundingSphere)vc.csObj;
         _this.radius = arg0;
         JSMgr.changeJSObj(vc.jsObjID, _this);
     }
 }
    static bool CullingGroup_SetBoundingSpheres__BoundingSphere_Array(JSVCall vc, int argc)
    {
        int len = argc;

        if (len == 1)
        {
            UnityEngine.BoundingSphere[] arg0 = JSDataExchangeMgr.GetJSArg <UnityEngine.BoundingSphere[]>(() =>
            {
                int jsObjID = JSApi.getObject((int)JSApi.GetType.Arg);
                int length  = JSApi.getArrayLength(jsObjID);
                var ret     = new UnityEngine.BoundingSphere[length];
                for (var i = 0; i < length; i++)
                {
                    JSApi.getElement(jsObjID, i);
                    ret[i] = (UnityEngine.BoundingSphere)JSMgr.datax.getObject((int)JSApi.GetType.SaveAndRemove);
                }
                return(ret);
            });
            ((UnityEngine.CullingGroup)vc.csObj).SetBoundingSpheres(arg0);
        }

        return(true);
    }
 /// <summary>Calcule la distance entre un plan et une sphère. Peut être négatif : entre 0 si le plan est tangeant à la surface de la sphère, et -rayon si le centre de la sphère est sur le plan.</summary>
 public static float Dist(Plane p, Sphere s)
 {
     return(Dist(s, p));
 }
 /// <summary>Calcule la distance minimum entre une sphère et une boite. Si c'est nagatif, indique la profondeur de la sphère dans la boite.</summary>
 public static float Dist(Sphere s, BoxCollider b)
 {
     return(Dist(b, s));
 }
Exemplo n.º 13
0
    void Start()
    {
        forward_hash = Animator.StringToHash( "Forward" );
        SpawnGroup();

        culling_group.targetCamera = target_cam;

        culling_group.onStateChanged += OnStateChanged;

        bounding_spheres = new BoundingSphere[agents.Count];
        for ( int i = 0; i < agents.Count; ++i ) {
            BoundingSphere bounding_sphere = new BoundingSphere( agents[i].transform.position, 1.5f );
            bounding_spheres[i] = bounding_sphere;
        }

        culling_group.SetBoundingSpheres( bounding_spheres );

        culling_group.SetDistanceReferencePoint( target_cam.transform );
        culling_group.SetBoundingDistances( bounding_distances );
    }
Exemplo n.º 14
0
 /// <summary></summary>
 public static bool Collide(Sphere s1, Sphere s2)
 {
     return(DistanceUtil.Dist(s1, s2) <= 0);
 }
Exemplo n.º 15
0
 /// <summary></summary>
 public static bool Collide(Plane p, Sphere s)
 {
     return(Collide(s, p));
 }
 /// <summary>Calcule la distance entre un plan et une sphère. Peut être négatif : entre 0 si le plan est tangeant à la surface de la sphère, et -rayon si le centre de la sphère est sur le plan.</summary>
 public static float Dist(Sphere s, Plane p)
 {
     return(Dist(s.position, p) - s.radius);
 }
Exemplo n.º 17
0
        public bool isCharacterOnTile(Point2 tilePos)
        {
            BoundingBox tile         = new BoundingBox();
            BoundingSphere character = new BoundingSphere();

            character.Center.X = m_position.X;
            character.Center.Y = m_position.Y;
            character.Radius   = m_characterRadius;

            tile.Min.X = Map.m_staticMapInstance.getTileWidth() * tilePos.X;
            tile.Min.Y = Map.m_staticMapInstance.getTileHeight() * tilePos.Y;
            tile.Max.X = tile.Min.X + Map.m_staticMapInstance.getTileWidth();
            tile.Max.Y = tile.Min.Y + Map.m_staticMapInstance.getTileHeight();
            return tile.Intersects(character);
        }
Exemplo n.º 18
0
        public bool movePosition(float frameTime, Map _theMap, Character[] _characterArray, bool slideAgainstWalls, bool canUseSlides)
        {
            bool movingOnSlide = false;

            bool slideAgainstDiagonalWalls = slideAgainstWalls && true;
            bool environmentCollision = false;

            // todo this shouldnt be assigned here each frame
            m_characterRadius = m_tileSet.getTileWidth() / 2 * 8 / 10;

            Point2 change = new Point2();

            int tileIndexX = m_position.X / _theMap.getTileWidth();
            int tileIndexY = m_position.Y / _theMap.getTileHeight();
            TileType tileTypeStoodOn = _theMap.getMapTileType(tileIndexX, tileIndexY);

            Boolean onSlide = Map.isTileTypeSlide(tileTypeStoodOn) && canUseSlides;
            int SLIDE_EXIT_LENGTH = 10;
            // If not sliding (on slide exit) then allow movement
            if (!onSlide)
            {
                float moveSpeed = m_moveSpeedPerSecond * frameTime;

                float cos = (float)Math.Cos(m_rotation);
                float sin = (float)Math.Sin(m_rotation);

                change.X = (int)( sin * moveSpeed);
                change.Y = (int)(-cos * moveSpeed);
            }

            Point2 newPos = new Point2();

            // Velocity is only for slide movement
            if (m_velocity.Length() > MAX_VELOCITY)
            {
                m_velocity.Normalize();
                m_velocity *= MAX_VELOCITY;
            }

            change.X += (int)(m_velocity.X * frameTime);
            newPos.X = m_position.X + change.X;

            change.Y += (int)(m_velocity.Y * frameTime);
            newPos.Y = m_position.Y + change.Y;

            if (Map.isTileTypeSlide(tileTypeStoodOn) && canUseSlides)
            {
                Vector2 targetPoint = new Vector2();
                Vector2 charPoint = new Vector2(m_position.X, m_position.Y);
                targetPoint.X = tileIndexX * _theMap.getTileWidth() + m_tileSet.getTileWidth() / 2;
                targetPoint.Y = tileIndexY * _theMap.getTileHeight() + m_tileSet.getTileHeight() / 2;

                if (tileTypeStoodOn == TileType.SLIDE_DOWN)
                {
                    targetPoint.Y += m_tileSet.getTileHeight();
                }
                else if (tileTypeStoodOn == TileType.SLIDE_UP)
                {
                    targetPoint.Y -= m_tileSet.getTileHeight();
                }
                else if (tileTypeStoodOn == TileType.SLIDE_LEFT)
                {
                    targetPoint.X -= m_tileSet.getTileWidth();
                }
                else if (tileTypeStoodOn == TileType.SLIDE_RIGHT)
                {
                    targetPoint.X += m_tileSet.getTileWidth();
                }

                Vector2 vector = targetPoint - charPoint;

                // Its important this is high to keep the player in the center of the slide
                // So they dont come out off-center and get stuck in collision
                const float VELOCITY_INCREASE = 200.0f;
                m_velocity += vector * VELOCITY_INCREASE * frameTime;
                movingOnSlide = true;
            }
            else if (m_velocity.Length() > 0)
            {
                // dubious code to reduce velocity
                m_velocity *= (25 * frameTime);

                change.X += (int)(m_velocity.X * frameTime);
                change.Y += (int)(m_velocity.Y * frameTime);
                newPos.X = m_position.X + change.X;
                newPos.Y = m_position.Y + change.Y;
                if (m_velocity.Length() < SLIDE_EXIT_LENGTH)
                {
                    m_velocity.X = 0;
                    m_velocity.Y = 0;
                    stopMovement();
                }
            }
            else
            {
                newPos.X = m_position.X + change.X;
                newPos.Y = m_position.Y + change.Y;
            }

            Point2 lastPos = new Point2(newPos);

            // check per tile here
            if (Map.isTileTypeSlide(tileTypeStoodOn) == false && BuildConstants.COLLISION_OFF == false)// && onSlide == false)// && m_teleporting == false)
            {
                // Check against the very boundarys of the map
                newPos.X = capValue(newPos.X, m_characterRadius, _theMap.getWidth() - m_characterRadius);
                newPos.Y = capValue(newPos.Y, m_characterRadius, _theMap.getHeight() - m_characterRadius);

                if (lastPos.X != newPos.X || lastPos.Y != newPos.Y)
                {
                    environmentCollision = true;
                }

                int minX = capValue(tileIndexX - 1, 0, _theMap.getWidth() / _theMap.getTileWidth());
                int maxX = capValue(tileIndexX + 2, 0, _theMap.getWidth() / _theMap.getTileWidth());

                int minY = capValue(tileIndexY - 1, 0, _theMap.getHeight() / _theMap.getTileHeight());
                int maxY = capValue(tileIndexY + 2, 0, _theMap.getHeight() / _theMap.getTileHeight());

                m_boundingCharCircle.Center = new Vector3(newPos.X, newPos.Y, 0);
                m_boundingCharCircle.Radius = m_characterRadius;

                for (int y = minY; y < maxY; y++)
                {
                    for (int x = minX; x < maxX; x++)
                    {
                        if (x >= _theMap.getWidth() / _theMap.getTileWidth() &&
                            y >= _theMap.getHeight() / _theMap.getTileHeight())
                        {
                                 continue;
                        }

                        TileType tileType = _theMap.getMapTileType(x, y);

                        Point2 pixel = new Point2(
                            x * _theMap.getTileWidth(),
                            y * _theMap.getTileHeight());

                        bool intersects = false;

                        int pixelCenX = pixel.X + _theMap.getTileWidth() / 2;
                        int pixelCenY = pixel.Y + _theMap.getTileHeight() / 2;

                        m_boundingTileCircle.Center = new Vector3(pixelCenX, pixelCenY, 0);
                        m_boundingTileCircle.Radius = _theMap.getTileWidth() / 2;

                        if (Map.isTileTypeSquareBlock(tileType, m_frameIndexRendering) || (canUseSlides == false && Map.isTileTypeSlide(tileType)))
                        {
                            m_boundingTileBox = BoundingBox.CreateFromSphere(m_boundingTileCircle);
                            bool localIntersects = m_boundingCharCircle.Intersects(m_boundingTileBox);

                            if(localIntersects)
                            {
                                if (slideAgainstWalls)
                                {
                                    if (GetSlidePositionOffBlock(m_position, newPos, new Point2(pixelCenX, pixelCenY), _theMap.getTileWidth(), m_characterRadius, ref newPos))
                                    {
                                        environmentCollision = true;
                                    }
                                }
                                else
                                {
                                    intersects = true;
                                }
                            }
                        }
                        else if (Map.isTileTypeCircle(tileType))
                        {
                            intersects = m_boundingCharCircle.Intersects(m_boundingTileCircle);
                        }
                        else if (_theMap.isTileTypePixelCollision(tileType))
                        {
                            TileType pixelCheckType = _theMap.GetTileTypePixelCollision(tileType);
                            Point2 topLeft = new Point2(
                                    newPos.X - m_tileSet.getTileWidth() / 2,
                                    newPos.Y - m_tileSet.getTileHeight() / 2);
                            bool localIntersects = m_tileSet.checkForCollision(_theMap.getTileSet(), m_frameIndexCollision, topLeft, (int)pixelCheckType, pixel);

                            if (localIntersects && (!Map.isTileTypeDiagonalWall(tileType) || slideAgainstDiagonalWalls == false))
                            {
                                intersects = localIntersects;
                            }

                        }

                        if (intersects)
                        {
                            environmentCollision = true;
                            newPos = new Point2(m_position);
                        }
                    }
                }

                // 2nd pass for diagonal walls
                if (slideAgainstDiagonalWalls)
                {
                    TestPositionAgainDiagonalWalls(_theMap, minX, minY, maxX, maxY, ref environmentCollision, ref newPos);
                }

                m_boundingCharCircle.Center = new Vector3(newPos.X, newPos.Y, 0);
                m_boundingCharCircle.Radius = m_characterRadius;

                if (_characterArray != null)
                {
                    // Check against other characters
                    for (int c = 0; c < _characterArray.Length; c++)
                    {
                        if (_characterArray[c] == this || _characterArray[c].m_health <= 0 || _characterArray[c].m_finishedLevel)
                        {
                            continue;
                        }

                        BoundingSphere otherCharBounding = new BoundingSphere();
                        otherCharBounding.Center = new
                            Vector3(_characterArray[c].m_position.X, _characterArray[c].m_position.Y, 0);
                        otherCharBounding.Radius = m_characterRadius;

                        if (m_boundingCharCircle.Intersects(otherCharBounding))
                        {
                            if (m_frameIndexRendering == (int)CharacterTile.BADDY)
                            {
                                _characterArray[c].applyDamageDrain(frameTime, GameConstants.baddyDrainAmountPerSec);
                                continue;
                            }
                            // characters are facing each other
                            // This means if characters do occupy the same space (via resurrection or teleport) then they can still move appart
                            else if (IsFacing(_characterArray[c]))
                            {
                                newPos = new Point2(m_position);
                            }

                        }

                    }

                }

            }

            if (slideAgainstWalls)
            {
                m_position.X = newPos.X;
                m_position.Y = newPos.Y;
            }
            else
            {
                int realChangeX = newPos.X - m_position.X;
                int percentageX = 100;
                // This will let user get stuck on things instead of just sliding around
                if (change.X * change.X > realChangeX * realChangeX)
                {
                    percentageX = 100 * realChangeX / change.X;
                }

                int realChangeY = newPos.Y - m_position.Y;
                int percentageY = 100;
                // This will let user get stuck on things instead of just sliding around
                if (change.Y * change.Y > realChangeY * realChangeY)
                {
                    percentageY = 100 * realChangeY / change.Y;
                }

                int lowestPercentage = percentageX < percentageY ? percentageX : percentageY;

                // Calculate final position
                m_position.X += change.X * lowestPercentage / 100;
                m_position.Y += change.Y * lowestPercentage / 100;
            }

            SetMovingOnSlideState(movingOnSlide);
            return environmentCollision;
        }
 /// <summary>Calcule la distance minimum entre une sphère et un mesh. Si c'est nagatif, indique la profondeur du mesh dans la sphère.</summary>
 public static float Dist(MeshCollider m, Sphere s)
 {
     return(Dist(m, s.position) - s.radius);
 }
 /// <summary>Calcule la distance minimum entre une sphère et un mesh. Si c'est nagatif, indique la profondeur du mesh dans la sphère.</summary>
 public static float Dist(Sphere s, MeshCollider m)
 {
     return(Dist(m, s));
 }
 /// <summary>Calcule la distance minimum entre une sphère et une boite. Si c'est nagatif, indique la profondeur de la sphère dans la boite.</summary>
 public static float Dist(BoxCollider b, Sphere s)
 {
     return(Dist(b, s.position) - s.radius);
 }
Exemplo n.º 22
0
 /// <summary></summary>
 public static bool Collide(Line l, Sphere s)
 {
     return(Collide(s, l));
 }
Exemplo n.º 23
0
 /// <summary></summary>
 public static bool Collide(Sphere s, Line l)
 {
     return(DistanceUtil.Dist(s, l) <= 0);
 }
Exemplo n.º 24
0
        //public void Intersects(ref BoundingBox box, out float? result)
        //{
        //    result = Intersects(box);
        //}
        //public float? Intersects(BoundingFrustum frustum)
        //{
        //    throw new NotImplementedException();
        //}
        //public float? Intersects(BoundingSphere sphere)
        //{
        //    float? result;
        //    Intersects(ref sphere, out result);
        //    return result;
        //}
        //public float? Intersects(Plane plane)
        //{
        //    throw new NotImplementedException();
        //}
        //public void Intersects(ref Plane plane, out float? result)
        //{
        //    throw new NotImplementedException();
        //}
        public static float? Intersects(this Ray ray, BoundingSphere sphere)
        {
            float? result = null;

            // Find the vector between where the ray starts the the sphere's centre
            Vector3 difference = sphere.Center - ray.origin;

            float differenceLengthSquared = difference.sqrMagnitude;
            float sphereRadiusSquared = sphere.Radius * sphere.Radius;

            float distanceAlongRay;

            // If the distance between the ray start and the sphere's centre is less than
            // the radius of the sphere, it means we've intersected. N.B. checking the LengthSquared is faster.
            if (differenceLengthSquared < sphereRadiusSquared)
            {
                return result = 0.0f;
            }

            //Vector3Helper.Dot(ref this.Direction, ref difference, out distanceAlongRay);
            distanceAlongRay = Vector3Helper.Dot(ray.direction, difference);
            // If the ray is pointing away from the sphere then we don't ever intersect
            if (distanceAlongRay < 0)
            {
                return result = null;
            }

            // Next we kinda use Pythagoras to check if we are within the bounds of the sphere
            // if x = radius of sphere
            // if y = distance between ray position and sphere centre
            // if z = the distance we've travelled along the ray
            // if x^2 + z^2 - y^2 < 0, we do not intersect
            float dist = sphereRadiusSquared + distanceAlongRay * distanceAlongRay - differenceLengthSquared;

            return result = (dist < 0) ? null : distanceAlongRay - (float?)Math.Sqrt(dist);
        }
Exemplo n.º 25
0
 /// <summary></summary>
 public static bool Collide(Sphere s, Plane p)
 {
     return(DistanceUtil.Dist(s, p) <= 0);
 }
Exemplo n.º 26
0
    /// <summary>
    /// Prepares a shadow cascade camera.
    /// </summary>
    /// <param name='light'>
    /// Shadow casting light.
    /// </param>
    /// <param name='lightCamera'>
    /// Light camera.
    /// </param>
    /// <param name='eyeCamera'>
    /// Eye camera.
    /// </param>
    /// <param name='eyeNearClip'>
    /// Eye near clip for this cascade.
    /// </param>
    /// <param name='eyeFarClip'>
    /// Eye far clip for this cascade.
    /// </param>
    /// <param name='snapResolution'>
    /// Cascade resolution for quantizing.
    /// </param>
    /// <param name='totalShadowBounds'>
    /// Bounding sphere for the entire Lightmap.  Used for positioning the camera on Z.
    /// </param>
    public static void SetupShadowCamera(Light light, Camera lightCamera, Camera eyeCamera, float eyeNearClip, float eyeFarClip, float paddingZ, float paddingRadius, int snapResolution, ref BoundingSphere totalShadowBounds, ref ShadowCameraTemporalData temporalData)
    {
        var lightCameraTransform = lightCamera.transform;

        BoundingSphere bounds = new BoundingSphere();
        if(Sunshine.Instance.UsingCustomBounds)
            bounds = Sunshine.Instance.CustomBounds;
        else
            bounds = FrustumBoundingSphereBinarySearch(eyeCamera, eyeNearClip, eyeFarClip, true, paddingRadius, 0.01f, 20);

        float maxRadius = QuantizeValueWithoutFlicker(bounds.radius, 100, temporalData.boundingRadius);
        temporalData.boundingRadius = maxRadius;
        float maxDimension2D = maxRadius * 2f;

        //Set Camera Properties
        lightCamera.aspect = 1.0f;
        lightCamera.orthographic = true;
        lightCamera.nearClipPlane = eyeCamera.nearClipPlane;
        lightCamera.farClipPlane = (totalShadowBounds.radius + paddingZ + lightCamera.nearClipPlane) * 2f;
        lightCamera.orthographicSize = maxDimension2D * 0.5f;

        lightCameraTransform.rotation = Quaternion.LookRotation(light.transform.forward);

        lightCameraTransform.position = bounds.origin;

        //Quantize:
        Vector3 lightWorldOrigin = lightCameraTransform.InverseTransformPoint(Vector3.zero);

        float camUnits = maxDimension2D / (float)snapResolution;
        lightWorldOrigin.x = QuantizeValueWithoutFlicker(lightWorldOrigin.x, camUnits, temporalData.lightWorldOrigin.x);
        lightWorldOrigin.y = QuantizeValueWithoutFlicker(lightWorldOrigin.y, camUnits, temporalData.lightWorldOrigin.y);
        //lightWorldOrigin.z = QuantizeValueWithoutFlicker(lightWorldOrigin.z, camUnits, temporalData.lightWorldOrigin.z);
        temporalData.lightWorldOrigin = lightWorldOrigin;

        lightCameraTransform.position -= lightCameraTransform.TransformPoint(lightWorldOrigin);

        // Make the lightCamera's Z Position uniform between all Cascades!
        // This may not be required in the future, when we impliment staggered cascade rendering...
        Vector3 shadowCenterInLight = lightCameraTransform.InverseTransformPoint(totalShadowBounds.origin);
        lightCameraTransform.position += lightCameraTransform.forward * (shadowCenterInLight.z - (totalShadowBounds.radius + lightCamera.nearClipPlane + paddingZ));
    }
 /// <summary>Calcule la distance entre une droite et une sphère. Peut être négatif : entre 0 si la droite est tangeante à la surface de la sphère, et -rayon si la droite traverse le centre de la sphère.</summary>
 public static float Dist(Sphere s, Line l)
 {
     return(Dist(s.position, l) - s.radius);
 }
 /// <summary>Calcule la distance entre un point et une sphère. Peut être négatif : entre 0 si c'est sur la surface, et -rayon si le point est au centre de la sphère.</summary>
 public static float Dist(Point p, Sphere s)
 {
     return(Dist(s, p));
 }
Exemplo n.º 29
0
 /// <summary></summary>
 public static bool Collide(BoxCollider b, Sphere s)
 {
     return(DistanceUtil.Dist(b, s) <= 0);
 }
Exemplo n.º 30
0
 /// <summary></summary>
 public static bool Collide(Sphere s, MeshCollider m)
 {
     return(Collide(m, s));
 }
 /// <summary>Calcule la distance entre une droite et une sphère. Peut être négatif : entre 0 si la droite est tangeante à la surface de la sphère, et -rayon si la droite traverse le centre de la sphère.</summary>
 public static float Dist(Line l, Sphere s)
 {
     return(Dist(s, l));
 }
Exemplo n.º 32
0
 /// <summary></summary>
 public static bool Collide(MeshCollider m, Sphere s)
 {
     return(DistanceUtil.Dist(m, s) <= 0);
 }
Exemplo n.º 33
0
 /// <summary></summary>
 public static bool Collide(Sphere s, BoxCollider b)
 {
     return(Collide(b, s));
 }
 /// <summary>Calcule la distance minimum entre deux sphère. Peut être négatif : entre 0 si les deux sphères n'ont qu'un seul point en commun, et -(s1.rayon + s2.rayon) si les deux centres sont confondus.</summary>
 public static float Dist(Sphere s1, Sphere s2)
 {
     return(Dist(s1.position, s2.position) - s1.radius - s2.radius);
 }