001 //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/branches/2.2_testing/src/org/deegree/ogcwebservices/wpvs/utils/SunLight.java $
002 /*---------------- FILE HEADER ------------------------------------------
003
004 This file is part of deegree.
005 Copyright (C) 2001-2008 by:
006 EXSE, Department of Geography, University of Bonn
007 http://www.giub.uni-bonn.de/deegree/
008 lat/lon GmbH
009 http://www.lat-lon.de
010
011 This library is free software; you can redistribute it and/or
012 modify it under the terms of the GNU Lesser General Public
013 License as published by the Free Software Foundation; either
014 version 2.1 of the License, or (at your option) any later version.
015
016 This library is distributed in the hope that it will be useful,
017 but WITHOUT ANY WARRANTY; without even the implied warranty of
018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019 Lesser General Public License for more details.
020
021 You should have received a copy of the GNU Lesser General Public
022 License along with this library; if not, write to the Free Software
023 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
024
025 Contact:
026
027 Andreas Poth
028 lat/lon GmbH
029 Aennchenstraße 19
030 53177 Bonn
031 Germany
032 E-Mail: poth@lat-lon.de
033
034 Prof. Dr. Klaus Greve
035 Department of Geography
036 University of Bonn
037 Meckenheimer Allee 166
038 53115 Bonn
039 Germany
040 E-Mail: greve@giub.uni-bonn.de
041
042 ---------------------------------------------------------------------------*/
043 package org.deegree.ogcwebservices.wpvs.utils;
044
045 import javax.vecmath.Color3f;
046
047 /**
048 * class for calculating sun light according to a specific tima, day of
049 * the year (northern hemisper)
050 *
051 *
052 * @version $Revision: 9345 $
053 * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
054 * @author last edited by: $Author: apoth $
055 *
056 * $Revision: 9345 $, $Date: 2007-12-27 17:22:25 +0100 (Do, 27 Dez 2007) $
057 *
058 */
059 public class SunLight {
060
061 private static final float BASE_LIGHT_INTENSITY = 0.95f;
062 private SunPosition sunPosition;
063 private double latitude;
064
065 /**
066 * @param latitude the position on the earth
067 * @param sunPosition the Position of the sun
068 */
069 public SunLight( double latitude, SunPosition sunPosition ){
070 this.latitude = latitude;
071 this.sunPosition = sunPosition;
072 }
073
074
075 /**
076 * @return a Color of the sunlight
077 */
078 public Color3f calculateSunlight( ) {
079
080 double vDir = sunPosition.getVerticalSunposition( latitude );
081 float c = 7.25f*((float)Math.sin( vDir ));
082
083 float r = (float)(BASE_LIGHT_INTENSITY + (c/16.0) + 0.05)*0.6f;
084 float g = (float)(BASE_LIGHT_INTENSITY + (c/18.5) + 0.05)*0.6f;
085 float b = (float)(BASE_LIGHT_INTENSITY +(c/17.0) + 0.05)*0.55f;
086 if ( r > 1 ) r = 1;
087 if ( g > 1 ) g = 1;
088 if ( b > 1 ) b = 1;
089
090 return new Color3f( r, g, b );
091 }
092
093 /**
094 * @param cloudFactor describing howmuch clouds cover the sun
095 * @return the intensity of the
096 */
097 public float calcSunlightIntensity( float cloudFactor) {
098 if( cloudFactor < 0 || cloudFactor > 1.0 )
099 cloudFactor = 1;
100 Color3f vec = calculateSunlight( );
101 return ((vec.x + vec.y + vec.z)* 0.33333f )* cloudFactor;
102 }
103
104 }