2014-09-15 10:32:27 +00:00
|
|
|
#include "PaintedGridBrush.h"
|
|
|
|
|
|
|
|
#include <cmath>
|
|
|
|
#include "NoiseGenerator.h"
|
|
|
|
#include "PaintedGrid.h"
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
PaintedGridBrush::PaintedGridBrush(double hard_radius, double smoothed_size, double total_radius)
|
|
|
|
: hard_radius(hard_radius), smoothed_size(smoothed_size), total_radius(total_radius) {
|
2014-09-15 10:32:27 +00:00
|
|
|
}
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
void PaintedGridBrush::getArea(double x, double y, int *xstart, int *ystart, int *xend, int *yend) const {
|
2014-09-15 10:32:27 +00:00
|
|
|
double s = smoothed_size + hard_radius;
|
|
|
|
|
|
|
|
*xstart = (int)floor(x - s);
|
|
|
|
*xend = (int)ceil(x + s);
|
|
|
|
*ystart = (int)floor(y - s);
|
|
|
|
*yend = (int)ceil(y + s);
|
|
|
|
}
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
double PaintedGridBrush::getInfluence(double dx, double dy) const {
|
2014-09-15 10:32:27 +00:00
|
|
|
double distance = sqrt(dx * dx + dy * dy);
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
if (distance > hard_radius) {
|
|
|
|
if (distance <= hard_radius + smoothed_size) {
|
2014-09-15 10:32:27 +00:00
|
|
|
return 1.0 - (distance - hard_radius) / smoothed_size;
|
2015-11-09 21:30:46 +00:00
|
|
|
} else {
|
2014-09-15 10:32:27 +00:00
|
|
|
return 0.0;
|
|
|
|
}
|
2015-11-09 21:30:46 +00:00
|
|
|
} else {
|
2014-09-15 10:32:27 +00:00
|
|
|
return 1.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
double PaintedGridBrush::getValue(const PaintedGrid *, double, double, double basevalue, double, double) const {
|
2014-09-15 10:32:27 +00:00
|
|
|
return basevalue;
|
|
|
|
}
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
double PaintedGridBrushRaiseLower::getValue(const PaintedGrid *, double, double, double basevalue, double influence,
|
|
|
|
double force) const {
|
2014-09-15 10:32:27 +00:00
|
|
|
return basevalue + influence * force;
|
|
|
|
}
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
double PaintedGridBrushSmooth::getValue(const PaintedGrid *grid, double x, double y, double basevalue, double influence,
|
|
|
|
double force) const {
|
2014-09-15 10:32:27 +00:00
|
|
|
double ideal, factor;
|
|
|
|
ideal = grid->getFinalValue((x + total_radius * 0.5), y);
|
|
|
|
ideal += grid->getFinalValue((x - total_radius * 0.5), y);
|
|
|
|
ideal += grid->getFinalValue(x, (y - total_radius * 0.5));
|
|
|
|
ideal += grid->getFinalValue(x, (y + total_radius * 0.5));
|
|
|
|
ideal /= 4.0;
|
|
|
|
factor = influence * force;
|
2015-11-09 21:30:46 +00:00
|
|
|
if (factor > 1.0) {
|
2014-09-15 10:32:27 +00:00
|
|
|
factor = 0.0;
|
|
|
|
}
|
|
|
|
return basevalue + (ideal - basevalue) * factor;
|
|
|
|
}
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
double PaintedGridBrushAddNoise::getValue(const PaintedGrid *, double x, double y, double basevalue, double influence,
|
|
|
|
double force) const {
|
2014-09-15 10:32:27 +00:00
|
|
|
return basevalue + generator->get2DTotal(x / total_radius, y / total_radius) * influence * force * total_radius;
|
|
|
|
}
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
double PaintedGridBrushReset::getValue(const PaintedGrid *grid, double x, double y, double basevalue, double influence,
|
|
|
|
double force) const {
|
2014-09-15 10:32:27 +00:00
|
|
|
double ideal = grid->getInitialValue(x, y);
|
|
|
|
return basevalue + (ideal - basevalue) * influence * force;
|
|
|
|
}
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
double PaintedGridBrushFlatten::getValue(const PaintedGrid *, double, double, double basevalue, double influence,
|
|
|
|
double force) const {
|
2014-09-15 10:32:27 +00:00
|
|
|
double ideal = target;
|
|
|
|
return basevalue + (ideal - basevalue) * influence * force;
|
|
|
|
}
|