5 July 2012

Setting up Nvidia Apex SDK on Visual Studio 2010

APEX is a multi-platform, scalable dynamics framework. Rather than providing a low-level API that requires a physics programmer, APEX creates an environment where artists can create complex, high-level, dynamic systems without any programming. APEX is completely artist focused by providing the artist with familiar and easy to use authoring tools.
APEX consists of two major components:
  • the authoring component, provides high-level authoring of dynamic systems through DCC plug-ins (3dsMax/Maya), standalone tools, or game engine plug-ins.
  • the runtime component, consists of a modular SDK which includes the framework that supports all APEX modules and provides a render interface to allow minimal integration into game engines.
Here I'll show you how to setup the SDK so that you can start using Apex SDK in Visual Studio in your c++ programs.

Download following files from you Apex account -
1. Nvidia PhysX sdk installer (mostly named as PhysX_2.8.4.6_for_PC_Core.msi). If  you are using Apex  1.1 SDK, then you need to install PhysX 2.8.4 and not later version.
2. Then you need Apex SDK (mostly named as APEXSDK-1.1-Build112-PhysX_2.8.4-WIN-VC9.zip).
3. Latest Microsoft DirectX SDK which can be downloaded from here.

Install DirectX SDK, Nvidia PhysX and then Apex SDK. Now you need to add Nvidia PhysX installed location to your system path. To do this, go to System Properties->Advanced System Settings->Environment Variable. Click on New in the top list. Add the variable name NXPATH and variable value as <Location> of your physx sdk(For my case it was "C:\Program Files (x86)\NVIDIA Corporation\NVIDIA PhysX SDK\v2.8.4_win").


Now you are ready to open the visual studio sample projects given with ApexSDK.
  1. Go to your apex installed location/samples/compiler\vc9WIN32-PhysX_2.8.4 or /samples/compiler\vc9WIN64-PhysX_2.8.4 folder. Open the Apex_Samples project. This project consists of 8 sub projects. 
  2. Right click on the properties of SampleRenderer-MT. Go to C/C++->General->Additional Include Directories. Replace the directX include path with the one on your system. (For me it was C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Include).
  3. Similarly replace the directx include path in the properties of project "SamplePlatform-MT".
Now compile your projects and you are ready to go. Mostly the project names in the properties are different from the one which are built e.g. ApexHelloWorld sample builds with the name ApexHelloWorldDebug.exe So you'll have to change this name in properties so that you may debug them directly from your visual studio editor. The build location is in ApexSDK home location/bin.


1 July 2012

Creating animated splash screen in Qt

The QSplashScreen widget in Qt provides a splash screen that can be shown during application startup. A splash screen is a widget that is usually displayed when an application is being started. Splash screens are often used for applications that have long start up times to provide the user with feedback that the application is loading. The splash screen appears in the center of the screen. It may be useful to add the Qt::WindowStaysOnTopHint to the splash widget's window flags if you want to keep it above all the other windows on the desktop.

Many times you might feel to add animated splash screens for better look of the splash screen. This can be achieved in multiple ways. One way is to make your own splash screen class by inheriting from QSplashScreen and painting the screen as you wish. I would show a relatively simple approach just by changing the series of images with changing time.

To get a series of images, use a video making tool like After Effect or Sony Vegas. Design your complete splash screen as a video using these tools. When you are ready, publish this video and in publish settings, change the output to png or jpg mode. This will render your video as series of image files. Now you just need to copy these images in your project folder so that they can be easily available while loading splash.

For my case, I copied all my images in icons/splash/ folder. The image names follow the following pattern
SplashScreen_#####. Where ##### is the sequence of image.


QString name = "./icons/splash/SplashScreen_000";
QStringList fileNames;
for(int i=0; i<100; i++)
{
    if(i<10)
       fileNames << (name+QString("0%1").arg(i));
    else
       fileNames << (name+QString("%1").arg(i));
}


Here I read all the image file names into a list. Make sure you don't add the splash images to your resources file as they will be packaged into your build and would consume a lot of useless space. Moreover, if the count of your splash images is too much, then if would fail to compile. So its better to read it from the folder itself.


QSplashScreen *splashScreen = new QSplashScreen(QPixmap(":/icons/splashscreen.png"));
splashScreen->show();
QTime finishingTime = QTime::currentTime().addSecs(5);
int count = 0;
while(QTime::currentTime()<=finishingTime)
{
    if(count>299)
      splashScreen->setPixmap(QPixmap(":/icons/splashscreen.png"));
    else
      splashScreen->setPixmap(QPixmap(fileNames[count/3]));
    count++;
}
splashScreen->hide();



I have taken a timer of 5 seconds to show how the splash images would change to give a feel of animation. Moreover you can ignore the count/3 part in the code. I rendered my splash images at 20fps, so I had to adjust the timing with number of images. You can adjust this based on your design. This method seems simple but I believe its better and simple to overload the QSplashScreen class and design everthing in modular form.