2013-12-01 18:24:53 +00:00
|
|
|
#include "CloudsRenderer.h"
|
|
|
|
|
|
|
|
#include "SoftwareRenderer.h"
|
|
|
|
#include "Scenery.h"
|
|
|
|
#include "CloudsDefinition.h"
|
2013-12-04 21:52:18 +00:00
|
|
|
#include "CloudLayerDefinition.h"
|
2013-12-01 18:24:53 +00:00
|
|
|
#include "BaseCloudLayerRenderer.h"
|
|
|
|
#include "CloudBasicLayerRenderer.h"
|
2013-12-17 22:45:09 +00:00
|
|
|
#include "CameraDefinition.h"
|
2013-12-01 18:24:53 +00:00
|
|
|
|
2013-12-04 21:52:18 +00:00
|
|
|
#include "clouds/BaseCloudsModel.h"
|
2014-03-18 20:08:17 +00:00
|
|
|
#include "clouds/CloudModelAltoCumulus.h"
|
2014-03-18 20:17:41 +00:00
|
|
|
#include "clouds/CloudModelCirrus.h"
|
2014-03-18 20:27:35 +00:00
|
|
|
#include "clouds/CloudModelCumuloNimbus.h"
|
2013-12-04 21:52:18 +00:00
|
|
|
#include "clouds/CloudModelStratoCumulus.h"
|
|
|
|
|
2013-12-01 18:24:53 +00:00
|
|
|
CloudsRenderer::CloudsRenderer(SoftwareRenderer* parent):
|
|
|
|
parent(parent)
|
|
|
|
{
|
2015-09-13 16:58:11 +00:00
|
|
|
quality = 0.5;
|
2015-08-19 17:28:36 +00:00
|
|
|
enabled = true;
|
2013-12-01 18:24:53 +00:00
|
|
|
fake_renderer = new BaseCloudLayerRenderer(parent);
|
2013-12-04 21:52:18 +00:00
|
|
|
|
|
|
|
CloudLayerDefinition* fake_layer = new CloudLayerDefinition(NULL);
|
|
|
|
fake_model = new BaseCloudsModel(fake_layer);
|
2013-12-01 18:24:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CloudsRenderer::~CloudsRenderer()
|
|
|
|
{
|
|
|
|
for (auto renderer : layer_renderers)
|
|
|
|
{
|
|
|
|
delete renderer;
|
|
|
|
}
|
|
|
|
delete fake_renderer;
|
2013-12-04 21:52:18 +00:00
|
|
|
|
|
|
|
for (auto model : layer_models)
|
|
|
|
{
|
|
|
|
delete model;
|
|
|
|
}
|
|
|
|
delete fake_model->getLayer();
|
|
|
|
delete fake_model;
|
2013-12-01 18:24:53 +00:00
|
|
|
}
|
|
|
|
|
2015-09-13 16:58:11 +00:00
|
|
|
void CloudsRenderer::setQuality(double factor)
|
|
|
|
{
|
|
|
|
this->quality = factor;
|
|
|
|
for (auto &renderer: layer_renderers)
|
|
|
|
{
|
|
|
|
renderer->setQuality(factor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-19 17:28:36 +00:00
|
|
|
void CloudsRenderer::setEnabled(bool enabled)
|
|
|
|
{
|
|
|
|
this->enabled = enabled;
|
|
|
|
}
|
|
|
|
|
2013-12-01 18:24:53 +00:00
|
|
|
void CloudsRenderer::update()
|
|
|
|
{
|
|
|
|
for (auto renderer : layer_renderers)
|
|
|
|
{
|
|
|
|
delete renderer;
|
|
|
|
}
|
|
|
|
layer_renderers.clear();
|
|
|
|
|
2013-12-04 21:52:18 +00:00
|
|
|
for (auto model : layer_models)
|
|
|
|
{
|
|
|
|
delete model;
|
|
|
|
}
|
|
|
|
layer_models.clear();
|
|
|
|
|
2013-12-01 18:24:53 +00:00
|
|
|
CloudsDefinition* clouds = parent->getScenery()->getClouds();
|
|
|
|
int n = clouds->count();
|
|
|
|
for (int i = 0; i < n; i++)
|
|
|
|
{
|
|
|
|
layer_renderers.push_back(new CloudBasicLayerRenderer(parent));
|
2013-12-04 21:52:18 +00:00
|
|
|
|
|
|
|
CloudLayerDefinition* layer = clouds->getCloudLayer(i);
|
|
|
|
BaseCloudsModel* model;
|
|
|
|
switch (layer->type)
|
|
|
|
{
|
|
|
|
case CloudLayerDefinition::STRATOCUMULUS:
|
|
|
|
model = new CloudModelStratoCumulus(layer);
|
|
|
|
break;
|
|
|
|
case CloudLayerDefinition::ALTOCUMULUS:
|
2014-03-18 20:08:17 +00:00
|
|
|
model = new CloudModelAltoCumulus(layer);
|
|
|
|
break;
|
2014-03-18 20:27:35 +00:00
|
|
|
case CloudLayerDefinition::CIRRUS:
|
|
|
|
model = new CloudModelCirrus(layer);
|
|
|
|
break;
|
2013-12-04 21:52:18 +00:00
|
|
|
case CloudLayerDefinition::CUMULONIMBUS:
|
2014-03-18 20:27:35 +00:00
|
|
|
model = new CloudModelCumuloNimbus(layer);
|
|
|
|
break;
|
|
|
|
case CloudLayerDefinition::STRATUS:
|
|
|
|
case CloudLayerDefinition::NIMBOSTRATUS:
|
|
|
|
case CloudLayerDefinition::CUMULUS:
|
|
|
|
case CloudLayerDefinition::ALTOSTRATUS:
|
2013-12-04 21:52:18 +00:00
|
|
|
case CloudLayerDefinition::CIRROCUMULUS:
|
|
|
|
case CloudLayerDefinition::CIRROSTRATUS:
|
|
|
|
model = new BaseCloudsModel(layer);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
layer_models.push_back(model);
|
|
|
|
model->update();
|
2013-12-01 18:24:53 +00:00
|
|
|
}
|
2015-09-13 16:58:11 +00:00
|
|
|
|
|
|
|
setQuality(quality);
|
2013-12-01 18:24:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BaseCloudLayerRenderer* CloudsRenderer::getLayerRenderer(unsigned int layer)
|
|
|
|
{
|
|
|
|
if (layer < layer_renderers.size())
|
|
|
|
{
|
|
|
|
return layer_renderers[layer];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-12-17 22:01:36 +00:00
|
|
|
qWarning("Asked for unknown layer renderer %d", layer);
|
2013-12-01 18:24:53 +00:00
|
|
|
return fake_renderer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-04 21:52:18 +00:00
|
|
|
BaseCloudsModel* CloudsRenderer::getLayerModel(unsigned int layer)
|
|
|
|
{
|
|
|
|
if (layer < layer_models.size())
|
|
|
|
{
|
|
|
|
return layer_models[layer];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-12-20 16:30:27 +00:00
|
|
|
qWarning("Asked for unknown layer model %d", layer);
|
2013-12-04 21:52:18 +00:00
|
|
|
return fake_model;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-20 16:30:27 +00:00
|
|
|
void CloudsRenderer::setLayerModel(unsigned int layer, BaseCloudsModel *model, bool delete_old)
|
|
|
|
{
|
|
|
|
if (layer < layer_models.size())
|
|
|
|
{
|
|
|
|
if (delete_old)
|
|
|
|
{
|
|
|
|
delete layer_models[layer];
|
|
|
|
}
|
|
|
|
layer_models[layer] = model;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qWarning("Asked to set an unknown layer model %d", layer);
|
|
|
|
delete model;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-01 18:24:53 +00:00
|
|
|
Color CloudsRenderer::getColor(const Vector3 &eye, const Vector3 &location, const Color &base)
|
|
|
|
{
|
|
|
|
CloudsDefinition* definition = parent->getScenery()->getClouds();
|
|
|
|
|
|
|
|
int n = definition->count();
|
2015-08-19 17:28:36 +00:00
|
|
|
if (not enabled or n < 1)
|
2013-12-01 18:24:53 +00:00
|
|
|
{
|
|
|
|
return base;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* TODO Iter layers in sorted order */
|
|
|
|
Color cumul = base;
|
|
|
|
|
|
|
|
for (int i = 0; i < n; i++)
|
|
|
|
{
|
|
|
|
BaseCloudLayerRenderer* layer_renderer = getLayerRenderer(i);
|
2013-12-04 21:52:18 +00:00
|
|
|
BaseCloudsModel* layer_model = getLayerModel(i);
|
2013-12-01 18:24:53 +00:00
|
|
|
|
2013-12-04 21:52:18 +00:00
|
|
|
Color layer_color = layer_renderer->getColor(layer_model, eye, location);
|
2013-12-01 18:24:53 +00:00
|
|
|
|
2013-12-11 09:24:35 +00:00
|
|
|
cumul.mask(layer_color);
|
2013-12-01 18:24:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return cumul;
|
|
|
|
}
|
|
|
|
|
2013-12-17 22:45:09 +00:00
|
|
|
bool CloudsRenderer::applyLightFilter(LightComponent &light, const Vector3 &at)
|
2013-12-01 18:24:53 +00:00
|
|
|
{
|
2013-12-04 22:28:34 +00:00
|
|
|
CloudsDefinition* definition = parent->getScenery()->getClouds();
|
|
|
|
|
|
|
|
int n = definition->count();
|
2015-08-19 17:28:36 +00:00
|
|
|
if (not enabled or n < 1)
|
2013-12-04 22:28:34 +00:00
|
|
|
{
|
2013-12-17 22:45:09 +00:00
|
|
|
return true;
|
2013-12-04 22:28:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* TODO Iter layers in sorted order */
|
|
|
|
for (int i = 0; i < n; i++)
|
|
|
|
{
|
|
|
|
BaseCloudLayerRenderer* layer_renderer = getLayerRenderer(i);
|
|
|
|
BaseCloudsModel* layer_model = getLayerModel(i);
|
|
|
|
|
2013-12-17 22:45:09 +00:00
|
|
|
layer_renderer->alterLight(layer_model, &light, parent->render_camera->getLocation(), at);
|
2013-12-04 22:28:34 +00:00
|
|
|
}
|
|
|
|
|
2013-12-17 22:45:09 +00:00
|
|
|
return true;
|
2013-12-01 18:24:53 +00:00
|
|
|
}
|
2015-09-29 20:31:25 +00:00
|
|
|
|
|
|
|
double CloudsRenderer::getHighestAltitude()
|
|
|
|
{
|
|
|
|
CloudsDefinition* definition = parent->getScenery()->getClouds();
|
|
|
|
double highest = 0.0;
|
|
|
|
|
|
|
|
int n = definition->count();
|
|
|
|
double low, high;
|
|
|
|
for (int i = 0; i < n; i++)
|
|
|
|
{
|
|
|
|
BaseCloudsModel* layer_model = getLayerModel(i);
|
|
|
|
layer_model->getAltitudeRange(&low, &high);
|
|
|
|
if (high > highest)
|
|
|
|
{
|
|
|
|
highest = high;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return highest;
|
|
|
|
}
|