title: How are game cinematics made?

text:
# Question
Title: How are game cinematics made?
How is a game cinematic made? I can't find a decent article anywhere to give at least starting point into understanding what it takes to create a cinematic.

I don't mean typical scripted game play, rather, the really nice cut scenes games have, like the ones Blizzard has for almost every game they develop.

http://www.youtube.com/watch?v=OGwCU\_qA22U

Note: I'm not sure what to tag this under.

# Answer
**Blood, sweat and tears beers**

For the movie-quality cinematics you see from companies like Blizzard, they are often following a process similar (albeit on a smaller scale) to the processes of professional movie studios like Pixar. This involves professional 3D artists, modellers, animators, etc, as well as various high-end technologies like 3DS Max, Maya, etc.

For the teaser trailer for Starcraft II, this interview with Blizzard (Part III particularly) mentions how the Marine 3D model had 5 million polygons, and the cinematic broke their renderer.

The Australian magazine Atomic also have a good article on Blizzard's cinematic development process here
> 16 votes

# Answer
They use a product like 3DS Max or Maya.
> 5 votes

# Answer
The creation process is very similar to building geometry for games. Same tools for modeling & animation Max, Maya, zBrush. Most characters for current gen are built to extremely high detail for normal map generation anyway, so often those assets can translate easily to the pre-rendered realm. The main differences are in shader complexity, rendering, and lighting.

A studio can do this all internally, particularly someone like Blizzard who are known for cinematics. It does require some individuals with a specific skillset so you need to keep them busy with work. Today most companies find it easier to farm out pre-rendered cinematics to external houses that focus on that sort of work. As an example you'll recognize several recent pieces done by Blur.
> 5 votes

# Answer
Step 1: Create assets in 3d program (3DS Max, Maya or blender)

Step 2: Rig assets

Step 3: Animate the needed animations on the rigged assets

Step 4: Create the scene, render and record.
> 4 votes

# Answer
Most companies have a cinematic team that is separate from the game development team. The models and scenes used in cinematics are often of a level of detail that would be completely unplayable in a live game, so it's likely the only shared assets are concept art. Large studios like Blizzard (I believe at least one of Sony's various sub-corps has one too) have their own internal cinematics team that works on the cutscenes, intros, and trailers for all of their products. Smaller companies may outsource this to another studio.

The Atomic article in jeffora's response is a great explanation of this process.
> 2 votes

# Answer
One of our (ArenaNet's) developers wrote a blog entry about how cinematics for Guild Wars 2 are created. There's also an accompanying video by our cinematic art lead -- this may not be exactly what you're after, though, since it's not fully pre-rendered 3D.

Back when I was a graphics programmer at Big Huge Games, we contracted with Blur for some of our cinema sequences (and another company, I believe, for the campaign cutscenes, but I am unfortunately drawing a blank as to who that was) -- there's a write-up on this process here. They were more disconnected videos, modeled, rigged, animated, and rendered out separately by the outsourcing team and we just played them back in-game at the appropriate point.
> 2 votes

---
Tags: video, trailer, cutscene
---


title: Licensing Theme Music from other games

text:
# Question
Title: Licensing Theme Music from other games
As part of my game, I thought it would be fun to make a hidden level that pays tribute to Mario Bros (one of the earliest games I ever played). It would be themed in that way with 8-bit graphics and question mark blocks and completing the level would say "Thank you but the princess is in another castle" or such.

For the sound track, I'm thinking of just overlaying the standard mario theme music by playing it on a virtual keyboard using a different instrument/timing or something.

My question is, am I legally safe? I'm not using anyone else's actual music, I'm just playing the same tune in a different way myself. Do I have to get licensing for this?

# Answer
I am not a lawyer.

Performing or rerecording a piece of music still requires that you get authorization from the creator, and Nintendo is very unlikely to grant that authorization at any price (I hear they turned down Justin Beiber). Fair use doesn't really apply in this case, either.

From an ethical perspective, I don't think you've got much to worry about, and Nintendo's not likely to go after your game unless it's really prominent (i.e. a AAA title). There are games out there that commit far worse appropriation of Mario, and they haven't been shut down.

If you want to be totally safe, compose or have someone compose a theme which is heavily reminiscent of the Mario overworld theme, but is an original composition.
> 4 votes

---
Tags: legal, music, licensing
---


# Question
Title: Triangulation A* (TA*) pathfinding algorithm
I need help understanding the Triangle A\* (TA\*) algorithm that is described by Demyen in his paper Efficient Triangulation-Based Pathfinding, on pages 76-81.

He describes how to adapt the regular A\* algorithm for triangulation, to search for other possibly more optimal paths, even after the final node is reached/expanded. Regular A\* stops when the final node is expanded, but this is not always the best path when used in a triangulated graph. This is exactly the problem I'm having.

The problem is illustrated on page 78, Figure 5.4:

I understand how to calculate the g and h values presented in the paper (page 80).

And I think the search stop condition is:

```
if (currentNode.fCost > shortestDistanceFound)
{
    // stop
    break;
}

```

where currentNode is the search node popped from the open list (priority queue), which has the lowest f-score. shortestDistanceFound is the actual distance of the shortest path found so far.

But how do I exclude the previously found paths from future searches? Because if I do the search again, it will obviously find the same path. Do I reset the closed list? I need to modify something, but I don't know what it is I need to change. The paper lacks pseudocode, so that would be helpful.

# Answer
I haven't implemented this, but as I read it, I think you'd do something like this:

```
shortestDistance = infinity
do A* with modified g cost
    if node.fCost > shortestDistance (section 5.5)
        don't open node
    if node.isGoal()
        run funnel algorithm (string pulling)
        update shortestDistance

```

The difference is that even if you find **a** path to the goal, it's not necessarily the **shortest** path. But you'll keep improving the upper bounds on the shortest path, meaning that you won't have to open all nodes. Eventually your open set should be empty, and the best path you've found so far should be the shortest.

The modified g cost that he describes seems like a big underestimate, so I'm skeptical about how well it works in practice.
> 3 votes

---
Tags: algorithm, path-finding
---


# Question
Title: What are some cool examples of procedural pixel shader effects?
What are some good examples of procedural or screen-space pixel shader effects? No code is necessary; I'm just looking for inspiration.

In particular, I'm looking for effects that are not dependent on geometry or the rest of the scene (so they would look okay rendered alone on a quad) and are not based on image processing (they don't require a "base image," though they can incorporate textures). Multi-pass or single-pass is fine. Screenshots or videos would be ideal, but ideas work too.

Here are a few examples of what I'm looking for (all from the RenderMonkey samples): alt text http://public.blu.livefilestore.com/y1pXcNg\_0EPZVzwu1T84a4Yek373x8062rhrNCA7UcftTjCkeiY-5uAuJiBYY29x2E53p5MO-uMA8FmEquvxsPCkA/effect1.jpg?psid=1alt text http://public.blu.livefilestore.com/y1p\_5Lx7BdjFyFRBkbcc0WakAT7Q-99fVcFOxmTXBbG4VtoFzC0UfAj51eSnE7ZOD84EYL2Y51HhMS2nWsohhn1mQ/effect2.jpg?psid=1 alt text http://public.blu.livefilestore.com/y1p\_5Lx7BdjFyE3KhYtHe-Cdg7XuXcJ9Ou-GKzED-kZnzACyB5ypA6NSCfsYfuKa0h3ztoDRwwq9qBddX2OfG0fhg/effect3.jpg?psid=1alt text http://nv3wrg.blu.livefilestore.com/y1p1iHFwf-wytDo8HlTJca8RfckA-iTKgvLiJm0t9iz3S35YgeEnt99NMjKDgotxa3Bv90wAhOYLabzx2Sd3LoEH2Hs76WR1vFM/effect5.jpg?psid=1

I'm aware of this question; I'm not asking for a source of actual shader implementations but instead for some inspirational ideas -- and the ones at the NVIDIA Shader Library mostly require a scene or are image processing effects.

# Answer
Interior mapping is a pretty awesome effect. It takes a boring flat quad and makes it look like a building with interiors, all entirely within the pixel shader. It's semi-procedural in that some of the assets are hand-crafted, but the shader places them procedurally.
> 29 votes

# Answer
For great inspiration don't forget to checkout the oldskool demo effects. Things like plasma, fire, copperbars, warps, lenses, rotozoomers come to mind.

Of course it would require some porting on your end, but thats a challenge i guess.

Here's a nice resource with some effects and the sourcefiles: http://www.oldskool.org/demos/explained/demo\_graphics.html
> 7 votes

# Answer
Check out Facewound. In particular look at the examples in the shader tutorial.
> 6 votes

# Answer
ShaderToy is a WebGL shader renderer which shows different shaders in your browser. It has many examples, and you can edit the examples and compile them on the fly! I've spent hours playing with it :)

You will need WebGL running in your browser, though. Chrome is probably your best bet at the moment.
> 3 votes

# Answer
There is a great set of shader examples here

Some great stuff you can build on and draw inspiration from.
> 2 votes

# Answer
Also have a look at software like Mental Mill. It allows node based shader programming with math operations. Add a bunch of random waves and images and see what comes out the other end. Can often find out far more from the process than images i find ("hey this looks like lightning swarms").
> 1 votes

# Answer
If you have a copy of the original Unreal, you can go through the texture packs in the editor and see all the neat effects. They're similar to the examples you posted in the original question.
> 1 votes

---
Tags: graphics, textures, art, shaders
---


# Question
Title: Software for game system design overview
Yes so this is a question more oriented towards the planning / project part of game development. What software do you use to plan your game, I am talking about visual stuff like a mindmap application for making some neat diagrams and so on, sort of like database design only it's for the game instead, is there any good ones?

Thanks

# Answer
Freeplane is an awesome fork of Freemind, but you may also like VUE.

For me, the best tools for game design have always been a pencil and graph paper. Then Google Docs or a wiki to disseminate information throughout the team. Google Groups is useful as well.
> 3 votes

