# Question
Title: Write to one channel of R16G16 texture on Xbox
I was going to draw my shadow map into one channel of a 16 bit texture and then draw a different shadow map into another channel of the same texture.

I realized that this might not be possible to do efficiently since my targetted hardware (Xbox) does not support blending R16G16 formats. (Although the HDRBlendable might make it possible if I need a blendable format to do this.)

Is it possible to mask one channel of a R16G16 texture on the Xbox? How do I do that?

# Answer
> 3 votes
No you can't mask a R16G16 channel in XNA.

You can do it with a blendable format though, in my case, to use floating point the best you can do is to use HDRBlendable (R10G10B10A2 on the Xbox), and set ColorWriteChannels in the blendstate used appropriately, e.g.:

```
    myBlendState = new BlendState()
    {
        AlphaSourceBlend = Blend.One,
        ColorSourceBlend = Blend.One,
        AlphaDestinationBlend = Blend.Zero,
        ColorDestinationBlend = Blend.Zero,
        ColorWriteChannels = ColorWriteChannels.Red
    };

```

---
Tags: xna-4.0, hlsl
---


title: Correctly Implementing a "Double Jump"

text:
# Question
Title: Correctly Implementing a "Double Jump"
I'm working on a 2D iPhone game using Corona (Trial version, so I can't use their forums). The game involves the character falling through the sky, and I'm trying to implement a "double jump" for the character, for him to be able jump up while falling. I'm using Corona's physics library to have the character fall, and so far the best method of having him jump is using the vertical impulse method

```
object:applyLinearImpulse(0, -0.4, object.x, object.y)

```

The problem I face is that when the character is just starting out (vertical velocity is low), he jumps really high, and when he's been falling for a while (vertical velocity is high), the jump is negligible. I'm guessing that the best solution is to use some sort of equation with the velocity as input to make the jump the same regardless of velocity, but I can't figure out what that equation would be.

Okay, so that's all my thoughts. The end question is, how exactly do you implement a double jump with physics? Is there a proper equation for my problem? Should I take a different approach? It's been done before in games like Smash Bros, so there's a repeatable solution, right?

# Answer
> 37 votes
Just set the vertical velocity to zero, and just call the same code you use to do the first jump.

# Answer
> 1 votes
I'm not sure, but I think games like UT2K4 might use logic like this:
if (jumped already && !doubled jumped yet && !touching ground && velocity.up is approximately 0.0f) DoDoubleJump();

Where up is your y or z component (Depending on which one is up)
This means that your player can only do a double jump when they are at the maximum height of their first jump and are just about to start come down again.
I like this method because it creates a little bit of skill (You have to time it to happen inside of "velocity.up is approximately 0.0f").
Depending on what you want, you could bias "approximately 0.0f" towards positive numbers so they can only double jump when still moving up for example.

---
Tags: 2d, physics
---


# Question
Title: CCLayerColor gets black when pushed onto the current scene
In my cocos2d iphone project I have one major layer, the game layer. When the user presses the pause button the scene is paused and another scene is pushed onto it, the pause scene.

```
[[CCDirector sharedDirector] pushScene:[PauseLayer node]];

```

I realize the pause scene as a CCLayerColor. I want the layer to be transparent but I can't set both color and opacity. The layer is always black, although I can see my menu on it.

```
self = [super initWithColor:ccc4(255, 255, 255, 50)]

```

Any ideas?

# Answer
when you are changing the scene, no function is called from your gameScene so CCLayerColor draw itself on a black screen. to solve this you have to either not change the scene or add your game scene to the background layer of puase scene. ar you can also override pause scene draw method and call \[gamescene draw\] inside it.
> 1 votes

---
Tags: cocos2d-iphone
---


# Question
Title: What are ways I can transition from enterprise application development into gaming development?
I'm currently a software architect using the Microsoft stack of enterprise app development tools (.NET, C#, SQL Server, etc.). I've been thinking about transitioning over to game dev.

* What paradigms exist in gaming that don't in enterprise development that
* I'd need to learn? I'm deeply versed in DB design, design patterns, theory etc. Will this help me?
* Overall, will it be like I'm starting over from scratch in changing careers?

# Answer
Irrespective of your background, you need to bring something good to the table when looking for a job. Maybe you're a wizard at server load balancing and optimizing database queries for example, which would be pretty valuable for an MMO development project. Or maybe you're really good at project management or user interface design.

Overall though, it's pretty amazing what backgrounds people come from in the game industry. If you want to see what I mean, go to http://valvesoftware.com/company/people.html and read the backgrounds some of the people at Valve have.

I'd personally start out by keeping the day job and making a few indie games on the side. It would be a great learning experience, plus it gives you a way to develop a portfolio. You might also look into modding a popular game like Half-Life 2. Being able to demonstrate a well made mod or game gives you credibility and shows you can do something. It's also getting you doing development that is essentially identical to that at a game company, minus the resources, larger team, etc.
> 8 votes

# Answer
This seems like a pretty close dupe to this question, so my answer would be almost identical:

Game architecture for someone with a background in LOB Apps
> 2 votes

# Answer
Assuming you want to work for a big established company, note that there is a lot of overlap between enterprise applications and games on the back-end. On the front-end they are very different domains, but on the back-end of a large MMO they have pretty much the same concerns going on with the database architecture, user data security, etc.
> 0 votes

---
Tags: .net, career
---


# Question
Title: Drawbacks of using reflection for a component based system at loading-time
I'm coding a little casual game in Java using Slick2D.

This game use a lot of different "objects", managed in a composite way. So, firearms, furniture in the map, NPC and player character will be composites objects using components to define their behaviors.

Since I'm going to need a lot of, for instance, "shotgun" object, I'm using a sort of prototype pattern. When the player starts the game, XML files are read, and from those XML, typical objects are built and stored in a "EntityPool" class' hashtable. Then, when I'll need a shotgun, for instance, I'll ask for it to the EntityPool, which will give me a clone of this object.

My problem is as follow : I'm using JDOM to parse my XML. I don't know how many components I'm going to use, nor their exact methods. So I'd like to use reflection; a `Class.forName(nameOfMyClass)` in order to get the exact component for this class, and then a `Class.getMethod("set" + propertyName)` to fill the information I need.

So my XML can be like that :

```
<Entity name="window">
  <Component class="Breakable">
    <health>12</health>
    <newEntityAfterBeingBroken>brokenWindow<newEntityAfterBeingBroken>
  </Component>
  <Component class="Renderer">
     <tileset>object.png</tileset>
     <imgnum>2</imgnum>
  </Component>
</Entity>
...

```

There are obvious drawbacks to using reflection, particularly the lack in performance. But this is done only once, when loading the game. Do you see other problems with this method? Would you do it differently, and how? Thanks in advance for your advice!

# Answer
> 3 votes
There are no drawbacks really. What you have described looks like not only a perfectly valid way to do it, but the way that I would recommend to many people when working with a component based system.. They are designed for situations just like this, where a new object can be created in an editor as opposed to in code.

To chime in a bit with The Duck, you may want to look into an instancing-beyond-xml-definition method. Use the XML to load up base templates of components (default values instead of tracked values) then instanced versions placed in a level or an inventory or a characters save file.. whatever. This might just save you on the amount of processing you have to do. (This is more for memory concerns however, not load speed performance)

Now, those are the main reasons to use this kind of system. Load speeds should not be a deterrent from this as there are many Many ways to improve load speeds. Having an asset pipeline and an engine that can understand the assets in a few ways is very handy for development. The raw text XML version is nice for editors as well as being human readable for quick iteration and debugging if need be. Having a production or compiled version of the assets (instead of raw text load binary data directly) will remove any concerns over load speed. If you still want to be faster then you compile assets to their complete run time format, they can be loaded into memory, their pointers fixed up, and away you go.

While it is always good to try and look down the road, this one is free and clear with many solutions if your concerns ever do become an issue.

# Answer
> 5 votes
You're moving a bunch of error checking and such that could occur in the compiler to the run-time, which is both unsafe and slower, and you're going to have to waste serious time writing all the boilerplate code to make it work. Static typing and compilers exist for a reason, and it's because when your program compiles without error, then it ensures that it doesn't have certain kinds of error- something that you can no longer guarantee. Performance isn't the problem here- it's correctness. Oh, and performance is going to bite you in the ass (nom nom!) when it comes to testing, because your testers are going to have to wait for your game to load in order to test it.

And for what benefit? You haven't mentioned any plans to change the file after deployment, so it may as well be static data anyway. I mean, what benefit are you hoping to get from the system, exactly? If you need an object pool, those exist independently of how you choose to define your objects.

You need to pick a system that matches your *requirements*. You don't mention any requirements for dynamic entity definition, and the costs of doing it are very obvious, so logically, this system is way overkill for what you've said you *need*, and I can only recommend just getting a normal object pool and ditching the XML altogether.

