ENGINEERING (MENGE, GIT, & OPENGL) MENGE German for multitude, - - PowerPoint PPT Presentation

engineering
SMART_READER_LITE
LIVE PREVIEW

ENGINEERING (MENGE, GIT, & OPENGL) MENGE German for multitude, - - PowerPoint PPT Presentation

ENGINEERING (MENGE, GIT, & OPENGL) MENGE German for multitude, many, or crowd Modular pedestrian simulation framework Black box pedestrian simulation Simple experiments Complex, time-varying scenarios Development of


slide-1
SLIDE 1

ENGINEERING

(MENGE, GIT, & OPENGL)

slide-2
SLIDE 2

MENGE

2

  • German for multitude, many, or crowd
  • Modular pedestrian simulation framework
  • Black box pedestrian simulation
  • Simple experiments
  • Complex, time-varying scenarios
  • Development of novel pedestrian models
  • Modular in two senses
  • Swap pedestrian models for comparisons
  • Construct complex scenarios from simple modules

University of North Carolina at Chapel Hill

Menge

slide-3
SLIDE 3

MENGE

3 University of North Carolina at Chapel Hill

Menge

slide-4
SLIDE 4

MENGE

4

<?xml version="1.0"?> <Experiment version="2.0"> <Common time_step="0.1" visible_neighbors="0" /> <Helbing agent_scale="2000" obstacle_scale="4000" reaction_time="0.5" body_force="1200" friction="2400" force_distance="0.015" /> <Dummy stddev="0.05" /> <AgentSet> <Common max_angle_vel="360" max_neighbors="10"

  • bstacleSet="1" neighbor_dist="5" r="0.19" class="1" pref_speed="1.04"

max_speed="2" max_accel="5" priority="0.0"/> <FD factor="1.57" buffer="0.9" /> <Helbing mass="80" /> <ORCA tau="3" tauObst="0.15" /> <Agent p_x="2.0" p_y="0" /> </AgentSet> …

University of North Carolina at Chapel Hill

Menge

Scene specification

slide-5
SLIDE 5

MENGE

5

<?xml version="1.0"?><Population> <GoalSet id="0"> <Goal type="point" id="0" x="-3" y="0.0"/> <Goal type="point" id="1" x="3" y="0.0"/> </GoalSet> <Behavior class="1" initVel="ZERO"> <State name="Walk1" speedPolicy="min" final="0" > <AbsoluteGoal goalSet="0" goal="0" perAgent="0" /> <VelComponent type="goal" weight="1.0" /> </State> <State name="Reverse1" speedPolicy="min" final="0"> <AbsoluteGoal goalSet="0" goal="1" perAgent="0" /> <VelComponent type="goal" weight="1.0"/> <Action type="offset_property" property="r" dist="c" value="0.05" exit_reset="0"/> <Action type="scale_property" property="pref_speed" dist="c" value="1.05" exit_reset="0"/> </State> <Transition order="0" type="goal_circle" from="Walk1" to="Reverse1" radius="0.2" inside="1" /> <Transition order="0" type="goal_circle" from="Reverse1" to="Walk1" radius="0.2" inside="1" /> </Behavior> …

University of North Carolina at Chapel Hill

Menge

Behavior specification

slide-6
SLIDE 6

MENGE

6 University of North Carolina at Chapel Hill

Menge

slide-7
SLIDE 7

MENGE

7 University of North Carolina at Chapel Hill

Menge

slide-8
SLIDE 8

8

  • Works with a particular kind of pedestrian model
  • Abstract function: f: ( R2 x S )  R2
  • Given:
  • a preferred velocity in R2
  • The local simulation state
  • Produces actual velocity

University of North Carolina at Chapel Hill

Menge

PHILOSOPHY

slide-9
SLIDE 9

9

  • This is a very common model
  • van den Berg et al., 2008, van den Berg et al.,

2009, Helbing et al., 2000, Shukla et al., 2005, Karamouzas et al., 2009, Johansson et al., 2007, Narain et al., 2009, Zanlungo et al., 2010, Chraibi et al., 2010, Reynolds, 1995, cellular automata, and even more….

  • (although there are some exceptions)
  • Treuille et al. 2006, Kapadia et al., 2011

University of North Carolina at Chapel Hill

Menge

PHILOSOPHY

slide-10
SLIDE 10

PEDESTRIAN SIMULATOR ARCHITECTURE

10

  • Simulation State: obstacles (static & dynamic), agents
  • Goal Selection: High-order model of what the agent wants
  • Static Planning: Plan to reach goal vs. static obstacles
  • Local Collision Avoidance: Adapt plan because of other agents

Simulator State

University of North Carolina at Chapel Hill

Goal Selection Static Planning Goal Local Collision Avoidance

v0

Menge

slide-11
SLIDE 11

11

  • Factors out the computation of the inputs:
  • Preferred velocity
  • Local state
  • Factors out the scene integration
  • A pedestrian simply defines the function, f: ( R2 x S )

 R2

  • Single scene and behavior specification can be used

across arbitrary models.

  • Facilitates experimentation and comparison

University of North Carolina at Chapel Hill

Menge

ARCHITECTURE

slide-12
SLIDE 12

ARCHITECTURE

12

  • Expandable
  • Uses a plug-in architecture to define new

elements to be used at runtime

  • Pedestrian models
  • Spatial query structures
  • Elevation (for 2.5D simulation)
  • Path planning algorithms
  • Behavioral components

University of North Carolina at Chapel Hill

Menge

slide-13
SLIDE 13

ARCHITECTURE

13

  • Behavior  preferred velocity
  • Limited interpretation – motion in space
  • Where is the agent going, how is it getting there
  • Finite state machine  time-varying

University of North Carolina at Chapel Hill

Menge

Behavior FSM Simulator v0 state

slide-14
SLIDE 14

SIMULATOR

14

  • Data
  • Maintains environment
  • Agent state
  • Static environment
  • Elevation data
  • Functions
  • Nearest neighbor
  • Integrator
  • Pedestrian model

University of North Carolina at Chapel Hill

Menge

Simulator

Spatial Query Elevation Integrator Ped Model Agents Obstacles

slide-15
SLIDE 15

SIMULATOR

15

  • Accelerated k-Nearest

Neighbor Queries

  • Grid
  • KD-tree
  • Navigation mesh
  • Bounding volume hierarchy

(BVH)

  • Support k-nearest and visibility

queries

University of North Carolina at Chapel Hill

Menge

Simulator

Spatial Query Elevation Integrator Ped Model Agents Obstacles

slide-16
SLIDE 16

SIMULATOR

16

  • Elevation queries
  • Height field
  • Function composition
  • Navigation mesh
  • Support height at pos (x,y) and

gradient as pos queries

  • Models 2.5D

University of North Carolina at Chapel Hill

Menge

Simulator

Spatial Query Elevation Integrator Ped Model Agents Obstacles

slide-17
SLIDE 17

SIMULATOR

17

  • Integrator (all explicit)
  • Euler-forward
  • RK-2
  • RK-4
  • Not currently architected for

user-configuration

University of North Carolina at Chapel Hill

Menge

Simulator

Spatial Query Elevation Integrator Ped Model Agents Obstacles

slide-18
SLIDE 18

SIMULATOR

18

  • Pedestrian model
  • “Dummy”
  • Helbing
  • ORCA
  • Implement
  • newVelocity( pref, state)
  • XML parsing callbacks

University of North Carolina at Chapel Hill

Menge

Simulator

Spatial Query Elevation Integrator Ped Model Agents Obstacles

slide-19
SLIDE 19

BEHAVIORAL FSM

19

  • States
  • Velocity components
  • Actions
  • Transitions
  • Goal
  • Specification and selection
  • Specified by XML

University of North Carolina at Chapel Hill

Menge

slide-20
SLIDE 20

STATES

20

  • Primary purpose
  • Determine an agent’s preferred velocity
  • Velocity Component (you’ll be making one of

these)

  • Secondary purpose
  • Temporarily change the agent’s state while in the

state

  • Action

University of North Carolina at Chapel Hill

Menge

slide-21
SLIDE 21

VELOCITY COMPONENT

21

  • Model for computing preferred velocity
  • Includes
  • Don’t move (zero velocity)
  • Constant velocity/direction
  • Walk straight to goal
  • Follow path from navigation mesh/roadmap
  • Guidance field

University of North Carolina at Chapel Hill

Menge

slide-22
SLIDE 22

TRANSITIONS

22

  • Conditions under which an agent changes state
  • Temporal
  • Spatial
  • Probabilistic
  • Agent state (including custom agent state)

University of North Carolina at Chapel Hill

Menge

slide-23
SLIDE 23

GOALS

23

  • Each agent has a goal point
  • Which point?
  • The agent’s position upon entering the state
  • Offset of agent’s initial position
  • Mirror over world origin
  • Selecting point from goal specification

University of North Carolina at Chapel Hill

Menge

slide-24
SLIDE 24

GOALS

24

  • Goal Specification
  • GoalSets: a weighted collection of Goals
  • Goal selected from set
  • Explicitly
  • Randomly (with uniform or weighted

probability)

  • Euclidian distance (near/far)
  • Path distance (nav mesh/road map)

University of North Carolina at Chapel Hill

Menge

slide-25
SLIDE 25

GOALS

25

  • Goal
  • Point
  • Disk
  • Axis-aligned box
  • Oriented box

University of North Carolina at Chapel Hill

Menge

slide-26
SLIDE 26

MENGE

26

<?xml version="1.0"?><Population> <GoalSet id="0"> <Goal type="point" id="0" x="-3" y="0.0"/> <Goal type="point" id="1" x="3" y="0.0"/> </GoalSet> <Behavior class="1" initVel="ZERO"> <State name="Walk1" speedPolicy="min" final="0" > <AbsoluteGoal goalSet="0" goal="0" perAgent="0" /> <VelComponent type="goal" weight="1.0" /> </State> <State name="Reverse1" speedPolicy="min" final="0"> <AbsoluteGoal goalSet="0" goal="1" perAgent="0" /> <VelComponent type="goal" weight="1.0"/> <Action type="offset_property" property="r" dist="c" value="0.05" exit_reset="0"/> <Action type="scale_property" property="pref_speed" dist="c" value="1.05" exit_reset="0"/> </State> <Transition order="0" type="goal_circle" from="Walk1" to="Reverse1" radius="0.2" inside="1" /> <Transition order="0" type="goal_circle" from="Reverse1" to="Walk1" radius="0.2" inside="1" /> </Behavior> …

University of North Carolina at Chapel Hill

Menge

Behavior specification

slide-27
SLIDE 27

MENGE

27

  • Code available on sourceforge
  • git clone git://git.code.sf.net/p/menge/code

menge-code

  • Documentation at
  • http://gamma.cs.unc.edu/PBlock/
  • More will be coming today
  • Hint of homework…

University of North Carolina at Chapel Hill

Menge

slide-28
SLIDE 28

28

  • Source control
  • http://git-scm.com/
  • Like SVN, CVS, and other but with some

philosophical differences

  • University of North Carolina at Chapel Hill

Menge

GIT

slide-29
SLIDE 29

29

  • Three reasons you want to use it
  • You have a full copy of the repository on your

machine

  • Files are not versioned separately – changes are

lumped together

  • That’s how you get the code for your homework

(and how you’ll inherit the inevitable bug fixes)

University of North Carolina at Chapel Hill

Menge

GIT

slide-30
SLIDE 30

30

  • 90% of what you need to do you can do with 2

commands

  • git add (adding changes to be committed)
  • git commit (performing the commit)
  • The rest of what you need
  • git clone (copying a repository from existing

repository)

  • git branch (creating a branch)
  • git merge (merge one branch into another)

University of North Carolina at Chapel Hill

Menge

GIT

slide-31
SLIDE 31

31

  • 90% of what you need to do you can do with 2

commands

  • git add (adding changes to be committed)
  • git commit (performing the commit)

University of North Carolina at Chapel Hill

Menge

GIT

slide-32
SLIDE 32

32

  • The rest of what you need
  • git clone (copying a repository from remote

repository)

  • git branch (creating a branch)
  • git merge (merge one branch into another)
  • git pull (update branch from remote repository)
  • git stash (temporarily stash your changes)

University of North Carolina at Chapel Hill

Menge

GIT

slide-33
SLIDE 33

33

  • State-based drawing
  • A “context” exists with certain state
  • Drawing color, line width, lighting information,

transformation matrix, etc.

  • We will use “immediate” mode
  • Simply perform a sequence of calls consisting
  • f state changes and drawing commands

University of North Carolina at Chapel Hill

Menge

OPENGL

slide-34
SLIDE 34

34

  • Menge has a class, SG::Context, which simplifies

much of what you want to do

  • Handles drawing text to the screen
  • Being able to select agents
  • This is the limit of what you need to do
  • See SimRuntime/BaseAgentContext.h

University of North Carolina at Chapel Hill

Menge

OPENGL

slide-35
SLIDE 35

35

  • Has several important

functions

  • drawUIGL
  • Draw things in

screen space (like an overlay)

  • draw3DGL
  • Draw things in the

actual 3D world

University of North Carolina at Chapel Hill

Menge

SG::CONTEXT

slide-36
SLIDE 36

36

  • Example: drawing orientation

// Acquire orientation Vector2 orient = agt->_orient; // Determine end point of vector Vector2 endPoint = agt->_pos + orient; // Disable alpha blending glDisable( GL_BLEND ); // Set the drawing color glColor3f( 0.75f, 0.75f, 0.75f ); // Inform the system we’re going to be drawing lines glBegin( GL_LINES ); // A sequence of vertex – each 2 are considered one line glVertex3f( agt->_pos.x(), Y, agt->_pos.y() ); glVertex3f(endPoint.x(), Y, endPoint.y() ); // Stop drawing glEnd(); // draw Text writeTextRadially( "orient", endPoint, agt->_orient );

University of North Carolina at Chapel Hill

Menge

OPENGL

slide-37
SLIDE 37

37

  • Changing state – and restoring it
  • Because of the “state”, what gets drawn depends on

the state.

  • Rule 1: If you change the state, put it back
  • OpenGL gives a good way of doing this
  • glPushAttrib( … )
  • Push some aspects of the current state onto a

stack (the ones you intend to change)

  • glPopAttrib()
  • Restore the last state attributes back

University of North Carolina at Chapel Hill

Menge

OPENGL

slide-38
SLIDE 38

38

  • Changing state – and restoring it
  • Example
  • glColor3f( 1.f, 0.f, 0.f ); // red
  • glPushAttrib( GL_COLOR_BUFFER_BIT )
  • glColor3f( 1.f, 1.f, 1.f ); // white
  • glPopAttrib();
  • // draw lines – what color are the lines

University of North Carolina at Chapel Hill

Menge

OPENGL

slide-39
SLIDE 39

39

  • Changing state – and restoring it
  • Always, always, always, make sure that you

match up your glPushAttrib and glPopAttrib calls.

  • If you fail to do this, you could destroy the

stack and crash your program

University of North Carolina at Chapel Hill

Menge

OPENGL

slide-40
SLIDE 40

40

  • Drawing primitives
  • glBegin( … ) and glEnd()
  • How OpenGL interprets vertices

glBegin( PRIMITIVE_TYPE ) glVertex3f( x0, y0, z0 ) glVertex3f( x1, y1, z1 ) glVertex3f( x2, y2, z2 ) glVertex3f( x3, y3, z3 ) glEnd()

University of North Carolina at Chapel Hill

Menge

OPENGL

slide-41
SLIDE 41

41

  • Drawing primitives
  • Options for glBegin():
  • GL_POINTS – every vertex a point (see glPointSize( size ) )
  • GL_LINES – every two vertices a line segment (see glLineWidth( w ) )
  • GL_LINE_STRIP – draw a poly line – n vertices  n-1 connected

segments

  • GL_LINE_LOOP – draw a closed poly line – n verts  n connected

segments

  • GL_TRIANGLES – every three vertices is a triangle
  • GL_TRIANGLE_FAN – vertices define a fan of triangles
  • GL_TRIANGLE_STRIP – vertices define a strip of triangles
  • GL_QUADS – 4 verts defines a quad
  • GL_QUAD_STRIP – vertices define a strip of quads
  • GL_POLYGON – vertices define a convex polygon

University of North Carolina at Chapel Hill

Menge

OPENGL

slide-42
SLIDE 42

42

  • Drawing controlling how things appear
  • Color
  • glColor3f( r, g, b) or glColor4f( r, g, b, a )
  • Transparency

glPushAttrib( GL_ENABLE_BIT ) glEnable( GL_BLEND ) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

  • Just memorize these

University of North Carolina at Chapel Hill

Menge

OPENGL

slide-43
SLIDE 43

43

  • Drawing text
  • BaseAgentContext has several helper functions

for drawing into the 3D world – currently this assumes y = 0.

  • writeText( text, 2D position)
  • writeTextRadially( text, 2D position, 2D

direction)

  • writeAlignedText( text, 2D position, alignment)
  • All are shortcuts to the SG::TextWriter class

University of North Carolina at Chapel Hill

Menge

OPENGL

slide-44
SLIDE 44

44

  • What’s in front?
  • OpenGL uses a “depth” buffer.
  • Two parts:
  • Store the depth of the closest thing at each

pixel

  • Test against the closest pixel (if behind, don’t

draw)

  • There are times when you want to disable one or

the other of these

University of North Carolina at Chapel Hill

Menge

OPENGL

slide-45
SLIDE 45

45

  • What if I want something ALWAYS behind?
  • Disable writing to depth buffer
  • glDepthMask( GL_FALSE )
  • Draw it first
  • Enable writing to depth buffer
  • glDepthMask( GL_TRUE )
  • Draw everything else

University of North Carolina at Chapel Hill

Menge

OPENGL

slide-46
SLIDE 46

46

  • What if I want something ALWAYS in front?
  • Turn off the depth test
  • glDisable( GL_DEPTH_TEST )
  • Draw it
  • Enable depth test
  • glEnable( GL_DEPTH_TEST )

University of North Carolina at Chapel Hill

Menge

OPENGL

slide-47
SLIDE 47

47

  • Use the glPushAttrib/glPopAttrib to put things back
  • glPushAttrib(GL_DEPTH_BUFFER_BIT )
  • glDepthMask( GL_FALSE )
  • // draw
  • glPopAttrib()

University of North Carolina at Chapel Hill

Menge

OPENGL

slide-48
SLIDE 48

48

  • Use the glPushAttrib/glPopAttrib to put things back
  • glPushAttrib(GL_ENABLE_BIT )
  • glDisable( GL_DEPTH_TEST )
  • // draw
  • glPopAttrib()
  • In both cases, I don’t know what the state was before

I needed to change the state, but I’ve put it back

University of North Carolina at Chapel Hill

Menge

OPENGL

slide-49
SLIDE 49

QUESTIONS?

49 University of North Carolina at Chapel Hill