| /******************************************************************************* |
| * Copyright (c) 2018 Agence spatiale canadienne / Canadian Space Agency |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Pierre Allard, |
| * Regent L'Archeveque - initial API and implementation |
| * |
| * SPDX-License-Identifier: EPL-1.0 |
| *******************************************************************************/ |
| package org.eclipse.apogy.core.environment.earth.surface.ui.impl; |
| |
| import javax.vecmath.Color3f; |
| |
| import org.eclipse.apogy.core.environment.earth.surface.AtmosphereUtils; |
| |
| public class EarthSurfaceUIUtilitiesCustomImpl extends EarthSurfaceUIUtilitiesImpl { |
| |
| public static final double LOWER_SUN_ALTITUDE_FOR_TRANSPARENCY = Math.toRadians(-5.0); |
| public static final double LOWER_SUN_ALTITUDE_TRANSPARENCY = 1.0; |
| public static final double UPPER_SUN_ALTITUDE_FOR_TRANSPARENCY = Math.toRadians(0.0); |
| public static final double UPPER_SUN_ALTITUDE_TRANSPARENCY = 0.0; |
| |
| public static final Color3f DAY_SKY_COLOR = new Color3f(0, 0, 1); |
| public static final Color3f SUNSET_SKY_COLOR = new Color3f(((float) 201 / 255), 0, 1); |
| |
| @Override |
| public Color3f getSunLightColor(double sunAltitude) { |
| Color3f color; |
| if (sunAltitude >= 0) { |
| // Applies extinction of green and blue. |
| double colorExtinctionFactor = 1.0 - Math.exp(-sunAltitude / 0.053); |
| color = new Color3f(1, (float) colorExtinctionFactor, (float) colorExtinctionFactor); |
| |
| // Applies atmosphere extinction. |
| double sunIntensity = AtmosphereUtils.INSTANCE.getDirectSunIntensity(sunAltitude, 0.0); |
| double sunMaximumIntensity = AtmosphereUtils.INSTANCE.getDirectSunIntensity(Math.toRadians(90), 0.0); |
| float extinction = (float) (sunIntensity / sunMaximumIntensity); |
| |
| color.scale(extinction); |
| } else { |
| color = new Color3f(0, 0, 0); |
| } |
| |
| // System.out.println("Sun Light Color : " + color); |
| |
| return color; |
| } |
| |
| @Override |
| public double getSkyTransparency(double sunAltitude) { |
| double transparency = 0.0; |
| |
| if (sunAltitude < LOWER_SUN_ALTITUDE_FOR_TRANSPARENCY) { |
| transparency = LOWER_SUN_ALTITUDE_TRANSPARENCY; |
| } else if ((sunAltitude >= LOWER_SUN_ALTITUDE_FOR_TRANSPARENCY) |
| && (sunAltitude < UPPER_SUN_ALTITUDE_FOR_TRANSPARENCY)) { |
| transparency = (sunAltitude - LOWER_SUN_ALTITUDE_FOR_TRANSPARENCY) * UPPER_SUN_ALTITUDE_TRANSPARENCY |
| + (UPPER_SUN_ALTITUDE_FOR_TRANSPARENCY - sunAltitude) * LOWER_SUN_ALTITUDE_TRANSPARENCY; |
| |
| transparency = transparency / (UPPER_SUN_ALTITUDE_FOR_TRANSPARENCY - LOWER_SUN_ALTITUDE_FOR_TRANSPARENCY); |
| } else { |
| transparency = UPPER_SUN_ALTITUDE_TRANSPARENCY; |
| } |
| |
| return transparency; |
| } |
| |
| @Override |
| public Color3f getSkyColor(double sunAltitude) { |
| Color3f color = new Color3f(); |
| |
| double max = Math.toRadians(10); |
| double min = Math.toRadians(0); |
| if (sunAltitude < max) { |
| if (sunAltitude > min) { |
| float t = (float) ((sunAltitude - min) / (max - min)); |
| color.interpolate(SUNSET_SKY_COLOR, DAY_SKY_COLOR, t); |
| } else { |
| color = SUNSET_SKY_COLOR; |
| } |
| } else { |
| color = DAY_SKY_COLOR; |
| } |
| |
| return color; |
| } |
| |
| } // EnvironmentUIUtilitiesImpl |