# Answer
> 3 votes
There is a slight loss in performance in using reflection in general, but if you claim it is only going to happen during loading you should have no problems (I can't say for Java, but I have seen benchmarks putting reflection at 10 million queries in 3 seconds in C#). Terraria has the slowest loading times I've ever seen (painfully slow), and that has been incredibly successful - thus showing slow loading times aren't a problem as long as your game meets standards.

It has the advantage of making everything much more flexible - no `Register` methods to remember to call, no dictionary keys to add..you can just plug and play.

The problem I can see in your design is that you will have to create one of every object at loading time. If you have 200,000 different objects, that's a lot of wasted memory. I personally am using a Factory method for mine, like:

`Entity e = Entity.Create("shotgun"); //load up the file and do it on the fly rather than at loading time`

I may switch to just loading the XML into memory and arranging it as commands - XML is not hugely fast to load.

EDIT: You mentioned the speed of reflection. This benchmark shows the time may be 15x slower, but 1 million calls in 450 milliseconds is not slow.

# Answer
> 3 votes
I would second Raine suggestion to use a scripting language with a decent object literal syntax (Groovy, Lua, Javascript... anything that is supported on the JVM). It would save you having to write the mapping between your XML and Java beans (which is probably automated, for sure).

---
Tags: java, component-based, xml, entity-system, data-driven
---


title: Implementing a 3d tile engine

text:
# Question
Title: Implementing a 3d tile engine
I have a pretty decent experience with tile based 2d games and I would like to try to create a mixed 3d-2d game. To 3d elements will be very simple (ground, walls and water), all other elements will be 2d sprites drawn onto this 3d map. (I am envisioning something similar to Final Fantasy III for iPad, top down view, always the same angle)

Now, here is my question: What are the technical aspects of implementing a 3d tile engine? Are there some good examples on how to do this? Basically I would like to create the maps the same way that I would do in a 2d tile based game.

# Answer
It's actually quite similar to a 2D tile engine. You need to create the level somehow (i.e.: procedural generation or a map saved into a file that you created in an editor). Then you need to read that data, create the tiles and transform them to the appropriate locations and rotations. Draw only the tiles or polygons that are visible on screen (frustum culling) to keep the performance snappy.

Depending on whether your play area includes tiles at varying heights, you will need to find a solution for defining the collision bounds of the floor, walls, and platforms. Include collision data in each tile or, better yet, simplify that data and store it elsewhere to enjoy both memory and performance savings.

I hope this answered your question!
> 3 votes

# Answer
Learn how to write a custom camera. A camera simply translates 3D coordinates in world space, into 2D screen space. (It also performs view culling.) Then you can draw your billboard sprites at those particular coordinates. This is a common pattern and learning resources abound.

I wrote a generalised version of this, a pseudo-3d tile engine that allows arbitrary rotation, tilt and zoom in real time using only affine transformation to create wall and floor perspectives, respectively. In this generalised version, the transformations and depth ordering were the hardest. Particularly if you plan a multi-storey approach, depth ordering will take a bit of time. In my case I used transformations for walls and floor specifically because I didn't want to be concerned with drawing angled tiles. In that sense, mine are more like textures than tiles. You might consider the benefits of this.
> 1 votes

---
Tags: 3d, architecture, tiles
---


# Question
Title: Can I use MobiForms for my game development?
Just now I found MobiForms. I am planning to create a game for the iPhone using it.

My problem is I know only Objective-C and I have designed only one app (which is also a game) that's currently in the AppStore.

Can I use MobiForms for game development?

# Answer
> 3 votes
MobiForms looks like it's designed for businesses to rapidly create domain specific business applications that basically look... like forms. It doesn't look like it's well-suited to making interesting games.

So while I'm sure you could leverage MobiForms to create some kind of program that would resemble a game, since it's not really designed for it I would say that you shouldn't use it -- especially since it costs money. You'd be better off putting that money elsewhere, like towards a Unity license, perhaps.

# Answer
> 0 votes
I can think of a number of games you could make with it!

* Press the button
* Press the button X times in Y seconds
* Press the button faster than anyone else
* Press the button timed to the background music
* Don't press the button
* Press the button... IF YOU DARE

These are sure winners, especially in the iPhone market!

More seriously though, I can imagine Minesweeper, Tic-Tac-Toe, and the Guess the Number game are examples of games which could indeed be made with this library, along with most (if not all) puzzle games and many casual games.

Games can exist on just about any medium in some form. Maybe not the games you're thinking of, but then you should perhaps look up the definitions of "game".

---
Tags: iphone
---


title: Nested input in an event-driven system

text:
# Question
Title: Nested input in an event-driven system
I am using an event-based input handling system with events and delegates. An example:

```
InputHander.AddEvent(Keys.LeftArrow, player.MoveLeft); //Very simplified code

```

However, I started wondering about how to deal with 'nested' input. For example in Half-Life 2 (or any Source game, really), you can pick up items with `E`. When you've picked up an item, you cannot fire with `Left Mouse`, but instead you throw the object. You can still jump with `Space`.

(I am saying nested input is where you press a certain key, and the actions you can do change. Not a menu.)

The three cases are:

* Being able to do the same action as before (like jumping)
* Not being able to do the same action (like firing)
* Doing a different action entirely (like in NetHack, where pressing the open door key means you do not move, but select a direction to open the door in)

My original idea was to just change it after the input had been received:

```
Register input 'A' to function 'Activate Secret Cloak Mode'

In 'Secret Cloak Mode' function:
Unregister input 'Fire'
Unregister input 'Sprint'
...
Register input 'Uncloak'
...

```

This suffers from large amounts of coupling, repetitive code, and other bad design signs.

I guess the other option is to maintain some kind of input state system - perhaps another delegate on the register function to refactor out those numerous register/deregister into a cleaner place (with some kind of stack on the input system) or maybe arrays of what to keep and what not to.

I'm sure someone here must've encountered this problem. How have you solved it?

**tl;dr How can I deal with specific input received after another specific input in an event system?**

# Answer
two options: if "nested input" cases are at most three, four, I'd just use flags. "Holding an object? Can't fire." Anything else is overengineering it.

Otherwise, you can keep a per-input-key stack of event handlers.

```
Actions.Empty = () => { return; };
if(IsPressed(Keys.E)) {
    keyEventHandlers[Keys.E].Push(Actions.Empty);
    keyEventHandlers[Keys.LeftMouseButton].Push(Actions.Empty);
    keyEventHandlers[Keys.Space].Push(Actions.Empty);
} else if (IsReleased(Keys.E)) {
    keyEventHandlers[Keys.E].Pop();
    keyEventHandlers[Keys.LeftMouseButton].Pop();
    keyEventHandlers[Keys.Space].Pop();
}

while(GetNextKeyInBuffer(out key)) {
   keyEventHandlers[key].Invoke(); // we invoke only last event handler
}

```

Or something to this effect :)

**Edit**: someone mentioned unmanageable if-else constructs. are we going to go full data-driven for an input event handling routine? You surely could, but why?

Anyway, for the heck of it:

```
void BuildOnKeyPressedEventHandlerTable() {
    onKeyPressedHandlers[Key.E] = () => {
        keyEventHandlers[Keys.E].Push(Actions.Empty);
        keyEventHandlers[Keys.LeftMouseButton].Push(Actions.Empty);
        keyEventHandlers[Keys.Space].Push(Actions.Empty);
    };
}

void BuildOnKeyReleasedEventHandlerTable() {
    onKeyReleasedHandlers[Key.E] = () => {
        keyEventHandlers[Keys.E].Pop();
        keyEventHandlers[Keys.LeftMouseButton].Pop();
        keyEventHandlers[Keys.Space].Pop();
    };
}

/* get released keys */

foreach(var releasedKey in releasedKeys)
    onKeyReleasedHandlers[releasedKey].Invoke();

/* get pressed keys */
foreach(var pressedKey in pressedKeys)
    onKeyPressedHandlers[pressedKey].Invoke();

keyEventHandlers[key].Invoke(); // we invoke only last event handler

```

**Edit 2**

Kylotan mentioned key mapping, which is a basic feature every game should have (think about accessibility, too). Including keymapping is a different story.

Changing behaviour depending on a key press combination or sequence is limiting. I overlooked that part.

Behaviour is related to game logic and not input. Which is fairly obvious, coming to think of it.

Therefore, I'm proposing the following solution:

```
// //>

void Init() {
    // from config file / UI
    // -something events should be set automatically
    // quake 1 ftw.
    // name      family         key      keystate
    "+forward" "movement"   Keys.UpArrow Pressed
    "-forward"              Keys.UpArrow Released
    "+shoot"   "action"     Keys.LMB     Pressed
    "-shoot"                Keys.LMB     Released
    "jump"     "movement"   Keys.Space   Pressed
    "+lstrafe" "movement"   Keys.A       Pressed
    "-lstrafe"              Keys.A       Released
    "cast"     "action"     Keys.RMB     Pressed
    "picknose" "action"     Keys.X       Pressed
    "lockpick" "action"     Keys.G       Pressed
    "+crouch"  "movement"   Keys.LShift  Pressed
    "-crouch"               Keys.LShift  Released
    "chat"     "user"       Keys.T       Pressed
}

void ProcessInput() {
    var pk = GetPressedKeys();
    var rk = GetReleasedKeys();

    var actions = TranslateToActions(pk, rk);
    PerformActions(actions);
}

void TranslateToActions(pk, rk) {
    // use what I posted above to switch actions depending
    // on which keys have been pressed
    // it's all about pushing and popping the right action
    // depending on the "context" (it becomes a contextual action then)
}

actionHandlers["movement"] = (action, actionFamily) => {
    if(player.isCasting)
        InterruptCast();
};

actionHandlers["cast"] = (action, actionFamily) => {
    if(player.isSilenced) {
        Message("Cannot do that when silenced.");
    }
};

actionHandlers["picknose"] = (action, actionFamily) => {
    if(!player.canPickNose) {
        Message("Your avatar does not agree.");
    }
};

actionHandlers["chat"] = (action, actionFamily) => {
    if(player.isSilenced) {
        Message("Cannot chat when silenced!");
    }
};

actionHandlers["jump"] = (action, actionFamily) => {
    if(player.canJump && !player.isJumping)
        player.PerformJump();

    if(player.isJumping) {
        if(player.CanDoubleJump())
            player.PerformDoubleJump();
    }

    player.canPickNose = false; // it's dangerous while jumping
};

void PerformActions(IList<ActionEntry> actions) {
    foreach(var action in actions) {
        // we pass both action name and family
        // if we find no action handler, we look for an "action family" handler
        // otherwise call an empty delegate
        actionHandlers[action.Name, action.Family]();
    }
}

// //<

```

This could be improved in many ways by people smarter than me, but I believe it's also a good starting point.
> 7 votes

# Answer
We used a state system, as you mentioned before.

We would create a map that would contain all the keys for a specific state with a flag that would allow pass through of previously mapped keys or not. When we changed states the new map would be pushed on or a previous map would be popped off.

Quick simple example of input states would be Default, In-Menu and Magic-Mode. Default is where you are running around and playing the game. In-Menu would be when you are at the start menu, or when you have opened up a shop menu, the pause menu, an options screen. In-Menu would contain the no pass through flag because as you navigate a menu you do not want your character moving around. On the other side, much like your example with the carrying of the item, the Magic-Mode would simply remap the action/item use keys to instead cast spells (we would also tie that to sound and particle effects but that is a bit beyond your question).

What causes the maps to be pushed and popped is up to you, and I also will honestly say is we had certain 'clear' events to make sure the map stack was kept clean, level loading being the most obvious time (Cutscenes as well at times).

Hope this helps.

TL;DR - Use states and an input map that you can push and/or pop. Include a flag to say whether or not the map completely removes previous input or not.
> 11 votes

# Answer
This looks like a case where inheritance could solve your problem. You could have a base class with a bunch of methods that implement the default behavior. You could then extends this class and override some methods. Switching mode is then just a matter of switching the current implementation.

Here's some pseudo-code

```
class DefaultMode
    function handle(key) {/* call the right method based on the given key. */}
    function run() { ... }
    function pickup() { ... }
    function fire() { ... }

class CarryingMode extends DefaultMode
      function pickup() {} //empty method, so no pickup action in this mode
      function fire() { /*throw object and switch to DefaultMode. */ }

```

