/* // * private void drawDayLightSide(int hinode, int hinoiri, int y) * { * // Log.d("WORLDCLOCK", "left = " +hinode + " right = " +hinoiri); * // Log.d("WorldClock", "y=" + y); * if (hinode <= hinoiri) * { * for (int i = hinode; i <= hinoiri; i++) * { * screen.SetPixel(i, y, worldmap.getPixel(i, y)); * } * } * else * { * for (int i = hinode; i < wholewidth; i++) * { * screen.SetPixel(i, y, worldmap.getPixel(i, y)); * } * for (int i = 0; i <= hinoiri; i++) * { * screen.SetPixel(i, y, worldmap.getPixel(i, y)); * } * } * } */ // private void drawTwilight(double latitude, int startx, int endx, int y) { int addition = startx <= endx ? 1 : -1; double longitude = 0.0; if (startx < 0 || startx >= wholewidth || endx < 0 || endx >= wholewidth) { return; } for (int i = startx; i != endx; i += addition) { longitude = (double)i / (double)wholewidth * 360.0; // double phai = StarPosition.getSidereal(timevalue, time / 24.0, longitude);//?P???? double phai = phai0 + longitude; //地方恒星時 =グリニッジ恒星時+経度 double altitude = StarPosition.getSunAltitude(asc, dec, latitude, phai); //???x if (altitude > 0.0) { continue; } if (!Double.IsNaN(altitude)) { double ratio = 1.0f - (8.0 + Math.Floor(altitude)) / 12.0; if (ratio >= 1.0) { screen.SetPixel(i, y, nightside); //screen.SetPixel(i, y, nightmap.getPixel(i, y)); } //else if(ratio > 1.0) screen.setPixel(i, y, worldmap.getPixel(i, y)); else { float alpha = nightside.a; alpha *= (float)ratio; screen.SetPixel(i, y, new Color(nightside.r, nightside.g, nightside.b, alpha)); } // screen.SetPixel(i, y, composeColors(nightmap.getPixel(i, y), worldmap.getPixel(i, y), ratio)); } } }
void Update() { //画角値の確認 if (!calibrated) { if (Calibration.calibrated) { horizontalFOV = Calibration.horizontal; verticalFOV = Calibration.vertical; calibrated_orientation = (int)Calibration.deviceOrientation; appdata.HorizontalAngle = horizontalFOV; appdata.VerticalAngle = verticalFOV; appdata.saveApplicationData(); calibrated = true; } else { #if UNITY_ANDROID // Javaのオブジェクトを作成 AndroidJavaClass nativeDialog = new AndroidJavaClass("studio.beautifulworld.dialoglibrary.MenuDialog"); // Context(Activity)オブジェクトを取得する AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); AndroidJavaObject context = unityPlayer.GetStatic <AndroidJavaObject>("currentActivity"); // AndroidのUIスレッドで動かす context.Call("runOnUiThread", new AndroidJavaRunnable(() => { // ダイアログ表示のstaticメソッドを呼び出す nativeDialog.CallStatic( "showMessages", context, "お知らせ", "画角の値が記録されていません。\nキャリブレーションを実行します。"); })); #endif moveToCalibration(); } } //データ選択・又は地点選択の場合、以後の処理はしない if (chooser.enabled | pointchooser.enabled | helpvisible) { return; } //処理開始 interval += Time.deltaTime; if (interval > 0.1f & ready) { currenteclipsedata.getPositions(current, posdata); clock.setTime(current); if (!Input.location.isEnabledByUser) { state = LOCATION_UNAVAILABLE; } else { LocationInfo locinfo = Input.location.lastData; magnetism = false; if (locinfo.longitude > 122.5f & locinfo.longitude <150.0f& locinfo.latitude> 23.0f & locinfo.latitude < 45.5f) { magnetism = true; //磁気偏角計算 float declination_angle = TerrestrialMagnetism.getMagneticDeclination(locinfo.longitude, locinfo.latitude); declination = Quaternion.Euler(0.0f, declination_angle, 0.0f); } float height = 0;//高度 if (locationmode == CURRENT_LOCATION) { longitude = locinfo.longitude; latitude = locinfo.latitude; height = locinfo.altitude; } float[,] matrix = caliculation.getMatrix(longitude, latitude, height); float[,] inverse = caliculation.getInverseMatrix(matrix); //debug /* * //分、秒を含めて時間で表す * double hour = current.Hour +9+ current.Minute / 60.0 + current.Second / 3600.0; * double T = StarPosition.getTime(current.Year, current.Month, current.Day, hour); * //太陽の黄経を計算するelon:ecliptic longitude * double elon = StarPosition.getSunEclipticLongitude(T); * //黄道傾角を計算する * double e = StarPosition.getInclination(T);// * //太陽の赤経に変換 * double asc = StarPosition.getRightAscension(elon, e);// * //太陽の赤緯に変換 * double dec = StarPosition.getDeclination(elon, e);// //恒星時を計算する * double phai0 = StarPosition.getSidereal(T, hour / 24.0, longitude);//経過時間を引く必要があるので時間を別に与える */ //食分計算 //VesselElements ve = new VesselElements(posdata[EclipseData.SUN_ASC], posdata[EclipseData.SUN_DEC], posdata[EclipseData.SUN_DIST], //posdata[EclipseData.MOON_ASC], posdata[EclipseData.MOON_DEC], posdata[EclipseData.MOON_DIST], current); double phai = posdata[EclipseData.PHAI] + longitude;// longitude;//地方恒星時=グリニッジ恒星時+経度。恒星時は反時計回り、経度は時計回り //太陽の方位・高度を計算する sun_direction = StarPosition.getSunDirection(posdata[EclipseData.SUN_ASC], posdata[EclipseData.SUN_DEC], latitude, phai); sun_altitude = StarPosition.getSunAltitude(posdata[EclipseData.SUN_ASC], posdata[EclipseData.SUN_DEC], latitude, phai); //コンパス空間に写像する //太陽の方向ベクトルを求める double sunz = Math.Sin(sun_altitude / RadToDeg); double suny = Math.Cos(sun_altitude / RadToDeg); double sunx = suny * Math.Cos((90.0 - sun_direction) / RadToDeg); suny = suny * Math.Sin((90.0 - sun_direction) / RadToDeg); double[] sun_vector = new double[] { sunx, suny, sunz };//角度から算出したベクトルなので、現在位置は引く必要はない //太陽への方向ベクトル単位化 double norm = Math.Sqrt(sun_vector[0] * sun_vector[0] + sun_vector[1] * sun_vector[1] + sun_vector[2] * sun_vector[2]); sun_vector[0] /= norm; sun_vector[1] /= norm; sun_vector[2] /= norm; //太陽の方向が地平線の下 if (sun_vector[2] < 0.0f) { state = UNDER_HORIZON; } else { //デバイスの向きを検出する Quaternion gyro = Input.gyro.attitude; camrotation.Set(-gyro.x, -gyro.y, gyro.z, gyro.w); camrotation = Quaternion.Euler(90.0f, 0.0f, 0.0f) * camrotation; //向き検出・終わり //デバイス座標系に変換 Quaternion inverseQ = Quaternion.Inverse(camrotation); Vector3[] sunandmoon = new Vector3[2]; sunandmoon[0] = inverseQ * new Vector3((float)sun_vector[0], (float)sun_vector[2], (float)sun_vector[1]); //sunandmoon[1] = inverseQ * new Vector3((float)moon_vector[0], (float)moon_vector[2], (float)moon_vector[1]); //最後に有効になったデバイス向きを取得する DeviceOrientation orientation = camview.getLastOrienation(); //画角とタンジェント値を得る float[] viewangles = new float[2]; getViewAngle(orientation, viewangles); float verticalFOV = viewangles[1] / RadToDeg; float horizontalFOV = viewangles[0] / RadToDeg; float screen_tangent_horizontal = Mathf.Tan(horizontalFOV); float screen_tangent_vertical = Mathf.Tan(verticalFOV); float ratio = 0.5f / (screen_tangent_vertical * 2); for (int i = 0; i < 1; i++) { //磁気補正 if (magnetism) { sunandmoon[i] = declination * sunandmoon[i]; } //後ろの場合も見えないので、手順をスキップする。 float x_angle = Mathf.Atan(sunandmoon[i].x / sunandmoon[i].z); float y_angle = Mathf.Atan(sunandmoon[i].y / sunandmoon[i].z); if (Mathf.Abs(x_angle) < horizontalFOV & Mathf.Abs(y_angle) < verticalFOV & sunandmoon[i].z > 0) { float screenX = Mathf.Tan(x_angle) / screen_tangent_horizontal * Screen.width / 2 + Screen.width / 2 - images[SUNIMAGE].width / 2; float screenY = Screen.height / 2 - Mathf.Tan(y_angle) / screen_tangent_vertical * Screen.height / 2 - images[SUNIMAGE].height / 2; //datas.targetposition.Set(x, y, targetbox.width, targetbox.height); switch (i) { case 0: state = INSIDE_SCREEN; sunrect.Set(screenX, screenY, images[SUNIMAGE].width * ratio, images[SUNIMAGE].height * ratio); break; //case 1: moonSeeable = true; moonrect.Set(screenX, screenY, moonbox.width * ratio, moonbox.height * ratio); break; } blink = true; blinkinterval = 0.0f; } else { state = OUTSIDE_SCREEN; //太陽の位置を示すアイコンを決める getGuideImage(sunandmoon[0]); } }//for終わり } //デバイス座標系に変換・終わり } //時間を一つ進める 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.GetKeyDown(KeyCode.Escape)) { Input.gyro.enabled = false; Input.location.Stop(); Input.compass.enabled = false; // アプリケーション終了処理 Application.Quit(); return; } } }