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-04 21:52:18 +00:00
|
|
|
#include "clouds/BaseCloudsModel.h"
|
|
|
|
#include "clouds/CloudModelStratoCumulus.h"
|
|
|
|
|
2013-12-01 18:24:53 +00:00
|
|
|
CloudsRenderer::CloudsRenderer(SoftwareRenderer* parent):
|
|
|
|
parent(parent)
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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::STRATUS:
|
|
|
|
case CloudLayerDefinition::NIMBOSTRATUS:
|
|
|
|
case CloudLayerDefinition::CUMULUS:
|
|
|
|
model = new BaseCloudsModel(layer);
|
|
|
|
break;
|
|
|
|
case CloudLayerDefinition::STRATOCUMULUS:
|
|
|
|
model = new CloudModelStratoCumulus(layer);
|
|
|
|
break;
|
|
|
|
case CloudLayerDefinition::ALTOCUMULUS:
|
|
|
|
case CloudLayerDefinition::ALTOSTRATUS:
|
|
|
|
case CloudLayerDefinition::CUMULONIMBUS:
|
|
|
|
case CloudLayerDefinition::CIRROCUMULUS:
|
|
|
|
case CloudLayerDefinition::CIRROSTRATUS:
|
|
|
|
case CloudLayerDefinition::CIRRUS:
|
|
|
|
model = new BaseCloudsModel(layer);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
layer_models.push_back(model);
|
|
|
|
model->update();
|
2013-12-01 18:24:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BaseCloudLayerRenderer* CloudsRenderer::getLayerRenderer(unsigned int layer)
|
|
|
|
{
|
|
|
|
if (layer < layer_renderers.size())
|
|
|
|
{
|
|
|
|
return layer_renderers[layer];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
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
|
|
|
|
{
|
|
|
|
return fake_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();
|
|
|
|
if (n < 1)
|
|
|
|
{
|
|
|
|
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-08 19:54:34 +00:00
|
|
|
bool CloudsRenderer::alterLight(LightComponent* light, const Vector3 &eye, const Vector3 &location)
|
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();
|
|
|
|
if (n < 1)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* TODO Iter layers in sorted order */
|
|
|
|
bool altered = false;
|
|
|
|
for (int i = 0; i < n; i++)
|
|
|
|
{
|
|
|
|
BaseCloudLayerRenderer* layer_renderer = getLayerRenderer(i);
|
|
|
|
BaseCloudsModel* layer_model = getLayerModel(i);
|
|
|
|
|
|
|
|
altered = altered || layer_renderer->alterLight(layer_model, light, eye, location);
|
|
|
|
}
|
|
|
|
|
|
|
|
return altered;
|
2013-12-01 18:24:53 +00:00
|
|
|
}
|