예제 #1
0
        private void CreateBackground(Background layers, int layerCount)
        {
            Sprite stars = new Sprite(Content.Load <Texture2D>("Images/nebula1"));

            stars.Color = Color.White * 0.2f;
            stars.Scale = 3.0f;
            layers.AddLayer(stars, new Vector2(0.02f, 0.02f));

            List <Texture2D> nebulas = new List <Texture2D>();

            nebulas.Add(Content.Load <Texture2D>("Images/nebula1"));
            nebulas.Add(Content.Load <Texture2D>("Images/nebula2"));

            Random    r        = new Random();
            float     parallax = 1.0f;
            Rectangle areaSize = CurrentLevel.Bounds;

            for (int i = 0; i < layerCount; i++)
            {
                int           spritesPerLayer = 5 + r.Next(100);
                List <Sprite> sprites         = new List <Sprite>();
                for (int j = 0; j < spritesPerLayer; j++)
                {
                    int    si  = r.Next(100) % nebulas.Count;
                    Sprite neb = new Sprite(nebulas[si]);
                    neb.Position = Interpolations.GetRandomRectanglePoint(areaSize, r);
                    neb.Scale    = (float)(r.NextDouble() * 2f) + 0.1f;
                    neb.Rotation = (float)r.NextDouble() * MathHelper.PiOver2;
                    sprites.Add(neb);
                }
                layers.AddLayer(sprites, new Vector2(parallax, parallax));
                parallax += (0.9f / layerCount);
            }
        }
예제 #2
0
        private Background CreateBackground(int layerCount)
        {
            Background background = new Background(camera);

            Sprite stars = new Sprite(StateManager.Content.Load <Texture2D>("Images/nebula1"));

            stars.Color = Color.White * 0.2f;
            stars.Scale = 3.0f;
            background.AddLayer(stars, new Vector2(0.02f, 0.02f));

            List <Texture2D> nebulas = new List <Texture2D>();

            nebulas.Add(StateManager.Content.Load <Texture2D>("Images/nebula1"));
            nebulas.Add(StateManager.Content.Load <Texture2D>("Images/nebula2"));

            Random r = new Random();

            for (int i = 0; i < layerCount; i++)
            {
                int    si  = r.Next(100) % nebulas.Count;
                Sprite neb = new Sprite(nebulas[si]);
                neb.Position = Interpolations.GetRandomRectanglePoint(idleStateArea, r);
                neb.Scale    = (float)r.NextDouble() + 0.1f;
                neb.Rotation = (float)r.NextDouble() * MathHelper.PiOver2;
                float r2 = (float)r.NextDouble() * neb.Scale;
                background.AddLayer(neb, new Vector2(r2, r2));
            }

            return(background);
        }
예제 #3
0
        /// <summary>
        /// Make transition to non-active sate.
        /// </summary>
        /// <returns>Nothing.</returns>
        private IEnumerator TransitionState()
        {
            var timer = 0f;

            var begin = _state ? _onPosition : _offPosition;
            var end   = !_state ? _onPosition :_offPosition;

            while (timer < TransitionTime)
            {
                timer += SceneManager.Instance.MenuDeltaTime;
                Slider.anchoredPosition = Vector2.Lerp(begin, end, Interpolations.Smootherstep(timer / TransitionTime));
                yield return(new WaitForEndOfFrame());
            }

            _state        = !_state;
            _inTransition = false;

            if (_state)
            {
                OnActivate.Invoke();
                AudioListener.pause = false;
            }
            else
            {
                OnDeactivate.Invoke();
                AudioListener.pause = true;
                switchSource.PlayOneShot(switchSound, switchVolume);
            }
        }
