Stop objects from overlapping the edge of the triangle in which they are placed. This should stop buildings encroaching roads etc.
This commit is contained in:
parent
2a9d39f201
commit
cf2619613d
@ -235,7 +235,8 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void addRandomPoints(float coverage,
|
void addRandomPoints(double coverage,
|
||||||
|
double spacing,
|
||||||
osg::Texture2D* object_mask,
|
osg::Texture2D* object_mask,
|
||||||
std::vector<std::pair<SGVec3f, float> >& points)
|
std::vector<std::pair<SGVec3f, float> >& points)
|
||||||
{
|
{
|
||||||
@ -271,22 +272,30 @@ public:
|
|||||||
float c = 1 - a - b;
|
float c = 1 - a - b;
|
||||||
SGVec3f randomPoint = a*v0 + b*v1 + c*v2;
|
SGVec3f randomPoint = a*v0 + b*v1 + c*v2;
|
||||||
|
|
||||||
if (object_mask != NULL) {
|
// Check that the point is sufficiently far from
|
||||||
SGVec2f texCoord = a*t0 + b*t1 + c*t2;
|
// the edge of the triangle by measuring the distance
|
||||||
|
// from the three lines that make up the triangle.
|
||||||
// Check this random point against the object mask
|
if (((length(cross(randomPoint - v0, randomPoint - v1)) / length(v1 - v0)) > spacing) &&
|
||||||
// blue (for buildings) channel.
|
((length(cross(randomPoint - v1, randomPoint - v2)) / length(v2 - v1)) > spacing) &&
|
||||||
osg::Image* img = object_mask->getImage();
|
((length(cross(randomPoint - v2, randomPoint - v0)) / length(v0 - v2)) > spacing) )
|
||||||
unsigned int x = (int) (img->s() * texCoord.x()) % img->s();
|
{
|
||||||
unsigned int y = (int) (img->t() * texCoord.y()) % img->t();
|
if (object_mask != NULL) {
|
||||||
|
SGVec2f texCoord = a*t0 + b*t1 + c*t2;
|
||||||
if (mt_rand(&seed) < img->getColor(x, y).b()) {
|
|
||||||
// The red channel contains the rotation for this object
|
// Check this random point against the object mask
|
||||||
points.push_back(std::make_pair(randomPoint, img->getColor(x,y).r()));
|
// blue (for buildings) channel.
|
||||||
}
|
osg::Image* img = object_mask->getImage();
|
||||||
} else {
|
unsigned int x = (int) (img->s() * texCoord.x()) % img->s();
|
||||||
points.push_back(std::make_pair(randomPoint, mt_rand(&seed)));
|
unsigned int y = (int) (img->t() * texCoord.y()) % img->t();
|
||||||
}
|
|
||||||
|
if (mt_rand(&seed) < img->getColor(x, y).b()) {
|
||||||
|
// The red channel contains the rotation for this object
|
||||||
|
points.push_back(std::make_pair(randomPoint, img->getColor(x,y).r()));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
points.push_back(std::make_pair(randomPoint, mt_rand(&seed)));
|
||||||
|
}
|
||||||
|
}
|
||||||
num -= 1.0;
|
num -= 1.0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -536,6 +536,7 @@ struct SGTileGeometryBin {
|
|||||||
std::vector<std::pair<SGVec3f, float> > randomPoints;
|
std::vector<std::pair<SGVec3f, float> > randomPoints;
|
||||||
|
|
||||||
i->second.addRandomPoints(object->get_coverage_m2(),
|
i->second.addRandomPoints(object->get_coverage_m2(),
|
||||||
|
object->get_spacing_m(),
|
||||||
mat->get_object_mask(i->second),
|
mat->get_object_mask(i->second),
|
||||||
randomPoints);
|
randomPoints);
|
||||||
std::vector<std::pair<SGVec3f, float> >::iterator l;
|
std::vector<std::pair<SGVec3f, float> >::iterator l;
|
||||||
|
Loading…
Reference in New Issue
Block a user