Skip to content

Commit

Permalink
Have added in basic visualisation of the collision forces.
Browse files Browse the repository at this point in the history
We hide navmap squares with no force by making them black (otherwise they just point in the default direction).
  • Loading branch information
Robadob committed Aug 16, 2022
1 parent 9adcc40 commit 54cddc3
Showing 1 changed file with 30 additions and 11 deletions.
41 changes: 30 additions & 11 deletions examples/pedestrian_navigation/src/main.cu
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ FLAMEGPU_AGENT_FUNCTION(output_pedestrian_location, flamegpu::MessageNone, flame
return flamegpu::ALIVE;
}
FLAMEGPU_AGENT_FUNCTION(output_navmap_cells, flamegpu::MessageNone, flamegpu::MessageArray2D) {
#ifdef VISUALISATION
// It would be far more efficient to set these once within the input file, as they do not change
if (FLAMEGPU->getStepCounter() == 0) {
FLAMEGPU->setVariable<float>("x_vis", (ENV_WIDTH / 256.0f) * FLAMEGPU->getVariable<int>("x") - (ENV_WIDTH / 2.0f) + (ENV_WIDTH / 512.0f));
FLAMEGPU->setVariable<float>("y_vis", 0.999f);
FLAMEGPU->setVariable<float>("z_vis", (ENV_WIDTH / 256.0f) * FLAMEGPU->getVariable<int>("y") - (ENV_WIDTH / 2.0f) + (ENV_WIDTH / 512.0f));
FLAMEGPU->setVariable<int>("is_active", FLAMEGPU->getVariable<float>("collision_x") + FLAMEGPU->getVariable<float>("collision_y") == 0 ? 0 : 1);
}
#endif

FLAMEGPU->message_out.setIndex(FLAMEGPU->getVariable<int>("x"), FLAMEGPU->getVariable<int>("y"));
FLAMEGPU->message_out.setVariable<int>("exit_no", FLAMEGPU->getVariable<int>("exit_no"));
FLAMEGPU->message_out.setVariable<float>("height", FLAMEGPU->getVariable<float>("height"));
Expand Down Expand Up @@ -376,8 +386,13 @@ int main(int argc, const char ** argv) {
navmap.newVariable<float>("exit5_y");
navmap.newVariable<float>("exit6_x");
navmap.newVariable<float>("exit6_y");
// navmap.newVariable<float>("x_vis"); // TODO, these need to be assigned a value
// navmap.newVariable<float>("y_vis");
#ifdef VISUALISATION
// Extra vars, not present in FLAMEGPU 1 version are required to visualise with stock visualiser
navmap.newVariable<float>("x_vis");
navmap.newVariable<float>("y_vis");
navmap.newVariable<float>("z_vis");
navmap.newVariable<int>("is_active");
#endif

navmap.newFunction("output_navmap_cells", output_navmap_cells).setMessageOutput("navmap_cell");
flamegpu::AgentFunctionDescription& gp_fn = navmap.newFunction("generate_pedestrians", generate_pedestrians);
Expand Down Expand Up @@ -477,17 +492,21 @@ int main(int argc, const char ** argv) {
pedestrian.setKeyFrameModel(flamegpu::visualiser::Stock::Models::PEDESTRIAN, "animate");
pedestrian.setModelScale(2.0f * 2.0f / 256.0f); // TBC
// Colour agents based on their targeted exit
pedestrian.setColor(flamegpu::visualiser::DiscreteColor<int>("exit_no", flamegpu::visualiser::Stock::Palettes::DARK2));
pedestrian.setColor(flamegpu::visualiser::DiscreteColor<int>("exit_no", flamegpu::visualiser::Stock::Palettes::DARK2, 1));
}
{
// auto& navmap = m_vis.addAgent("navmap");
// navmap.clearYVariable();
// navmap.setXVariable("x_vis"); // Can't vis int vars
// navmap.setZVariable("y_vis"); // Can't vis int vars
// navmap.setForwardXVariable("collision_x");
// navmap.setForwardZVariable("collision_y");
// navmap.setModel(flamegpu::visualiser::Stock::Models::ARROWHEAD);
// navmap.setModelScale(0.8f * 2.0f / 256.0f); // TBC
auto& navmap = m_vis.addAgent("navmap");
navmap.clearYVariable();
navmap.setXVariable("x_vis"); // Can't vis int vars
navmap.setYVariable("y_vis"); // Want to offset height
navmap.setZVariable("z_vis"); // Can't vis int vars
navmap.setForwardXVariable("collision_x");
navmap.setForwardZVariable("collision_y");
navmap.setModel(flamegpu::visualiser::Stock::Models::ARROWHEAD);
navmap.setModelScale(0.8f * 2.0f / 256.0f); // TBC
flamegpu::visualiser::DiscreteColor<int> nav_color("is_active", flamegpu::visualiser::Stock::Colors::BLACK);
nav_color[1] = flamegpu::visualiser::Stock::Colors::RED;
navmap.setColor(nav_color);
}
// Render the Subdivision of the navigation grid
{
Expand Down

0 comments on commit 54cddc3

Please sign in to comment.