Nez.Portable/ECS/Components/Renderables/PolygonLight/PolySpotLight.cs
/// <summary>
/// calculates the points needed to encompass the spot light. The points generate a polygon which is used for overlap detection.
/// </summary>
calculates the points needed to encompass the spot light. The points generate a polygon which is used for overlap detection.
calculates the points needed to encompass the spot light . The points generate a polygon which is used for overlap detection .
void recalculatePolyPoints()
        {
            if (entity == null)
                return;
            var expandedRadius = radius + radius * 0.1f;
            var sides = Mathf.ceilToInt(_spotAngle / 25) + 1;
            var stepSize = (_spotAngle * Mathf.deg2Rad) / sides;
            var verts = new Vector2[sides + 2];
            verts[0] = Vector2.Zero;
            for (var i = 0; i <= sides; i++)
                verts[i + 1] = new Vector2(
                    expandedRadius * Mathf.cos(stepSize * i),
                    expandedRadius * Mathf.sin(stepSize * i));
            if (_polygon == null)
                _polygon = new Polygon(verts);
            else
                _polygon._originalPoints = verts;
            Polygon.rotatePolygonVerts(
                entity.rotation - _spotAngle * 0.5f * Mathf.deg2Rad,
                _polygon._originalPoints,
                _polygon.points);
        }
void recalculatePolyPoints ( ) { if ( entity == null ) return ; var expandedRadius = radius + radius * 0.1f ; var sides = Mathf . ceilToInt ( _spotAngle / 25 ) + 1 ; var stepSize = ( _spotAngle * Mathf . deg2Rad ) / sides ; var verts = new Vector2 [ sides + 2 ] ; verts [ 0 ] = Vector2 . Zero ; for ( var i = 0 ; i <= sides ; i ++ ) verts [ i + 1 ] = new Vector2 ( expandedRadius * Mathf . cos ( stepSize * i ) , expandedRadius * Mathf . sin ( stepSize * i ) ) ; if ( _polygon == null ) _polygon = new Polygon ( verts ) ; else _polygon . _originalPoints = verts ; Polygon . rotatePolygonVerts ( entity . rotation - _spotAngle * 0.5f * Mathf . deg2Rad , _polygon . _originalPoints , _polygon . points ) ; }
calculates the points needed to encompass the spot light.
calculates the points needed to encompass the spot light .
// no need to recaluc if we dont have an Entity to work with // we only need a small number of verts for the spot polygon. We base how many off of the spot angle. Because we are approximating // an arc with a polygon we bump up the radius a bit so that our poly fully encompasses the spot area. // rotate our verts based on the Entity.rotation and offset half of the spot angle so that the center of the spot points in // the direction of rotation