CLean up before pr

This commit is contained in:
Sam Gateau 2015-02-26 10:45:00 -08:00
parent a757229c0e
commit fcb293d0b2
4 changed files with 42 additions and 74 deletions

View file

@ -26,7 +26,6 @@ function ticktack() {
Scene.setYearTime(day);
}
Scene.setDayTime(hour);
}
Script.setInterval(ticktack, 41);

View file

@ -2493,8 +2493,6 @@ void Application::loadViewFrustum(Camera& camera, ViewFrustum& viewFrustum) {
glm::vec3 Application::getSunDirection() {
// Sun direction is in fact just the location of the sun relative to the origin
// return glm::normalize(_environment.getClosestData(_myCamera.getPosition()).getSunLocation(_myCamera.getPosition()));
auto skyStage = DependencyManager::get<SceneScriptingInterface>()->getSkyStage();
return skyStage->getSunLight()->getDirection();
}
@ -2875,9 +2873,7 @@ void Application::displaySide(Camera& theCamera, bool selfAvatarOnly, RenderArgs
{
DependencyManager::get<DeferredLightingEffect>()->setAmbientLightMode(getRenderAmbientLight());
// DependencyManager::get<DeferredLightingEffect>()->setGlobalLight(-getSunDirection(), GLOBAL_LIGHT_COLOR, GLOBAL_LIGHT_INTENSITY);
auto skyStage = DependencyManager::get<SceneScriptingInterface>()->getSkyStage();
// DependencyManager::get<DeferredLightingEffect>()->setGlobalLight(-getSunDirection(), GLOBAL_LIGHT_COLOR, skyStage->_light->getIntensity());
DependencyManager::get<DeferredLightingEffect>()->setGlobalLight(skyStage->getSunLight()->getDirection(), skyStage->getSunLight()->getColor(), skyStage->getSunLight()->getIntensity());
PROFILE_RANGE("DeferredLighting");

View file

@ -21,8 +21,6 @@ void EarthSunModel::updateAll() const {
}
Mat4d EarthSunModel::evalWorldToGeoLocationMat(double longitude, double latitude, double absAltitude, double scale) {
// Longitude is along Z axis but - from east to west
Mat4d rotLon = glm::rotate(glm::radians(longitude), Vec3d(0.0, 0.0, 1.0));
@ -54,9 +52,7 @@ void EarthSunModel::updateWorldToSurface() const {
_surfacePos = Vec3d(_surfaceToWorldMat * Vec4d(0.0, 0.0, 0.0, 1.0));
}
void EarthSunModel::updateSurfaceToEye() const
{
void EarthSunModel::updateSurfaceToEye() const {
_surfaceToEyeMat = glm::inverse(_eyeToSurfaceMat);
_worldToEyeMat = _surfaceToEyeMat * _worldToSurfaceMat;
_eyeToWorldMat = _surfaceToWorldMat * _eyeToSurfaceMat;
@ -76,8 +72,7 @@ void EarthSunModel::updateSun() const {
// sun direction is looking up toward Y axis at the specified sun lat, long
Vec3d lssd = Vec3d(_worldToSurfaceMat * Vec4d(_sunDir.x, _sunDir.y, _sunDir.z, 0.0));
_surfaceSunDir = glm::normalize(Vec3(lssd.x, lssd.y, lssd.z));
}
}
float moduloRange(float val, float minVal, float maxVal) {
float range = maxVal - minVal;
@ -86,30 +81,48 @@ float moduloRange(float val, float minVal, float maxVal) {
return modf(rval, &intval) * range + minVal;
}
const float MAX_LONGITUDE = 180.0f;
const float MAX_LATITUDE = 90.0f;
float validateLongitude(float lon) {
return moduloRange(lon, -MAX_LONGITUDE, MAX_LONGITUDE);
}
float validateLatitude(float lat) {
return moduloRange(lat, -MAX_LATITUDE, MAX_LATITUDE);
}
float validateAltitude(float altitude) {
const float MIN_ALTITUDE = -1000.0f;
const float MAX_ALTITUDE = 100000.0f;
return std::min(std::max(altitude, MIN_ALTITUDE), MAX_ALTITUDE);
}
void EarthSunModel::setLatitude(float lat) {
_latitude = moduloRange(lat, -90.0f, 90.0f);
_latitude = validateLatitude(lat);
invalidate();
}
void EarthSunModel::setLongitude(float lon) {
_longitude = moduloRange(lon, -180.0f, 180.0f);
_longitude = validateLongitude(lon);
invalidate();
}
void EarthSunModel::setAltitude(float altitude) {
_altitude = moduloRange(altitude, -1000.f, 100000.f);
_altitude = validateAltitude(altitude);
invalidate();
}
void EarthSunModel::setSunLatitude(float lat) {
_sunLatitude = moduloRange(lat, -90.0f, 90.0f);
_sunLatitude = validateLatitude(lat);
invalidate();
}
void EarthSunModel::setSunLongitude(float lon) {
_sunLongitude = moduloRange(lon, -180.0f, 180.0f);
_sunLongitude = validateLongitude(lon);
invalidate();
}
const int NUM_DAYS_PER_YEAR = 365;
const float NUM_HOURS_PER_DAY = 24.0f;
const float NUM_HOURS_PER_HALF_DAY = NUM_HOURS_PER_DAY * 0.5f;
SunSkyStage::SunSkyStage() :
_sunLight(new Light())
@ -119,8 +132,11 @@ SunSkyStage::SunSkyStage() :
setSunIntensity(1.0f);
setSunColor(Vec3(1.0f, 1.0f, 1.0f));
// setOriginLocation(45.0f, 20.0f, 1.0f);
// Default origin location is a special place in the world...
setOriginLocation(122.407f, 37.777f, 0.03f);
// 6pm
setDayTime(18.0f);
// Begining of march
setYearTime(60.0f);
}
@ -151,12 +167,20 @@ void SunSkyStage::setSunIntensity(float intensity) {
_sunLight->setIntensity(intensity);
}
// THe sun declinaison calculus is taken from https://en.wikipedia.org/wiki/Position_of_the_Sun
double evalSunDeclinaison(double dayNumber) {
return -(23.0 + 44.0/60.0)*cos(glm::radians((360.0/365.0)*(dayNumber + 10.0)));
}
void SunSkyStage::updateGraphicsObject() const {
// Always update the sunLongitude based on the current dayTIme and the current origin
_earthSunModel.setSunLongitude(_earthSunModel.getLongitude() + (-180.0 + 360.0 * _dayTime / NUM_HOURS_PER_DAY));
// Always update the sunLongitude based on the current dayTime and the current origin
// The day time is supposed to be local at the origin
double signedNormalizedDayTime = (_dayTime - NUM_HOURS_PER_HALF_DAY) / NUM_HOURS_PER_HALF_DAY;
double sunLongitude = _earthSunModel.getLongitude() + (MAX_LONGITUDE * signedNormalizedDayTime);
_earthSunModel.setSunLongitude(sunLongitude);
// And update the sunLAtitude as the declinaison depending of the time of the year
_earthSunModel.setSunLatitude(-(23.0 + 44.0/60.0)*cos(glm::radians((360.0/365.0)*(_yearTime + 10))));
_earthSunModel.setSunLatitude(evalSunDeclinaison(_yearTime));
Vec3d sunLightDir = -_earthSunModel.getSurfaceSunDir();

View file

@ -22,16 +22,6 @@ typedef glm::mat4 Mat4;
class EarthSunModel {
public:
enum Preset
{
Toulouse = 0,
SanFrancisco,
Sydney,
Num_Presets,
};
static const std::string PresetNames[Num_Presets];
//void assignPreset( Preset p);
//Preset preset() const { return mPreset; }
void setScale(float scale);
float getScale() const { return _scale; }
@ -108,46 +98,6 @@ protected:
static Mat4d evalWorldToGeoLocationMat(double longitude, double latitude, double altitude, double scale);
};
namespace gpu {
class Batch;
};
class ProgramObject;
class Skybox {
public:
void recordBatch(gpu::Batch& batch, const Transform& viewTransform, const Mat4& projection);
Skybox();
~Skybox();
protected:
ProgramObject* createSkyProgram(const char* from, int* locations);
ProgramObject* _skyFromAtmosphereProgram;
ProgramObject* _skyFromSpaceProgram;
enum {
CAMERA_POS_LOCATION,
LIGHT_POS_LOCATION,
INV_WAVELENGTH_LOCATION,
CAMERA_HEIGHT2_LOCATION,
OUTER_RADIUS_LOCATION,
OUTER_RADIUS2_LOCATION,
INNER_RADIUS_LOCATION,
KR_ESUN_LOCATION,
KM_ESUN_LOCATION,
KR_4PI_LOCATION,
KM_4PI_LOCATION,
SCALE_LOCATION,
SCALE_DEPTH_LOCATION,
SCALE_OVER_SCALE_DEPTH_LOCATION,
G_LOCATION,
G2_LOCATION,
LOCATION_COUNT
};
int _skyFromAtmosphereUniformLocations[LOCATION_COUNT];
int _skyFromSpaceUniformLocations[LOCATION_COUNT];
};
// Sun sky stage generates the rendering primitives to display a scene realistically
// at the specified location and time around earth
class SunSkyStage {
@ -181,9 +131,8 @@ public:
protected:
LightPointer _sunLight;
// default day is 1st of january at noun
float _dayTime = 12.0f;
int _yearTime = 0;
float _dayTime;
int _yearTime;
mutable EarthSunModel _earthSunModel;