mirror of
https://github.com/overte-org/overte.git
synced 2025-04-25 23:36:41 +02:00
fixing compilation issue on macos
This commit is contained in:
parent
fcb293d0b2
commit
b04dbf7a34
1 changed files with 133 additions and 131 deletions
|
@ -1,19 +1,21 @@
|
||||||
//
|
//
|
||||||
// Stage.cpp
|
// Stage.cpp
|
||||||
// libraries/model/src/model
|
// libraries/model/src/model
|
||||||
//
|
//
|
||||||
// Created by Sam Gateau on 2/24/2015.
|
// Created by Sam Gateau on 2/24/2015.
|
||||||
// Copyright 2014 High Fidelity, Inc.
|
// Copyright 2014 High Fidelity, Inc.
|
||||||
//
|
//
|
||||||
// Distributed under the Apache License, Version 2.0.
|
// Distributed under the Apache License, Version 2.0.
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
//
|
//
|
||||||
#include "Stage.h"
|
#include "Stage.h"
|
||||||
|
|
||||||
#include <glm/gtx/transform.hpp>
|
#include <glm/gtx/transform.hpp>
|
||||||
using namespace model;
|
#include <math.h>
|
||||||
|
|
||||||
|
using namespace model;
|
||||||
|
|
||||||
|
|
||||||
void EarthSunModel::updateAll() const {
|
void EarthSunModel::updateAll() const {
|
||||||
updateWorldToSurface();
|
updateWorldToSurface();
|
||||||
updateSurfaceToEye();
|
updateSurfaceToEye();
|
||||||
|
@ -72,118 +74,118 @@ void EarthSunModel::updateSun() const {
|
||||||
// sun direction is looking up toward Y axis at the specified sun lat, long
|
// 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));
|
Vec3d lssd = Vec3d(_worldToSurfaceMat * Vec4d(_sunDir.x, _sunDir.y, _sunDir.z, 0.0));
|
||||||
_surfaceSunDir = glm::normalize(Vec3(lssd.x, lssd.y, lssd.z));
|
_surfaceSunDir = glm::normalize(Vec3(lssd.x, lssd.y, lssd.z));
|
||||||
}
|
}
|
||||||
|
|
||||||
float moduloRange(float val, float minVal, float maxVal) {
|
double moduloRange(double val, double minVal, double maxVal) {
|
||||||
float range = maxVal - minVal;
|
double range = maxVal - minVal;
|
||||||
float rval = (val - minVal) / range;
|
double rval = (val - minVal) / range;
|
||||||
float intval;
|
double intval;
|
||||||
return modf(rval, &intval) * range + minVal;
|
return modf(rval, &intval) * range + minVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
const float MAX_LONGITUDE = 180.0f;
|
const float MAX_LONGITUDE = 180.0f;
|
||||||
const float MAX_LATITUDE = 90.0f;
|
const float MAX_LATITUDE = 90.0f;
|
||||||
|
|
||||||
float validateLongitude(float lon) {
|
float validateLongitude(float lon) {
|
||||||
return moduloRange(lon, -MAX_LONGITUDE, MAX_LONGITUDE);
|
return moduloRange(lon, -MAX_LONGITUDE, MAX_LONGITUDE);
|
||||||
}
|
}
|
||||||
|
|
||||||
float validateLatitude(float lat) {
|
float validateLatitude(float lat) {
|
||||||
return moduloRange(lat, -MAX_LATITUDE, MAX_LATITUDE);
|
return moduloRange(lat, -MAX_LATITUDE, MAX_LATITUDE);
|
||||||
}
|
}
|
||||||
|
|
||||||
float validateAltitude(float altitude) {
|
float validateAltitude(float altitude) {
|
||||||
const float MIN_ALTITUDE = -1000.0f;
|
const float MIN_ALTITUDE = -1000.0f;
|
||||||
const float MAX_ALTITUDE = 100000.0f;
|
const float MAX_ALTITUDE = 100000.0f;
|
||||||
return std::min(std::max(altitude, MIN_ALTITUDE), MAX_ALTITUDE);
|
return std::min(std::max(altitude, MIN_ALTITUDE), MAX_ALTITUDE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EarthSunModel::setLatitude(float lat) {
|
void EarthSunModel::setLatitude(float lat) {
|
||||||
_latitude = validateLatitude(lat);
|
_latitude = validateLatitude(lat);
|
||||||
invalidate();
|
invalidate();
|
||||||
}
|
}
|
||||||
void EarthSunModel::setLongitude(float lon) {
|
void EarthSunModel::setLongitude(float lon) {
|
||||||
_longitude = validateLongitude(lon);
|
_longitude = validateLongitude(lon);
|
||||||
invalidate();
|
invalidate();
|
||||||
}
|
}
|
||||||
void EarthSunModel::setAltitude(float altitude) {
|
void EarthSunModel::setAltitude(float altitude) {
|
||||||
_altitude = validateAltitude(altitude);
|
_altitude = validateAltitude(altitude);
|
||||||
invalidate();
|
invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void EarthSunModel::setSunLatitude(float lat) {
|
void EarthSunModel::setSunLatitude(float lat) {
|
||||||
_sunLatitude = validateLatitude(lat);
|
_sunLatitude = validateLatitude(lat);
|
||||||
invalidate();
|
invalidate();
|
||||||
}
|
}
|
||||||
void EarthSunModel::setSunLongitude(float lon) {
|
void EarthSunModel::setSunLongitude(float lon) {
|
||||||
_sunLongitude = validateLongitude(lon);
|
_sunLongitude = validateLongitude(lon);
|
||||||
invalidate();
|
invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
const int NUM_DAYS_PER_YEAR = 365;
|
const int NUM_DAYS_PER_YEAR = 365;
|
||||||
const float NUM_HOURS_PER_DAY = 24.0f;
|
const float NUM_HOURS_PER_DAY = 24.0f;
|
||||||
const float NUM_HOURS_PER_HALF_DAY = NUM_HOURS_PER_DAY * 0.5f;
|
const float NUM_HOURS_PER_HALF_DAY = NUM_HOURS_PER_DAY * 0.5f;
|
||||||
|
|
||||||
SunSkyStage::SunSkyStage() :
|
SunSkyStage::SunSkyStage() :
|
||||||
_sunLight(new Light())
|
_sunLight(new Light())
|
||||||
{
|
{
|
||||||
_sunLight->setType(Light::SUN);
|
_sunLight->setType(Light::SUN);
|
||||||
|
|
||||||
setSunIntensity(1.0f);
|
setSunIntensity(1.0f);
|
||||||
setSunColor(Vec3(1.0f, 1.0f, 1.0f));
|
setSunColor(Vec3(1.0f, 1.0f, 1.0f));
|
||||||
|
|
||||||
// Default origin location is a special place in the world...
|
// Default origin location is a special place in the world...
|
||||||
setOriginLocation(122.407f, 37.777f, 0.03f);
|
setOriginLocation(122.407f, 37.777f, 0.03f);
|
||||||
// 6pm
|
// 6pm
|
||||||
setDayTime(18.0f);
|
setDayTime(18.0f);
|
||||||
// Begining of march
|
// Begining of march
|
||||||
setYearTime(60.0f);
|
setYearTime(60.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
SunSkyStage::~SunSkyStage() {
|
SunSkyStage::~SunSkyStage() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void SunSkyStage::setDayTime(float hour) {
|
void SunSkyStage::setDayTime(float hour) {
|
||||||
_dayTime = moduloRange(hour, 0.f, NUM_HOURS_PER_DAY);
|
_dayTime = moduloRange(hour, 0.f, NUM_HOURS_PER_DAY);
|
||||||
invalidate();
|
invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SunSkyStage::setYearTime(unsigned int day) {
|
void SunSkyStage::setYearTime(unsigned int day) {
|
||||||
_yearTime = day % NUM_DAYS_PER_YEAR;
|
_yearTime = day % NUM_DAYS_PER_YEAR;
|
||||||
invalidate();
|
invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SunSkyStage::setOriginLocation(float longitude, float latitude, float altitude) {
|
void SunSkyStage::setOriginLocation(float longitude, float latitude, float altitude) {
|
||||||
_earthSunModel.setLongitude(longitude);
|
_earthSunModel.setLongitude(longitude);
|
||||||
_earthSunModel.setLatitude(latitude);
|
_earthSunModel.setLatitude(latitude);
|
||||||
_earthSunModel.setAltitude(altitude);
|
_earthSunModel.setAltitude(altitude);
|
||||||
invalidate();
|
invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SunSkyStage::setSunColor(const Vec3& color) {
|
void SunSkyStage::setSunColor(const Vec3& color) {
|
||||||
_sunLight->setColor(color);
|
_sunLight->setColor(color);
|
||||||
}
|
}
|
||||||
void SunSkyStage::setSunIntensity(float intensity) {
|
void SunSkyStage::setSunIntensity(float intensity) {
|
||||||
_sunLight->setIntensity(intensity);
|
_sunLight->setIntensity(intensity);
|
||||||
}
|
}
|
||||||
|
|
||||||
// THe sun declinaison calculus is taken from https://en.wikipedia.org/wiki/Position_of_the_Sun
|
// THe sun declinaison calculus is taken from https://en.wikipedia.org/wiki/Position_of_the_Sun
|
||||||
double evalSunDeclinaison(double dayNumber) {
|
double evalSunDeclinaison(double dayNumber) {
|
||||||
return -(23.0 + 44.0/60.0)*cos(glm::radians((360.0/365.0)*(dayNumber + 10.0)));
|
return -(23.0 + 44.0/60.0)*cos(glm::radians((360.0/365.0)*(dayNumber + 10.0)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void SunSkyStage::updateGraphicsObject() const {
|
void SunSkyStage::updateGraphicsObject() const {
|
||||||
// Always update the sunLongitude based on the current dayTime and the current origin
|
// Always update the sunLongitude based on the current dayTime and the current origin
|
||||||
// The day time is supposed to be local at the 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 signedNormalizedDayTime = (_dayTime - NUM_HOURS_PER_HALF_DAY) / NUM_HOURS_PER_HALF_DAY;
|
||||||
double sunLongitude = _earthSunModel.getLongitude() + (MAX_LONGITUDE * signedNormalizedDayTime);
|
double sunLongitude = _earthSunModel.getLongitude() + (MAX_LONGITUDE * signedNormalizedDayTime);
|
||||||
_earthSunModel.setSunLongitude(sunLongitude);
|
_earthSunModel.setSunLongitude(sunLongitude);
|
||||||
|
|
||||||
// And update the sunLAtitude as the declinaison depending of the time of the year
|
// And update the sunLAtitude as the declinaison depending of the time of the year
|
||||||
_earthSunModel.setSunLatitude(evalSunDeclinaison(_yearTime));
|
_earthSunModel.setSunLatitude(evalSunDeclinaison(_yearTime));
|
||||||
|
|
||||||
Vec3d sunLightDir = -_earthSunModel.getSurfaceSunDir();
|
Vec3d sunLightDir = -_earthSunModel.getSurfaceSunDir();
|
||||||
|
|
||||||
_sunLight->setDirection(Vec3(sunLightDir.x, sunLightDir.y, sunLightDir.z));
|
_sunLight->setDirection(Vec3(sunLightDir.x, sunLightDir.y, sunLightDir.z));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue