Removed unused Circle system from Zone

This commit is contained in:
Michaël Lemaire 2014-09-15 09:36:48 +02:00
parent a37fb2b245
commit 5eed701803
2 changed files with 3 additions and 122 deletions

View file

@ -5,22 +5,6 @@
#include "PackStream.h" #include "PackStream.h"
#include "Vector3.h" #include "Vector3.h"
#define MAX_CIRCLES 10
namespace paysages {
namespace definition {
class Circle
{
public:
double value;
double centerx;
double centerz;
double softradius;
double hardradius;
};
}
}
Zone::Zone(BaseDefinition *parent): Zone::Zone(BaseDefinition *parent):
BaseDefinition(parent) BaseDefinition(parent)
{ {
@ -29,21 +13,16 @@ Zone::Zone(BaseDefinition *parent):
value_by_height->setDefault(1.0); value_by_height->setDefault(1.0);
value_by_slope = new Curve; value_by_slope = new Curve;
value_by_slope->setDefault(1.0); value_by_slope->setDefault(1.0);
circles_included_count = 0;
circles_included = new Circle[MAX_CIRCLES];
} }
Zone::~Zone() Zone::~Zone()
{ {
delete value_by_height; delete value_by_height;
delete value_by_slope; delete value_by_slope;
delete circles_included;
} }
void Zone::save(PackStream* stream) const void Zone::save(PackStream* stream) const
{ {
int i;
stream->write(&absolute_height); stream->write(&absolute_height);
stream->write(&relative_height_min); stream->write(&relative_height_min);
stream->write(&relative_height_middle); stream->write(&relative_height_middle);
@ -51,22 +30,10 @@ void Zone::save(PackStream* stream) const
value_by_height->save(stream); value_by_height->save(stream);
value_by_slope->save(stream); value_by_slope->save(stream);
stream->write(&circles_included_count);
for (i = 0; i < circles_included_count; i++)
{
stream->write(&circles_included[i].value);
stream->write(&circles_included[i].centerx);
stream->write(&circles_included[i].centerz);
stream->write(&circles_included[i].softradius);
stream->write(&circles_included[i].hardradius);
}
} }
void Zone::load(PackStream* stream) void Zone::load(PackStream* stream)
{ {
int i;
stream->read(&absolute_height); stream->read(&absolute_height);
stream->read(&relative_height_min); stream->read(&relative_height_min);
stream->read(&relative_height_middle); stream->read(&relative_height_middle);
@ -74,16 +41,6 @@ void Zone::load(PackStream* stream)
value_by_height->load(stream); value_by_height->load(stream);
value_by_slope->load(stream); value_by_slope->load(stream);
stream->read(&circles_included_count);
for (i = 0; i < circles_included_count; i++)
{
stream->read(&circles_included[i].value);
stream->read(&circles_included[i].centerx);
stream->read(&circles_included[i].centerz);
stream->read(&circles_included[i].softradius);
stream->read(&circles_included[i].hardradius);
}
} }
void Zone::copy(BaseDefinition* _destination) const void Zone::copy(BaseDefinition* _destination) const
@ -97,16 +54,12 @@ void Zone::copy(BaseDefinition* _destination) const
value_by_height->copy(destination->value_by_height); value_by_height->copy(destination->value_by_height);
value_by_slope->copy(destination->value_by_slope); value_by_slope->copy(destination->value_by_slope);
memcpy(destination->circles_included, circles_included, sizeof(Circle) * circles_included_count);
destination->circles_included_count = circles_included_count;
} }
void Zone::clear() void Zone::clear()
{ {
value_by_height->clear(); value_by_height->clear();
value_by_slope->clear(); value_by_slope->clear();
circles_included_count = 0;
} }
void Zone::setAbsoluteHeight() void Zone::setAbsoluteHeight()
@ -135,16 +88,6 @@ void Zone::setRelativeHeight(double min, double middle, double max)
relative_height_max = max; relative_height_max = max;
} }
void Zone::includeCircleArea(double value, double centerx, double centerz, double softradius, double hardradius)
{
Circle circle = {value, centerx, centerz, softradius, hardradius};
if (circles_included_count < MAX_CIRCLES)
{
circles_included[circles_included_count++] = circle;
}
}
void Zone::getHeightCurve(Curve* curve) const void Zone::getHeightCurve(Curve* curve) const
{ {
value_by_height->copy(curve); value_by_height->copy(curve);
@ -181,50 +124,10 @@ void Zone::addSlopeRangeQuick(double value, double hardmin, double softmin, doub
value_by_slope->addPoint(hardmax, 0.0); value_by_slope->addPoint(hardmax, 0.0);
} }
static inline double _getCircleInfluence(const Circle &circle, const Vector3 &position)
{
double radius, dx, dz;
dx = position.x - circle.centerx;
dz = position.z - circle.centerz;
radius = sqrt(dx * dx + dz * dz);
if (radius > circle.hardradius)
{
return 0.0;
}
else if (radius < circle.softradius)
{
return circle.value;
}
else
{
return circle.value * (circle.hardradius - radius) / (circle.hardradius - circle.softradius);
}
}
double Zone::getValue(const Vector3 &location, const Vector3 &normal) const double Zone::getValue(const Vector3 &location, const Vector3 &normal) const
{ {
int i;
double final_height; double final_height;
double value, value_height, value_steepness, value_circle; double value_height, value_steepness;
if (circles_included_count > 0)
{
value_circle = 0.0;
for (i = 0; i < circles_included_count; i++)
{
value = _getCircleInfluence(circles_included[i], location);
if (value > value_circle)
{
value_circle = value;
}
}
}
else
{
value_circle = 1.0;
}
if (absolute_height) if (absolute_height)
{ {
@ -254,26 +157,12 @@ double Zone::getValue(const Vector3 &location, const Vector3 &normal) const
value_steepness = value_by_slope->getValue(1.0 - normal.y); value_steepness = value_by_slope->getValue(1.0 - normal.y);
if (value_steepness < value_height) if (value_steepness < value_height)
{
if (value_circle < value_steepness)
{
return value_circle;
}
else
{ {
return value_steepness; return value_steepness;
} }
}
else
{
if (value_circle < value_height)
{
return value_circle;
}
else else
{ {
return value_height; return value_height;
} }
}
} }

View file

@ -8,8 +8,6 @@
namespace paysages { namespace paysages {
namespace definition { namespace definition {
class Circle;
class DEFINITIONSHARED_EXPORT Zone : public BaseDefinition class DEFINITIONSHARED_EXPORT Zone : public BaseDefinition
{ {
public: public:
@ -26,9 +24,6 @@ public:
void setAbsoluteHeight(); void setAbsoluteHeight();
void setRelativeHeight(double min, double middle, double max); void setRelativeHeight(double min, double middle, double max);
void includeCircleArea(double value, double centerx, double centerz, double softradius, double hardradius);
void excludeCircleArea(double centerx, double centerz, double softradius, double hardradius);
void getHeightCurve(Curve* curve) const; void getHeightCurve(Curve* curve) const;
void setHeightCurve(Curve* curve); void setHeightCurve(Curve* curve);
void addHeightRangeQuick(double value, double hardmin, double softmin, double softmax, double hardmax); void addHeightRangeQuick(double value, double hardmin, double softmin, double softmax, double hardmax);
@ -47,9 +42,6 @@ private:
Curve* value_by_height; Curve* value_by_height;
Curve* value_by_slope; Curve* value_by_slope;
Circle* circles_included;
int circles_included_count;
}; };
} }