Saturday, November 14, 2009

My Vista OGRE, Part II

A little more today on my trials and tribulations of using OGRE. :-)

To better explain a couple of things from my previous post:
The OGRE App Wizard works well with VS 2008. Creating a new C++ project will show the option to create a new OGRE application. After assigning a name, the "next" button will open the app wizard. The defaults for this are probably suitable for anyone, unless options such as CEGUI support are needed. The one thing to be careful about is copying files/folders from the OgreSDK location to your project (as needed). One specific issue with this is the OgreMain.lib and OgreMain_d.lib files. If a project is created in a directory other than the OgreSDK directory, these files will not be automatically found and the app will crash. These can be added to the project by copying the 'OgreSDK\lib' folder to the project directory, by opening the executable from the 'OgreSDK\bin\debug' folder, or making appropriate changes in VS to point to the right path.
Secondly, I didn't elaborate on setting the environmental variable for OGRE (in Vista) originally, but will so now:
- As an administrator, this can be done through the GUI: System Control Panel, Advanced Settings, Environmental Variables
- As a regular user: from the command line, enter: setx OGRE_HOME c:\OgreSDK.
Lastly, OGRE is not fond of spaces in file/folder names, so do so with caution.

So, now onto where I am in this journey:
After searching around Google's 3D Warehouse for the "perfect" city to use, I ultimately decided to create my own. Had I fully envisioned the amount of time this would take, I would not have been so picky. Creating my own street layout took two attempts. I took a more Agile approach and just "dove right in." Had I read a little first, I would have found out about connecting pieces (by endpoint in my case), rotating pieces, and filling in areas. The second attempt, with about three hours of work, produced a street map were X = [-1300, 1300], Y = 0, and Z = [-1120, 1100], with 40 intersections of different types (90 deg. intersections, 3-way', and 4-ways). I was really impressed with myself when I finished this, exported it, and used it in my OGRE application test.

However, what I didn't account for was initially was that, in order to script the movement of vehicles, I needed to know where each car would be when it entered an intersection, and where it would be when it left (depending on direction of turn), including yaw and turn translation. Thus began a LOT of trial and error for identifying where each position was. It didn't help that the road models I used, including the pieces of straight section of road, where slightly skewed. I know that there is a way in the OGRE API to use the mouse to identify a point on a mesh. However, I dove into my trial/error method thinking it would be a lot faster than it was (12 hours to identify entry and exit positions for 22 of the 40 intersections).

After deciding that I had enough intersection information for multiple paths, I decided it was time to test the movement of my camaro from/through intersections. I used the OGRE Intermediate Tutorial #1 as a guide. If my camaro would would have had animation defined, then the tutorial as it was written would have been perfect. But, I din't have animation defined, so out of luck there! What I did was use this same tutorial and make some minor changes:
- deleted the "Knot" entities and Robot entity
- Added my city.mesh
- Added my camaro.mesh
- commented out (for now) the mAnimationState lines from inside the if/else's that are inside the MoveDemoListener::frameStarted function
- changed the return to 'true'.

All of this worked well, except my car is facing sideways as it drives :-), which I will work on later tonight.

Sunday, November 8, 2009

My Vista OGRE

The classes for my Masters that I am taking right now are definitely difficult. In one class, we have a group project to create a real-time version of YouTube. That one has been fun (after moving quickly away from ffmpeg into the Red5 framework) and educational.

My other class is an individual project to create a 3D driving simulator with a focus not only on the data structures, but on a "collision-avoidance" algorithm. I should add that, like in real life, the requirements have changed slightly each week. However, the project has so far been a fun challenge. The biggest change is that we are to create it from the ground up, whereas initially we were going to be given the underlying model and were to just focus on the avoidance of collisions. This change brings me to the point of this post: OGRE and installing it on Vista.

In order to meet the requirements of this project without digging into my wallet, I decided to use the following:
- OGRE 1.6.4 (for Visual C++.NET 2008) Prebuilt SKD:
- Google Sketchup 7 (free version):
- Ogremeshexporter:
- DirectX or OpenGL (personal preference)
- OGRECommandLineTools (needed for OgreXMLConverter, which allows for conversions to the mesh format):

The reason I went with the prebuilt instead of building OGRE from source was more of a time concern than anything, although I will say that as of a month ago, the source as downloaded from soureforge was buggy.

The installation of the three products was as easy as double-clicking the installer for each one, in the order I have above, setting/verifying the OGRE_HOME environmental variable is set to "c:\OgreSDK", and restarting (not required, but I prefered). To verify that OGRE was correctly installed, the following folder structure should exist:
----\lib (should have "OgreMain.lib" and "OgreMain_d.lib")

Outside of the OGRE examples, Google Sketchup can be used to create a new mesh for OGRE. Sketchup can import directly from 3D Warehouse. Once a model has been imported, it can be exported to OGRE mesh format (tools->Export to Ogre Mesh). The Sketchup exporter will have its own directory ([root]\SketchupExporter) in which the exported .mesh, .material, etc. files will be saved to by defualt.

I intend to keep the OGRE thread going for awhile as I work through it, so I am not going to write directly about creating OGRE projects, as it can be a pain in the rear. There is some excellent information on the OGRE Wiki for this information. The last thing I wanted to add to this is that there are AppWizards for automatically creating a new VC++ project and it can be found here:
A lot of the links at this page go back to sourceforge, but apparently (I didn't use the wizard) these tools are good for each IDE for which they were written.