예제 #4
0
        private float GetAnimationScale(GameTime gameTime)
        {
            if (!Interpolations.LinearTransition2(gameTime.ElapsedGameTime, ClickBounceSpeed, direction, ref currentAngle, AngleMin, AngleMax))
            {
                if (direction > 0)
                {
                    currentAngle    = AngleMax;
                    direction       = -1;
                    currentAmplify *= 0.5f;
                    if (currentAmplify <= 0.05f)
                    {
                        currentAmplify = 0.0f;
                    }
                }
                else
                {
                    currentAngle = AngleMin;
                    direction    = 1;
                }
            }
            float scale;

            if (animatingIn)
            {
                scale = (3.0f / 4f) + (float)Math.Sin(currentAngle) / 4f * currentAmplify;
            }
            else
            {
                scale = 1.0f - ((float)Math.Sin(currentAngle) / 4f * currentAmplify);
            }
            return(scale);
        }
        public void TestNearestNeighborPoint3()
        {
            Point3 a = new Point3(0.0f, 0.0f, 0.0f);
            Point3 b = new Point3(1.0f, 1.0f, 1.0f);

            Assert.AreEqual(a, Interpolations.NearestNeighbor(a, b, 0.0f));
            Assert.AreEqual(a, Interpolations.NearestNeighbor(a, b, 0.25f));
            Assert.AreEqual(b, Interpolations.NearestNeighbor(a, b, 0.5f));
            Assert.AreEqual(b, Interpolations.NearestNeighbor(a, b, 0.75f));
            Assert.AreEqual(b, Interpolations.NearestNeighbor(a, b, 1.0f));
        }
        public void TestLinearPoint3()
        {
            Point3 a = new Point3(0.0f, 0.0f, 1.0f);
            Point3 b = new Point3(1.0f, -2.0f, 1.0f);

            Assert.AreEqual(a, Interpolations.Linear(a, b, 0.0f));
            Assert.AreEqual(new Point3(0.25f, -0.5f, 1.0f), Interpolations.Linear(a, b, 0.25f));
            Assert.AreEqual(new Point3(0.5f, -1.0f, 1.0f), Interpolations.Linear(a, b, 0.5f));
            Assert.AreEqual(new Point3(0.75f, -1.5f, 1.0f), Interpolations.Linear(a, b, 0.75f));
            Assert.AreEqual(b, Interpolations.Linear(a, b, 1.0f));
        }
        public void TestLinearFloat3()
        {
            float a = 1.0f;
            float b = 1.0f;

            Assert.AreEqual(1.0f, Interpolations.Linear(a, b, 0.0f));
            Assert.AreEqual(1.0f, Interpolations.Linear(a, b, 0.25f));
            Assert.AreEqual(1.0f, Interpolations.Linear(a, b, 0.5f));
            Assert.AreEqual(1.0f, Interpolations.Linear(a, b, 0.75f));
            Assert.AreEqual(1.0f, Interpolations.Linear(a, b, 1.0f));
        }
        public void TestNearestNeighborFloat()
        {
            float a = 0.0f;
            float b = 1.0f;

            Assert.AreEqual(a, Interpolations.NearestNeighbor(a, b, 0.0f));
            Assert.AreEqual(a, Interpolations.NearestNeighbor(a, b, 0.25f));
            Assert.AreEqual(b, Interpolations.NearestNeighbor(a, b, 0.5f));
            Assert.AreEqual(b, Interpolations.NearestNeighbor(a, b, 0.75f));
            Assert.AreEqual(b, Interpolations.NearestNeighbor(a, b, 1.0f));
        }
        public void TestLinearFloat2()
        {
            float a = 0.0f;
            float b = -2.0f;

            Assert.AreEqual(a, Interpolations.Linear(a, b, 0.0f));
            Assert.AreEqual(-0.5f, Interpolations.Linear(a, b, 0.25f));
            Assert.AreEqual(-1.0f, Interpolations.Linear(a, b, 0.5f));
            Assert.AreEqual(-1.5f, Interpolations.Linear(a, b, 0.75f));
            Assert.AreEqual(b, Interpolations.Linear(a, b, 1.0f));
        }
