I recently had to solve the problem of extracting rotations around individual axes in 3D space for arbitrary rotations represented as quaternions. I’ve seen a lot of people around forums and so on having problems with this, same as me, but not really getting any satisfying answers, so I thought I would share my approach to the problem here.

But first a rant, hah! Converting from quaternions to Euler angles is often fine, however when approaching certain orientations the values on some axes seem to unexpectedly flip 180 degrees. It turns out that the same quaternion has two valid Euler representations with one of them being the one you would expect and the other being flipped 180 degrees on two axes, and I haven’t been able to find a reliable method of determining which is the appropriate set of Euler angles for my purpose and any other possible solution I have looked into has had similar problems.

I would have expected this to be the sort of problem that is dealt with and solved quite routinely, so if I missed something or did something wrong I would certainly like to know!

Also, suggestions to simply store and handle your rotations as Euler angles are not very useful when, for example, you are relying on a physics engine to produce your rotations, not to mention that being able do calculations using quaternions is quite essential in general!

In any case, I came up with this geo-trigonometric method of extracting some angles that was useful for my case, perhaps they could be for others as well? It all boils down to the following method:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

/// <summary>

/// Computes the angle-axis rotation that rotates va into the intersecting line between the planes

/// of vb and vn.

/// Note: In cases where vb and vn are quasiparallel angle is set to 0 as no rotation could possibly

/// align va with the plane of vn as there is no intersecting line.

/// </summary>

/// <param name="angle">a reference to hold the angle parameter of the computed rotation</param>

Using it I was able to deconstruct my quaternion orientations axis for axis and get some fairly reliable results. The method computes the intersecting line between two planes and then the angle-axis rotation that would take the supplied vector vb into the line of intersection. So to calculate, for example, the pitch you would pass the right vector as va (the normal of the plane of rotation) and the forward facing vector as vb (the vector to rotate), both in the frame of the quaternion rotation, and lastly, as vn you would supply a normal facing upwards, to represent the horizontal plane. An example of this sort of rotation is seen in the image above, represented by the red arc;

It is always nice to see how to use the code and this sort of thing is probably easier to comprehend by playing around a bit with something interactive, so I put together this small Unity project.

Cheers!

moreless

Quaternion Unwind – Euler you failed me! ;-( was published on November 30th, 2016, under the Programming category. There are currently no comments on this article so far.

I’ve spent the past two, very exciting, years with Zero Point Software (with some amazing and talented people!) working on their Steam early access title Interstellar Marines as a game programmer. My time there gave me intimate knowledge of the Unity3D game engine, and related technologies such as Mecanim, Unity3D’s navigation system, uLink (which we used for all our networking purposes), and it taught me of the challenges of being an early access game.

My most significant contributions to Interstellar Marines is the animation system and additions to the character controller, character stamina, large parts of the weapon handling, the AI that are now used for the bots, as well as the server architecture, linking several game server instances together in the traversable clusters that are now used for the Hell Week game mode.

The video above should serve nicely as an introduction to the game at large.

Interstellar Marines was published on January 10th, 2016, under the Projects category. There are currently no comments on this article so far.

One of the first larger undertakings I was tasked with at Zero Point Software (the studio developing Interstellar Marines) was upgrading their character animation system to use Unity3D’s Mecanim. I would eventually end up having completely rewritten their character animation system and a character stamina system as well as a fully dynamic and physically-based swaying/bobbing to the weapons, causing them to behave differently based on the stamina and react naturally to perturbations of the character.

In the video above is Paul, the producer at the time, demonstrating and talking about the stamina system I created for the character controller. It also nicely demonstrates the state of the character controller itself and how weapon, camera and character animations look from a first person perspective.

Update video 10 features the crouch & jump system I created:

Update video 9 demonstrates the new animation system and fully dynamic and physically-based weapon swaying/bobbing. This is the point where we transitioned from the Unity3D’s legacy animation system to Mecanim, in connection with which I rewrote most of IM’s existing character animation system:

The next is a tutorial that might add a better sense of the crouch system

Lastly, here’s a community member, PepperBelly talking about the weapon handling. The tweaks he is talking about are not mine, but the underlying system that enabled them is my creation. In fact, this is a good example of the sort of challenge I enjoy a lot – the whole weapon handling is an economy of a lot of different numbers and influences (stamina, breathing, character motion, and influences from animated values such as bobbing and “aim down sight”) coming together in emergent behaviors that are appropriate to whatever situation that may be given, no pre-made animations here!

moreless

Interstellar Marines – Character Controller and Animation System was published on January 9th, 2016, under the Projects category. There are currently no comments on this article so far.

In connection with taking steps towards getting co-op missions into Interstellar Marines I created an AI to be used for enemies in the game. Through this work I familiarized myself with Unity3D’s navigation system.

and this let’s play, “Scares In The Dark”, features a couple of IM community members playing against my AI.

From my university time I have a very strong theoretical background within “artificial intelligence”, specifically machine learning techniques such as artificial neural networks, temporal difference learning or XCS, I know local and global search and optimization techniques, constraint satisfaction problems, planning and much more! Absolutely none of which was used for the AI that drives the bots in Interstellar Marines… :-)