This is similar to what James proposed.
> 2 votes

# Answer
I'm not writing the exact code in any particular language. I'm giving you the idea.

**1) Map your key actions to your events.**

(Keys.LeftMouseButton, left\_click\_event), (Keys.E, e\_key\_event), (Keys.Space, space\_key\_event)

**2) Assign/Modify your events as given below**

```
def left_click_event = fire();
def e_key_event = pick_item();
def space_key_event = jump();

pick_item() {
 .....
 left_click_action = throw_object();
}

throw_object() {
 ....
 left_click_action = fire();
}

fire() {
 ....
}

jump() {
 ....
}

```

Let your jump action remain decoupled with other events like jump and fire.

Avoid if..else.. conditional checks here as it'd lead to unmanageable code.
> 0 votes

# Answer
Instead of unregistering, just make a state and then re-register.

```
In 'Secret Cloak Mode' function:
Grab the state of all bound keys- save somewhere
Unbind all keys
Re-register the keys/etc that we want to do.

In `Unsecret Cloak Mode`:
Unbind all keys
Rebind the state that we saved earlier.

```

Of course, extending this simple idea would be that you might have separate states for moving, and such, and then instead of dictating "Well, here's all the things I *can't* do whilst in Secret Cloak Mode, here's all the things I *can* do in Secret Cloak Mode.".
> 0 votes

---
Tags: c#, architecture, input, events
---


# Question
Title: Loading premade .xnb files with content manger
I am trying to load premade .xnb files with the content pipeline. when I call `contentManager.Load<model>("grass");`, for which I have a "grass.xnb" file in the corresponding directory, it crashes with: "Error loading "grass\_0". File not found."

The grass.xnb file was created using a MSBuild wrapper to build the .fbx files. I initialized the content manager with : `contentManager = new ContentManager(mainXnaWindow.Services, projectFileOpen + "../Assets/XNB/"));` I am pretty sure the content manager has the right directory, because when I deleted "grass.xnb" from the directory, It just told me "Error loading "grass" File not found"

Does anyone know why it could be adding a "\_0" to the name?

Edit: I forgot to include a built version of th texture associated with it. Problem Solved.

# Answer
> 1 votes
The .xnb file wouldn't load because it was looking for another .xnb file, the texture to go with the model.

I fixed this by making sure that all of the built .xnb files were in the directory I was loading from.

---
Tags: xna
---


# Question
Title: Where does the Framework (XNA) end and the API (DX) begin?
I have read a lot of interesting questions asking about XNA vs. OpenTK vs. SlimDX vs. OpenGL vs. DX, and while it is really useful to get others general impressions from 100s of hours using these various APIs/Frameworks, I haven't seen any answer which clearly defines what the scope of each is.

It's understood what the difference between an API, Engine and Framework is in theory, but for someone who has limited experience with graphics systems, its harder to see what on the practical side falls into each category. (Not made easier by all the overlap! e.g. XNA implementing a content pipeline as an integral part)

Take for example face culling - XNA 'does' this in the background without the programmer needing to think about it, but where does it happen? Is there a 'cull face' function in DX that must be called, or perhaps above in XNA? Or does the GPU or its driver do it?

I read in the documentation for one of the managed projects (annoyingly I can't remember which) about how difficult it was to implement efficient rendering code, and how that project abstracted it. This unnerved me a bit, and made me wonder just what XNA is doing beneath DrawIndexedPrimitives that would have to be done manually should the framework be left for something more flexible.

What does XNA *do* in the background, when rendering that cube, that a managed API would not?

# Answer
I think the question would be better answered if you inversed it. How exactly does a graphics card work, and what calls are made by DirectX or OpenGL to utilise these features?

This wouldn't answer your question per se, but as DirectX and OpenGL add a lot of higher level classes to simplify things for you I believe the difference is too vague with what XNA provides for example.

For the basics you will find similarities in DirectX/XNA calls because at a certain (lower) level, things cannot be more abstacted and the calls will have to be made by yourself.

So I'd say go create a **simple** rendering engine in OpenGL (I'd say more accessible to get lower level) and see where that takes you!
> 0 votes

# Answer
A framework, essentially, provides an API. Often it uses or wraps other APIs in order to do this. The two terms are not necessarily distinct, there's no clear difference in scope, and it's not really important for you to be able to tell the difference - what is important is to know what level of abstraction any given API, library, framework, engine, platform, or package operates at. Finding this out varies on a case by case basis unfortunately.
> 1 votes

# Answer
The framework starts... where the API ends. The API is a limited set of functions/classes/whatever that you can use, and the framework just wraps all that stuff up.

If you're asking about how much *stuff* goes on in between your call to whatever framework function you're using to get to whatever API method its calling, that really isn't answerable in the general case. Some things are easy, some things are really abstracted away and may be hiding things that would be useful to know about (which is why I'm assuming you're asking this question).

For XNA specifically, you can probably see the code by using a tool like ILSpy to break open the XNA DLLs and see what's going on under the hood.
> 0 votes

---
Tags: architecture
---


title: Kinematics of a die roll?

text:
# Question
Title: Kinematics of a die roll?
I'm working on a simple 3D game. In the game, sometimes the players have to roll die (a D8 to be exact). I wish to represent the rolling die with a 3D model, and I'd like to animate it in 3D space as if it was really rolled.

Can anyone help me describe the way the die spins around in real life?

PS: I'm working on this in WPF, using `Storyboards` and `Rotation3DAnimationUsingKeyFrames`

# Answer
Blender 3D is open source, and free.

It is a modeling and rendering application, but it comes with easy to use soft-body, fluid, and ridged-body physics solvers.

You could set up a number of slightly different simulations, that match the dimensions of the area in your game, and export the animation data from blender to use in your engine.

In the game, just use a regular pseudo random number generator, and select an animation that matches that number, use a few variations on each number to reduce monotony.
> 4 votes

# Answer
You could 'cheat' the system.. An 8 sided die only has 8 possible values. If you randomly pick a number you could then play 1 of 8 animations that end on the number that was randomly generated. You would not get it to look like a random roll every time, but it would roll to a randomly generated number.

A second step to the canned animations would be randomizing the texture... If you can move which side of the die are the 'number' all you would need to do is have a random set of animations where the final side is known, and then a set of textures that you could choose from to make the final side be the known number. (I can expand on this if need be)
> 2 votes

# Answer
I think since it's almost a very simple mesh (D8 means 8 triangles), you can directly give the mesh to your physics engine. if you want to draw some more complicated mesh you can still give some simple mesh to physics engine to do physics of dice.
> 0 votes

---
Tags: 3d, wpf, rigid-body-dynamics
---


# Question
Title: TileBased Game: Blitting Hero or Sprite?
So my environment is all set up and now I'm working on the movement physics of my character. I used blitting to copy over my tiles from a tilesheet. But since they are static, they are only copied over once. And with the Hero (main player character), I figured that I might blit him into his continuously changing position. But now, I'm not quite sure it's necessary?

Is there a real big perfomance-save to copy the Hero sprite into a new position constantly using Blitting, OR, is it fine to just copy it into the game once, and simply move the Hero sprite as a movieclip?

# Answer
> 1 votes
If you are moving 1 simple object around, blitting will not give you any performance increase.

But if you want tons of complex objects, particles and enemies, you should probably use blitting for everything.

# Answer
> 1 votes
A MovieClip still needs to be rendered by the Flash Player. If it's a animated vector shape, it will take longer than blitting a bitmap. But as AttackingHobo said, you might not see the difference with only one sprite.

---
Tags: flash, actionscript-3, sprites, bit-blit
---


# Question
Title: Running Unreal 3D Engine (2003) on Windows 7
General question. My company developed a custom software for simulating combat scenarios using the Unreal 3D Engine (2003). It currently runs on XP-based Dell system. Sometime in the Fall Dell is going to stop supplying XP systems. So we need to port it over to a Windows 7 environment.

However, we expect to run into compatibility issues that could be expensive to resolve.

Couple questions:

(1) What kind of issues can we anticipate running the software on a Windows 7 environment?

(2) Are there any solutions to having to fully upgrade the SW to run on Windows 7? For example, is there any way we can run the software on a XP-based virtual OS?

# Answer
> 1 votes
Microsoft makes a lot of effort to not break compatibility between different versions of their operating systems. Windows 7 is widely available and cheap to purchase, the best thing you can do is buy a copy, install it, then see what if anything is broken, then attempt to fix it. If nothings broken, you've nothing to worry about.

You could always purchase copies of XP and install them onto the new PC's?

# Answer
> 2 votes
UT2003 Engine Compatibility with 32-bit Windows 7:

The first Unreal works in 32-bit Windows 7, (implying, that) you should probably have no problems with the newer UT2003 engine. (Which turns out to basically be the case, please see the end.) So, I went to the trouble, to test the *ACTUAL* UT2003 engine for you, in 32-bit Windows 7 (Ultimate.)

Testbed (my) hardware: This, (the CPU,) actually turns out to matter, below...

* Motherboard: Asus M2R32-MVP
* CPU: AMD Athlon 64 X2 5200+ 2.6GHz Dual-Core
* Memory: Kingston 4GB DDR2 800 (PC2-6400) CL5
* Video Card: Sapphire ATI Radeon HD 4850 1GB w/ 11-5\_vista32\_win7\_32\_dd\_ccc\_ocl
* Hard Drive 1: Mushkin Callisto Deluxe 240GB SATA II MLC SSD
* Hard Drive 2: Western Digital 500GB 7200RPM 16MB Cache SATA
* Optical Drive: LG Black 12X BD-R SATA Super Multi WH12LS30

(Windows Updates installed, up to 6/8/2011. As well as various programs.)

Testing and results:

I installed "Unreal Tournament 2003 Retail Version 2107", from three CDs. (On C:\\, the SSD.) It won't launch un-patched. (Even before Windows 7. It gives a serious Critical Error.) Then I applied the (last) official "Unreal Tournament 2003 Retail Patch 2225 for Windows". (Epic's 2225 Patch also removes their own SecuROM CD-check, for their Play Disc (Disc 1.)) The game launched flawlessly. I cranked up all of the settings until it said, "HOLY SH\*T!" I started "SINGLE PLAYER", watched the intro, beat the first two levels, and entered the third. I quit the game, and then re-launched it, but it wouldn't re-launch! It crashed, saying:

Negative delta time! History: UGameEngine::Tick \<- UpdateWorld \<- MainLoop

It's a Known Compatibility Issue with AMD X2 Dual-Cores, here are three quickly found fixes:

1) Run UT2003 in Windows 98 / Windows ME Compatibility mode. (Very easy...) (Right-click the 'Play UT2003' icon \> Properties \> Compatibility, it's there, near the top.)

2) Install "AMD Dual-Core Optimizer Version 1.1.4" from http://support.amd.com/us/Pages/dynamicDetails.aspx?ListID=c5cd2c08-1432-4756-aafa-4d9dc646342f&ItemID=153 It's basically an updated CPU driver, to compensate for incompatibilities with multi-core CPUs.

3) Use "Win2000 Launcher" from http://www.majorgeeks.com/Win2000\_Launcher\_d438.html

Oh, and 4) you could also use a single-core CPU. NOT recommended.

I tested 1), and it works. I went to test number 2) for you... I turned off number 1), but, after two (very quick) launches, the launching problem DID NOT return. So I'm unable to test number 2), (without much trouble,) but I'm quite sure it'd also work... Wait... After waiting (I waited about 30 minutes,) the problem DID return, at which time I tested number 2). Number 2) also works, independently of number 1). It will (almost certainly) only work for AMD CPUs. I didn't bother testing number 3). (Or 4).)

Problem, Solved. \[Your two questions: (1): Issues are listed here. (2): UT2003 will run anywhere.\]

(Also know, versions of Unreal Tournament 2003 purchased from *Steam*, (by other users,) may not work.)

I then also went "ON-LINE" and played on three different 2225 multi-player servers, without any problems. I went back, used my new ON-LINE account, and watched the single player tutorial which I skipped earlier. I have carefully tested most major functions of the program without experiencing any problems with it.\** That's as completely as I can practically test it for you, without having your content. Or getting paid!

Summary and Solution:

So great news, yes, the UT2003 2225 engine works perfectly fine in Windows 7 32-bit! :O) \**However, multi-core CPU drivers, may not work well with UT2003! If your CPUs are AMD brand, install the "AMD Dual-Core Optimizer", (OR, you can:) If they're Intel: Run it in Windows 98 / Windows ME Compatibility mode.

If you have any other problems, they would be with the content that you purchased/developed, in which case, see the content creators. And if you can't get their help, there are easily thousands of capable "3D content creators" who would love to help you. (Interview 5 or 10, and surely one (or two) of them will take care of you.) But, you SHOULDN'T have any problems. Definitely not from Windows 7, anyway! Good luck! :O)

Of course, you should test it on a single installation first. Search newegg.com for Windows 7. ($100.) I just did... (6/8/2011) Microsoft Windows 7 Home Premium SP1 32-bit - OEM $99.99 + Free Shipping ...looks good. (I wouldn't think the difference between Ultimate and Home Premium would matter here.)

P.S. If you're Buying multiple new Computers to run this on, buy just one first, and test it like I did, (if not even more,) first. (If they won't sell or lend you just one, to test with, buy them somewhere else. Really.) P.P.S. (Among other reasons,) to avoid Hardware Compatibility problems, I always strongly recommend avoiding Dell. You said, "However, we expect to run into compatibility issues that could be expensive to resolve." With you using Dell, I totally believe that.

# Answer
> 0 votes
I don't thinks there should be any issues with it running on Windows 7. I have played every version of Unreal on my Windows 7 desktop.

Windows 7 does require more RAM than Windows XP, so you should take that into account when ordering the computers, as if you have too little ram, the game's performance might not be as high.

I do not know what you have specifically done to the engine in your simulation, but you really just should test this out on Windows 7 machine. You really should be able to find a machine that has Windows 7 on it to test.

# Answer
> 0 votes
Right click the app icon in Windows 7 and bring up the properties. Under the "Compatibility" tab you'll find a checkbox to run the program under compatibility mode for a number of versions of Windows, including XP SP2 and SP3.

---
Tags: windows, unreal, compatibility
---


# Question
Title: XNA Framework and looking around relative to the world instead of camera?
So I've been toying around with creating a game in the XNA framework. A great place to start is simply being able to move and walk around.

I kinda have looking around...

I start off with the camera position/direction as follows:

```
cameraDirection = Matrix.CreateLookAt(new Vector3(0, 0, 1.5f), new Vector3(0, 1, -1), Vector3.Up);

```

I also have a small cube rendered in a static location, on which I plan to walk around. I'm manipulating the cameraDirection from a controller as follows:

```
GamePadState one = GamePad.GetState(PlayerIndex.One);
if (one.Buttons.Back == ButtonState.Pressed)
    this.Exit();
if (one.ThumbSticks.Right.Length() > .1f) {//Deadzone, must push stick at least 10%
    cameraDirection *= Matrix.CreateRotationY((float)(gameTime.ElapsedGameTime.TotalMilliseconds * (.002 * one.ThumbSticks.Right.X)));
    cameraDirection *= Matrix.CreateRotationX((float)(gameTime.ElapsedGameTime.TotalMilliseconds * (-.002 * one.ThumbSticks.Right.Y)));
}

```

And at first this appeared to work. Then I realized that the X and Y axes are relative to the camera's current orientation. If I turn left and right while looking straight forward, that appears to work. If I look straight down and then turn left and right, I'm rotating along a different axis. I want to look around in relation to the world's axes instead of the camera's... How can I do this?

# Answer
First, you should be aware that there really is no such thing as a camera. There is only the camera view and projection matricies, which transform all the vertices in the world into a position relative to the camera.

That said, your problem is due to the order of transformations applied to the camera view matrix.

Instead of applying transformations to the camera view matrix over and over, which results in weird skewing of the view, and other fun unwanted stuff (like gimbal lock, as 3nixios pointed out).

The order of matrix multiplication matters. If you multiply by x and then by y, you get a different result from y by x. So multiplying many times in a row by different amounts along different axis produces a different result from what you were expecting.

Instead, try this:

Store yaw, pitch (and roll) in 3 separate floats in your camera. Store position in a Vector3.

Then at each camera update, do this:

```
cameraView = Matrix.CreateRotationX(Pitch);
cameraView *= Matrix.CreateRotationY(Yaw);
cameraView *= Matrix.CreateTranslation(Position);

```

Remember that the order of those multiplications matters!

Then just add to yaw/pitch like this:

```
float elapsed = (float)(gameTime.ElapsedGameTime.TotalMilliseconds;
Yaw += elapsed * (.002 * one.ThumbSticks.Right.X));

if(Yaw > (MathHelper.Pi * 2)){
    Yaw -= MathHelper.Pi * 2;
}

```

(And the same for pitch and roll.)

Add to position like this:

```
// Move up by 5 units per second.
Position += new Vector3(0, 1, 0) * elapsed * 5.0f;

```

This way you are recreating the camera view from yaw and pitch each frame, which will help you understand what is going on, and avoid incorrect transformations. It's also about equal in runtime efficiency, if you're worried about that.
> 2 votes

---
Tags: c#, xna-4.0, first-person-shooter
---


title: Tool for editing .X

text:
# Question
Title: Tool for editing .X
I am trying to use .X files (whoa.. huh? lol), but I found no good software for importing .X files then editing them then exporting them.. all this with animations, all this in text format (optional, but would be great), all this with having multiple meshes in one .X file. Found some good software to do the half of the jobs done, but is there any way to do it in one step? (I mean really - what do other programmers use at all? I found no good stuff on net.. am I to implement one myself, or such?)

So any good suggestion would be great, and without garbage: .X files in text with animations with multiple meshes to import and then edit and then export.

Thanks: Péter

*edit: I already tried Blender. The 2.49b was the last version supporting import directx in text. After these versions blender is not even importing .x, only exports. 2.49b can export animated .x, but can not import animation. 2.49b can export multiple meshes but will only import one of the meshes - from the same export it did (unmodified). Thanks for the suggestion, but blender is no solution for this, unless you can suggest a working script too please?*

**solution:** for above mentioned problem there were some solutions. Here I try to sum up stuff:

* Blender is a partially working solution; see edit above.
* Milkshape seemed to work with directx files, but for my tests it showed up, that only preview worked well, on main screen the textures were bad and no animations were imported. Versions checked are: 1.7.0 and 1.8.4 or something like that, I don't remember.
* TrueSpace seemed to not work for any of the .X files. No idea why; tried with tiny.x provided by the DirectX SDK, but nope. \*- Good solution is to use quick converter - see post bellow, marked as good answer. Found this allright, because it is closest to my goal.
* Found a program (**UU3D** \- Ultimate Unwrap 3D) that loads .X well, with more meshes and multiple animations and the textures are just fine too. Because it is not free, I could not try that if it can save with text as well (saving is simply disabled in demo). For those, who can afford such I could only recommend, because it looks promising.\*

# Answer
> 5 votes
How about blender?

----- Edit -----

Looking more into it, Blender now only support exporting .X files with a script that needs to be activated via User Preferences, see this forum post.

You could try converting your .x files into another format to import them fo the tool you want, Milkshape may work.

----- Edit -----

After looking even more into it, I see that people reccommend TrueSpace 7.6 which is now completely free and should allow you to import .x files.

If you don't like the modeller after that, you can just export to a different format and use your favourite modeller.

----- Edit -----

After managing to find this on CodeProject, DirectX apparently once provided a tool to convert from .x to .3ds. The link (not tested) should be a Dx8 Extras pack that comes with the conv3ds.exe utility. Here it is, good luck.

# Answer
> 0 votes
Blender's website lists DirectX as a supported file type

# Answer
> 0 votes
I believe Blender allows for .x importing (it ships with the import script)

---
Tags: directx
---


title: List of all games names?

text:
# Question
Title: List of all games names?
Is there any list of game names anywhere, so i can choose a name for my game and avoid (legal) conflicts with other games as much as possible?

# Answer
> 8 votes
I'm not sure if it's complete but I guess you can complete it yourself if you want/need:

http://en.wikipedia.org/wiki/Lists\_of\_video\_games

Looks like there are TONS of pages \*_\_*

For your licence problem, **a google search might be more useful**.

Also, from comments :

I think the only thing you can do to make sure you got a licence not registered is to register it. The laws of different countries and other things makes it hard to check if you have legal rights on a licence you're creating a name for. If you can't find anything on google, check again, check variants. Then if you don't find, maybe try a legal move. They will tell you if it's already taken. Or they should.

Contact a lawyer for details relative to your country laws and international laws.

# Answer
> 8 votes
You can use Google to fast-discard some names, but if you are doing something seriously and professional I really encourage you to pay some legal advocates/experts to do that. There exists many registry for products and brand names, and all this stuff is too much complex to be managed by someone that is not an expert.

