Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction General Data Structures - Arrays, Linked Lists - Stacks & Queues - Hash Tables & Binary Search Trees - Graphs Spatial Data Structures -Why.

Similar presentations


Presentation on theme: "Introduction General Data Structures - Arrays, Linked Lists - Stacks & Queues - Hash Tables & Binary Search Trees - Graphs Spatial Data Structures -Why."— Presentation transcript:

1 Introduction General Data Structures - Arrays, Linked Lists - Stacks & Queues - Hash Tables & Binary Search Trees - Graphs Spatial Data Structures -Why care? - Binary Space Partitioning (BSP) trees

2 You tell me.. Which data structure is suitable? Tile maps & Terrain maps Inventory (Hint: Dynamic storage) Efficient searching Command queuing Menus Collision Detection Visibility

3 Arrays & Linked Lists 2D arrays and linked lists are used as: - Single and multi- layered Tile maps in 2D scenes in which each tile acts like a pixel. - Terrain maps in 3D world where 2D array represents the height of each tile in a level. Utility: - Abstracts the idea of pixels to a higher level significantly simplifying a drawing engine: Demo-1; Demo-2 - Linked Lists can be used for inventory: Demo-3

4 Stacks & Queues Stacks: used to construct Menu, Submenus: Demo-4 Queues: used for command queuing e.g. Real Time Strategy (RTS) games such as Command & Conquer, War craft, Star craft: Demo-5 Trade Off: When expandability is more important than speed, use linked stacks and queues; otherwise use arrayed stacks and queues.

5 Others.. Hash Tables & Binary Search Trees: - searching; Demo-6 Trees: - Map editor (hierarchy of maps); - Skill system like RPGs such as Diablo 2 do. option to choose the skills e.g. healing skills or fighting skills. Graphs: - Portal Engine; games like Descent, Quake 2. more efficient method for rendering things:Demo-7

6 Spatial Partitioning What do we mean by spatial partitioning? Spatial partitioning mean dividing up the game world into regions that can be used to find spatial relationships between objects. Why do we need spatial partitioning? Scenegraphs are great for recording the dynamic relationships between dynamic objects, e.g. parts of a body. They are not so good for storing information about static elements in a game world, e.g. walls in a building.

7 Using Spatial Partitioning Spatial partitioning data structures are used to: Determine which parts of large static objects are visible, e.g. buildings, terrains. Determine neighborhood relationships between dynamic objects, e.g. for collision detection. Determine how much data needs to be sent across a network, e.g. based on what is currently visible to the client.

8 Spatial data Structures Spatial data structures store data indexed in some way by their spatial location –For instance, store points according to their location, or polygons, … –Before graphics, used for queries like “Where is the nearest hotel?” or “Which stars are strong enough to influence the sun?”

9 Applications Multitude of uses in computer games –Visibility - What can I see? –Ray intersections - What did the player just shoot? –Collision detection - Did the player just hit a wall? –Proximity queries - Where is the nearest power- up?

10 Spatial Partitioning Schemes Two common spatial partitioning schemes are: - Binary Space Partitioning (BSP) - Quadtree/Octree Partitioning The partitioning schemes are similar in some ways, both: - Recursively subdivide a space into smaller spaces - Construct tree data-structure that can be searched quickly - Are expensive to modify, hence they are best used for static features of a world when they can be pre-computed once

11 Binary Space Partitioning Binary space partitioning works by dividing a space into two subspaces at each recursion with a plane Choosing the best plane to divide a given space into two equally complex subspaces is the most difficult part. Most game engines analyze the geometry of a world and choose an existing polygon to define a plane. The analysis should determine which polygon will result in the most balanced tree.

12 Binary Space Partitioning Example Suppose that this figure - 1 represents the walls of a building in a game We want to pre-process this complex shape into a BSP tree consisting of simpler regions to assist real-time rendering

13 Walls of a building as space

14 First subdivision: Split occurs at polygon 16

15 Second subdivision: Split at polygon 4, 21

16 Final BSP tree

17 BSP Tree Node Data Structure What needs to be stored in a node? –Children pointers (always two) –Parent pointer - useful for moving about the tree –If a leaf node: Extents of cell How might we store it? –If an internal node: The split plane –List of pointers to the contents of the cell –Neighbors are useful in many algorithms Typically only store neighbors at leaf nodes Cells can have many neighboring cells –Portals are also useful - holes that see into neighbors

18 Building a BSP Tree Define a function, buildNode, that: –Takes a node with its cell defined and a list of its contents –Sets the splitting plane, creates the children nodes, divides the objects among the children, and recurses on the children, or –Sets the node to be a leaf node Create the root node and call buildNode with all the objects –Do we need the root node’s cell? What do we set it to? When do we choose to stop creating children? What is the hard part?

19 Choosing Splitting Planes Goals: –Trees with few cells –Planes that are mostly opaque (best for visibility calculations) –Objects not split across cells Some heuristics: –Choose planes that are also polygon planes –Choose large polygons first –Choose planes that don’t split many polygons –Try to choose planes that evenly divide the data –Let the user select or otherwise guide the splitting process –Random choice of splitting planes doesn’t do too badly

20 Drawing Order from BSP Trees BSP tress can be used to order polygons from back to front, or vice-versa –Descend tree with viewpoint –Things on the same side of a splitting plane as the viewpoint are always in front of things on the far side Can draw from back to front –Removes need for z-buffer, but few people care any more –Gives the correct order for rendering transparent objects with a z-buffer, and by far the best way to do it Can draw front to back –Use info from front polygons to avoid drawing back ones –Useful in software renderers (Doom?)

21 Dynamic Lights and BSPs Dynamic lights usually have a limited radius of influence to reduce the number of objects they light The problem is to find, using the BSP tree, the set of objects lit by the light (intersecting a sphere center (x,y,z) radius r) Solution: Find the distance of the center of the sphere from each split plane –What do we do if it’s greater than r distance on the positive side of the plane? –What do we do if it’s greater than r distance on the negative side of the plane? –What do we do if it’s within distance r of the plane? –Any leaf nodes reached contain objects that might be lit

22 BSP and Frustum Culling You have a BSP tree, and a view frustum –With near and far clip planes At each splitting plane: –Test the boundaries of the frustum against the split plane –What if the entire frustum is on one side of the split plane? –What if the frustum intersects the split plane? What do you test in situations with no far plane? What do you do when you get to a leaf?

23 References Data Structures for Game programmers by Ron Penton http://www.cs.wisc.edu/~schenney/course s/cs679-f2003/cs679.htmlhttp://www.cs.wisc.edu/~schenney/course s/cs679-f2003/cs679.html http://www.soi.city.ac.uk/~rob/Lecture08.p dfhttp://www.soi.city.ac.uk/~rob/Lecture08.p df http://www.gamedev.net


Download ppt "Introduction General Data Structures - Arrays, Linked Lists - Stacks & Queues - Hash Tables & Binary Search Trees - Graphs Spatial Data Structures -Why."

Similar presentations


Ads by Google