Unity3D’s builtin navigation is used to pathfind to wherever the bots need to go. In addition to that, the AI has a set of “hand coded” behaviors for which it keeps a score up to date, and every once in a while the AI evaluates what behavior is the most beneficial for it, be it to wander, patrol, investigate sounds such as footsteps and gunshots, pursue an enemy, engage an enemy or escape (in case the bot needs to reload or the enemy is otherwise out of reach).

moreless

Interstellar Marines – Artificial Intelligence was published on January 8th, 2016, under the Projects category. There are currently no comments on this article so far.

At ZPS we made an effort to create a different and awesome game mode which became Hell Week for which I created the server architecture. In the video above the “Professor” examines, explains and demonstrates the Hell Week game mode :-)

So this was not my favorite thing to work on, to be totally honest, but I soldiered on and now it’s done and working just fine, thank spaghetti monster! :-)
For the game mode Hell Week it was necessary to have a cluster of multiple servers that players could travel between, with one central server managing the cluster and the state of the game. It fell upon me to spearhead this new direction and during this work I dug a little deeper with uLink then I normally have while implementing more casual networked gameplay elements, and it got me even more intimate with uLink and networking in general.

The basic outline of the system requirements was to:

– Connect cluster nodes (game server instances) to a “cluster master”
– Connect cluster nodes with each other
– Connect players to the cluster, either by connecting to the master or directly to a cluster node
– Manage game state and player data and syncing data where necessary.
– Transfer players from one cluster node to another as well as a means of transferring data along with the player

moreless

Interstellar Marines – Hell Week multi server architecture was published on January 6th, 2016, under the Projects category. There are currently no comments on this article so far.

My thesis work is offset in an existing technique which adapts motion capture data to conform with new constraints while maintaining a style of motion likely in the physical realm. New constraints might specify a different landing position in a jumping motion -or all the in-betweens of two extreme landing positions. This is advantageous when simple interpolation fails to produce believable motion.

My contribution in this relation is a balance objective that is more grounded in dynamics and enables believable motion transformations for a wider range of motion editing problems. This dynamic balance objective is offset in the 3D spring-loaded inverted pendulum model but also incorporates rotational dynamics.

In this project we made an effort to add to the input scheme generally used with first person shooters by using a head mounted display together with head tracking.

The input scheme that was opted for allows players to peek over boxes, lean to see what’s around the corner or look over the railing of a staircase or platform by performing gestures reminiscent of the real world.

The project is the result of a group effort, in which I was mainly responsible for the programming. The project is based on TrackIR, Ogre3D and PhysX and offered experience with alternative input schemes, integrating PhysX with Ogre3D and general game programming.

In the beginning we didn’t really know what to expect from our crazy input scheme… would it even work? Feel responsive? Feel natural? In the end it turned out surprisingly well. The hardware was responsive enough for our use, and our experience is that after a short while using our input scheme came quite natural, added a new dimension to the gameplay and was a very enjoyable experience!

moreless

Head Tracking in FPS Games was published on June 9th, 2013, under the Projects category. There are currently no comments on this article so far.

This project was an exercise in doing things from scratch using OpenGL and CEGUI in C++. Most notably, the project taught me about collision detection and golf ball physics. It also offered an opportunity to show off my skeletal animation system, exemplified in a waving flag which is rigged with a single bone, behold :)

The idea with this project was to recreate the cableway ride to Sugarloaf Mountain with the view of the city of Rio de Janeiro gradually unveiling. The purpose in doing so was to explore contemporary and relevant processes and tools for world building for game engines with an emphasizes on visually realistic landscapes. The project involved Unity3D, World Machine, City Engine, 3ds Max and a bit of C++.

Takashi’s Gladiators was a group project in which I did the programming together with another other group member. The project offered lessons on Unreal Engine and UnrealScript, as well as development methodologies.

Takashi’s Gladiators was published on May 28th, 2013, under the Projects category. There are currently no comments on this article so far.