Wednesday 4 December 2013

Scene Graphs

 Only nine more days until the final examination for Game Engines so I decided to review some things that might be on the final exam. Why not start with scene graphs? Scene graphs are very useful when designing games because they keep everything really organized. They show the relationships between different objects in game. Scene graphs are a very helpful tool when design games. They are used to show the relationships between objects in the game. They form a hierarchy to display how nodes are parented to each other either as a parent or a child.
http://archive.gamedev.net/images.gamedev.net/features/programming/scenegraph/image001.jpg
The picture above shows a basic scene graph similar to how the homework question "solar system" works. The root node is that "star" at the top. The picture depicts how the planets are children of the sun. The moons are not parents at all since there is nothing below any of them. The planets on the other hand are parents to the moons and children of the star. Again, this is just a basic diagram but it shows exactly how the base homework question number four works.
Scene graphs aren't just a great tool to keep organization and to visually show how everything is connected. They are also great for transformation and inheritance. When a game uses animation it requires for the children to follow suit with the parent. If  transformations or movement is done by a parent a child will react accordingly but not the other way a round. If you move your finger does your forearm move? No it doesn't, but on the other hand if you move your forearm your finger will move positions as well.
http://resumbrae.com/ub/dms423_f09/07/articulated-upper.jpg
This picture above helps add to my example stated above. From the graph you can see if you move the body, which is the root node, of the character forward five steps, every child i.e. head, lower arm, right hand, etc. will move five steps as well. If the lower right arm moves up five centimeters the parents above it wont be affected by this transformation, and neither will the left hand or lower left arm. The right hand will move as well though simply because it is the child node  of the lower right arm. This is due to the hierarchy stated above.

Scene graphs are also great for applying certain effects and elements in game to more than one subject. Say you have a  fire that starts in the living room of a house. The fire won't just immediately jump to the upstairs bathroom on the opposite side of the house. The fire would be rendered in the living room at first. It would find the children to the room. The children would be adjacent rooms and objects inside the room. This helps the game understand how the fire should appropriately and realistically act. It also helps systems graphically as it knows to only engulf the house it is in. Realistically the fire would spread, but in many video games you see  fire just staying attached to a car that's about to explode (like in grand theft auto) but the fire doesn't catch onto a tree if it is nearby. Also, the documentation would be shorter and cleaner since the programmers working on this piece of the game wouldn't need to write a bunch of if statements saying if fire catches here move here etc.

http://static3.wikia.nocookie.net/__cb20080620024452/gtawiki/images/b/b3/JustBusiness-GTASA.jpg 

Check out the shrubbery in the bottom left corner. The game knew to make the wheels of the car catch fire and explode but to save the GPU some constraints it doesn't catch onto the bush.

In conclusion, scene graphs are really useful tools that help structure and format a game engine. They are great for transformations, animations, shader effects and are a great way to use and depict hierarchy.

No comments:

Post a Comment