If you are starting a game I also suggest you to take a PROJECT name and leave the decision of the final PRODUCT game to a more advanced stage.

# Answer
> 5 votes
There is a much easier way around this: go onto Google, or your favourite search engine, and search for `<yourgamenamehere> game`. If nothing comes up, it either a) does not exist, or b)is too obscure to worry about - it could be a small open source project that was abandoned for example.

# Answer
> 4 votes
Using a longer name with more elements in it should open your options. For example (and I have no idea if these are real game titles because I just pulled them out of my *ahem!! Moving right along...*):

* Potential conflict: **Wizard Boxing**
* More likely available: **Wizards of *the Kingdom of Norr* Boxing Championships**

Although it isn't a definitive way to check, "Googling" your game name ideas can help to prevent the majority of conflicts. Reserving a matching internet domain name will usually do the trick though (especially for computer games).

**An important note about using Google to check names:** If your game name includes multiple words, enclose it "*within quotations marks*" to instruct Google to handle your phrase as a single keyword. This will save you a lot of time because fewer (if any) results, that are also more relevant, will be returned.

(***Study exercise:** Try using http://www.Google.com/ to search for both the game names I suggested above, or something similar of your own creation, and try it with and without enclosing "quotation marks." You'll be running four queries in total.*)

# Answer
> 2 votes
You can try Mobygames, they're trying to build a comprehensive index of all games.

---
Tags: legal, game-industry
---


# Question
Title: Question about Monster Rancher/My Brute generators
I want to build a system based on the idea of Monster Rancher's monster generation system.

First, is it legal per se?

Obviously, I don't know how they built theirs and I will be generating my own "generator". But the idea itself of being able to randomly create a character or monster based on something..is it copyrighted? patented?

# Answer
> 4 votes
I'm not a lawyer.

You can't copyright game mechanics in the U.S. or Canada. The same likely applies to many other countries.

Apart from that, cloning games happens all of the time. I wouldn't worry too much about copying game mechanics, especially if you are adding your own little spin.

Using the same names as another game however, can be a different matter.

# Answer
> 2 votes
I'm not a lawyer either.

While you cannot copyright the mechanics of a software design, you can patent them. This is why IBM spends a fortune on patent discovery during their software development.

You can search patents online, but it is tedious... I have my doubts a monster generator would make the grade but whoknows (tm).

Much better to make sure you're not copying anything too closely... in this case pick a different prng seed method...

---
Tags: legal, random, procedural-generation
---


title: game maker book for beginner

text:
# Question
Title: game maker book for beginner
Which book is more a beginner to learn to program in c++ (or GML) and more fun: "Game Maker 8 Cookbook" (available for pre-order), or "The Game Maker's Companion" ?

# Answer
I created a game in Game Maker long ago, and was frustrated with the lack of control over many of the game elements. They try to take the programming out of game making. So I'm afraid you won't find Game Maker to be much help if you're trying to learn C++, or really programming in general. I would recommend going with Beginning C++ Through Game Programming, Third Edition if you want to achieve your intended goal.
> 2 votes

# Answer
I don't think either of them look all that great, and certainly they don't appear to teach C++ at all (focusing instead entirely on Game Maker and GML, it's internal language).

"Cookbook" style books tend to be more focused around isolated, individual techniques rather than providing a unifying educational "narrative," so I would shy away from the "Game Maker 8 Cookbook" entirely if that's what you are looking for.

Additionally, "The Game Maker's Companion" is a follow-up, so perhaps the first book in the series, The Game Maker's Apprentice is a better choice overall.
> 1 votes

# Answer
Both books will teach you Game Maker's drag and drop, neither will teach you C++. Im not sure if the cookbook teaches you GML, though i know the companion does. Both books have their own style of teaching. So on that matter, purely subjective. The Cookbook is slightly cheaper (thought not much) The Companion is out already. The companion might (i'm not positive) require you to get the game makers apprentice as well.

Overall i would say companion. The sooner the better, and it will teach everything you need to get started. The Game Makers apprentice might be needed first though.

And regarding C++... Well thats a totally different area. If you want to jump straight into it, neither of these books will help. However if you want to learn the basics of using logic to do things before delving into the details of the language, well it might help to learn GML first.
> 1 votes

---
Tags: software-engineering, books, game-maker
---


# Question
Title: Reusing a render target to create multiple Texture2D's (XNA)
i want to be able to loop through a hole bunch of textures, and render them on an object. I then want the rendered image to be placed onto a texture2D.

The point? well hopefully i will end up with an array of Texture2D's containing a model with multiple skins.

Here's my code:

```
        for (byte i = 1; i < allBlockIso.Count(); i++)
        {
            DisplayBox.SetValue(i);
            GraphicsDevice.SetRenderTarget(cubeTarget);
            GraphicsDevice.Clear(Color.Transparent);
            DrawIsoCube();
            GraphicsDevice.SetRenderTarget(null);
            allBlockIso[i] = (Texture2D)cubeTarget;
        }

```

DisplayBox.SetValue is a function which goes through and sets the texture. This is working! DrawIsoCube() draws the cube (the test model) and this is working too. The problem is definitely something to do with the unreusability of the render target.

Pretty simple yet it's not working. It appears that whatever the last image being rendered is, is shown in every image of the allBlockIso array.

Anyone know a fix? Cheers.

P.S. sorry if this wan't explained well. I'm not very good at explaining :P

# Answer
A `RenderTarget2D` is also a `Texture2D`. You don't ever "convert" it to a texture - it simply already *is* a texture. So you're simply passing the one object around and reusing it.

(You can prove this in the Debugger by giving the object a marker - you will see that every texture in your array is the *same* object!)

So you have two options:

* You could create multiple `RenderTarget2D` objects and use one for each texture.
* You could create multiple `Texture2D` objects, and copy your render target into a texture, using the `GetData` and `SetData` functions, after each time you render to it. (Your data will have to go through (copied into and then copied out of) a buffer, which you *can* reuse because it is not used in the final result.)

If you are doing this while your game is running (it is happening each frame or frequently), you should probably use the first approach. If you are doing this at load time (it happens once or occasionally), then you should probably use the second approach.

See also this question.

Also look into the difference between value types and reference types (see this document for *lots* of information about the .NET type system). `Texture2D` is a reference type, which means that the variable you hold is a *reference* to the object - not the object itself.
> 6 votes

---
Tags: xna, textures, xna-4.0
---


# Question
Title: How to get PS3/Xbox 360 experience without having access to Dev kits?
I am a budding game programmer trying to get into the industry programming for PS3, Xbox 360. The main problem I see is the need to demonstrate my skills to a potential employer, but without access to Dev kits for the PS3 or Xbox 360, doing this directly is impossible.

My question is, what is the best alternative way to show console developers my skills?

C++ programming in DirectX for Windows seems close to showing Xbox 360 programming skills, and C++ programming in OpenGL seems relatively close to showing PS3 programming skills. Unfortunately, it seems from web research as if both Xbox 360 and PS3 actually have their own propietary libraries, therefore seeming to make this not a 100% fruitful endeavor. This approach seems closest, but also most time consuming. Plus you're not actually making anything run on the console.

On the other hand, programming in XNA has the benefit that your games are actually on the console, though I get the impression that this is looked upon as not "the real deal" since it is just a wrapper around DirectX and uses C# instead of C++.

Does anyone have knowledge or experience from inside the industry so as to know what kind of game demos would be most useful to show to a potential employer? C++ in DirectX, OpenGL, XNA, Unreal Engine, Unity3d, Flash, etc etc etc? There are only so many hours in the day, and I'd love to know how to direct my efforts.

My gut feeling is that DirectX would be the best choice, as it seems closer to what is used on the Xbox 360, but if having a good demo in another language/engine is just as good, it would obviously be less time consuming to go another route.

Thanks in advance for your help and advice!

# Answer
Depends what path you are going down, frankly most people don't expect specific platform skills in a junior.

If your a games programmer, make a lot of games.

If your a technical programmer make a load of tech demos. Read interesting white papers and try new stuff out. If you do something interesting that makes the programmers go OOOoo we will WANT to talk to you. We want to chat about this little interesting thing you have done. It doesn't need to be a game.

KEY FACT: Your demo's should run on a wide range of machines, include a video recording as a back-up. Edited not raw.
> 17 votes

# Answer
For a junior role I'm not looking for a lot of experience in any particular API, but instead a good grasp of the concepts involved.

If it's a graphics related position you're looking for, demonstrate you know 3D maths, and how to use an API *well* (OpenGL or D3D, don't care which really - just make sure you optimise it well). Frankly all APIs more or less boil down to making lists of things to draw, submitting them, and managing state - and there are good ways and bad ways to do those things, so understand that.

For more general console programming, make sure you have a handle on the particular problems an embedded platform entails. Limited memory (no swap, fragmentation bad, etc.), strict rules on coping with crashes, limited I/O bandwidth, no (or limited) ability to patch/update, etc.

It's about the style of coding, not the specifics.

I'd actually *avoid* XNA if you're looking for a commerical position, because it's not actually that useful in that arena.
> 8 votes

# Answer
FWIW, I would consider programming on Xbox 360 in C#/XNA to be a *very* good substitute for "the real deal".

Consider:

* In XNA on 360, you have to deal with garbage collection; specifically, you need to avoid making too many, if any, allocations per-frame. While in C++ on 360, you don't have to deal with garbage collection (unless you're dealing with a scripting language, like Lua), but you *do* still want to avoid making many, if any, allocations per-frame.
* In order to take advantage of much of the 360's processing power, you need to make your code multi-threaded. This is just as true, if not more so, in XNA as it is in C++, due to the desire to make up for Managed code being slightly less performant than C++.
* Aside from a great many helper functions and classes XNA provides, the graphics API in XNA, given that it is based on DirectX, is extremely similar to DirectX/C++ on 360.

The wonderful thing about XNA is that it allows you to focus less on the technical issues of getting something on the screen, and more on making your game. Simply making a game (any game!), that is relatively bug-free and runs at a decent frame rate -- especially in the limited environment that XNA affords -- will give you a lot of experience, a demo that you can demonstrate, and hopefully, a foot in the door.
> 7 votes

# Answer
If you want PS3 programming skills, you may look for:

* knowledge of the PPC architecture; this you can get by doing C/C++ development on a PowerPC machine, be it OS X on an old G5 Mac, or Linux on any PowerPC machine including the PS3.
* knowledge of AltiVec; again, you can get this with a Mac or with Linux on a recent PowerPC machine, but knowledge of SSE3 might be enough.
* knowledge of the SPU: you can only practice this on the PS3 using Linux.

This won't teach you how to program the PS3 video chip, or how to use the official SDKs. Though for the video programming, generic OpenGL and DirectX skills will probably be enough, with some HLSL too. There is also a lot of information and material all around the Internet, not all of which is illegal to get ahold of (for instance, Sony's modified version of GCC for the PS3 is covered by the GPL).

