예제 #1
0
 // Update is called once per frame
 void Update()
 {
     date = GlobalClock.GetTime();
     updatePosition(date);
     IDictionary <string, double> result = SunPosition.CalculateSunPosition(date, latitude, longitude);
     //Debug.Log(date);
 }
예제 #2
0
파일: Sun.cs 프로젝트: cyung3/183db
    // Update is called once per frame
    void Update()
    {
        date = GlobalClock.GetTime();
        updatePosition(date);
        IDictionary <string, double> result = SunPosition.CalculateSunPosition(date, 34, 118);

        Debug.Log(date);
    }
예제 #3
0
파일: Sun.cs 프로젝트: cyung3/183db
    void updatePosition(System.DateTime date)
    {
        IDictionary <string, double> result = SunPosition.CalculateSunPosition(date, 34, 118);
        float X = (float)(sunDistance * System.Math.Cos(result["azimuth"]));
        float Y = (float)(sunDistance * System.Math.Sin(result["azimuth"]));
        float Z = (float)(sunDistance * System.Math.Sin(result["altitude"]));

        transform.position = new Vector3(X, Y, Z);
    }
예제 #4
0
    void SetPosition()
    {
        Vector3 angles = new Vector3();

        SunPosition.CalculateSunPosition(time, (double)latitude, (double)longitude, out azi, out alt);
        angles.x = (float)alt * Mathf.Rad2Deg;
        angles.y = (float)azi * Mathf.Rad2Deg;
        transform.localRotation = Quaternion.Euler(angles);
        light.intensity         = Mathf.InverseLerp(-12, 0, angles.x);
    }
예제 #5
0
    public float[] GetAngles(DateTime datTim)
    {
        double alt;
        double azi;

        SunPosition.CalculateSunPosition(datTim, latitude, longitude, UTC, out azi, out alt);
        return(new float[2] {
            (float)alt, (float)azi
        });;
    }
예제 #6
0
    void updatePosition(System.DateTime date)
    {
        IDictionary <string, double> result = SunPosition.CalculateSunPosition(date, latitude, longitude);

        x = (float)(sunDistance * System.Math.Cos(result["azimuth"]) * System.Math.Cos(result["altitude"]));
        z = (float)(sunDistance * System.Math.Sin(result["azimuth"]) * System.Math.Cos(result["altitude"]));
        y = (float)(sunDistance * System.Math.Sin(result["altitude"]));
        transform.position          = new Vector3(x, y, z);
        lighting.transform.position = new Vector3(x, y, z);
    }
예제 #7
0
    // Update is called once per frame
    void Update()
    {
        lightComp.shadows = LightShadows.Hard;
        lightComp.type    = LightType.Directional;
        lightComp.color   = Color.blue;


        //Getting GPS coordinates of the device from Location Service
        latitude  = LocationService.Instance.latitude;
        longitude = LocationService.Instance.longitude;
        Debug.Log("Latitude: " + latitude + "Longitude: " + longitude);

        //Getting Azimuth and Alitutde angle according to Sun's current position using SunPosition Service
        //PSA algorithm can also be used from class SunPositionPSA
        //PSA algorithm was valid from 1999-2015 after that it introduces a error in calculatin SunPosition

        SunPosition sp = new SunPosition();

        sp.CalculateSunPosition(DateTime.Now, latitude, longitude);
        azimuthAngle  = sp.azimuth;
        altitudeAngle = sp.altitude;
        Debug.Log("Azimuth: " + azimuthAngle + " altitude: " + altitudeAngle);

        //Estimating the position of sun according to the users GPS coordinates(latitude,longitude)
        calculateSunDirection(azimuthAngle, altitudeAngle);

        //Hitting the web api to find out the current skycondition(Cloudy,Partly Cloudy,Clear sky)
        skyCondition = WeatherApi.Instance.skyCondition;
        skyCondition = "clear-day";
        float[] sensorValue = null;
        //Calculating shadow Strength according to SkyConditions
#if UNITY_ANDROID
        if (plugin != null)
        {
            //Initializing the plugin to read Ambient sensor light value in lux units
            sensorValue = plugin.Call <float[]>("getSensorValues", "light");
            if (sensorValue != null)
            {
                lightComp.shadowStrength = calculateShadowIntensity(sensorValue[0], skyCondition);
            }
            else
            {
                lightComp.shadowStrength = 0F;
            }
        }
    #endif

        message = "The shadow strength is: " + lightComp.shadowStrength + " ALS value is: " + sensorValue[0] +
                  " Latitude is: " + latitude + " Longitude is: " + longitude + " Sky Condition is: " + skyCondition +
                  " Azimuth is: " + azimuthAngle + " Altitude is: " + altitudeAngle;
    }
예제 #8
0
    /*
     * Called at each frame
     * Rotate the sun given the speed
     */
    void Update()
    {
        dateTime = dateTime.AddHours(speed * Time.deltaTime);
        Vector3 angles = new Vector3();
        double  alt;
        double  azi;

        SunPosition.CalculateSunPosition(dateTime, latitude, longitude, UTC, out azi, out alt);

        angles.x = (float)alt * Mathf.Rad2Deg;
        angles.y = (float)azi * Mathf.Rad2Deg;

        transform.eulerAngles = angles;
        sunLight.intensity    = Mathf.InverseLerp(-12, 0, angles.x);
    }