# Answer
When I was at EA, we used some mindmapping software especially during meetings. Design docs were mostly done in Word, although the company has moved to doing most of that in Mediawiki now. Personally, I think wikis are a great fit for game design:

1. They're non-linear and easily cross-linked.
2. They support images inline.
3. Content is easy to edit by many people (since designs change often).
4. Anyone can view the docs with just a browser.
5. A history of changes is stored with every page.
> 4 votes

# Answer
The most important element in game planning is a good design document. The typical example is Chris Taylor's game design document. Also check out this question: "Design Document Contents"

Also for the technology involved in storing and editing documents and team management, check out "What type of document for game design?"
> 2 votes

# Answer
Nothing too exciting:

* Word Docs for initial outline
* Powerpoint to flesh out the pitch and get people excited
* Transition to Wiki once getting into actual prototyping. Wiki's are great for splitting up design tasks among several designers, showing how mechanics cross link and giving the rest of the team and easily sorted and searchable database of what should be in the game.
* Continue with focused powerpoints for mechanics when needed. Lots of people are visual learners and I've found you can just communicate ideas more quickly this way.
* Post-it notes and a big section of wall somewhere for doing scoping and auditing exercises.

*NOTE*

Wiki's don't police themselves and can get out of control or just die if you don't have at least one resident Nazi who keeps the whole look & quality consistent. Build out templates for content pages and stick to them. For information that changes regularly (like tuning numbers), put it in source control and just link to it from the page. Keep all other information in the Wiki.
> 0 votes

# Answer
My personal workflow is as follows:

* A Google text document to capture the initial set of ideas under a meaningful title.
* Later, I'd move those ideas into a mind-map to start organising and building upon them.
* Then, I just keep a To-Do list of tasks necessary to complete the project.
* I might draw out complicated systems as UML, although I've never been happy with any of the tools for that so I tend to use pencil and paper.

That works for me as a lone developer. When working in a team we had good results when working with a Wiki for the design (my preference was DokuWiki but there may be something better, eg. Confluence) and issue and task tracking software for tasks (again, we used JIRA but you can get by with Bugzilla, Trac, Redmine, etc)
> 0 votes

---
Tags: game-design, project-management, planning
---


# Question
Title: [Unity] Render an animated texture to a screen
I'm looking for a way to write a typed text on a texture, and then render it on a screen: in the game it's just the screen of a computer where a scientist is typing text on.

The texture will be already generated: it will have several textures in it.

I can't find any obvious way to do a simple render to texture with unity, how could I do that ?

# Answer
> 2 votes
You can also just texture directly with an .mov, .mpg, .avi and so on.

Details here: Movie Texture

NOTE: Texturing with a video file is only available in Unity Pro and isn't supported on iOS/Andoid

# Answer
> 1 votes
I don't think you can use render textures in anything but Unity Pro. But assuming you have that...

http://unity3d.com/support/documentation/ScriptReference/Camera-targetTexture.html

Basically set up a camera pointing to whatever you want your render texture to be. You can set up layers so that you camera can only see things on a certain layer instead of having to have it off in the middle of nowhere. You then just have your screen's texture point to that render texture you've created.

Then you can just point the camera to whatever you want. If you want to just swap between textures it would be pretty easy to write a script to cycle some object to go between textures. You could also do it dynamically with 3D text if you wanted to save on texture space (and assuming you already had a font texture loaded).

---
Tags: unity, textures, rendering
---


# Question
Title: Persisting high score table in flash game without a network. (Featuring: HttpListenerException)
this question is very programming-centric, but it's for a game so I figured I might as well post it here.

I'm doing polishing work on a GGJ '11 game because it will be shown at an indie arcade tomorrow afternoon, and they're expecting our final build in the morning.

We'd like to have a high score table that displays during attract mode, but since it's Flash (Flixel) it would require some networking, Mochi, or something to keep a record of these scores. Only problem is the machine we'd be running on probably won't have network access.

As a quick solution, I thought I'd just write up a dinky little high score server in C#/.NET that could take basic GET requests for submitting scores and getting the score list. We're talking REAL basic, like blocking while waiting for an incoming request, run & forget console app, etc.

There's no guarantee that our .swf won't get reloaded, and we'd like the scores to persist, so this server would pretty much exists to keep a safe copy of the scores that the game can add to and request, and occasionally the server will write the scores to a flat text file.

But, HttpListener is giving me Error Code 87 'The parameter is incorrect.' Have any idea what I'm doing wrong? Or better yet, am I barking up the wrong tree and missing an obviously simpler solution?

This is all I've got so far in my Main():

```
HttpListener listener = new HttpListener();
listener.Prefixes.Add("http://localhost:66666/");
listener.Start();

```

The exception happens at `listener.Start();` and the stack trace is:

```
   at System.Net.HttpListener.AddAllPrefixes()
   at System.Net.HttpListener.Start()
   at WOSEBCE_ScoreServer.Program.Main(String[] args) in C:\Users\Michael\Documents\Visual Studio 2010\VS2010 Projects\WOSEBCE_ScoreServer\WOSEBCE_ScoreServer\Program.cs:line 24
   at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()

```

# Answer
Have you considered using SharedObject? It allows you to store data on the hard disk, and the data is accessible even if the SWF is reloaded. Seems to meet your requirements, and doesn't require a separate program of any sort.
> 5 votes

---
Tags: c#, flash, networking, .net, leaderboards
---


# Question
Title: Todo List for game design and development
Is there and TODO list for a game design and development. I'm going to do a game in XNA and I would like to do my TODO list like:

1. Logo
2. Backgroud
3. Music

etc.

Any tips?

# Answer
As far as game design goes, you should start a wiki or document with your other collaborators and just keep adding to it. The new Google docs is really good for collaboration I find.

As well, try and "play the game in your head", and imagine how a player will interact with the finished product. Take note of everything. The user launches the game, what does he see? Is there an intro video? Can he hit a key to skip it? How does the screen transition from the intro video to the main menu? Is there an animation on the main menu, such as the game title scrolling into frame? Should there be? How does the user select a menu option? Does it play a sound effect when he does? etc. etc. etc. Just keep asking yourself questions from the user perspective throughout the development of the game.

Also, this article has some good things to check for regardless of platform: http://create.msdn.com/en-US/education/catalog/article/bestpractices\_31
> 5 votes

# Answer
Try this: http://agilezen.com/
> 0 votes

---
Tags: xna
---


# Question
Title: What are some good resources on creating and reading 2D game levels in Java?
Could some resources be listed in relation to the creation and management of simplistic, efficient 2D game levels, that are available for use with Java?

# Answer
> 3 votes
Have a look at Tiled or OGMO Editor. These editors allow you to create your levels and can also write the level-data to XML. Parsing the XML data in Java should be rather simple. Alternatively you could have a look at the AndEngine which comes with a parser for the TMX format (TMX is an XML format written by Tiled).

# Answer
> -3 votes
try to look at www.processing.org it's a simple and quite power system for making 2d in java

---
Tags: 2d, java, level-design
---


# Question
Title: How can I selectively update XNA GameComponents?
I have a small 2D game I'm working on in XNA. So far, I have a player-controlled ship that operates on vector thrust and is terribly fun to spin around in circles. I've implemented this as a **DrawableGameComponent** and registered it with the game using **game.Components.Add(this)** in the Ship object constructor.

How can I implement features like pausing and a menu system with my current implementation? Is it possible to set certain GameComponents to not update?

Is this something for which I should even be using a DrawableGameComponent? If not, what are more appropriate uses for this?

# Answer
> 6 votes
You can set the Enabled property on the game component to false. The game won't update it. You can also set the Visible property to false and the game won't tell it to draw. It can get kind of messy when you have a lot of game components. You might want to consider using some game state management and sub dividing your game components into separate states.

That way game components that are part of the game play can be told to not draw/update when the game state is told not to update or draw, etc.

This is a pretty good example of game state management: Game State Management Sample

So then you could have your PlayScreen (the state with the game play in it) and have a the PauseScreen come on top of it. The PlayScreen wouldn't be updated, but it would still draw. (or something of that nature)

---
Tags: xna, design-patterns
---


# Question
Title: Improving first person camera and implementing third person camera
I want to improve upon my first person camera implementation and extend it to, so the user can toggle between third person/first person view.

My current setup: draw()::

```
glPushMatrix();
    m_pCamera->ApplyCameraTransform();

    // Render gameObjects
glPopMatrix();

```

Camera is strongly coupled to the player, so much so, that it is a friend of player. This is what the Camera::ApplyCameraTransform looks like:

```
glm::mat4 l_TransformationMatrix;
m_pPlayer->m_pTransformation->GetTransformation(l_TransformationMatrix, false);

l_TransformationMatrix = glm::core::function::matrix::inverse(l_TransformationMatrix);
glMultMatrixf(glm::value_ptr(l_TransformationMatrix));

```

So, I take the player's transformation matrix and invert it to yield First person camera view.

---

