56 lines
2.2 KiB
C++
56 lines
2.2 KiB
C++
#include "BaseCloudsModel.h"
|
|
|
|
#include "Maths.h"
|
|
#include "CloudLayerDefinition.h"
|
|
#include "Vector3.h"
|
|
|
|
BaseCloudsModel::BaseCloudsModel(CloudLayerDefinition *layer) : layer(layer) {
|
|
}
|
|
|
|
BaseCloudsModel::~BaseCloudsModel() {
|
|
}
|
|
|
|
void BaseCloudsModel::update() {
|
|
}
|
|
|
|
void BaseCloudsModel::getAltitudeRange(double *min_altitude, double *max_altitude) const {
|
|
*min_altitude = layer->altitude;
|
|
*max_altitude = layer->altitude * layer->scaling;
|
|
}
|
|
|
|
void BaseCloudsModel::getDetailRange(double *min_step, double *max_step) const {
|
|
double min_altitude, max_altitude, thickness;
|
|
getAltitudeRange(&min_altitude, &max_altitude);
|
|
thickness = max_altitude - min_altitude;
|
|
*min_step = thickness * 0.001;
|
|
*max_step = thickness * 0.2;
|
|
}
|
|
|
|
BaseCloudsModel::CloudDensityInfo BaseCloudsModel::getDensity(const Vector3 &, double) const {
|
|
return {0.0, 1.0};
|
|
}
|
|
|
|
static inline Vector3 _getPseudoNormal(const BaseCloudsModel *model, const Vector3 &base, const Vector3 &direction,
|
|
double base_density, double precision) {
|
|
double density = model->getDensity(base.add(direction.scale(precision * 10.0)), precision).density;
|
|
double diff = base_density - density;
|
|
return direction.scale(diff > 0.0 ? diff : 0.0);
|
|
}
|
|
|
|
Vector3 BaseCloudsModel::getNormal(const Vector3 &location) const {
|
|
double precision = 0.3;
|
|
Vector3 normal = VECTOR_ZERO;
|
|
double base_density = getDensity(location, precision).density;
|
|
normal = normal.add(_getPseudoNormal(this, location, VECTOR_UP, base_density, precision));
|
|
normal = normal.add(_getPseudoNormal(this, location, VECTOR_DOWN, base_density, precision));
|
|
normal = normal.add(_getPseudoNormal(this, location, VECTOR_EAST, base_density, precision));
|
|
normal = normal.add(_getPseudoNormal(this, location, VECTOR_WEST, base_density, precision));
|
|
normal = normal.add(_getPseudoNormal(this, location, VECTOR_NORTH, base_density, precision));
|
|
normal = normal.add(_getPseudoNormal(this, location, VECTOR_SOUTH, base_density, precision));
|
|
return normal.normalize().scale(Maths::smoothstep(0.0, 0.1, normal.getNorm()));
|
|
}
|
|
|
|
double BaseCloudsModel::getDetailValue(const Vector3 &, double, double) const {
|
|
return 0.0;
|
|
}
|