예제 #10
0
    private float perlinNoise(double x, double y, double z)
    {
        if (repeat > 0)
        {
            x = x % repeat;
            y = y % repeat;
            z = z % repeat;
        }

        int xi = (int)x % 255;
        int yi = (int)y % 255;
        int zi = (int)z % 255;

        double xf = x - (int)x;
        double yf = y - (int)y;
        double zf = z - (int)z;

        //float u = interp.triangleInterpolation ((float)xf,0.5f,0,0,1f,0.001f);
        //float v = interp.triangleInterpolation ((float)yf,0.5f,0,0,1f,0.001f);
        //float w = interp.triangleInterpolation ((float)zf,0.5f,0,0,1f,0.001f);

        float u = Interpolations.perlinEaseCurve((float)xf);
        float v = Interpolations.perlinEaseCurve((float)yf);
        float w = Interpolations.perlinEaseCurve((float)zf);

        int aaa, aba, aab, abb, baa, bba, bab, bbb;

        aaa = p[p[p[xi] + yi] + zi];
        aba = p[p[p[xi] + inc(yi)] + zi];
        aab = p[p[p[xi] + yi] + inc(zi)];
        abb = p[p[p[xi] + inc(yi)] + inc(zi)];
        baa = p[p[p[inc(xi)] + yi] + zi];
        bba = p[p[p[inc(xi)] + inc(yi)] + zi];
        bab = p[p[p[inc(xi)] + yi] + inc(zi)];
        bbb = p[p[p[inc(xi)] + inc(yi)] + inc(zi)];

        float x1, x2, y1, y2;

        // The gradient function calculates the dot product between a pseudorandom
        // gradient vector and the vector from the input coordinate to the 8
        // surrounding points in its unit cube.
        // This is all then lerped together as a sort of weighted average based on the faded (u,v,w)
        // values we made earlier.

        x1 = Mathf.Lerp(grad(aaa, xf, yf, zf), grad(baa, xf - 1, yf, zf), u);
        x2 = Mathf.Lerp(grad(aba, xf, yf - 1, zf), grad(bba, xf - 1, yf - 1, zf), u);
        y1 = Mathf.Lerp(x1, x2, v);

        x1 = Mathf.Lerp(grad(aab, xf, yf, zf - 1), grad(bab, xf - 1, yf, zf - 1), u);
        x2 = Mathf.Lerp(grad(abb, xf, yf - 1, zf - 1), grad(bbb, xf - 1, yf - 1, zf - 1), u);
        y2 = Mathf.Lerp(x1, x2, v);

        return((Mathf.Lerp(y1, y2, w) + 1) / 2);
    }
예제 #11
0
    public float[] GamePointToGeoPoint(Vector3 GamePoint)
    {
        Vector3 gp = GamePoint;

        gp.x /= mapBoundaries.Scale.x;
        gp.z /= mapBoundaries.Scale.y;
        gp.x += MinPointOnMap.x;
        gp.z += MinPointOnMap.z;
        float[] ret = Interpolations.SimpleInterpolation(gp.x, gp.z, GameBoundaries, MinMaxLat, MinMaxLon);
        return(ret);
    }
예제 #12
0
        public Key(double inTime, object inValue, double inbTangentTime, object inbTangentValue, double inaTangentTime, object inaTangentValue, Interpolations inInterpolation)
        {
            _time  = inTime;
            _value = inValue;

            _interpolation = inInterpolation;

            _bTangentTime  = inbTangentTime;
            _bTangentValue = inbTangentValue;
            _aTangentTime  = inaTangentTime;
            _aTangentValue = inaTangentValue;
        }
예제 #13
0
    /// <summary>
    /// Converts a unity 3d space position to latitude/longitude
    /// </summary>
    /// <param name="position">Unity position</param>
    /// <returns>WGS84 [latitude, longitude] </returns>
    public static float[] Vector3ToLatLon(Vector3 position)
    {
        Vector3 reversescale = new Vector3(1f / mapboundary.Scale.x, 1, 1f / mapboundary.Scale.y);

        position.Scale(reversescale);
        position = position + MinPointOnMap;
        position = new Vector3(direction * position.x, 0, position.z);
        var calclat = Interpolations.linear(position.x, minmaxX[0], minmaxX[1], (float)databaseBounds.minlat, (float)databaseBounds.maxlat);
        var calclon = Interpolations.linear(position.z, minmaxY[0], minmaxY[1], (float)databaseBounds.minlon, (float)databaseBounds.maxlon);

        return(new float[] { calclat, calclon });
    }
        public void TestCubicFloat1()
        {
            float a = 0.0f;
            float b = 1.0f;
            float c = 1.0f;
            float d = 0.0f;

            Assert.AreEqual(b, Interpolations.Cubic(a, b, c, d, 0.0f));
            Assert.AreEqual(1.09375f, Interpolations.Cubic(a, b, c, d, 0.25f));
            Assert.AreEqual(1.125f, Interpolations.Cubic(a, b, c, d, 0.5f));
            Assert.AreEqual(1.09375f, Interpolations.Cubic(a, b, c, d, 0.75f));
            Assert.AreEqual(c, Interpolations.Cubic(a, b, c, d, 1.0f));
        }