If you want X360 programming skills, you will look for:

* knowledge of the PPC architecture: see above
* knowledge of AltiVec: see above
* knowledge of DirectX: this you can practice on Windows.
* knowledge of the Xbox 360 SDK: the similarities are such that practicing XNA will help a lot.

Other important skills probably include multithreaded programming (general knowledge, but also atomic operations, lock-free algorithms), portability (endianness, pointer sizes, video hardware features, etc.).

So yes, as you mentioned, I believe DirectX will be the most rewarding skill you can master. However, be aware that the competition will go this way too, and a few extras may make a difference.

***Source***: I did all of the above and got myself an awesome job in the industry.
> 5 votes

# Answer
This question (or rather, your aspirations) need scope. Nowadays in the industry there is hardly such a thing as a 'game programmer'. Unless you're aiming to go for a very small studio or rendering programmer, DirectX or OpenGl doesn't really matter. The things that set consoles apart from PC's are limited performance, limited memory and multicore issues. No matter what branch of programming in the industry you aspire, those are important, so showing that you are aware of how to deal with those will, imo, help. Know your C++. Know the pitfalls of C++. Know how not to use STL. Make sure your code is framerate independent, multi-threaded, and uses custom memory allocators. Highlight that, of course. I think what is really important is that your demo is *finished*. A lot of programmers stop when the core mechanic works, whereas the drag in game programming is the finalling - show that you know how to do it.

Most studios want to know what your skill is, AI, Gameplay, Rendering, Systems, Audio, Physics, whatnot. Try to figure that out. Being a generalist, without experience in the industry, will be a hard sell.

Good luck!
> 3 votes

# Answer
DirectX is a great choice. It's the easiest demo for us to run as we have PCs with Windows already most likely. If you do choose to go with the console option, a video is a nice demo instead. But nothing beats looking at your live code running.

Do try and run your code on several machines to make sure you're allowing for different video cards etc. These days that's mostly automatic, but some differences can still occur.
> 1 votes

# Answer
Knowledge of any 3D API is good. It shouldn't matter whether it is DirectX or OpenGL. 3D concepts are the same everywhere, just the APIs are different. Knowing OpenGL does not put you at a disadvantage to someone who knows Direct3D when competing for a junior level XBOX job. What you need to be demonstrating is your ability to code something and that you understand C++ (or any other language), the standard libraries, data structures and algorithms. Knowledge of a game engine such as UDK or Unity is a bonus. This demonstrates your ability to work with middleware, which is common in games companies. Flash has been used in front-end development, it is also a skill not to overlook.

Most important is that you just build a demo (in any language), make it good and see it through to the end. Good luck!
> 0 votes

---
Tags: opengl, directx, software-engineering
---


title: X, Y, Z coordinate standards?

text:
# Question
Title: X, Y, Z coordinate standards?
I'm pretty new to 3D development of any kind, nonetheless games. As I read through tutorials and examples, I find that the X/Y/Z coordinates seem a bit backwards than my first guess.

I had imagined that if a person were walking around a field, their X/Y position would be changing and if they were to jump or walk up or down a hill, then their Z position would be changing. My assumptions appear to be wrong because walking around a field seems to change X/Z and jumping or going up/down a hill alters the Y.

1) Are my observations correct? 3D is new to me and I may not be thinking about things properly.

2) What's the logic behind horizontal movement being X/Z and vertical movement being Y?

3) Would it be so wrong of me to use X/Y as horizontal movement and Z as vertical movement in the XNA Framework?

# Answer
Your assumptions aren't wrong: each engine treats these coordinates differently. Generally speaking X is almost always the East-West axis but whether Y or Z is the Altitude axis tends to vary. As I understand it, Quake 3, the Source Engine, and the Torque engine all have Z as up. So does the modelling tool 3DS Max. It's not uncommon.

It makes sense to have a coordinate system that is ordered roughly in descending order of importance, so that flattening a representation into fewer dimensions is easier to understand. For example, if your game is set on a 2D height map, it makes sense for Z to be 'up', because then your X and Y coordinates in the 3D world map directly to the X and Y coordinates on the height map. On the other hand, if you think primarily in terms of rendering (and many game engine developers do), you're used to X and Y being the screen coordinates, so adding a 3rd axis naturally goes in or out of the screen.

Use what is easiest for you, but be aware that any choice is arbitrary and that you may need to convert between them and use multiple coordinate systems within one program.
> 24 votes

# Answer
Imagine looking at a piece of paper held out in front of you with a chart on it, the axes are typically labeled X across the bottom and Y up the vertical; this leaves Z to be the outwards axis along the ground.

It's merely a convention, but it's used a lot in graphics where we think of Z as the depth into the scene.

In other fields like CAD your version would be more common.
> 6 votes

# Answer
The idea is that the x and y axes stay the same - y is 'up' on the screen, and x is across.

z - the third dimension, projects back into the screen (ignoring the issues of handedness here). In 3 dimensions this gets a bit odd, but for positioning things in screen space it makes more sense.

3) You can if you want, but it would be painful and clunky. I would advise just to get used to the Z-projects-into/out of-the-monitor.
> 4 votes

# Answer
1) Yes your observations are correct.

2) The standard global XYZ coordinate system makes sense when you think in terms of a first person shooter, when you are looking through the eyes of a character in the scene with a blank(identity) transformation matrix. Like it would when you draw a coordinate system on a piece of paper, X points to right and Y points upwards. According to the right hand rule (x-\>thumb, y-\>index finger, z-\>middle finger), Z points towards you.

3) It wouldn't be wrong, but it would be a diversion from standards. There are three problems that I can think of at the moment: (a) Let's say one day you want to use a physics library that uses the standard coordinate frame. If you did not follow the standard, now you have to think about the transformation that takes you from your world to the physics world. Can get annoying when you want to fix a bug. (b) When you want to share code with someone, or bring someone over to help with development, they have to get used to your convention. (c) When using standard 3D models, you always have to have a transformation above them to prevent them from looking sideways.

Now to add to question 2, it is sooo useful to think of X, Y, and Z as not just three letters, but as right, up and backwards. Every character in the scene has a local coordinate system attached to them, and in their local coordinate frames X is always right, Y is up and Z is backwards. Once you have this, now you can make sense of vectors that you print out, or write your algorithms in a way that makes sense. Let's say you have two characters A and B, and you want to do something if one of them is facing the other. You can simply find B's location in A's coordinate frame (Ta^-1 * p\_b), look at the vector you get and see if Z(backwards) is negative and X(right) and Y(up) are small, because that vector tells you how much backwards, right and up B is with respect to A.
> 1 votes

---
Tags: orientation
---


# Question
Title: How do game clients know that a server is running on their LAN?
In lots of multiplayer games there is the option for LAN play. My question though is how does a client know where a server is on the LAN?

The only ways I can think of

1. Send out broadcasts over the broadcast address. This has the disadvantage of being filtered sometimes by routers or switches in different network environments.
2. Attempt to connect to a server on every IP in your subnet. This has the disadvantage of being slow (Especially if the network uses 10.XXX.XXX.XXX for their IPs) and a mini ddos attack, but isn't going to be filtered.

How do games do this especially in other network environments?

# Answer
For games with LAN play, the standard thing to do is for the clients to send broadcast packets to discover servers. (The client sends a broadcast, the server sends a direct reply to the client)

In general, the client will send somewhere between three and five broadcast messages, each about a second apart, and will then decide that there must be no server if it hasn't heard any reply within that time. Sending multiple packets makes service discovery a little more packet-loss-tolerant (though that is pretty uncommon on LANs), and having time between them keeps them from disrupting other network traffic too much.

Nobody (to my knowledge) does your option #2, because it will degrade performance of the LAN (or will take quite a while, if you stagger the connection attempts).

But to cope with cases where broadcast is filtered by the local LAN (which is quite unusual, but not unheard-of), most games will allow players to directly enter an IP address to connect to. This allows players in these sorts of situations to connect to a known server, even it they can't broadcast to automatically find it.

For games over the internet, clients will send a direct request to a static **meta server**, which replies with the addresses for known current server instances. Servers, likewise, contact that meta server to inform them of their own location so that clients can be directed to them. Due to the complexities of NAT, though, this approach usually does not work for servers hosted inside a LAN. This is why this sort of approach is not typically used for LAN games.

Extra side note: It's common practice for internet games to contact a **point server** first. The point server tells the game on what address it can find the meta server, which will tell it where servers can be found. Point servers are often (though certainly not always) implemented as a simple web server, and are the only piece of this system with an address that is hardcoded into the game. This allows game developers to move their meta server around from one machine to another as required, simply by updating the address returned by the point server. It can also be used to implement a simple form of load-balancing or region-switching by having the point server send users to different meta servers based upon server load or geographical proximity.
> 35 votes

---
Tags: multiplayer
---


title: Network Game testing via Wireshark

text:
# Question
Title: Network Game testing via Wireshark
How can i check/inspect the performance of my network game via **Wireshark** and **specifically the Graphs available in Wireshark**,i want to test the performance of my network game. which kind of graphs can be helpful and relevant and give me the idea of network performance of my game? i m really newbie to networking so i m unable to decide.

