Space Blok Qt

Porting Space Blok XNA to Qt

The issues and thoughts that arose during the porting of the application are addressed here.

Drawing of 3D objects

The drawing of 3D models is built into XNA. XNA for Windows Phone 7 lacks the possibility to code new shaders, but it manages to provide a decent list of features with the fixed shaders. There were no technical restrictions when Space Blok XNA was implemented.

Qt is getting its corresponding features from Qt3D. Qt3D provides a rich set of features, on a high abstraction level, to implement the drawing of 3D objects. Qt3D also provides programmable shader support via QtOpenGL and it was decided to show off this functionality.

Qt3D turned out to be a good choice to implement the graphical side of the application. At the moment Qt3D is still in heavy implementation phase, so the deployment for target platforms is a little painful.

Physics simulation model

Space Blok XNA utilises the open-source BEPUphysics library to implement the rigid body and collision simulation. It turned out that this library was not available for C++ and it would have been too large a task to port the library. Instead, we chose another open-source library, Bullet physics.

BEPUphysics and Bullet are somewhat similar to use. To represent the world where the simulation objects exist, BEPUphysics has Space, and Bullet has btDiscreetWorld. They both have abstractions for differently shaped collision shapes such as box and sphere, enabling correct collision simulation. In both engines, the world/space had to be 'ticked' in order for the world to continue simulating. Both of the physics engines had abstraction for compound objects, in order to glue several child collision shapes together into a larger collision shape.

BEPUphysics was inserted into the project as assembly, making it easy to use. With Bullet, the sources were added to the project via a separate PRI file. It would have been possible to compile a library from Bullet, but as there are different target platforms, we decided to just add the sources to the project, making the deployment easier for each target.

Importing 3D models

When the porting of Space Blok XNA to Qt was started, the 3D models were in FBX format as XNA for Windows Phone provides in-built support for Autodesk FBX files when importing 3D models.

Qt3D does not support FBX files, but it does support OBJ and 3DS. The FBX files were converted to OBJ files by using Autodesk FBX Converter 2012. The texture coordinates were lost in the converting operation, or they didn't exist to begin with, so they had to be made with Blender.

The importing of the level was a hard task in the Qt version. The size, position, and rotation of each cube in the level model had to be calculated manually from the vertexes. It was necessary to know the size, position, and rotation of each cube in order to create collision objects for them. In the XNA version, the FBX importer handled many of these steps.

Multitouch support

Both XNA for Windows Phone and Qt support multitouch on devices. The main concepts in both technologies are the same so this was a good porting target.

The touch points were provided in a list. Each point was marked with an ID, identifying the corresponding touch point within simultaneous touch points.

Audio support

In the XNA version no audio was implemented, although it would have been possible to implement it.

We decided to use the Qt GameEnabler audio engine, because this was a good opportunity to demonstrate its features. Besides, using Qt GameEnabler is really easy.

View management

In the XNA version it was possible to mix drawing 2D and 3D graphics, making the implementation of menus very easy. The main menu, info view, results view, and game view were implemented as separate views. A custom screen handler was implemented for managing the views.

In the Qt version, everything is 3D. The menus were done by rendering the menu views to a texture and updating the texture to the face of a 3D object filling the camera view. All of the menus were made with QML, thus allowing them to be very rich and easy to implement. The rendering of the QML to the texture required days of work to make the update efficient enough. I think that later, when Qt3D is mature enough, this will be much easier to implement.

Porting the UI of the application

The overall goal in the UI porting was to implement a 1:1 match in the Qt version. Of course, we had the custom shader support and Qt GameEnabler so we did some extra work.

The menu layouts matched almost without changes. Back buttons were added to the info and results views as the targeted devices for the Qt version do not have a Back button. A Pause button also had to be added in the bottom of the screen in the game view. The swipe feature of Harmattan had to be disabled in-game to prevent accidental swipes. When in menus, the swipe was again enabled, allowing the sending of the application to the background.

Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2011 All rights reserved