예제 #15
0
        protected override void GenerateParticle(Particle p)
        {
            // Get a point along the line specified for this line emitter
            p.Position = Position;
            float spr = Interpolations.LinearInterpolate(
                Rotation - Spread / 2,
                Rotation + Spread / 2,
                random.NextFloat());

            p.LinearVelocity = new Vector2(
                MathFunctions.Sin(spr) * p.InitialSpeed,
                -MathFunctions.Cos(spr) * p.InitialSpeed);
        }
        public void TestCubicFloat2()
        {
            float a = 0.0f;
            float b = 1.0f;
            float c = 1.0f;
            float d = 2.0f;

            Assert.AreEqual(b, Interpolations.Cubic(a, b, c, d, 0.0f));
            Assert.AreEqual(1.046875f, Interpolations.Cubic(a, b, c, d, 0.25f));
            Assert.AreEqual(1.0f, Interpolations.Cubic(a, b, c, d, 0.5f));
            Assert.AreEqual(0.953125f, Interpolations.Cubic(a, b, c, d, 0.75f));
            Assert.AreEqual(c, Interpolations.Cubic(a, b, c, d, 1.0f));
        }
        public void TestCubicPoint3()
        {
            Point3 a = new Point3(0.0f, 0.0f, 0.0f);
            Point3 b = new Point3(1.0f, 1.0f, 1.0f);
            Point3 c = new Point3(1.0f, 1.0f, 2.0f);
            Point3 d = new Point3(0.0f, 2.0f, 3.0f);

            Assert.AreEqual(b, Interpolations.Cubic(a, b, c, d, 0.0f));
            Assert.AreEqual(new Point3(1.09375f, 1.046875f, 1.25f), Interpolations.Cubic(a, b, c, d, 0.25f));
            Assert.AreEqual(new Point3(1.125f, 1.0f, 1.5f), Interpolations.Cubic(a, b, c, d, 0.5f));
            Assert.AreEqual(new Point3(1.09375f, 0.953125f, 1.75f), Interpolations.Cubic(a, b, c, d, 0.75f));
            Assert.AreEqual(c, Interpolations.Cubic(a, b, c, d, 1.0f));
        }
        private TrackingEntry GetDataLinearAtIndex(int index, double time)
        {
            int[]         pair   = GetIndexPairFromIndex(index);
            TrackingEntry entry1 = m_entries[pair[0]];
            TrackingEntry entry2 = m_entries[pair[1]];
            float         t      = NormalizeTimeAtRange(time, entry1.TimeStamp, entry2.TimeStamp);

            return(new TrackingEntry(
                       time,
                       Interpolations.Linear(entry1.Position, entry2.Position, t),
                       Interpolations.Linear(entry1.Rotation, entry2.Rotation, t)
                       ));
        }
        private TrackingEntry GetDataCubicAtTime(int index, double time)
        {
            int[]         quad   = GetIndexQuadFromIndex(index);
            TrackingEntry entry1 = m_entries[quad[0]];
            TrackingEntry entry2 = m_entries[quad[1]];
            TrackingEntry entry3 = m_entries[quad[2]];
            TrackingEntry entry4 = m_entries[quad[3]];
            float         t      = NormalizeTimeAtRange(time, entry2.TimeStamp, entry3.TimeStamp);

            return(new TrackingEntry(
                       time,
                       Interpolations.Cubic(entry1.Position, entry2.Position, entry3.Position, entry4.Position, t),
                       Interpolations.Cubic(entry1.Rotation, entry2.Rotation, entry3.Rotation, entry4.Rotation, t)
                       ));
        }
예제 #20
0
        protected override void GenerateParticle(Particle p)
        {
            // Spawn randomly to any direction from the point
            float direction = Rotation;

            if (Flags.HasFlag(EmitterModes.RandomDirection))
            {
                direction = Interpolations.LinearInterpolate(
                    -MathConstants.PI, MathConstants.PI, random.NextFloat());
            }
            p.Position       = this.Position;
            p.LinearVelocity = new Vector2(
                MathFunctions.Sin(direction) * p.InitialSpeed,
                -MathFunctions.Cos(direction) * p.InitialSpeed);
        }
예제 #21
0
    void Start()
    {
        client  = ServicePropertiesClass.GetGapslabsService(ServicePropertiesClass.ServiceUri);
        geoinfo = transform.GetComponent <GeoInfo>();

        var go = GameObject.Find("AramGISBoundaries");

        mapBoundaries = go.GetComponent <MapBoundaries>();
        wcfCon        = mapBoundaries.OverrideDatabaseConnection ? mapBoundaries.GetOverridenConnectionString() : ServicePropertiesClass.ConnectionPostgreDatabase;

        boundsTemp = client.GetBounds(wcfCon);
        // Temporary - it appears the data for sweden includes some data that go to the north pole and it ruins all interpolations.
        boundsTemp.maxlon = 32;

        MinMaxLat = new float[2];
        MinMaxLon = new float[2];
        // Setting local values for target boundaries (Openstreetmap database). Used in interpolation as destination boundary.
        MinMaxLat[0] = (float)boundsTemp.minlat;
        MinMaxLat[1] = (float)boundsTemp.maxlat;
        MinMaxLon[0] = (float)boundsTemp.minlon;
        MinMaxLon[1] = (float)boundsTemp.maxlon;



        // Setting local values for 3d world boundaries. Used in interpolation as source boundary
        GameBoundaries        = new BoundsWCF();
        GameBoundaries.minlat = mapBoundaries.minMaxX[0];
        GameBoundaries.maxlat = mapBoundaries.minMaxX[1];
        GameBoundaries.minlon = mapBoundaries.minMaxY[0];
        GameBoundaries.maxlon = mapBoundaries.minMaxY[1];
        GameBoundLat          = new float[2];
        GameBoundLat[0]       = (float)GameBoundaries.minlat;
        GameBoundLat[1]       = (float)GameBoundaries.maxlat;
        GameBoundLon          = new float[2];
        GameBoundLon[0]       = (float)GameBoundaries.minlon;
        GameBoundLon[1]       = (float)GameBoundaries.maxlon;



        float[] MinPointOnArea =
            Interpolations.SimpleInterpolation(
                (float)mapBoundaries.minLat,
                (float)mapBoundaries.minLon,
                boundsTemp,
                GameBoundLat, GameBoundLon);
        MinPointOnMap = new Vector3(MinPointOnArea[0], 0, MinPointOnArea[1]);
    }
예제 #22
0
    void DoMyWindow(int windowID)
    {
        if (Application.isPlaying && windowID == 1)
        {
            // var result=Interpolations.SimpleInterpolation((float)node.lat,(float)node.lon,boundsTemp/*SelectedArea*/,minmaxX,minmaxY);

            float[] ToWorld = Interpolations.SimpleInterpolation(59.339589f, 17.9391974f, boundsTemp, GameBoundLat, GameBoundLon);
            ToWorld[0] -= MinPointOnMap.x;
            ToWorld[1] -= MinPointOnMap.z;
            ToWorld[0] *= mapBoundaries.Scale.x;
            ToWorld[1] *= mapBoundaries.Scale.y;
            //float[] p_prime=GamePointToGeoPoint(new Vector3(ToWorld[0],0,ToWorld[1]));
            float[] tempw = ToWorld;
            tempw[0] /= mapBoundaries.Scale.x;
            tempw[1] /= mapBoundaries.Scale.y;
            tempw[0] += MinPointOnMap.x;
            tempw[1] += MinPointOnMap.z;
            float[] p_prime = Interpolations.SimpleInterpolation(tempw[0], tempw[1], GameBoundaries, MinMaxLat, MinMaxLon);


            // float[] PointA = GamePointToGeoPoint(geoinfo.previousPositionA);
            float[] PointA = new float[] { geoinfo.previousPositionA.x, geoinfo.previousPositionA.z };
            PointA[0] /= mapBoundaries.Scale.x;
            PointA[1] /= mapBoundaries.Scale.y;
            PointA[0] += MinPointOnMap.x;
            PointA[1] += MinPointOnMap.z;
            PointA     = Interpolations.SimpleInterpolation(PointA[0], PointA[1], GameBoundaries, MinMaxLat, MinMaxLon);

            GUI.Label(new Rect(10, 20, WindowSize.width, 20), "Point A:" + geoinfo.previousPositionA.x + ", " + geoinfo.previousPositionA.z);
            GUI.Label(new Rect(10, 40, WindowSize.width, 20), "Point A\":" + PointA[0] + ", " + PointA[1]);
            GUI.Label(new Rect(10, 60, WindowSize.width, 20), "Point B:" + geoinfo.previousPositionB.x + ", " + geoinfo.previousPositionB.z);
            GUI.Label(
                new Rect(10, 80, WindowSize.width, 20),
                "Real: 59.3395890f,17.9391974f");
            GUI.Label(
                new Rect(10, 100, WindowSize.width, 20),
                "WORLD:" + ToWorld[0] + ", " + ToWorld[1]);
            GUI.Label(
                new Rect(10, 120, WindowSize.width, 20),
                "TEST Reverse:" + p_prime[0] + ", " + p_prime[1]);


            GUI.DragWindow(new Rect(0, 0, 10000, WindowSize.height));
        }
    }
