mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-26 22:57:00 +02:00
Start with low stifness to let zones pass through each other - typical temperature fall.
This commit is contained in:
parent
33eb28b570
commit
435b9f7881
@ -25,10 +25,13 @@ VCMI_LIB_NAMESPACE_BEGIN
|
|||||||
class CRandomGenerator;
|
class CRandomGenerator;
|
||||||
|
|
||||||
CZonePlacer::CZonePlacer(RmgMap & map)
|
CZonePlacer::CZonePlacer(RmgMap & map)
|
||||||
: width(0), height(0), scaleX(0), scaleY(0), mapSize(0), gravityConstant(0), stiffnessConstant(0),
|
: width(0), height(0), scaleX(0), scaleY(0), mapSize(0),
|
||||||
|
gravityConstant(5e-4f),
|
||||||
|
stiffnessConstant(3e-3f),
|
||||||
|
stifness(0),
|
||||||
|
stiffnessIncreaseFactor(1.05f),
|
||||||
map(map)
|
map(map)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int3 CZonePlacer::cords(const float3 & f) const
|
int3 CZonePlacer::cords(const float3 & f) const
|
||||||
@ -311,9 +314,6 @@ void CZonePlacer::placeZones(CRandomGenerator * rand)
|
|||||||
Connected zones attract, intersecting zones and map boundaries push back
|
Connected zones attract, intersecting zones and map boundaries push back
|
||||||
*/
|
*/
|
||||||
|
|
||||||
gravityConstant = 5e-4f;
|
|
||||||
stiffnessConstant = 3e-3f;
|
|
||||||
|
|
||||||
TZoneVector zonesVector(zones.begin(), zones.end());
|
TZoneVector zonesVector(zones.begin(), zones.end());
|
||||||
assert (zonesVector.size());
|
assert (zonesVector.size());
|
||||||
|
|
||||||
@ -333,8 +333,8 @@ void CZonePlacer::placeZones(CRandomGenerator * rand)
|
|||||||
TDistanceVector distances;
|
TDistanceVector distances;
|
||||||
TDistanceVector overlaps;
|
TDistanceVector overlaps;
|
||||||
|
|
||||||
const int MAX_ITERATIONS = 100;
|
//Start with low stiffness. Bigger graphs need more time and more flexibility
|
||||||
for (int i = 0; i < MAX_ITERATIONS; ++i) //until zones reach their desired size and fill the map tightly
|
for (stifness = stiffnessConstant / zones.size(); stifness <= stiffnessConstant; stifness *= stiffnessIncreaseFactor)
|
||||||
{
|
{
|
||||||
//1. attract connected zones
|
//1. attract connected zones
|
||||||
attractConnectedZones(zones, forces, distances);
|
attractConnectedZones(zones, forces, distances);
|
||||||
@ -561,7 +561,7 @@ void CZonePlacer::separateOverlappingZones(TZoneMap &zones, TForceVector &forces
|
|||||||
float minDistance = (zone.second->getSize() + otherZone.second->getSize()) / mapSize;
|
float minDistance = (zone.second->getSize() + otherZone.second->getSize()) / mapSize;
|
||||||
if (distance < minDistance)
|
if (distance < minDistance)
|
||||||
{
|
{
|
||||||
float3 localForce = (((otherZoneCenter - pos)*(minDistance / (distance ? distance : 1e-3f))) / getDistance(distance)) * stiffnessConstant;
|
float3 localForce = (((otherZoneCenter - pos)*(minDistance / (distance ? distance : 1e-3f))) / getDistance(distance)) * stifness;
|
||||||
//negative value
|
//negative value
|
||||||
forceVector -= localForce * (distancesBetweenZones[zone.second->getId()][otherZone.second->getId()] / 2.0f);
|
forceVector -= localForce * (distancesBetweenZones[zone.second->getId()][otherZone.second->getId()] / 2.0f);
|
||||||
overlap += (minDistance - distance); //overlapping of small zones hurts us more
|
overlap += (minDistance - distance); //overlapping of small zones hurts us more
|
||||||
@ -577,7 +577,7 @@ void CZonePlacer::separateOverlappingZones(TZoneMap &zones, TForceVector &forces
|
|||||||
float3 boundary = float3(x, y, pos.z);
|
float3 boundary = float3(x, y, pos.z);
|
||||||
auto distance = static_cast<float>(pos.dist2d(boundary));
|
auto distance = static_cast<float>(pos.dist2d(boundary));
|
||||||
overlap += std::max<float>(0, distance - size); //check if we're closer to map boundary than value of zone size
|
overlap += std::max<float>(0, distance - size); //check if we're closer to map boundary than value of zone size
|
||||||
forceVector -= (boundary - pos) * (size - distance) / this->getDistance(distance) * this->stiffnessConstant; //negative value
|
forceVector -= (boundary - pos) * (size - distance) / this->getDistance(distance) * this->stifness; //negative value
|
||||||
};
|
};
|
||||||
if (pos.x < size)
|
if (pos.x < size)
|
||||||
{
|
{
|
||||||
|
@ -57,6 +57,8 @@ private:
|
|||||||
|
|
||||||
float gravityConstant;
|
float gravityConstant;
|
||||||
float stiffnessConstant;
|
float stiffnessConstant;
|
||||||
|
float stifness;
|
||||||
|
float stiffnessIncreaseFactor;
|
||||||
//float a1, b1, c1, a2, b2, c2;
|
//float a1, b1, c1, a2, b2, c2;
|
||||||
//CMap * map;
|
//CMap * map;
|
||||||
//std::unique_ptr<CZoneGraph> graph;
|
//std::unique_ptr<CZoneGraph> graph;
|
||||||
|
Loading…
Reference in New Issue
Block a user