Tutorial 1
From NaviWiki
Contents |
Tutorial 1 - "Your First Navi"
Okay, let's start!
In your project's target directory (where the binary will be running from), make a new folder called "NaviLocal". This is where we will store all local Navi-related media assets.
Make a new file called "helloworld.html" (you can right-click, New Text Document, rename it if you aren't hiding known file extensions). Open it up and type this:
<html> <body> <p>Hello world!</p> </body> </html>
Save it, close it. Done.
Initializing NaviManager
NaviManager needs a handle to your window and so you must initialize it with your Ogre::RenderWindow. Although NaviManager is a singleton, you must still explicitly instantiate it (most similar to Ogre::Root), for example:
using namespace NaviLibrary; Ogre::RenderWindow* renderWin = root->getAutoCreatedWindow(); NaviManager* naviMgr = new NaviManager(renderWin); // now that we've instantiated the singleton, we can access it from anywhere NaviManager* naviMgr = NaviManager::GetPointer();
If you would like to redirect the local:// specifier (more on this later) to a directory other than "NaviLocal", you need to tell NaviManager this. Let's say we want to use a relative directory "Media\NaviStuff" instead:
using namespace NaviLibrary; Ogre::RenderWindow* renderWin = root->getAutoCreatedWindow(); // Remember to escape the backslash! NaviManager* naviMgr = new NaviManager(renderWin, "Media\\NaviStuff");
So far so good, let's keep going!
Creating a Navi
Alrite, time for our first Navi (exciting!). We will name this Navi "helloNavi" and will initialize it with the "helloworld.html" page we made earlier. We want our Navi to be centered in the middle of the screen and with dimensions 400 by 320 pixels.
Navi* helloNavi = naviMgr->createNavi("helloNavi", "local://helloworld.html", NaviPosition(Center), 400, 320);
It's really that simple!
Injecting Mouse Input
The API for injecting Mouse Input is very straight-forward. You must tell NaviManager four things:
- Where the mouse is (absolute coordinates).
- When a mouse button goes down and which button.
- When a mouse button goes up and which button.
- Optional: How much the mouse wheel has turned (relative).
Here is an example from the NaviDemo how to inject these inputs using OIS MouseListeners (note: class NaviDemo is a registered OIS::MouseListener):
bool NaviDemo::mouseMoved(const OIS::MouseEvent &arg)
{
if(arg.state.Z.rel != 0)
naviMgr->injectMouseWheel(arg.state.Z.rel);
return naviMgr->injectMouseMove(arg.state.X.abs, arg.state.Y.abs);
}
bool NaviDemo::mousePressed(const OIS::MouseEvent &arg, OIS::MouseButtonID id)
{
return naviMgr->injectMouseDown(id);
}
bool NaviDemo::mouseReleased(const OIS::MouseEvent &arg, OIS::MouseButtonID id)
{
return naviMgr->injectMouseUp(id);
}
Note: In the above example 'arg.state.Z.rel' is OIS's way to telling us how much the mouse wheel has turned.
Keeping NaviManager Up-To-Date
In your application's main loop or in your FrameListener, type this to update NaviManager:
naviMgr->Update();
Cleanly Shutting Down
When your application is ready to close, if you would be so kind as to add this one command:
delete naviMgr;
The Code Ethics police thanks you.
Conclusion
Alrite, you're done! Those are all the basics of getting up and running with NaviLibrary.
If you did everything right, it should look something like this when you run it:
Hungry for more knowledge? Tutorial 2 will fill you up with tasty goodness!