예제 #23
0
        /// <summary>
        /// Moves camera and player if transition is in progress.
        /// </summary>
        void LateUpdate()
        {
            if (_activeTransition)
            {
                _transitionTimer = Mathf.Min(_transitionTimer + SceneManager.Instance.DeltaTime, CameraTransitionTime);
                var lerpRatio = _transitionTimer / CameraTransitionTime;

                lerpRatio = Interpolations.Interpolation(lerpRatio, CameraInterpolation);

                _cameraTransform.position = Vector3.Lerp(_cameraBeginPosition, CameraPosition.position, lerpRatio);
                _playerTransform.position = Vector3.Lerp(_playerBeginPosition, _playerTargetPosition, lerpRatio);
                _camera.orthographicSize  = Mathf.Lerp(_oldSize, NewWieportSize / 2f, lerpRatio);

                if (_transitionTimer >= CameraTransitionTime)
                {
                    _activeTransition = false;
                    _player.CheckpointRelease();
                }
            }
        }
예제 #24
0
파일: Gradient.cs 프로젝트: still-scene/t3
        public virtual void Read(JToken inputToken)
        {
            Steps.Clear();
            JToken gradientToken = inputToken[typeof(Gradient).Name];

            if (gradientToken == null)
            {
                return;
            }

            try
            {
                if (inputToken["Interpolation"] != null)
                {
                    Interpolation = (Interpolations)Enum.Parse(typeof(Interpolations), inputToken["Interpolation"].Value <string>());
                }

                foreach (var keyEntry in (JArray)gradientToken["Steps"])
                {
                    Steps.Add(new Step
                    {
                        NormalizedPosition = keyEntry["NormalizedPosition"].Value <float>(),
                        Id    = Guid.Parse(keyEntry["Id"].Value <string>()),
                        Color = new Vector4(keyEntry["Color"]["R"].Value <float>(),
                                            keyEntry["Color"]["G"].Value <float>(),
                                            keyEntry["Color"]["B"].Value <float>(),
                                            keyEntry["Color"]["A"].Value <float>()),
                    });
                }
            }
            catch (Exception e)
            {
                Log.Warning("Can't read gradient property " + e);
                if (Steps == null || Steps.Count < 1)
                {
                    Steps = CreateDefaultSteps();
                }
            }
        }
예제 #25
0
        protected override void GenerateParticle(Particle p)
        {
            // Get a point along the line specified for this line emitter
            p.Position = line.Lerp(random.NextFloat());
            if (Flags.HasFlag(EmitterModes.PositionRelative))
            {
                p.Position += Effect.Position;
            }

            // Spawn randomly to any direction (should change probably to
            // cast the particle to perpendicular direction from the line
            float direction = Rotation;

            if (Flags.HasFlag(EmitterModes.RandomDirection))
            {
                direction = Interpolations.LinearInterpolate(
                    -MathConstants.PI, MathConstants.PI, random.NextFloat());
            }
            p.LinearVelocity = new Vector2(
                MathFunctions.Sin(direction) * p.InitialSpeed,
                -MathFunctions.Cos(direction) * p.InitialSpeed);
        }