Since, Third person camera view is just a 'translated' first person view behind the player; what would be a good way to improve upon this (keeping in mind that I will be extending it to Third person camera as well.

Thanks

# Answer
> 4 votes
Not entirely sure what kind of improvements you're after here, so I will suggest two different kinds:

1. I don't see that it's necessary to strongly-couple the camera and the player object, certainly not to the point where they grant friendship. All it seems like you're doing in this example is grabbing the transform of the player, which is something I would expect you could do via the player's public interface -- in fact, I would expect it to be something you could do via a more generalized interface -- any entity with a position. For improved code health, I would suggest decoupling these two.
2. If the only different between your first-person and third-person camera is a transformation tweak to place the camera behind the target object, I think you'll notice some unpleasantly jerky camera dynamics in response to user input in 3rd person mode. Many 3rd person camera's implement a spring-like system to damp their movements in response to player input (example here), so you might consider implementing damping constraints that you can have applied separately for both camera modes.

---
Tags: architecture, camera, first-person-shooter, third-person-view
---


# Question
Title: Rendering skybox in first person shooter
I am trying to get a skybox rendered correctly in my first person shooter game. I have the skybox cube rendering using GL\_TEXTURE\_CUBE\_MAP. I author the cube with extents of -1 and 1 along X,Y and Z.

However, I can't wrap my head around the camera transformations that I need to apply to get it right. My render loop looks something like this:

* mp\_Camera-\>ApplyTransform() :: Takes the current player transformation and inverts it and pushes that on the modelview stack.
* Draw GameObjects
* Draw Skybox

DrawSkybox does the following:

```
glEnable(GL_TEXTURE_CUBE_MAP);
glDepthMask(GL_FALSE);

// draw the cube here with extents

glDisable(GL_TEXTURE_CUBE_MAP);
glDepthMask(GL_TRUE);

```

---

Do I need to translate the skybox by the translation of the camera ? (btw, that didn't help either)

**EDIT**: I forgot to mention: It looks like a small cube with unit extents. Also, I can strafe in/out of the cube. Screenshot:

# Answer
What you want to do is construct a matrix with *only* the rotation of the camera, and use that for the camera's world matrix, render the skybox there (i.e., as if the camera is at 0,0,0), and then render the other geometry with the camera's real position.
> 4 votes

---
Tags: rendering, camera, terrain-rendering, sky
---


# Question
Title: Most efficient way to generate 2D portraits
I am not sure if this is a fitting question for gamedev, or if it is too art related. I am currently trying, to create 2D character protraits for my game.

At first I tried to draw them and even though it helped polishing my drawing skills the end result either required way too much time or it simply looked like it was created by a grade school kid.

So I am currently looking into some tools which from which people like me who are not out of the art-world might benefit. Especially tools which can create a 3D head+hair, so that I can render them. I have tried several 3D generation tools such as makehead and makehuman to create the basic head-shape.

But I have to admit I am not well versed in what other options are available/what has the best quality/etc.

# Answer
> 2 votes
It's hard to give you an advice since you didn't tell us anything about the art-style you're going for.

If you're planning to create realistic looking portraits you'll have to have pretty solid art skills and they abviously require a lot of work. The fastest way to get there would probably be: Downloading an existing 3d model and modify it, or paint over a photo.

Luckily, we only need some very basic shapes to recognize something as a human face. You could use that to your advantage (and also give your game an unique look). Take Nintendos Mii as an example. There are only a few basic elements available to create portraits from, yet you can create almost every portrait and expression you want.

Of course this is going to look out of place if your other game-art is completely different. IMHO the key is consistency in your art-style. Keep things simple. It's going to look good, if you can keep the same level of simplicity and art-style throughout your game. And if you're not happy with what you can do, ask somebody who has got the talent... better waste your time on things you're good at ;-)

---
Tags: tools, art, procedural-generation
---


# Question
Title: Separating physics and game logic from UI code
I'm working on a simple block-based puzzle game.

The game play consists pretty much of moving blocks around in the game area, so it's a trivial physics simulation. My implementation, however, is in my opinion far from ideal and I'm wondering if you can give me any pointers on how to do it better.

I've split the code up into two areas: Game logic and UI, as I did with a lot of puzzle games:

* The game logic is responsible for the general rules of the game (e.g. the formal rule system in chess)
* The UI displays the game area and pieces (e.g. chess board and pieces) and is responsible for animations (e.g. animated movement of chess pieces)

The game logic represents the game state as a logical grid, where each unit is one cell's width/height on the grid. So for a grid of width 6, you can move a block of width 2 four times until it collides with the boundary.

The UI takes this grid, and draws it by converting logical sizes into pixel sizes (that is, multiplies it by a constant). However, since the game has hardly any game logic, my game logic layer \[1\] doesn't have much to do except collision detection. Here's how it works:

1. Player starts to drag a piece
2. UI asks game logic for the legal movement area of that piece and lets the player drag it within that area
3. Player lets go of a piece
4. UI snaps the piece to the grid (so that it is at a valid logical position)
5. UI tells game logic the new logical position (via mutator methods, which I'd rather avoid)

I'm not quite happy with that:

* I'm writing unit tests for my game logic layer, but not the UI, and it turned out all the tricky code is in the UI: Stopping the piece from colliding with others or the boundary and snapping it to the grid.
* I don't like the fact that the UI tells the game logic about the new state, I would rather have it call a `movePieceLeft()` method or something like that, as in my other games, but I didn't get far with that approach, because the game logic knows nothing about the dragging and snapping that's possible in the UI.

I think the best thing to do would be to get rid of my game logic layer and implement a physics layer instead. I've got a few questions regarding that:

1. Is such a physics layer common, or is it more typical to have the game logic layer do this?
2. Would the snapping to grid and piece dragging code belong to the UI or the physics layer?
3. Would such a physics layer typically work with pixel sizes or with some kind of logical unit, like my game logic layer?
4. I've seen event-based collision detection in a game's code base once, that is, the player would just drag the piece, the UI would render that obediently and notify the physics system, and the physics system would call a onCollision() method on the piece once a collision is detected. What is more common? This approach or asking for the legal movement area first?

\[1\] *layer* is probably not the right word for what I mean, but *subsystem* sounds overblown and *class* is misguiding, because each layer can consist of several classes.

# Answer
I'll try an attempt to answer this question as I can understand what you're asking, though I don't have much game development experience since I'm still only learning.

As I see it, you to to separate the GUI code from your game logic and domain objects, that is, the puzzle pieces. These are indeed three separate layers - and yes, `layer` is an appropriate term in my opinion. It is often used to explain the concepts of separating each objects level of a system into subsystems that are independent from each other.

In regards of object-oriented programming, each object shall be a class. So, each piece of your puzzle shall consist of a class per itself, and so the game board. The game board should contains **X** pieces of puzzle depending on its size and movement capacity that you want to give to the player.

So, here are my thoughts on the topic - I hope that it will help:

1. The GUI layer: This layer shall contain methods only to display the pieces on the game board to allow the interaction between the the game itself and the player;
2. The Game Controller layer: Is responsible for the player's inputs. That is the layer that should tell a piece to move in the different directions, and ask the game board whether there will be collisions upon movement and so on;
3. The Business layer: This layer shall contains all of your business classes, that is, the pieces of your game and the game board object that contains the puzzle pieces.

In this architecture, you would have the GUI layer show the player of the game state, the location of each pieces of puzzle. The GUI layer would then be responsible for getting the player inputs and pass it to an underlying Game Controller layer, which would then be responsible for collision detection. If there's none, then the piece can be ordered to move into that input direction. To do so, you would simply have to call this piece's `MoveLeft`, `MoveRight`, etc. methods to make the piece move. You might as well let the game board know what piece you want to move, and then it orders by itself the piece's movement, and piece then moves into the demanded direction. This architecture makes it easy for testing each piece of code into the different layers, and then allows you for unit testing, integration testing and functional testing.

I know this might seem a little confusing at for sight, and thank god if it isn't! Should you require further details and help, please feel free to ask, I'll be glad to help the best I can though I'm a beginner into game development.

Thanks for reading! =)
> 4 votes

---
Tags: architecture, software-engineering, physics, gui, logic
---


title: Model format for small game

text:
# Question
Title: Model format for small game
I'm writing my own small-time game from scratch, and now I'm looking to start creating models. I've been wondering- what is the best model format to use? Given that I will be writing the model loading code myself and using whatever program generates them. Ideally, I'd look for a format that has fairly wide support between modelling programs, so I can pick the one I like most to actually perform the building, and the format itself would be relatively simple to load, rather than having all of the latest features.

# Answer
> 3 votes
I have used Value's SMD format for a while to good effect (there's an *extremely bare bones* loader checked in to the SlimDX repository; it's in C# but it should be easily translatable to C++). I picked it because it was straightforward to load and debug (since it's a text-based format), supported textures and skeletal animation, and was natively supported by the XSI Mod Tool.

I used it as an interchange format which was eventually compiled down to a proprietary binary format.

Although it seems like Valve has replaced SMD with DMX, which I don't know much about.

.X is a reasonable choice as well -- although it's being phased out to a degree by the DX SDK, it's still possibly to load the files even in later versions of Direct3D (if you don't mind round-tripping through the 9 D3DX interfaces) and you can find exporters for just about every modeling tool out there.

.obj is also common, but lacks animation support (if that matters).

If you don't mind setting up a longer asset pipeline, and cannot find a combination of format + modelling tool + exporter that works for you, you might consider looking in to FBX or Collada. They're both interchange formats -- so you probably don't want to load them directly (Collada, in particular, is painfully verbose), but you may be able to construct an asset transformation pipeline using the tools associated with both formats to allow you to use the model format you want with the modelling tool you like best.

# Answer
> 2 votes
Since you've tagged DirectX, you could use .X meshes. You can then export 3D Studio Max models using the Panda Exporter (Found here: http://www.andytather.co.uk/Panda/directxmax.aspx)

If you don't want to use the DX meshes for any reason, you could potentially use Lib3DS (Found at: http://code.google.com/p/lib3ds/) Although it's not very well documented and you might end up pulling your hair out :) There is a tutorial on using it here: http://www.donkerdump.nl/node/207

The advantage here is that you don't need to export your .3DS meshes.

Of course if you want the format to be used in a wide variety of modelling programs, then you're probably going to need an exporter (Like Panda above). You could also use the .OBJ format which is a human readable file, so it's not too difficult to parse and write some loading code for it. I'm no expert in OBJ files, since the .X format has been suitable for my needs so far.

Hope that helps.

# Answer
> 1 votes
If you want to use non-animated models and want to write your own loader, I would recommend OBJ format. I have used it several times and it's simple and easy to load.

---
Tags: c++, directx, models
---


# Question
Title: How were art assets created in the late 16-bit/early 32-bit era?
How were 2d and 3d art assets typically created in the early-to-mid 1990's (16-bit and 32-bit eras?)

# Answer
> 10 votes
For 2D, Deluxe Paint was pretty popular in those days.

For 3D, 3D Studio was around on the PC (eventually becomming Autodesk 3D Studio Max later in it's life). On the Amiga you had Lightwave (which was also used for TV and film).

---
Tags: assets, art, asset-creation
---


# Question
Title: iPhone image asset recommended resolution/dpi/format
I'm learning iPhone development and a friend will be doing the graphics/animation. I'll be using cocos2d most likely (if that matters).

My friend wants to get started on the graphics, and I don't know what image resolution or dpi or formats are recommended.

This probably depends on if something is a background vs. a small character.

Also, I know I read something about using @2x in image file names to support high res iphone screens. Does cocos2d prefer a different way? Or is this not something to worry about at this point?

What should I know before they start working on the graphics?

# Answer
> 4 votes
I can't speak to anything Cocos2D related, but for UIKit you want your images to be 72 DPI. The iPhone, iPhone 3G and iPhone 3GS have a native resolution of 320 x 480. The iPhone 4 has a native resolution of 640 x 960, which is exactly double the size of the older devices.

To make it easier for developers, they play a trick with how graphics are handled in iOS. You don't deal in Pixels, you deal in "points". The iPhone screen is 320 x 480 *points*, no matter what model it is. If you have an image that's 320 x 480 *pixels*, it's drawn at native resolution on the iPhone 3G, and it's doubled to fill the size of the iPhone 4.

To get even more clear images on the iPhone 4, you can also provide @2x images that are the correct size to match the native iPhone 4 screen. As an example, if you have an image called `AvatarIcon.png` on your app that's 100 x 50 pixels. You could also create on called `AvatarIcon@2x.png` that's 200 x 100 pixels. Now you get a crisp image on both the iPhone 3G and the iPhone 4.

Make sense?

---
Tags: iphone, graphics, animation, cocos2d-iphone, file-format
---


# Question
Title: Drawing particles with CPU instead of GPU (XNA)
I'm trying out modifications to the following particle system. http://create.msdn.com/en-US/education/catalog/sample/particle\_3d

I have a function such that when I press Space, all the particles have their positions and velocities set to 0.

```
for (int i = 0; i < particles.GetLength(0); i++)
{
    particles[i].Position = Vector3.Zero;
    particles[i].Velocity = Vector3.Zero;
}

```

However, when I press space, the particles are still moving. If I go to FireParticleSystem.cs I can turn settings.Gravity to 0 and the particles stop moving, but the particles are still not being shifted to (0,0,0).

As I understand it, the problem lies in the fact that the GPU is processing all the particle positions, and it's calculating where the particles should be based on their initial position, their initial velocity and multiplying by their age. Therefore, all I've been able to do is change the initial position and velocity of particles, but I'm unable to do it on the fly since the GPU is handling everything.

I want the CPU to calculate the positions of the particles individually. This is because I will be later implementing some sort of wind to push the particles around. How do I stop the GPU from taking over? I think it's something to do with VertexBuffers and the draw function, but I don't know how to modify it to make it work.

# Answer
> 6 votes
The particle system you are using as a base is explicitly designed to perform all its animation on the GPU. To disable that, you need to use a different design.

You can modify the baseline you have to remove all position update/animation code from the vertex shader (see `ComputeParticlePosition`) and move that to your application. You'll have to employ dynamic vertex buffers -- locking the buffer each frame, copying the position out of the particle system data structure and in to the buffer (although with the rest of the particle's vertex attributes), and then unlocking the buffer. You may want to remove/modify the rest of the `ComputeParticleWhatever` methods in the shader, since any modifications they make to the particle system will clobber any updates you do on the CPU.

Then you'll have complete CPU-side control over the particle attributes, at the cost of decreased performance due to the additional cost of updating the vertex buffer each frame -- this the bottleneck that the sample describes avoiding in the description:

> When displaying large numbers of particles, games can easily become bottlenecked by the amount of CPU work involved in updating everything and transferring the latest particle positions across to the GPU for drawing. This sample avoids that by animating particles entirely on the GPU, so the CPU overhead remains low regardless of how many particles are active. Moving eye candy to the GPU leaves the CPU free for other things such as gameplay, physics, or AI.

So you should be aware that you are eliminating this optimization by moving per-frame update back to the GPU. Note that, depending on the complexity of your "wind" function, you could probably instead push that computation to the GPU as well, which would give you the finer control you are after as well as obviate the need to update a vertex buffer every frame.

# Answer
> 1 votes
Alternatively, you can modify the shader used to update your particles so that it does the wind calculations on the GPU as well. That way you have the added wind control, but don't lose the performance benefits of the GPU particle system. Obviously there are limitations to what you can do with a GPU particle system, but adding wind shouldn't be one of them. Good Luck!

---
Tags: xna
---


# Question
Title: Scene Graph for Deferred Rendering Engine
As a learning exercise I've written a deferred rendering engine. Now I'd like to add a scene graph to this engine but I'm a bit puzzled how to do this.

On a normal (forward rendering engine) I would just add all items (All implementing IDrawable and IUpdateAble) to my scene graph, than travel the scene-graph breadth first and call Draw() everywhere.

However in a deferred rendering engine I have to separate draw calls. First I have to draw the geometry, then the shadow casters and then the lights (all to different render targets), before I combine them all. So in this case I can't just travel over the scene graph and just call draw. The way I see it I either have to travel over the entire scene graph 3 times, checking what kind of object it is that has to be drawn, or I have to create 3 separate scene graphs that are somehow connected to each other. Both of these seem poor solutions, I'd like to handle scene objects more transparent.

One other solution I've thought of was traveling trough the scene graph as normal and adding items to 3 separate lists, separating geometry, shadow casters and lights, and then iterating these lists to draw the correct stuff, is this better, and is it wise to repopulate 3 lists every frame?

# Answer
> 6 votes
An approach I've used in a C++ project is that the scene-graph (which has the spatial index) fills up a 'visible' std::vector of hits based on the current viewing frustum. This visible list is managed by the scene-graph so is only recalculated when the camera moves - moving objects in the graph are moved in this list and using tombstones and unsorted change-lists that get sorted and merged back in as-needed.

The list of visible items is sorted by shader-ID first and within each type by distance from camera. The shader IDs are assigned such that terrain sorts first and then buildings and then units and then projectiles and then particles and so on - it being an RTS. Some models have more than one shader, but they only advertise their primary shader. When they are asked to draw, those which need bits drawn with another shader too add themselves to a next-pass single linked list.

So drawing goes through the visible array in one pass, and in that one pass a linked list of those items to revisit is created, and they get drawn a second pass and so on.

Drawing front-to-back and opaque-then-transparent helps keep everything sane.

This is perhaps not minimising the number of shader changes etc but it is fairly workable and straightforward to implement.

I have no idea about XNA and how applicable this is and how much of this low-level stuff you create I'm afraid. It would be most interesting to know what the veterans think of this approach for C++ RTSes however.

# Answer
> 3 votes
My suggestion would be a 2-step approach tailored to your specific requirements similar to what you described yourself. You need a scene graph and a "render collection" for each of the rendering steps, in your case shadow, geometry, lights (maybe a fourth being transparent objects?)

The scene graph can be based on any type of relationships, but my personal preference would be based on spatial relationships where each node can contain the other nodes to facilitate fast culling.

The render collections can be any type of data structure tailored to the specific step. For instance, the shadow collection could be a list or tree sorted by depth to maximize early-z rejection. The geometry collection could be sorted by shader usage to minimize shader (state) changes. The light collection could be a list or tree sorted by light distance, size or a combination of those so you can limit light rendering to only the most effective lights if performance is an issue.

Whatever data structures you pick, be sure the insert operation is fast and make sure it uses pooling and other techniques to eliminate any allocation/destruction of data because you will be clearing and filling these lists each frame.

Now tying it all together is easy. Just walk through the scene graph and add each item to the relevant render collection(s). It helps if your data structure automatically sorts/structures new entries based on the requirements. When you're done, go through the render collections in the required order and render them.

Because your data structures have fast insert and don't generate garbage, there is no penalty for repopulating lists as you mentioned.

---
Tags: xna, c#, scene-graph
---


# Question
Title: What is a good practice for 2D scene graph partitioning for culling?
I need to know an efficient way to cull the scene graph objects, to render exclusively the ones in the view, and as fast as possible.

I am thinking of doing it the following way, having in each object a local boundingbox which holds the object bounds, and a global boundingbox which holds the bounds of the object and all children.

When a camera is moved, the render list is updated by traversing the global boundingboxes. When only the object is being moved, it tries to enlarge or shrink the ancestors global boundingboxes, and in the end updating or not the renderlist.

What do you think of this approach? Do you think it will provide a fast and efficient culling?

Also, because the render list is a contiguous list, it could accelerate the rendering, right?

Any further tips for a 2D scene graphs are highly appreciated!

# Answer
> 6 votes
Can't comment either, heh.

I'm not sure a quad tree is the best solution. I believe quad trees (and oct trees in 3D) are typically used to sub-divide space for rendering and bounds checking of **static** geometry, and are pre-generated and accessed only at load-time. If I understand the question, Devil is looking for a way to do scene culling of **dynamic** geometry every frame at run-time. Having to re-calculate a quad tree every frame could get expensive.

If you are really looking for a way to **just** do view culling (as opposed to intelligent collision detection), have you tried simply checking for bounding rect intersection with the screen rect? This can be done relatively cheaply in screen coordinate space, even faster if you maintain a separate bounding rect in screen space for your dynamic objects and update only as necessary. This should work fine unless you have a great many objects on screen at once.

As for techniques of doing collision detection between dynamic objects, I have personally used the **binning** technique quite successfully in a 2D side-scrolling shooter. We tried using a dynamically-updated quad tree but took a pretty significant performance hit.

# Answer
> 1 votes
Cannot comment so will answer

I think what you are referring to is a QuadTree : http://en.wikipedia.org/wiki/Quadtree and from the article, it seems that this is a quick method. Looks also useful with regards to collision detection (a quick pass before going into the nitty gritty) as well as identifying appropriate culling.

Additionally useful for painter's algorithm because the leaves of the quadtree could be drawn last working from the root to the leaves - allowing back to front render and completing all the spatial information you need to draw correctly. So overall quite a lot of information and usefulness to store in one scene graph!

# Answer
> 1 votes
Scene graphs is a way to go. I recommend this gamedev thread.

# Answer
> 1 votes
The 3D variation of this question was asked recently: Scene Graph for Deferred Rendering Engine

I recommend a quadtree. Objects would typically best be represented by bounding boxes, rather than points (it always puzzles me that all the 'tutorials' seem to think games are made from point clouds). A node would contain four children - quadtree sub-nodes - and a list of those objects that straddle more than one child (which is way simpler than allowing objects to be in multiple nodes at once).

As items move they check to see if they are not fully-within their quadtree node's bounds and if not they remove themselves from their current node and then re-add themselves to the quadtree.

It is not uncommon to put projectiles and other very-fast-moving objects into a separate always-visit list or such, as adding and removing them constantly from the quadtree can hurt performance. An approach I favour though is adding the bounds of their flight in some number of game time steps to the quadtree. In this way they get moved around in the tree much more rarely, and they get found by all the nearest neighbour searches and such - this allows projectiles to actually hit things accidentally etc. It can dramatically simplify collision detection by not having several code paths and the interaction of several lists.

When rendering 3D you tend to want to draw front-to-back and opaque-then-transparent and in general this is true of 2D too, although you may know something about your artwork that lets you be less careful perhaps. So you take a frustum - or however you decide what is visible - and you cast this through your octree. This will be very fast.

You might want to hoist the list of currently visible items into the quadtree manager so that the frustum is painted onto the quadtree only when the camera moves, and bit-flags in the octree that track those sub-nodes that are fully-in-view or partially-in-view allow you to efficiently add and remove your visible items from the list.

At this point its all likely so blazingly fast - compared to your rendering cost - that you don't need to optimise it further with all the various special cases when moving things around and such, or deferred re-sorting of changing visibility lists and such.

---
Tags: 2d, culling
---


title: how can i move static box2d object

text:
# Question
Title: how can i move static box2d object
how can i move static box2d sprites. i have tried this tutorial from . http://www.raywenderlich.com/475/how-to-create-a-simple-breakout-game-with-box2d-and-cocos2d-tutorial-part-12.

I managed to add another "paddle" object with box2d body, but i can seam to be able to make the code to move the second "paddle" body. Can anyone direct me how to do it?

Is there a way to move a "b2\_staticBody" box 2d object? i have tried, but i can only move it when i use "b2\_dynamicBody" if i used "b2\_staticBody" i can move it at all.

# Answer
> 1 votes
You want to use a dynamic body, if you want bodies to move in your physics. That is, the nature of bodies in box2d. You make a dynamic body, and apply impulse or force to it in the direction you want it to move.

I recently wrote this very basic tutorial to create a pong game using Farseer physics engine (which is a C# port of Box2d), so the same things would apply.

Also, it would help to know what kind of a game are you making ?

# Answer
> 0 votes
I'm not sure which version you are working with, but version 2.1.0 has 'kinematic bodies'.

Instead of `bodyDef.type = b2_dynamicBody;` you would put `bodyDef.type = b2_kinematicBody;`.

They are sort of like static bodies, only you can move them. They only move how you tell them to, so they aren't affected by collisions or other forces (like gravity).

From the box2d docs at http://www.box2d.org/manual.html

> A kinematic body moves under simulation according to its velocity. Kinematic bodies do not respond to forces. They can be moved manually by the user, but normally a kinematic body is moved by setting its velocity. A kinematic body behaves as if it has infinite mass, however, Box2D stores zero for the mass and the inverse mass. Kinematic bodies do not collide with other static or kinematic bodies.

---
Tags: box2d, cocos2d-iphone
---


title: Modern techniques for spriting

text:
# Question
Title: Modern techniques for spriting
I would like to know the flow for making modern 2D game artwork.

How are the assets made nowadays? Bitmap? Vector-based? Hand-drawn and painted? Drawn digitally? Modeled in 3D and exported to bitmaps?

I would like some information on programs as well, for fine looking art. Why does Flash's vector art style look good in most games? How do I make equivalent graphics with external tools? Or equaly good and not vector-based, anyway.

Any special hints for animating?

An answer oriented towards a one-man-army indie developer with little experience but some artistic sense would be appreciated! Not a complete dummy with paint programs, but also not a master at all, just need efficient ways to achieve results.

Thanks.

NOTE: Pixel art is not the goal of this question, nothing related to direct pixel manipulation should be brought up here, but you're free to do exactly that :)

# Answer
Well, it all depends. First, different kinds of games require different methods, based on the output desired by developers. Here is the usual pipeline of sprite making:

1. Sketches, how the artist sees the character, object, you name it.
2. Based on sketches artist produces raw sprites, just to outline features.
3. High resolution version of the sprite is produced to be further dissected into resolutions and other requirements of the tech.
4. Final version of sprites to be used in game.

That's basically it. If you need animated sprites, or pixel art, multiply this work by factor of 10. Also, most of the painting is done in Adobe Photoshop using digital pen (google wacom bamboo). 90% of all graphics processing is done in Photoshop.

If you need vector based images, you use special vector editors like Flash. But generally vector art is used for special cases, like flash game, where bandwidth is important, or if style of the game requires multiply mosifications and resize of your images.

And remember, best graphics comes not from tools, but from the artists experience and talent. Technology is just a way to assist artist with his work, they are not going to do the job for you.
> 1 votes

# Answer
> How are the assets made nowadays? Bitmap? Vector-based? Hand-drawn and painted? Drawn digitally? Modeled in 3D and exported to bitmaps?

Well, all of these techniques are used in modern games. I guess the 3D modeling and rendering to bitmaps has become less popular with the possibilities to use rather high-poly models directly in your game.

But any technique is valid. I just recently saw a game where all assets were hand-painted. It looks gorgeous.

> I would like some information on programs as well, for fine looking art. Why does Flash's vector art style look good in most games? How do I make equivalent graphics with external tools? Or equaly good and not vector-based, anyway.

It isn't the program that makes a good artist. Expensive software like Photoshop or Illustrator (or the free counterparts GIMP and Inkscape) won't magically turn your art into masterpieces. Use the software that you feel comfortable with. The better you know a tool, the less it will stand in your way, increasing productivity and creativity.

I don't share your opinion on the Flash vector graphics though. I think a lot of these games look awful, but that's just personal taste.

Sadly, there's no *best* or most efficient way to achieve good results. However, I think it's important to sketch out a style and then stick with it. If an asset doesn't fit into the overall style of your game, redo it. Familiarize yourself with your tools, so that you can turn your ideas into artwork. Personally I always use paper and pencil first, because it's the "tool" I feel most comfortable with and I can achieve results *fast*. When I'm happy with the drawings, I can scan them and continue working on them in another tool.
> 1 votes

---
Tags: sprites, art
---


# Question
Title: How to implement turn-based game engine?
Let's imagine game like Heroes of Might and Magic, or Master of Orion, or your turn-based game of choice. What is the game logic behind making next turn? Are there any materials or books to read about the topic? To be specific, let's imagine game loop:

```
void eventsHandler(); //something that responds to input
void gameLogic(); //something that decides whats going to be output on the screen
void render(); //this function outputs stuff on screen

```

All those are getting called say 60 times a second. But how turn-based enters here? I might imagine that in gameLogic() there is a function like endTurn() that happens when a player clicks that button, but how do I handle it all? Need insights.

# Answer
A turn based game is going to be governed by a state machine. Basically, you would lay out a series of states that can occur in a logical order.

At a high level, a player's turn could be the start of a new state, followed by all the possible actions that are allowed during that turn.

For instance

* State - change player
    + it is now player 1's turn
* Actions allowed
    + attack
        - select enemy to attack
    + defend
        - select unit to defend
    + move unit
        - select unit to move
        - check to ensure movement is allowed
    + etc

Obviously this will balloon quite quickly, as I've only sketched out an extremely limited plan. Having a good grasp on possible states early on will mean that you should be in a good position to implement. I'd highly stress sketching out exactly how you want the game to run....a good turn-based game requires a lot of planning IMO.
> 23 votes

# Answer
I have recently built a turn based strategy game similar to Master of Orion (it's only single player right now, multi-player would be a bit more complex, but a similar idea), here is what my endTurn function logic looks like (in my main Game Controller class):

```
//for all computer players:
computerTakeTurn(player)

//for all players
moveShips(player)

//for all players
endTurn(player)//see this function below

//for all planets
planet.repairFleet()

//for all players
resolvePlanetaryConflicts(player)

//check to see if any players were destroyed or if the game is over
checkPlayerDestroyedAndGameOver()

```

My player end turn function will perform functions specific to that player that isn't affected by the order it takes place between players:

```
eatAndStarve()

generatePlayerResources()

buildPlayerPlanetImprovements()

growPlayerPlanetPopulation()

```

Where appropriate, these functions return status messages and/or trigger events so that the GUI can show what happened during the turn or let the player know a computer was destroyed, etc...
> 3 votes

---
Tags: turn-based
---


# Question
Title: What is the best practice to resize game views-assets in WPF/silverlight?
I am working on simple game using WPF/C#, and I am wondering what is the best practice to resize the game (views, assets…) when user re-sizes the game window? Is it good practice to use the ViewBox control for this job?

# Answer
> 2 votes
This depends on the size you designed you application at and what resolutions you want to support, I've played with using a **ScaleTransform** to try getting my 800x600 app down to a smaller size for the windows phone 7 (I ran into other problems while converting my silverlight app to the windows phone 7 sdk so I gave up, but the scaling worked pretty nicely).

Mike Snow has a very good article on how to do this along with hooking up to the Content\_Resized event in your Page: Silverlight Tip of the Day #33: How to Scale your entire App and its Elements to your Browsers Size

You do want to be careful since scaling your app down too small will make certain elements like text too small to read and unusable.

---
Tags: game-design, wpf, silverlight
---


# Question
Title: Improve mouse movement in first person game
In my current FPS game, I have the mouse setup in a way, that it always forces the position of the mouse to be centered at the screen. This gets the job done, but also gets very annoying, since the mouse is "fixed" at the center of the screen.

Here is what I am doing:

* get mouse current position
* find offset from center of the screen
* set mouse current position to center of the screen
* apply difference to m\_pTransformation (transformation matrix of the player)

---

Is there a better way to deal with this ?

# Answer
That's a pretty standard solution. Try hiding the mouse cursor and superimposing a fixed targeting reticule (if your game needs one) if it's a distraction
> 2 votes

# Answer
Also make sure to unlock the mouse if the user alt-tabs out of the game and your game somehow still controls the cursor. Don't forget to test for that!

Otherwise I agree that yours is the standard solution. The alternative is to capture raw mouse input; MSDN documentation is here. This Stack Overflow question might help you starting to implement it in Mac and Linux.

I can't help but recommend against raw input though. I think you would need to test for anomalies and somehow handle all the different types of mice (different DPI, USB vs PS/2, etc.) and have a robust in-game system for sensitivity since raw input bypasses the operating system's mouse settings (acceleration, sensitivity, etc.).

It seems to me your method is just fine. It's simple (at least, much more simple than raw input) and you haven't indicated that it is broken in any way, so why are you trying to fix it? This almost seems a case of premature optimization. :)
> 4 votes

---
Tags: input, movement, first-person-shooter
---


# Question
Title: Is there a common word that encompasses handling of position, rotation, and scale together?
I'm looking for a name for my class that manipulates 4x4 matrices that handle position, rotation, and scale. Is there a common word that encompasses all three?

(I'm splitting the matrix math into its own file/class.)

# Answer
transform, or transformation

http://en.wikipedia.org/wiki/Transformation\_matrix
> 23 votes

# Answer
If you add shear to your list (although rarely used in games), it is generally known in mathematics as an affine transformation.

The general term 'transformation' has been mentioned already, is a usually considered a superset and includes projection transformations as well (which are not affine).
> 8 votes

# Answer
I've seen PRS used (position, rotation, scale), but "transformation matrix" is a pretty informative name, and also covers other kinds of transformations (skewing etc).
> 1 votes

# Answer
I've seen several engines shorten the term to `Xform` as well.
> 1 votes

# Answer
Some variant of `Transform` or `Transformation` would work.
> 1 votes

---
Tags: mathematics, matrix
---


title: OpenGL ES Loading

text:
# Question
Title: OpenGL ES Loading
I want to know what is the norm of loading rendering code.

Take a button. When the application is loaded, a texture is loaded which has the image of the button on it. When the button is tapped, it then adds a loader into a queue, which is loaded on render thread. It then loads up an array buffer with vertexes and tex coords when render is called. It then adds to a render tree. Then it renders.

the render function looks like this

```
void render()
{
    update();
    mBaseRenderer->render();
}

```

`update()` is when the queue is checked to see if anything needs loading. `mBaseRenderer->render()` is the render tree.

What I am asking then is, should I even have the `update()` there at all and instead have everything preloaded before it renders? If I can have it loaded when need, for instance when there is tap, then how can it be done (My current code causes an `dequeueing buffer error (Unknown error: -75)` which I assume is to do with OpenGL ES and the context)?

# Answer
**In general** I think you should pre-load all the assets you are going to need immediate access to -- UI-related assets, especially -- otherwise your application may feel unresponsive and laggy as the user has to wait for load requests to queue up and complete the first time they click on any bit of UI.

You can subdivide your assets into two classes: important ones that must be loaded as soon as possible, and less-important ones that can be delay loaded. The critical assets should be loaded immediately (if you have enough of them that it introduces a delay in your application start up, place this loading behind a loading screen of some sort perhaps). The rest of them can be loaded lazily on a background thread.

This latter class of delay-loadable assets typically corresponds to in-game or other gameplay-related stuff, so if the background load queue isn't finished by the time the game starts, you can put up another load screen if you need to in order to get everything in-memory and prepared so that when actually rendering you don't have to worry about it.

*Admittedly*, however, loading screens are kind of lame. If you really want to avoid them, you can implement a streaming asset system. In order to do that you'll need a fair bit more information about what assets you're going to need *before* you need them, so you'll still need to know which assets are high-priority UI-related files. Even in a streaming system you want to get the assets you need loaded as early as possible and not wait until they have to be loaded on-demand, unless such on-demand loading is fast enough for your platform.

An old, but relatively classic, paper on streaming systems can be found here, discussing the streaming world implementation used in Dungeon Siege.

**In your specific case** it sounds like you have a very unusual process. From the description in your question it sounds like the geometry and texture coordinates (et cetera) are not loaded for the button until the user taps on it. But if that is the case, how did the button appear at all for the user to tap on? You must have had some geometry and texture coordinates loaded already, so it doesn't seem like you'd need to load anything else. The vertex data should be the same for both the unpressed and pressed button states -- the only thing different should be the image.

You can use sprite sheets to pack multiple images into one texture and thus avoid having to manage the load of multiple texture assets per button. This will also mean that you only need to adjust the texture coordinates in the existing vertex buffer data for the button, or, if you're using ES 2.0 and have access to shaders, just offset the texture coordinates in the shader code as needed to access a different "frame" in the sprite sheet texture.

Essentially, it does not sound like your `update` method is necessary and in fact sounds to me like you're over-complicating your code by having it, so I would remove it in favor of pre-loaded assets and a simpler UI codepath that does not create new geometry for every button state. You might also see if loading the assets you need on-demand is fast enough do simply do exactly when you need it (it might be, although I wouldn't really recommend such an approach since it may not scale well).
> 4 votes

---
Tags: c++, android, opengl-es
---


# Question
Title: What should be contained in a game scene graph?
Would you help me to clarify, please, what what exactly **should be contained within a game scene graph?** See the following list, please:

* *Game Actors?* (obviously yes, all the objects changing state should be the major prart of the Scene Graph)
* *Simple static game ojbects?* (I mean ojects places in the background that do not get animated, neither do they collide)
* Game *Triggers?*
* Game *Lights?*
* Game *Cameras?*
* Weapon *Bullets?*
* Game Explosions and *Special Effects?*

The above considered object types. Now to the **coverage of the scene graph:**

* Should a scene graph contain the **whole game level map** since the level start, or should it contain only the **visible portion of the map?** If the second is true, it would mean that scene graph would be continuously updated, by adding/removing game objects, as the player moves. However, containing only the visible are of the map obviously would be much faster to traverse and update.

# Answer
> 5 votes
I think a good bit of reading up on what other scene graph technologies are doing would yield a lot of benefits for you.

**Background**
For example, look at the Ogre3D description. It is a scene graph based graphics engine which is open source. I would suggest looking at the tutorials and see how scene nodes are being used (Note: I'm not telling you to learn how to use Ogre, rather what features are present in Ogre's scene nodes and scene managers)

SceneNode documentation:
http://www.ogre3d.org/docs/api/1.9/class\_ogre\_1\_1\_scene\_node.html

SceneManager documentation: http://www.ogre3d.org/docs/api/1.9/class\_ogre\_1\_1\_scene\_manager.html

Something else worth looking at is the following link:
http://sgl.sourceforge.net/#features

It is an OpenGL based scene graph solution and the features page there shows all of the nodes that it can contain.

**Your Suggested Nodes**
I'm of the opinion that a scene graph should be as abstracted away as much as possible from the game logic so you don't have any dependency issues. For each of your bullet points I would say the following:

*Game Actors*
I'd probably say no. Similar to Ogre, I would have a base Entity class (which would contain the object specific logic) and a base SceneNode with an Entity member pointer to get the appropriate information to render the object (Position, Orientation, etc)

*EDIT: I'm not saying to not include your game actors in the scene graph here (otherwise nothing would show up :P) I'm saying to have a scene node with a reference to the logical game actor class, so you've still got loose coupling of the rendering and updating of game objects.*

*Simple static game ojbects*
Yes

*Game Triggers?*
No, this sounds like game specific logic to me.

*Game Lights?*
Yes

*Game Cameras?*
Yes

*Weapon Bullets?*
Not completely certain about this one, but I'd probably say yes, but you'd probably want all bullets as children to a "BulletCollection" parent scene node, just so you can cache that position and you won't have to traverse the scene graph much to remove and add bullets to render.

*Game Explosions and Special Effects?*
Not certain, I'll let someone else answer that.

**Scene Graph Coverage**
If you have a relatively small level, you should be able to store the entire level in a scene graph and then optimize for visibility using an Octree (usually for outdoor environments) or a BSP tree (usually for indoor environments).

If you have a much larger level and you don't want to do any level loading, this is where streaming would come into play, but that's another issue entirely. I'd start out with a small level and incrementally see how large you can make it without adversely affecting performance.

**Conclusion**
To me a scene graph is for the Render portion of a game loop. You shouldn't couple your rendering and your logic updates too closely together, otherwise you're going to run into annoying dependency issues.

# Answer
> 11 votes
**My inclination is to suggest putting *fewer* things in a scene graph.** See in particular this article by Tom Forsyth: "Scene Graphs -- Just Say No."

The crux of Forsyth's article is that you shouldn't be trying to cram a bunch of unrelated stuff into one big master data structure. This is much akin to the ideas that I touched on in this answer as regards deriving everything in the game from `GameObject` and then shoving it all in one big heterogeneous list (which is to say, that's bad).

Relatively few objects in the world truly exhibit a strong parent-child relationship as befits a tree structure. The canonical example of a coffee cup on a table is usually used here -- sure, you could consider it to be a 'child' of the table... at least until it gets knocked off. Then is it really still a child of the table? This means your 'tree' can end up pretty shallow and kind of degenerates to a list anyhow.

**So I would suggest you use multiple data structures for multiple things, as makes the most sense for those things.** Static geometry and lights, for example, seem like a reasonable thing to shove into a scene graph. Even if the represented objects don't have natural parent-child relationships, the fact that they are static means you can give them structural parent-child relationships knowing that they never change.

Game actors... I'm not so sure about. Anything that tends to move, in fact, means you usually need to keep them near the root of the graph or re-parent them constantly (which is a chore and not super efficient).

Bullets, triggers, special effects and other transient objects I would store elsewhere. Nothing that renders or has a visual representation (a trigger is typically an invisible bounding volume, a bullet is usually just a ray-cast) should be in a render graph. **You should strive for separation of render and logic layers**.

For what it's worth, I have never used a tree-like scene graph in any of the renderers I have built for non-academic use (obviously I have built tree-like scene graphs before, which is how I came to the conclusions that I am now attempting to get you to agree with).

I use spatial partitioning methods that are appropriate to the style of game (quad-tree, octree, BSP, et cetera) to group/cull the logical entities in the game that are should be (a) processed this frame and (b) rendered this frame. I then end up feeding the set of objects from list (b) into a system that maps logical objects to render descriptions and sorts those descriptions into buckets based on properties (for example, anything that uses transparency will be shoved into the bucket for "stuff that should be rendered back-to-front). Then I render every bucket in order, and for each bucket render every description in order. I guess you could call this a "tree," but it's doesn't exhibit the typical state/transform propagation methods that traditional tree-oriented scene graphs do. YYMV, because the system certainly has deficiencies, but it works pretty well for me.

---
Tags: game-design, architecture, scene-graph
---


# Question
Title: Given a start and end point, how can I constrain the end point so the resulting line segment is horizontal, vertical, or 45 degrees?
I have a grid of letters. The player clicks on a letter and drags out a selection. Using Bresenham's Algorithm I can create a line of highlighted letters representing the player's selection.

However, what I *really* want is to have the line segment be constrained to 45 degree angles (as is common for crossword-style games).

So, **given a start point and an end point, how can I find the line that passes through the start point and is closest to the end point?**

**Bonus**: To make things super sweet I'd like to get a list of points in the grid that the line passes through, and for super MEGA bonus points, I'd like to get them in order of selection (i.e. from start point to end point).

# Answer
> 2 votes
I didn't test this results, but i think it should work.

Lets call the things by the names: Start point coordinates: (X1,Y1) End point coordinates: (X2, Y2) Resultant closest End Point: (RX, RY)

A line that passes in Start point can be described as \[y = x + (Y1 - X1)\], for 45 degree slope. Slope equals the tangent of the desired angle, tan(pi/4) = 1. 45 degree is pi/4 radians.

Now you have a line with beginning on your Start Point, and with no end, defined by the given equation. We need to find it's End Point.

The End Point is closer to the line 1 wherever the line 1 intersects a line 2 with inverse slope, which passes in EndPoint. This line could be represented by \[y = -x + (Y2+X2)\], following the same principle, which has now -45 degrees slope.

The point of intersection is therefore described by: \[RX = (-Y1+X1+Y2+X2)/2\] And you can find its corresponding image calculating RX for the Line 1 (the one that we have interest in) \[RY = RX + (Y1-X1)\]

And done, you have your line ready, its a line generated by the function \[y = x + (Y1-X1)\] with a start in StartPoint and a end in (RX,RY).

Bonus: Since you have the line equation, you can calculate list of points the line passes through by changing x for any value between X1 and RX.

To get them for the order of selection, you just need to start changing x for X1 and go up to RX. Pretty straightforward.

Tell me if it works :) If you want the line in -45 degrees too, its the same, but the Line 2 is the important one instead of Line 1. You figure it out easily. Hope it helps.

# Answer
> 0 votes
Also not tested, but this is one way to approach it..

Some preliminary calculations:

```
// Vector from x1,y1 to x2,y2:

xd = x2 - x1
yd = y2 - y1
len = sqrt(xd*xd + yd*yd)

```

Now we can test the trivial cases:

```
if (xd == 0) // exactly vertical
if (yd == 0) // exactly horizontal
if (abs(xd) == abs(yd)) // exactly diagonal

```

Otherwise, we'll need to round a bit.. First, let's see which way the axes are going

```
xsign = (x > 0) ? 1 : -1
ysign = (y > 0) ? 1 : -1

```

Now, let's check the x major case.

```
// x major
if (abs(xd) > abs(yd))
{
  d = yd / xd
  if (floor(d+0.5) == 0)
  {
    // about horizontal
    yd = 0
    xd = len * xsign
  }
  else
  {
    // about diagonal
    xd = len / sqrt(2) * xsign
    yd = len / sqrt(2) * ysign
  }
}

```

And similarly the y major case.

```
// y major
if (abs(yd) > abs(xd))
{
  d = xd / yd
  if (floor(d+0.5) == 0)
  {
    // about vertical
    xd = 0
    yd = len * ysign
  }
  else
  {
    // about diagonal
    yd = len / sqrt(2) * ysign
    xd = len / sqrt(2) * xsign
  }
}

```

Finding all the steps between these is a matter of building a line-drawing algorithm from (x1),(y1) to (x1+xd),(y1+yd).

# Answer
> 0 votes
The method I ended up using is to:

1. Get the vector from the start point to the end point
2. Get the angle of that vector
3. Snap that angle to a multiple of 45 degrees
4. Create a new vector with the same magnitude as the starting velocity but rotated by the snapped angle amount
5. Add this vector to the start point to get the snapped end point

The code I'm using, in Lua is:

```
function snapEndpoint(startpos, endpos)
  -- startpos and endpos are vectors
  local velocity = endpos - startpos
  local step = math.rad(45)

  local angle = -math.atan2(-velocity.y, velocity.x)

  local snapped = (round(angle / step) % 8) * step

  local base = vector(1, 0) * round(velocity:len())
  local tmp = startpos + base:rotated(snapped)

  return vector(round(tmp.x), round(tmp.y))
end

```

This gives me the end point of line segment that snaps to 45 degree angles and is the correct length. If I then use the start and end point with Bresenham's Algorithm I can generate a list of points within the line.

This list of points is always returned in left-to-right, top-to-bottom order. I can look at the direction of the original line and, based on that, reverse the order of the returned points to get an ordered selection.

---
Tags: algorithm
---


# Question
Title: "Optimal" game loop for 2D side-scroller
Is it possible to describe an "optimal" (in terms of performance) layout for a 2D side-scroller's game loop? In this context the "game loop" takes user input, updates the states of game objects and draws the game objects.

For example having a GameObject base class with a deep inheritance hierarchy could be good for maintenance... you can do something like the following:

```
foreach(GameObject g in gameObjects) g.update();

```

However I think this approach can create performance issues.

On the other hand all game objects' data and functions could be global. Which would be a maintenance headache but might be closer to an optimally performing game loop.

**Any thoughts?** I'm interested in practical applications of near optimal game loop structure... even if I get a maintenance headache in exchange for great performance.

# Answer
> For example having a GameObject base class with a deep inheritance hierarchy could be good for maintenance...

Actually, deep hierarchies are generally worse for maintainability than shallow ones, and the modern architectural style for game objects is trending towards shallowing, aggregation-based approaches.

> However I think this approach can create performance issues. On the other hand all game objects' data and functions could be global. Which would be a maintenance headache but might be closer to an optimally performing game loop.

The loop you've shown potentially has performance issues, but not, as is implied by your subsequent statement, because you have instance data and member functions in the `GameObject` class. Rather, the problem is that you if you treat *every* object in the game as exactly the same, you probably aren't grouping those objects intelligently -- they're likely randomly scattered about throughout that list. Potentially, then, every call to the update method for that object (whether that method is a global function or not, and whether than object has instance data or "global data" floating around in some table you're indexing into or whatever) is different from the update call in the last loop iterations.

This can put increased pressure on the system as you may need to page the memory with the relevant function in and out of memory and re-fill the instruction cache more frequently, resulting in a slower loop. Whether or not this is observable by the naked eye (or even in a profiler) depends on exactly *what* is a considered a "game object," how many of them exist on average, and what else is going on in your application.

Component-oriented object systems are a popular trend right now, leveraging the philosophy that aggregation is preferable to inheritance. Such systems potentially allow you to split the "update" logic of components (where "component" is roughly defined as some unit of functionality, such as the thing that represents the physically-simulated portion of some object, which is processed by the physics system) on to multiple threads -- discriminated by component type -- if possible and desired, which could have a performance gain. At the very least you can organize the components such that all components of a given type update *together*, making optimal use of the CPU's cache. An example of a such component-oriented system is discussed in this thread.

Such systems are often highly decoupled, which is a boon to maintenance as well.

Data-oriented design is a related approach -- it's about orienting yourself around the data required of objects as a first priority, so that that data can be effectively processed in bulk (for example). This generally means an organization that tries to keep data used for the same purpose cluster together and operated on all at once. It is not fundamentally incompatible with OO design, and you can find some chatter on the subject here at GDSE in this question.

In effect, a more optimal approach to the game loop would be, instead of your original

```
foreach(GameObject g in gameObjects) g.update();

```

something more like

```
ProcessUserInput();
UpdatePhysicsForAllObjects();
UpdateScriptsForAllObjects();
UpdateRenderDataForAllObjects();
RenderEverything();

```

In such a world, each `GameObject` might have a pointer or reference to its own `PhysicsData` or `Script` or `RenderData`, for the cases where you might need to interact with objects on an individual basis, but the actual `PhysicsData`, `Scripts`, `RenderData`, et cetera would all be owned by their respective subsystems (physics simulator, script hosting environment, renderer) and processed in bulk as indicated above.

It is **very important** to note that this approach isn't a magic bullet and will not always yield performance improvement (although it is generally a better *design* than a deep inheritance tree). You're especially likely to notice basically no performance difference if you have very few objects, or very many objects you cannot effectively parallelize the updates for.

Unfortunately, there is no such magic loop that is the most optimal -- every game is different and may need performance tuning in different ways. So it's very important to measure (profile) things before you blindly go taking the advice of some random guy on the internet.
> 45 votes

# Answer
Game-object style of programming is fine for smaller projects.As the project becomes really huge you will end up with deep inheritance hierarchy and the Game-object base will become really heavy!

As an example... Suppose you started creating Game-object base with minimum attributes say Position(for x and y),displayObject(this refers to the image if its a drawing element),width,height etc...

Now later on if we need to add a sub class which will have an animation state,then you probably move 'animation control code' (say currentAnimationId,Number of frames for this animation,etc..) to GameObjectBase in the thought that most of the objects will have animation.
Later if you want to add a rigid body which is static (doesn't have any animation),you need to check the 'animation control code'in the update function of GameObject Base(eventhough its a check whether animation is there or not...it matters!) Contrary to this if you follow Component based Structure, you will have a 'animation Control Component' attached to your object.If its needed you will attach it.For a Static body you will not attach that component.This way, we can avoid un-necessary checks.

So, the selection of choosing the style depends on the size of the project.GameObject structure is only easy to master for smaller projects.Hope this helps a bit.
> 2 votes

---
Tags: optimization, performance, game-loop
---


title: What is a rim shader used for?

text:
# Question
Title: What is a rim shader used for?
What does a rim shader do and what is it used for? In what cases would it make sense to utilize a rim shader?

# Answer
In the context of graphics programming and shaders, a "rim" shader would be one that focuses on achieving a lighting effect related to the silhouette or other feature/contour edges of an object (crudely, "the outline" of the object). Typically this would be to simulate rim lighting (more examples), which comes about from back-lighting a subject.

I suppose if you wanted to stretch it, you could consider shaders employ other edge-related effects (such as drawing the outlines on cel shaded scenes) "rim shaders" as well, since they do have something to do with the feature edges of the object. More I think more traditionally the term is used to refer to the lighting effect.
> 7 votes

---
Tags: shaders
---


title: Scene Graph as Object Container?

text:
# Question
Title: Scene Graph as Object Container?
Scene graph contains game nodes representing game objects. At a first glance, it might seem practical to use Scene Graph as physical container for in game objects, instead of std::vector\<\> for example.

My question is, **is it practical to use Scene Graph to contain the game objects**, or should it be used only to define scene objects/nodes linkages, while keepig the objects stored in separate container, such as std::vector\<\>?

# Answer
Deciding on what type of scene management to use depends very heavily on what type of logic you are trying to run. Consider the different consumers of your scene:

**Rendering Consumer**

The renderer probably just wants to know what is currently visible to the user at any given point. It wants a bounding volume hierarchy for fast culling (BVH wiki article) so that it can figure out that a chair inside a boat doesn't need to be drawn because the boat's bounds are outside the view frustum. This might be embedded into an octree.

It also might want to have an idea that the chair is on its back inside the boat, and that the boat is rolling up and down on some waves when it finally comes into view. That way to find the final world coordinates of the chair's vertices it can concatenate the chair and boat transforms and be done with it (this also makes your job as a programmer easier).

Yet another way of looking at this problem is that the renderer is probably running a good card, and ultimately just wants a pile of triangles sorted so as to minimize texture, shader, material, lighting, and transform state changes. This last will probably help you more than a BVH, preformance-wise.

**Game Logic Consumer**

The game logic probably just wants a flat list of things that can talk to each other by a messaging system, so a std::vector is probably fine.

The game might also want a way of keeping track of who is closest to what, so some sort of \[nearest-neighbor\]\[3\] information might be helpful in that case. This can be provided by a BVH also, but having to up and down the graph might be annoying.

The game might even just want to know that when it moves A, A's item B should move too... in which case we are back to a sort of transform hierarchy.

**Physics Consumer**

Your game physics might want to have a \[special representation\]\[4\] of indoor spaces for very fast collision detection. Alternately it might use some sort of octree or \[spatial hashing\]\[5\] to efficiently find things that might collide.

None of the above physics data structure really looks like a "scene graph" in the Java3D sense.

**Audio Consumer**

An audio engine just wants geometry, perhaps a potentially visible (audible) set, or some sort of bounding volume hierarchy to calculate sound attenuation and propogation. Again, not really a normal sort of scene graph, though it may well be a graph of geometry in your scene.

**Ultimately...** ...it really just depends on the exact needs of your application. I'd suggest using a flat list to start with, and seeing where your issues arise. You might even try a flat list with a transform hierarchy, because that is perhaps the one sort of scenegraph useful for reasons other than efficiency.

Good luck!
> 5 votes

# Answer
There's one good reason not to use the scene graph as the container for game objects, and that's instancing. If you want to reuse some resources, it makes much more sense to just refer to the resource from your scene graph several times than to have several actual copies.
> 3 votes

# Answer
Separating your objectmodel and viewmodel(your scenegraph) is usually a good idea.

See this article on the subject.

Among many things this will allow for the use of object pools. Which might be essensial for efficient memory managment.
> 2 votes

---
Tags: architecture, scene-graph
---


title: Hashing 3D position into 2D position

text:
# Question
Title: Hashing 3D position into 2D position
I am doing volumetric raycasting and curently working on depth jitter. I have 3D position on ray and want to sample 2D noise texture to jitter the depth.

Function for converting (or hashing) 3D position to 2D have to produce absolutely different numbers for a little changes (especialy because i am sampling in texture space so sample values differs very very little) and **have to be "shader-wise"** \- so forget about branches, cycles etc.

I'm looking forward for yours nice and fast solutions.

# Answer
> 1 votes
I'm not sure it is quite what you are looking for, but this article on spatial hashing is interesting (and has some HLSL code as well): perfect spatial hashing.

---
Tags: directx, textures, raycasting, gpgpu
---


# Question
Title: Looking for games in environments similar to a pinball table
I'm on a team of students working on a third-person adventure game that takes place inside a pinball machine (like, small scale, on the surface, avoiding pinballs, etc).

One of my responsibilities on the project is to find games that are similar to this concept in appearance and/or gameplay for reference.

So, does anyone know of games (other than pinball) that takes place in a pinball-like environment? Or, adventure games that take place in small, cramped environments with multiple paths around the world? Or games in which the player is often bombarded with balls (or other similar unintelligent obstacles)? Or games that take place on a small scale?

# Answer
> 5 votes
I can think of a few games that might fit what you're looking for.

**Odama:** An old Gamecube game that plays like an RTS inside a pinball machine

**Marvel Ultimate Alliance 2:** This might be an appropriate 3rd person example of the "cramped environment" that you're looking for

**Toy Soldiers:** A recent XBLA game that does a great job of convincingly depicting small scale.

# Answer
> 2 votes
> Or games that take place on a small scale?

Micro Machines

(never played the new one)

# Answer
> 1 votes
Not sure how popular it is now, but before Counter-Strike: Source (and even somewhat after), there used to be loads of what were called "rats" maps. Basically they were maps where the scale and texture of the world was designed to make the player feel like they were a rat in a kitchen or some other environment.

While the gameplay was generally still very Counter-Strike like it may not be what you're looking for, but it may help give you some ideas on general concepts of the player being in a world where every day looking objects are huge.

# Answer
> 1 votes
Both Mario 64 and Banjo Kazooie have parts where objects are sliding down towards you, and also have slope dynamics (where you can climb up a certain grade but slide down others). Although there's no literal roof in these games, you can only jump a certain height. I think the frantic nature of some of these levels would really help for the feel of being inside a pinball machine.

---
Tags: game-design, level-design
---


title: Small 3D Scene Graph

text:
# Question
Title: Small 3D Scene Graph
I'm looking for a 3D graphics library (not a complete game engine). Preferred a **scene graph**. **Something small** (unlike jME, XNA or Unity), that I can easily expand and change.

Preferred features:

* Cross Platform
* Wrriten in Java/Scala (JOGL or LWJGL), C# (preferred OpenTK), Python or JavaScript/WebGL.
* Support for OpenGL is a must. Direct3D is optional.
* Some material system
* Full support for some model format with full animation support (preferred COLLADA)
* Level of Detail (LOD) support
* Lighting support
* Shaders, GUI, Input and Terrain/Water support are also preferred, but not required

Thanks!

# Answer
> 2 votes
Panda3D.

* Cross platform ( All desktop OSes )
* Python API ( although the core is written in C++ )
* OpenGL support
* At least I'm sure you can import models from Blender (there's a Blender plugin for that)
* shaders, HUD, input, and whatnot
* and it's open source (meaning that you can expand it)

# Answer
> 2 votes
**Xith3D**

* Cross Platform - **Yes (java)**
* Wrriten in Java/Scala (JOGL or LWJGL), C# (preferred OpenTK), Python or JavaScript/WebGL. - **Yes (java)**
* Support for OpenGL is a must. Direct3D is optional. - **Yes (java)**
* Some material system- **Yes (java)**
* Full support for some model format with full animation support (preferred COLLADA)- **Yes (.obj,.md2,.md3,.md5,.dae (somewhat), .ase,.3ds, and others)**
* Level of Detail (LOD) support - **Yes**
* Lighting support- **Yes**
* Shaders, GUI, Input and Terrain/Water support are also preferred, but not required - **Yes (no multipass shaders, but otherwise good enough; terrain system does exist; GUI is there and easy to use)**

Xith3D is a useful Java-based engine in the spirit of Java3D, but with a lot of the crazy and overengineering removed. The community is helpful, and the documentation is a lot better than I've seen for similar projects. Tutorials exist and are succinct.

# Answer
> 0 votes
## Ogre4J

* Cross Platform - **Yes**
* Written in Java
* Support for OpenGL is a must. Direct3D is optional. - **Both**
* Some material system - **Yes**
* Full support for some model format with full animation support (preferred COLLADA) - Ogre animations which has exports for Maya and 3d Studio Max
* Level of Detail (LOD) support - **Yes**
* Lighting support - **Yes**
* Shaders, GUI, Input and Terrain/Water support are also preferred, but not required - **Yes**

Ogre4J is a binding to the Ogre C++ graphics renderer. Going straight to C++ is probably preferred though.

Ogre is a scene graph based rendering engine which does everything you're looking for.

---
Tags: graphics, scene-graph
---