# Answer
> 2 votes
Tools like WireShark are excellent (partly because they're free and open source, but also because the functionality they offer is fantastic), but they'll only be useful with regards to knowing what's going on on your network.

Some things to keep in mind when developing network communications for your network game:

* Minimize the number of packets (e.g., send an error code with a text description in one packet instead of separating these items into two separate packets).
* Send the smallest pieces of information possible (e.g., design your protocol to send a single byte code for "use weapon" or "move forward one tile" instead of sending a command like "USE WEAPON" or "MOVE FORWARD").

To test out your networking, set up some separate hosts on your network and start transferring large amounts of data between them to saturate your network (tools like WireShark will be very helpful here because you'll be able to see what's going on with your network during this time), then see how your game performs.

What you want to do is to create a scenario where your game will lag, and then you want to see how your game works during these lag times. I'd venture a guess that one very common scenario would be that the players are also running torrent transfers in the background (possibly without even realizing that they are, either because the application minimizes to a System Tray icon {out of sight, out of mind}, or they have SpyWare installed {anyone remember KaZaa?}), so you may want to test your game with these sorts of things running as well to see how your game performs.

I recommend you put a lot of careful thought into your protocol. Ask yourself questions like "What commands will the player likely be triggering more often?" The less common commands could be two bytes or longer while the more common ones should be kept to one byte. Another advantage of using byte codes for commands is that fewer CPU cycles are required for command generation and parsing, which means that the rest of the game play gets more processing power to make the overall experience just a little bit better for the players.

---
Tags: java, networking, multiplayer, performance, testing
---


title: Copyright notices on a web game portal

text:
# Question
Title: Copyright notices on a web game portal
I notice that for several games on Kongregate, the copyright notice either uses the author's handle name (login name), the name of the group that produce it or a domain name.

Are all those valid copyright notices?

# Answer
> 8 votes
That probably depends upon the court, and in some countries to a great deal on how well the lawyers fight.

In any case, do remember, copyright applies no matter such notices. They may make claiming damages easier, but a missing notice is in no way a carte blanche for copyright infringement.

# Answer
> 3 votes
In general, your copyright notice should be either using your name or the name of your company. If the name of your company happens to include the TLD of your website, so be it.

# Answer
> 3 votes
Yes, I'd say they're valid copyright notices. IANAL but in the US works under a pseudoname are just as copyrighted as they would be under a legal name, however they'd have to be able to prove that you're 'insertnamehere'.

Kongregate only attributes them that way because they don't require more information and I wouldn't recommend doing it for your own project.

# Answer
> 2 votes
As a general rule I think a copyright notice would have to identify the legal name of the owner ... your name, your company's registered name, etc. if for no other reason than to be able to look it up in the event of a dispute.

It is possible that a domain name may be appropriate (since they're registered), but a handle or other alias probably isn't valid (after all, you'd have to prove that you are the person the handle identifies).

Strictly opinion.

# Answer
> 2 votes
It will depend upon the country where the copyright is held, and generally you dont have to file it anywhere. You should look into the jurisdiction where the website is located/hosted.

If it is US based the copyright standards dont require it to be their given name, only something that connects the authors identity to the material work they are presenting. That could be their email, login, company name, domain, logo etc.

---
Tags: legal, copyright
---


title: Loading and using an HLSL shader?

text:
# Question
Title: Loading and using an HLSL shader?
I've been looking everywhere and all I can find are tutorials on writing the shaders. None of them showed me how to incorporate them into my scene.

So essentially:

Given an hlsl shader, if I were to have a function called drawTexturedQuad() and I wanted the shader to be applied to the result, how exactly could I do this?

Thanks

# Answer
There are three steps:

1. Load effect and set the technique
2. Provide data to the effect
3. Render

1) Load effect and set the technique

```
  // Declaration of your effect variable
  LPD3DXEFFECT  mDSEGeometryStage;
  ...
  initEffects()
  {
  //With this method you load your effect file
  HR(**D3DXCreateEffectFromFile**( d3ddev, "./DeferredEffect_MaterialsStage.fx", 0, 0, D3DXSHADER_DEBUG, 0, &mDSEGeometryStage, &errors);)
        // Some Error checking
    if( errors )
    {
        MessageBoxA(0, (char *)errors->GetBufferPointer(), 0, 0);
        errors->Release();
    }
    // Retrieve a Technique from your effects handler
    D3DXHANDLE mhTech = mDSEGeometryStage->**GetTechniqueByName**("MaterialsTech");
            // Set the technique to be used
    HR(mDSEGeometryStage->SetTechnique(mhTech));
  }

```

2) Provide data to the effect:

```
renderGeometryStage()
{
    // Effect values handlers (String parameter is the name of a variable in your .fx file)
D3DXHANDLE mhView       = mDSEGeometryStage->GetParameterByName(0, "gView");
D3DXHANDLE mhProjection = mDSEGeometryStage->GetParameterByName(0, "gProjection");
D3DXHANDLE mhNearClip = mDSEGeometryStage->GetParameterByName(0, "gNearClip");
D3DXHANDLE mhFarClip = mDSEGeometryStage->GetParameterByName(0, "gFarClip");

    // Set effect values indicating the handler and the data as paramters
HR(mDSEGeometryStage->SetMatrix(mhProjection, &(camera->getProjectionMatrix())));
HR(mDSEGeometryStage->SetMatrix(mhView, &(camera->getViewMatrix())));
HR(mDSEGeometryStage->SetFloat(mhFarClip, camera->getFarClip()));

    ...

```

3) Render: As said in a previous answer

> ID3DXEffect provides Begin() and BeginPass() methods.

So, in the same rendering method you can start to render by calling the device BeginScene() method and inside call the Begin or BeginPass methods of your effect.

```
    ...

// Begin Scene
HR(d3ddev->BeginScene());
{
                ...

    // Clear targets surface
    d3ddev->Clear(0, NULL, D3DCLEAR_TARGET |D3DCLEAR_ZBUFFER,
        D3DCOLOR_ARGB(0, 0,0,0), 1.0f, 0);

    // Begin Effect passes.
    UINT numPasses = 0;
    HR(mDSEGeometryStage->Begin(&numPasses, 0))
    {
       // PLACE HERE YOUR RENDERING STUFF
       // like:  drawTexturedQuad();
    }
    // End Effect passes
    HR(mDSEGeometryStage->End());
}
// End scene rendering
HR(d3ddev->EndScene());
}// End of renderGeometryStage method

```

Hope it helps, but your question is not about a chunk of code that you can copy/paste, its more about "basic" concepts. So for this kind of things I really recommend you to follow some tutorial because you will understand all the underlying concepts better. Cheers!
> 9 votes

# Answer
ID3DXEffect provides `Begin()` and `BeginPass()` methods. All you have to do is call DrawQuad() appropriately between them and their equivalent `End()` and `EndPass()` methods.
> 1 votes

# Answer
Depends if you want to use OpenGL or Direct3D.

For D3D the SDK has all the gory details.
> -2 votes

---
Tags: c++, directx, shaders, hlsl
---


# Question
Title: Linear Interpolation Causing Gimbal Lock?
I have created an **object movement path** in a *3D authoring application*. Then, I **exported the path** (100 frames) into my custom text file in the form of **Euler Angles**.

The next point was loading the animation into my game. To make it smoother, I performed **linear interpolation** between all the animation frames. Because of the interpolation, the object was moving correctly and **smoothly, in about 80% of its path**. In the **remaining 20%**, it **jumps once to different orientation** for a moment. Then, it jumps back, and smoothly finishes remaining of the path.

Do I face **Gimbal Lock** issue, please? Is there any way of fixing it? My tests have proven, that linear interpolation, which I perform, is correct. However, without linear interpolation, the object does not introduce this smoothness issue. Without interpolation, the object movement is obviously more aliased.

*To summarize:* Could I kndly ask to confirm that the issue I have here is gimbal lock? Can I ask for practical solution, please? Thank you.

*I am adding the animation data. The **issue occurs somewhere after frame 80**.*

---

## Animation Data

The *Animation data* might help you. It is stored in the format: `PosX, PosY, PosZ, RotX, RotY, RotZ, SclX, SclY, SclZ`.