예제 #26
0
        private void AddPlanets(BackgroundLayer layer)
        {
            List <Texture2D> planets = new List <Texture2D>();

            planets.Add(Content.Load <Texture2D>("Images/sun"));
            planets.Add(Content.Load <Texture2D>("Images/earth"));
            planets.Add(Content.Load <Texture2D>("Images/jupiter"));

            Random        r           = new Random();
            Rectangle     areaSize    = CurrentLevel.Bounds;
            List <Entity> testList    = new List <Entity>();
            const float   minDistance = 1500;

            for (int i = 0; i < 20; i++)
            {
                Planet planet = new Planet(planets[r.Next(planets.Count)], areaSize, CurrentLevel.PhysicsWorld);
                bool   found  = false;
                while (!found)
                {
                    planet.Position = Interpolations.GetRandomRectanglePoint(areaSize, r);
                    int tooClose = 0;
                    foreach (Entity e in testList)
                    {
                        if (Vector2.Distance(planet.Position, e.Position) < minDistance)
                        {
                            tooClose++;
                        }
                    }

                    found = (tooClose == 0);
                }
                planet.Scale          = 2.0f;
                planet.Rotation       = (float)r.NextDouble() * MathHelper.PiOver2;
                planet.PlanetRotation = (float)r.NextDouble() * 0.0005f;
                CurrentLevel.AddEntity(planet, layer, true);
                testList.Add(planet);
            }
        }
예제 #27
0
    /// <summary>
    /// Converts a unity 3d space position to latitude/longitude given the MapBoundaries object.
    /// </summary>
    /// <param name="position">Unity position.</param>
    /// <param name="mb">MapBoundaries object.</param>
    /// <returns>WGS84 [latitude, longitude].</returns>
    public static float[] Vector3ToLatLon(Vector3 position, MapBoundaries mb)
    {
        var databaseBounds = new BoundsWCF()
        {
            minlat = mb.dbBoundMinLat,
            maxlat = mb.dbBoundMaxLat,
            minlon = mb.dbBoundMinLon,
            maxlon = mb.dbBoundMaxLon
        };

        float[] MinPointOnArea = SimpleInterpolation((float)mb.minLat, (float)mb.minLon, databaseBounds, mb.minMaxX, mb.minMaxY);
        var     MinPointOnMap  = new Vector3(direction * MinPointOnArea[0], 0, MinPointOnArea[1]);

        Vector3 reversescale = new Vector3(1f / mb.Scale.x, 1, 1f / mb.Scale.y);

        position.Scale(reversescale);
        position = position + MinPointOnMap;
        position = new Vector3(direction * position.x, 0, position.z);
        var calclat = Interpolations.linear(position.x, mb.minMaxX[0], mb.minMaxX[1], (float)mb.dbBoundMinLat, (float)mb.dbBoundMaxLat);
        var calclon = Interpolations.linear(position.z, mb.minMaxY[0], mb.minMaxY[1], (float)mb.dbBoundMinLon, (float)mb.dbBoundMaxLon);

        return(new float[] { calclat, calclon });
    }
예제 #28
0
    string wcfCon = ServicePropertiesClass.ConnectionPostgreDatabase; // .ConnectionDatabase;
    // Use this for initialization
    void Start()
    {
        locatorArrowA = GameObject.CreatePrimitive(PrimitiveType.Cube);
        locatorArrowA.transform.localScale = new Vector3(0.5f, 100, 0.5f);
        locatorArrowA.transform.position   = Vector3.zero;
        locatorArrowA.GetComponent <Renderer>().material = Resources.Load("A") as Material;
        locatorArrowA.name = "A";
        Object.DestroyImmediate(locatorArrowA.GetComponent <BoxCollider>());
        previousPositionA = Vector3.zero;

        locatorArrowB = GameObject.CreatePrimitive(PrimitiveType.Cube);
        locatorArrowB.transform.localScale = new Vector3(0.5f, 100, 0.5f);
        locatorArrowB.transform.position   = Vector3.zero;
        locatorArrowB.GetComponent <Renderer>().material = Resources.Load("B") as Material;
        Object.DestroyImmediate(locatorArrowB.GetComponent <BoxCollider>());
        locatorArrowB.name = "B";
        previousPositionB  = Vector3.zero;

        var go         = GameObject.Find("AramGISBoundaries");
        var connection = go.GetComponent <MapBoundaries>();

        wcfCon = connection.OverrideDatabaseConnection ? connection.GetOverridenConnectionString() : ServicePropertiesClass.ConnectionPostgreDatabase;

        client = ServicePropertiesClass.GetGapslabsService(ServicePropertiesClass.ServiceUri);

        Interpolations.MyLog("init Router");
        try
        {
            client.InitializeRouter(wcfCon);
        }
        catch (System.TimeoutException timeout)
        {
            Debug.LogException(timeout);
        }
        Interpolations.MyLog("Router initialized successfully.");
    }
