コード例 #1
0
    // Update is called once per frame
    void Update()
    {
        if (menuvisible | helpvisible | chooser.enabled)
        {
            return;
        }

        //処理開始
        interval += Time.deltaTime;
        if (interval > 0.1f & ready & !chooser.getEnabled())
        {
            //終了時刻よりあとの時刻か
            if (current.CompareTo(finish) > 0)
            {
                if (shadowrenderer.getMode() == UmbralShadowRenderer.RECORDMODE)
                {
                    String filename = EclipseCalendar.getDateString(start.Year, start.Month, start.Day);

                    currenteclipsedata.writeJSON(filename + ".json");
                    saveTexture(filename, result);
                    if (umbralshadow != null)
                    {
                        saveTexture(filename + "_umbra", umbralshadow);
                    }
                    return;

                    ready    = false;
                    interval = 0.0f;
                }
                else if (shadowrenderer.getMode() == UmbralShadowRenderer.PLAYMODE)
                {
                    current = new DateTime(start.Year, start.Month, start.Day, start.Hour, start.Minute, 0, DateTimeKind.Utc);
                }
            }

            clock.setTime(current);
            //影描画
            shadowrenderer.drawLines(current);

            //テクスチャに結果を描き込む
            if (shadowrenderer.getMode() == UmbralShadowRenderer.RECORDMODE)
            {
                writeResult(earthshadow, result);
            }

            //地球の昼夜を描く
            currenteclipsedata.getPositions(current, posdata);
            shadowrenderer.drawNightSide(posdata);

            earthshadow.Apply();
            //時間を一つ進める
            current = current.AddMinutes(1.0);

            interval = 0.0f;
        }

        if (Application.platform == RuntimePlatform.Android & !chooser.enabled & !helpvisible)
        {
            // エスケープキー取得
            if (Input.GetKeyDown(KeyCode.Escape))
            {
                // アプリケーション終了処理
                Application.Quit();
                return;
            }
        }
    }