```
#new animation###############
<
no TopRightApproach
np Scene_Root

#begin 100 animation frames
as 100
a 8.984154 9.694528 10009.996094 -180.001068 85.938065 -89.102135 1.000000 1.000000 1.000000
a 8.987644 9.461698 10006.712891 -179.542618 85.955078 -89.218880 1.000000 1.000000 1.000000
a 8.995170 8.773152 9996.920898 -178.195877 86.005127 -89.568436 1.000000 1.000000 1.000000
a 8.998324 7.653935 9980.741211 -176.004623 86.085548 -90.150589 1.000000 1.000000 1.000000
a 8.984107 6.137118 9958.277344 -173.016205 86.192795 -90.968750 1.000000 1.000000 1.000000
a 8.935911 4.263794 9929.640625 -169.279999 86.322464 -92.028351 1.000000 1.000000 1.000000
a 8.834530 2.078479 9894.919922 -164.849365 86.469925 -93.338814 1.000000 1.000000 1.000000
a 8.659353 -0.368791 9854.232422 -159.778748 86.630211 -94.910629 1.000000 1.000000 1.000000
a 8.389198 -3.028332 9807.674805 -154.125946 86.798615 -96.757645 1.000000 1.000000 1.000000
a 8.003077 -5.851116 9755.331055 -147.951019 86.970734 -98.895927 1.000000 1.000000 1.000000
a 7.481458 -8.786425 9697.345703 -141.313080 87.142395 -101.340607 1.000000 1.000000 1.000000
a 6.806078 -11.788560 9633.822266 -134.272385 87.310028 -104.107964 1.000000 1.000000 1.000000
a 5.960865 -14.813670 9564.890625 -126.886299 87.470482 -107.211334 1.000000 1.000000 1.000000
a 4.931985 -17.821638 9490.685547 -119.207855 87.621101 -110.659729 1.000000 1.000000 1.000000
a 3.707599 -20.777081 9411.324219 -111.282890 87.759743 -114.454948 1.000000 1.000000 1.000000
a 2.278911 -23.646814 9326.969727 -103.144257 87.884651 -118.585815 1.000000 1.000000 1.000000
a 0.638988 -26.402788 9237.757813 -94.811073 87.994583 -123.027390 1.000000 1.000000 1.000000
a -1.216847 -29.020498 9143.830078 -86.285469 88.088776 -127.737762 1.000000 1.000000 1.000000
a -3.291077 -31.478796 9045.333984 -77.551552 88.166946 -132.656998 1.000000 1.000000 1.000000
a -5.583939 -33.759590 8942.430664 -68.577599 88.229309 -137.709320 1.000000 1.000000 1.000000
a -8.094282 -35.848312 8835.259766 -59.323414 88.276596 -142.810486 1.000000 1.000000 1.000000
a -10.819101 -37.732933 8723.966797 -49.746075 88.309952 -147.873535 1.000000 1.000000 1.000000
a -13.753524 -39.403763 8608.709961 -39.808613 88.330864 -152.817459 1.000000 1.000000 1.000000
a -16.891382 -40.853546 8489.634766 -29.487383 88.341103 -157.574615 1.000000 1.000000 1.000000
a -20.225103 -42.077068 8366.883789 -18.776186 88.342537 -162.094757 1.000000 1.000000 1.000000
a -23.745558 -43.070892 8240.607422 -7.687020 88.337074 -166.345886 1.000000 1.000000 1.000000
a -27.442255 -43.833294 8110.949707 3.750950 88.326576 -170.313156 1.000000 1.000000 1.000000
a -31.303263 -44.364086 7978.052734 15.494358 88.312828 -173.995956 1.000000 1.000000 1.000000
a -35.315113 -44.664520 7842.061035 27.489048 88.297478 -177.404449 1.000000 1.000000 1.000000
a -39.462746 -44.737206 7703.111328 39.673283 88.282089 -180.556396 1.000000 1.000000 1.000000
a -43.729130 -44.586052 7561.345215 51.980412 88.268150 -183.474457 1.000000 1.000000 1.000000
a -48.095078 -44.216312 7416.899902 64.340660 88.257141 -186.184448 1.000000 1.000000 1.000000
a -52.539017 -43.634575 7269.907227 76.681992 88.250580 -188.714432 1.000000 1.000000 1.000000
a -57.036156 -42.848896 7120.494141 88.930428 88.250122 -191.094437 1.000000 1.000000 1.000000
a -61.557461 -41.869068 6968.793457 101.009323 88.257713 -193.357132 1.000000 1.000000 1.000000
a -66.068169 -40.707054 6814.946777 112.837379 88.275726 -195.539856 1.000000 1.000000 1.000000
a -70.527527 -39.377113 6659.050781 124.323631 88.307304 -197.689606 1.000000 1.000000 1.000000
a -74.883102 -37.897480 6501.245605 135.359741 88.356773 -199.870743 1.000000 1.000000 1.000000
a -79.073669 -36.288589 6341.615723 145.780823 88.423538 -202.204208 1.000000 1.000000 1.000000
a -83.048775 -34.563198 6180.319824 155.424957 88.500549 -204.807938 1.000000 1.000000 1.000000
a -86.761948 -32.734024 6017.475098 164.176315 88.589706 -207.753723 1.000000 1.000000 1.000000
a -90.160110 -30.820969 5853.197266 171.880707 88.693443 -211.151733 1.000000 1.000000 1.000000
a -93.182159 -28.853851 5687.632324 178.311142 88.814514 -215.184875 1.000000 1.000000 1.000000
a -95.760071 -26.874413 5520.888672 183.514175 88.955826 -220.189575 1.000000 1.000000 1.000000
a -97.817413 -24.940729 5353.116211 187.123825 89.119591 -226.856110 1.000000 1.000000 1.000000
a -99.271843 -23.130093 5184.452637 187.359161 89.304878 -236.833206 1.000000 1.000000 1.000000
a -100.037704 -21.542662 5015.049316 179.437531 89.497887 -254.771408 1.000000 1.000000 1.000000
a -100.031853 -20.303196 4845.088379 151.451355 89.629776 -292.446320 1.000000 1.000000 1.000000
a -99.182739 -19.559208 4674.762695 291.944275 90.458984 -161.182373 1.000000 1.000000 1.000000
a -97.442368 -19.473804 4504.315918 273.930450 90.745369 -187.833755 1.000000 1.000000 1.000000
a -94.799210 -20.211189 4334.016113 268.405609 91.116585 -201.273117 1.000000 1.000000 1.000000
a -91.287979 -21.916485 4164.151367 267.106964 91.525215 -209.631729 1.000000 1.000000 1.000000
a -86.987350 -24.667471 3995.015137 267.965698 91.931450 -214.846268 1.000000 1.000000 1.000000
a -81.982269 -28.356201 3826.834717 270.173737 92.298965 -217.592072 1.000000 1.000000 1.000000
a -76.352097 -32.819702 3659.774414 272.429474 92.621109 -219.038483 1.000000 1.000000 1.000000
a -70.173721 -37.898491 3493.952393 274.095367 92.895790 -219.690750 1.000000 1.000000 1.000000
a -63.521225 -43.437111 3329.450684 274.800812 93.122452 -219.787338 1.000000 1.000000 1.000000
a -56.465767 -49.284065 3166.322266 274.642273 93.301178 -219.443222 1.000000 1.000000 1.000000
a -49.076012 -55.291142 3004.602539 273.902985 93.432320 -218.706345 1.000000 1.000000 1.000000
a -41.418377 -61.312618 2844.312744 272.626160 93.516396 -217.581085 1.000000 1.000000 1.000000
a -33.557667 -67.204132 2685.466797 270.890015 93.554153 -216.036774 1.000000 1.000000 1.000000
a -25.557846 -72.821381 2528.081299 268.807770 93.546745 -214.007919 1.000000 1.000000 1.000000
a -17.482519 -78.019058 2372.174316 266.533997 93.496086 -211.387970 1.000000 1.000000 1.000000
a -9.391724 -82.652771 2217.783691 264.253021 93.414352 -208.041183 1.000000 1.000000 1.000000
a -1.305104 -86.605675 2065.017334 262.132111 93.330910 -203.849457 1.000000 1.000000 1.000000
a 6.781445 -89.769653 1914.023193 260.402527 93.255775 -198.631531 1.000000 1.000000 1.000000
a 14.872069 -92.022461 1764.984375 259.315521 93.202789 -192.187439 1.000000 1.000000 1.000000
a 22.971615 -93.223053 1618.113037 259.088806 93.193535 -184.352234 1.000000 1.000000 1.000000
a 31.085062 -93.204956 1473.673706 259.803406 93.260254 -175.099915 1.000000 1.000000 1.000000
a 39.216648 -91.768005 1332.016479 261.265259 93.447968 -164.682587 1.000000 1.000000 1.000000
a 47.368805 -88.667946 1193.618896 262.938171 93.814819 -153.698944 1.000000 1.000000 1.000000
a 55.539368 -83.604195 1059.160889 264.085083 94.432259 -142.955521 1.000000 1.000000 1.000000
a 63.715828 -76.209015 929.650635 264.077515 95.391594 -133.161606 1.000000 1.000000 1.000000
a 71.863411 -66.050301 806.609619 262.599335 96.807785 -124.729851 1.000000 1.000000 1.000000
a 79.806870 -52.886086 691.773071 259.552643 98.523193 -117.801910 1.000000 1.000000 1.000000
a 87.138481 -36.938866 586.204651 255.640915 100.443077 -111.729950 1.000000 1.000000 1.000000
a 93.392937 -18.585585 490.532349 251.516113 102.569275 -105.945999 1.000000 1.000000 1.000000
a 98.084183 1.707072 404.999969 247.688187 104.917473 -100.041023 1.000000 1.000000 1.000000
a 100.718758 23.406570 329.519897 244.617203 107.524292 -93.681702 1.000000 1.000000 1.000000
a 100.808044 45.916389 263.785370 242.749939 110.458992 -86.582306 1.000000 1.000000 1.000000
a 97.899155 68.556969 207.378372 242.493729 113.836517 -78.531448 1.000000 1.000000 1.000000
a 91.653503 90.539482 159.840546 64.095169 62.185379 -249.486740 1.000000 1.000000 1.000000
a 82.035561 110.984665 120.341881 66.671341 58.309464 -239.938141 1.000000 1.000000 1.000000
a 69.303429 128.851440 86.450623 70.901794 55.979618 -228.105255 1.000000 1.000000 1.000000
a 52.973385 141.918472 55.832756 83.709579 55.103844 -205.541702 1.000000 1.000000 1.000000
a 33.546043 142.795471 29.466892 116.969391 46.180241 -154.715836 1.000000 1.000000 1.000000
a 19.857452 129.141251 15.259699 129.680740 25.349024 -120.760765 1.000000 1.000000 1.000000
a 12.343875 112.144974 8.724246 127.029526 14.333036 -108.347511 1.000000 1.000000 1.000000
a 7.821478 95.381325 5.209990 122.078331 8.939495 -102.264587 1.000000 1.000000 1.000000
a 4.932919 79.590408 3.140254 116.943588 5.913023 -98.623123 1.000000 1.000000 1.000000
a 3.046561 65.016060 1.870584 112.077103 4.031883 -96.189346 1.000000 1.000000 1.000000
a 1.816201 51.780125 1.082831 107.615768 2.781020 -94.455673 1.000000 1.000000 1.000000
a 1.027526 39.939304 0.597993 103.613441 1.909752 -93.170593 1.000000 1.000000 1.000000
a 0.540331 29.559338 0.308290 100.096359 1.286182 -92.199020 1.000000 1.000000 1.000000
a 0.255917 20.679609 0.143687 97.080849 0.833416 -91.459457 1.000000 1.000000 1.000000
a 0.103634 13.330984 0.057448 94.579781 0.504789 -90.900986 1.000000 1.000000 1.000000
a 0.032585 7.548802 0.017888 92.605690 0.271279 -90.491302 1.000000 1.000000 1.000000
a 0.006448 3.381170 0.003515 91.172569 0.115071 -90.210548 1.000000 1.000000 1.000000
a 0.000409 0.855556 0.000222 90.297157 0.024915 -90.045868 1.000000 1.000000 1.000000
a 0.000000 0.000000 0.000000 89.999992 0.004890 -90.009010 1.000000 1.000000 1.000000
#end 100 animation frames

>
#end animation

```

# Answer
As you've noted, performing linear interpolation of the individual angles composing a set of euler angles (your "rotX, rotY, rotZ" values) does not result in a linear rotation. This is partly because angles don't interpolate linearly to begin with (for example, 179 degrees and -179 degrees are nearly the same angle, but linearly interpolating from one to the other as if they were simple numbers would go the long way around), and partly because euler angles do suffer from gimbal lock, as you mentioned, where the order in which you apply the three rotations affects later rotations in the sequence.

A better way to interpolate these orientations is to convert your euler angles into another representation before interpolating them; quaternions are one extremely popular choice. Rotation matrices are another. These other representations of orientation will interpolate far more successfully than euler angles do.
> 5 votes

# Answer
It looks like your problem lies in your exporter not producing continuous euler data. The discontinuity appears late, when the X and Z swap roles in the orientation, which is what gives you the odd looking interpolation. it's these lines:

```
a 97.899155 68.556969 207.378372 242.493729 113.836517 -78.531448 1.000000 1.000000 1.000000
a 91.653503 90.539482 159.840546 64.095169 62.185379 -249.486740 1.000000 1.000000 1.000000

```

you can solve this one of two ways, either make the exporter export continuous eulers (and then allow for euler elements outside the normal range), or interpolate as quaternions rather than as eulers.

You don't need to export as quaternion as the euler to quaternion conversion isn't very expensive, and if you're interpolating over a number of frames you could even cache the quaternions and the information you have to generate to perform the interpolation (information such as which way round to interpolate)
> 1 votes

---
Tags: opengl, opengl-es, animation, rotation, gimbal-lock
---