예제 #29
0
        public unsafe ColorMatrix Resize(Int32Size size, Interpolations interpolation)
        {
            var result = new ColorMatrix(size.Height.UInt32(), size.Width.UInt32());

            var xs = Columns.Single() / size.Width.Single();
            var ys = Rows.Single() / size.Height.Single();

            float fracx, fracy, ifracx, ifracy, sx, sy, l0, l1, rf, gf, bf;
            int   c, x0, x1, y0, y1;
            byte  c1a, c1r, c1g, c1b, c2a, c2r, c2g, c2b, c3a, c3r, c3g, c3b, c4a, c4r, c4g, c4b;
            byte  a, r, g, b;

            int[] pixels = new int[Columns * Rows];

            var total = 0;

            for (uint x = 0; x < Columns; x++)
            {
                for (uint y = 0; y < Rows; y++)
                {
                    pixels[total++] = Convert(GetValue(y, x));
                }
            }

            int widthSource = Columns.Int32(), heightSource = Rows.Int32();

            //Nearest Neighbor
            if (interpolation == Interpolations.NearestNeighbor)
            {
                for (var y = 0; y < size.Height; y++)
                {
                    for (var x = 0; x < size.Width; x++)
                    {
                        sx = x * xs;
                        sy = y * ys;
                        x0 = (int)sx;
                        y0 = (int)sy;

                        var i  = y0 * widthSource + x0;
                        var cc = Convert(pixels[i]);
                        result.SetValue(y.UInt32(), x.UInt32(), cc);
                    }
                }
            }

            //Bilinear
            else if (interpolation == Interpolations.Bilinear)
            {
                for (var y = 0; y < size.Height; y++)
                {
                    for (var x = 0; x < size.Width; x++)
                    {
                        sx = x * xs;
                        sy = y * ys;
                        x0 = (int)sx;
                        y0 = (int)sy;

                        // Calculate coordinates of the 4 interpolation points
                        fracx  = sx - x0;
                        fracy  = sy - y0;
                        ifracx = 1f - fracx;
                        ifracy = 1f - fracy;
                        x1     = x0 + 1;
                        if (x1 >= widthSource)
                        {
                            x1 = x0;
                        }
                        y1 = y0 + 1;
                        if (y1 >= heightSource)
                        {
                            y1 = y0;
                        }


                        // Read source color
                        c   = pixels[y0 * widthSource + x0];
                        c1a = (byte)(c >> 24);
                        c1r = (byte)(c >> 16);
                        c1g = (byte)(c >> 8);
                        c1b = (byte)(c);

                        c   = pixels[y0 * widthSource + x1];
                        c2a = (byte)(c >> 24);
                        c2r = (byte)(c >> 16);
                        c2g = (byte)(c >> 8);
                        c2b = (byte)(c);

                        c   = pixels[y1 * widthSource + x0];
                        c3a = (byte)(c >> 24);
                        c3r = (byte)(c >> 16);
                        c3g = (byte)(c >> 8);
                        c3b = (byte)(c);

                        c   = pixels[y1 * widthSource + x1];
                        c4a = (byte)(c >> 24);
                        c4r = (byte)(c >> 16);
                        c4g = (byte)(c >> 8);
                        c4b = (byte)(c);


                        // Calculate colors
                        // Alpha
                        l0 = ifracx * c1a + fracx * c2a;
                        l1 = ifracx * c3a + fracx * c4a;
                        a  = (byte)(ifracy * l0 + fracy * l1);

                        // Red
                        l0 = ifracx * c1r + fracx * c2r;
                        l1 = ifracx * c3r + fracx * c4r;
                        rf = ifracy * l0 + fracy * l1;

                        // Green
                        l0 = ifracx * c1g + fracx * c2g;
                        l1 = ifracx * c3g + fracx * c4g;
                        gf = ifracy * l0 + fracy * l1;

                        // Blue
                        l0 = ifracx * c1b + fracx * c2b;
                        l1 = ifracx * c3b + fracx * c4b;
                        bf = ifracy * l0 + fracy * l1;

                        // Cast to byte
                        r = (byte)rf;
                        g = (byte)gf;
                        b = (byte)bf;

                        result.SetValue(y.UInt32(), x.UInt32(), Color.FromArgb(a, r, g, b));
                    }
                }
            }
            return(result);
        }
예제 #30
0
 public override void Apply(Particle p, float elapsedSeconds)
 {
     p.Depth = Interpolations.LinearInterpolate(
         Initial, Final, p.TTLPercent);
 }