コード例 #2
0
    // Update is called once per frame
    void Update()
    {
        if (datachooser.enabled | helpvisible)
        {
            return;
        }

        //処理開始
        interval += Time.deltaTime;
        if (interval > 0.1f & ready)
        {
            currenteclipsedata.getPositions(current, posdata);

            //影描画
            shadowrenderer.drawLines(current);
            earthshadow.Apply();

            //時計に時間を通知
            clock.setTime(current);

            //太陽位置を計算してライトの位置と向きを変更する
            {
                //恒星時をもとに、背景の回転を行う(恒星時は春分点の時角)
                Material skybox = RenderSettings.skybox;
                skybox.SetFloat("_Rotation", (float)-posdata[EclipseData.PHAI]);//時角のマイナス方向に回転。skyboxのマテリアルは左右が逆

                //赤緯・赤経は北極から見て時計回り。時角、恒星時は反時計回り。時角に合わせて計算する
                //float ramda = -(float)((-asc + phai0) * DegToRad);これを書き換えて下の式になる
                float ramda       = (float)((posdata[EclipseData.SUN_ASC] - posdata[EclipseData.PHAI]) * DegToRad);
                float psy         = (float)(posdata[EclipseData.SUN_DEC] * DegToRad);
                float sundistance = 400;
                float x           = Mathf.Cos(psy) * Mathf.Cos(ramda) * sundistance;
                float y           = Mathf.Cos(psy) * Mathf.Sin(ramda) * sundistance;
                float z           = Mathf.Sin(psy) * sundistance;

                Vector3 sunpos = sunlight.transform.position;
                sunpos.Set(x, z, y);
                sunlight.transform.position = sunpos;
                sunpos.Normalize();
                sunpos *= -1;
                sunlight.transform.forward = sunpos;
            }

            //時間を一つ進める
            current = current.AddMinutes(1.0);
            //終了時刻よりあとの時刻か
            if (current.CompareTo(finish) > 0)
            {
                current = new DateTime(start.Year, start.Month, start.Day, start.Hour, start.Minute, 0, DateTimeKind.Utc);
            }
            interval = 0.0f;
        }

        //ピンチ操作
        //タッチによるスワイプを取得する
        //画面の縮小拡大を取得する
        if (Application.platform == RuntimePlatform.Android)
        {
            if (Input.touchCount == 0)
            {
                //windows の場合はコメントアウト
                if (pinch)
                {
                    pinch = false;
                }
                if (pressed)
                {
                    pressed = false;
                }
            }
            else if (Input.touchCount == 1 & lastTouchCount > 1)
            {
                if (pinch)
                {
                    pinch = false;
                }
                Touch[] touches   = Input.touches;
                Vector2 fingerpos = touches[0].position;
                lastx          = fingerpos.x;
                lasty          = fingerpos.y; //画面は左上が原点、マウスは左下が原点。なぜかタッチは左上原点のようだ。
                pressed        = true;
                lastTouchCount = Input.touchCount;
            }
            else if (Input.touchCount > 1)
            {
                if (pressed)
                {
                    pressed = false;
                }
                if (!pinch)
                {
                    pinch = true; lastRadius = 0.0f; lastTouchCount = Input.touchCount;
                }

                float Xamount = 0.0f;
                float Yamount = 0.0f;

                Touch[] alltouch = Input.touches;

                foreach (Touch t in alltouch)
                {
                    Vector2 pos = t.position;
                    Xamount += pos.x;
                    Yamount += pos.y;
                }
                float Xcenter       = Xamount / Input.touchCount;
                float Ycenter       = Yamount / Input.touchCount;
                float largestRadius = 0.0f;

                foreach (Touch t in alltouch)
                {
                    Vector2 pos    = t.position;
                    float   xdiff  = pos.x - Xcenter;
                    float   ydiff  = pos.y - Ycenter;
                    float   length = Mathf.Sqrt(xdiff * xdiff + ydiff * ydiff);
                    if (length > largestRadius)
                    {
                        largestRadius = length;
                    }
                }

                if (lastRadius != 0.0f & lastTouchCount == Input.touchCount)
                {
                    //カメラ画角の変更
                    float angleaddition = (lastRadius - largestRadius) * 0.05f;
                    maincam.fieldOfView = maincam.fieldOfView + angleaddition;
                    //画角の最小・最大角度はここでコントロールする
                    if (maincam.fieldOfView <= leastAngle)
                    {
                        maincam.fieldOfView = leastAngle;
                    }
                    else if (maincam.fieldOfView >= largestAngle)
                    {
                        maincam.fieldOfView = largestAngle;
                    }
                }
                lastTouchCount = Input.touchCount;
                lastRadius     = largestRadius;
            }
        }
        //ピンチ操作・終わり

        //マウス検知
        if (Input.GetMouseButtonDown(0))
        {
            Vector3 mousepos = Input.mousePosition;
            float   x        = mousepos.x;
            float   y        = Screen.height - mousepos.y; //画面は左上が原点、マウス(タッチ)は左下が原点

            if (!pressed)
            {
                pressed = true;
            }
            lastx = mousepos.x;
            lasty = mousepos.y;
        }

        //左ボタン上がった
        if (Input.GetMouseButtonUp(0))
        {
            if (pressed)
            {
                pressed = false;
            }
            //if (slidertapped) slidertapped = false;
        }

        if (pressed)
        {
            float xdiff = Input.mousePosition.x - lastx;
            float ydiff = Input.mousePosition.y - lasty;

            if (xdiff != 0.0f | ydiff != 0.0f)
            {
                positionUpdated(xdiff, ydiff);
            }

            lastx = Input.mousePosition.x;
            lasty = Input.mousePosition.y;
        }

        if (Application.platform == RuntimePlatform.Android)
        {
            // エスケープキー取得
            if (Input.GetKeyDown(KeyCode.Escape))
            {
                // アプリケーション終了処理
                Application.Quit();
                return;
            }
        }
    }