예제 #9
0
    private void ChangeSunPosition()
    {
        var    angles = new Vector3();
        double alt;
        double azi;

        SunPosition.CalculateSunPosition(dateTimeNow, (double)latitude, (double)longitude, out azi, out alt);
        angles.x = (float)alt * Mathf.Rad2Deg;
        angles.y = (float)azi * Mathf.Rad2Deg;

        EnviromentSettings.SetSunAngle(angles);

        UpdateWheelAccordingToSun();
        UpdateNumericInputs();
    }
예제 #10
0
    private void X_SetSunAngle()
    {
        double  alt, azi;
        Vector3 angles = new Vector3();

        // Berechnen
        SunPosition.CalculateSunPosition(_time, (double)_latitude, (double)_longitude, out azi, out alt);
        // Als Euler Winkel speichern
        angles.x = (float)alt * Mathf.Rad2Deg;
        angles.y = (float)azi * Mathf.Rad2Deg;
        _sunLight.transform.rotation = Quaternion.Euler(angles);
        // Sonne und Nachtlicht (de)aktivieren
        _sunLight.intensity = Mathf.InverseLerp(-12, 0, angles.x);
        _sunLight.gameObject.SetActive(_sunLight.intensity > 0);
        _nightLight.gameObject.SetActive(_sunLight.intensity == 0);
    }
예제 #11
0
파일: Sun.cs 프로젝트: cyung3/183db
    // Update is called once per frame
    void Update()
    {
        date = new System.DateTime(2020, 4, 8, (int)hour, (int)minutes, 0);
        updatePosition(date);
        Debug.Log(date.ToString());
        IDictionary <string, double> result = SunPosition.CalculateSunPosition(date, 34, 118);

        minutes += 0.5f;
        if (minutes >= 60)
        {
            minutes = 0;
            hour   += 1;
        }
        if (hour >= 23)
        {
            hour = 0;
        }
    }
예제 #12
0
    IEnumerator AdjustLightAngle()
    {
        while (true)
        {
            // Refresh latitude/longitude
            lat = Input.location.lastData.latitude;
            lon = Input.location.lastData.longitude;

            // Refresh Sun position
            SunPosition.Position sunPos = SunPosition.CalculateSunPosition(DateTime.Now, lat, lon);
            sunAltitude = sunPos.Altitude;
            sunAzimuth  = sunPos.Azimuth;

            double xRot = sunAltitude;
            // Adjust to account for initial orientation of phone
            double yRot = sunAzimuth - initialNorthOffset + 180;

            // Adjust rotation angle of directional light (i.e. sun)
            transform.rotation = Quaternion.Euler((float)xRot, (float)yRot, 0.0f);

            yield return(new WaitForSeconds(shadowRefreshSeconds));
        }
    }
예제 #13
0
        protected override async void Start()
        {
            base.Start();

            hud = new MonoDebugHud(this);
            hud.Show(Color.Yellow, 24);

            var timeLabel = new Text {
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment   = VerticalAlignment.Top
            };

            timeLabel.SetColor(new Color(0f, 1f, 0f));
            timeLabel.SetFont(font: CoreAssets.Fonts.AnonymousPro, size: 30);
            UI.Root.AddChild(timeLabel);

            var azAltLabel = new Text {
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment   = VerticalAlignment.Bottom
            };

            azAltLabel.SetColor(new Color(0f, 1f, 0f));
            azAltLabel.SetFont(font: CoreAssets.Fonts.AnonymousPro, size: 30);
            UI.Root.AddChild(azAltLabel);

            ResourceCache.AutoReloadResources = true;
            Viewport.SetClearColor(Color.Black);

            earthNode = RootNode.CreateChild();
            earthNode.SetScale(5f);
            earthNode.Rotation = new Quaternion(0, -180, 0);
            var earthModel = earthNode.CreateComponent <Sphere>();

            earthModel.Material = Material.FromImage("Textures/Earth.jpg");

            Zone.AmbientColor = new Color(0.2f, 0.2f, 0.2f);
            LightNode.ChangeParent(Scene);
            LightNode.Position = Vector3.Zero;
            Light.Range        = 10;
            Light.Brightness   = 1f;
            Light.LightType    = LightType.Directional;

            AddMarker(0, 0, "(0, 0)");
            AddMarker(53.9045f, 27.5615f, "Minsk");
            AddMarker(51.5074f, 0.1278f, "London");
            AddMarker(40.7128f, -74.0059f, "New-York");
            AddMarker(37.7749f, -122.4194f, "San Francisco");
            AddMarker(39.9042f, 116.4074f, "Beijing");
            AddMarker(-31.9505f, 115.8605f, "Perth");

            var sunNode      = RootNode.CreateChild();
            var sunModelNode = sunNode.CreateChild();

            sunModelNode.Position = new Vector3(0, 4, 0);
            sunModelNode.SetScale(1);

            var sun = sunModelNode.CreateComponent <Sphere>();

            sun.Color = new Color(15, 10, 5);

            // update the Sun's position based on time
            var   time = DateTime.Now;
            float alt, az;

            SunPosition.CalculateSunPosition(time, 0f, 0f, out az, out alt);
            sunNode.Rotation = new Quaternion(-az, 0, alt);
            LightNode.SetDirection(RootNode.WorldPosition - sunModelNode.WorldPosition);

            timeLabel.Value  = time.ToShortTimeString();
            azAltLabel.Value = $"Azimuth: {az:F1},  Altitude: {alt:F1}";
        }