Commit ac76d7bc authored by VAN TOLL Wouter's avatar VAN TOLL Wouter

GUI and toric worlds:

- Now drawing the bounding-box of a toric world.
- ZoomToFit() uses this bounding box as well.
parent f043046c
......@@ -48,6 +48,21 @@ public:
/// It moves all agents forward and then possibly teleports them to the other end of the world, to simulate a wrap-around effect.</summary>
virtual void DoStep_MoveAllAgents() override;
/// <summary>Returns the width of this toric world.</summary>
inline float GetWidth() const { return width_; }
/// <summary>Returns the height of this toric world.</summary>
inline float GetHeight() const { return height_; }
/// <summary>Creates and returns two 2D vectors denoting this world's bounding box.</summary>
/// <returns>A pair of Vector2D objects: the first denotes the bottom-left corner of the toric world,
/// and the second denotes the top-right corner.</returns>
inline std::pair<Vector2D, Vector2D> GetBoundingBox() const
{
float halfW = width_ / 2.f, halfH = height_ / 2.f;
return { Vector2D(-halfW,-halfH), Vector2D(halfW, halfH) };
}
private:
void computeNeighbors_Displaced(const Vector2D& position, const Vector2D& displacement, float search_radius, const Agent* queryingAgent,
NeighborList& result) const;
......
......@@ -34,6 +34,8 @@
#include <tools/Color.h>
#include <tools/HelperFunctions.h>
#include <Engine/core/worldToric.h>
// Vertex shader: calculates the position of a vertex in the OpenGL view, and passes a color onto the fragment shader.
static const char *vertexShaderSource =
"attribute vec3 vertex;\n"
......@@ -68,6 +70,7 @@ static const int nrThreadsForSimulation = 4;
static const std::string DefaultScenarioFile = "../examples/Circle15-RVO.xml";
const double Depth_Grid = 0.1;
const double Depth_GridBoundary = 0.15;
const double Depth_Obstacles = 0.2;
const double Depth_Agents = 0.5;
......@@ -224,7 +227,12 @@ void UMANSOpenGLWidget::OpenScenarioFileDialog()
void UMANSOpenGLWidget::ZoomToFit()
{
// find the bbox and aspect ratio of the environment
const std::pair<Vector2D, Vector2D>& bbox = { {-10, -10}, {10, 10} };
std::pair<Vector2D, Vector2D> bbox;
if (simulator->GetWorld()->GetType() == WorldBase::Type::TORIC_WORLD)
bbox = dynamic_cast<const WorldToric*>(simulator->GetWorld())->GetBoundingBox();
else
bbox = { {-10, -10}, {10, 10} };
double width_environment = bbox.second.x - bbox.first.x;
double height_environment = bbox.second.y - bbox.first.y;
double aspect_environment = width_environment / height_environment;
......@@ -400,33 +408,71 @@ void UMANSOpenGLWidget::drawAgent(const Agent& agent)
void UMANSOpenGLWidget::drawEnvironment(const bool refresh)
{
const WorldBase* world = simulator->GetWorld();
// clear the old visualization?
if (refresh)
{
visualizationData[Target_Grid]->ClearData();
visualizationData[Target_Environment_Solid]->ClearData();
visualizationData[Target_Environment_Contours]->ClearData();
}
// - draw the interior of all obstacles
for (const auto& ob : simulator->GetWorld()->GetObstacles())
for (const auto& ob : world->GetObstacles())
for (const auto& t : ob.GetTriangles())
addPointsToBuffer(t, QColor(195, 195, 195), Target_Environment_Solid, Depth_Obstacles);
// - draw a grid for scale
// - draw a grid
drawGrid(refresh);
}
void UMANSOpenGLWidget::drawGrid(bool refresh)
{
const WorldBase* world = simulator->GetWorld();
// clear the old visualization?
if (refresh)
{
visualizationData[Target_Grid]->ClearData();
}
// Determine the bounds of the grid
std::pair<Vector2D, Vector2D> bbox;
// - in toric worlds, use the actual width and height of the world
if (simulator->GetWorld()->GetType() == WorldBase::TORIC_WORLD)
{
bbox = dynamic_cast<const WorldToric*>(world)->GetBoundingBox();
// draw the bounding box in a different color
std::vector<LineSegment2D> grid_boundary = {
LineSegment2D({bbox.first.x, bbox.first.y }, {bbox.first.x, bbox.second.y}),
LineSegment2D({bbox.second.x, bbox.first.y }, {bbox.second.x, bbox.second.y}),
LineSegment2D({bbox.first.x, bbox.first.y }, {bbox.second.x, bbox.first.y }),
LineSegment2D({bbox.first.x, bbox.second.y}, {bbox.second.x, bbox.second.y})
};
addSegmentsToBuffer(grid_boundary, QColor(255, 0, 0), Target_Grid, Depth_GridBoundary);
}
// - otherwise, use a default range of -100 to +100
else
bbox = { {-100,-100}, {100, 100} };
std::vector<LineSegment2D> grid, grid_major;
const int xMin = -100, xMax = 100, yMin = -100, yMax = 100, majorSteps = 10;
for (int x = xMin; x <= xMax; ++x)
const int majorSteps = 10;
// vertical lines
for (int x = (int)ceil(bbox.first.x); x <= bbox.second.x; ++x)
{
LineSegment2D seg(Vector2D(x, yMin), Vector2D(x, yMax));
LineSegment2D seg(Vector2D(x, bbox.first.y), Vector2D(x, bbox.second.y));
if (x % majorSteps == 0)
grid_major.push_back(seg);
else
grid.push_back(seg);
}
for (int y = yMin; y <= yMax; ++y)
// horizontal lines
for (int y = (int)ceil(bbox.first.y); y <= bbox.second.y; ++y)
{
LineSegment2D seg(Vector2D(xMin, y), Vector2D(xMax, y));
LineSegment2D seg(Vector2D(bbox.first.x, y), Vector2D(bbox.second.x, y));
if (y % majorSteps == 0)
grid_major.push_back(seg);
else
......
......@@ -75,7 +75,8 @@ private:
void drawSimulation();
void drawAgent(const Agent& agent);
void drawEnvironment(const bool refresh=false);
void drawEnvironment(const bool refresh = false);
void drawGrid(const bool refresh = false);
void addPointsToBuffer(const std::vector<Vector2D>& points, const QColor& color, const std::string& target, const double depth);
void addSegmentsToBuffer(const std::vector<LineSegment2D>& segments, const QColor& color, const std::string& target, const double depth);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment