Today I decided to try something different, following Hernan Moraldo's code snippet I made a video playing in the texture of an object:
Showing posts with label ogre. Show all posts
Showing posts with label ogre. Show all posts
Tuesday, August 21, 2007
Wednesday, August 15, 2007
Ogre: Object Picking
To create the effect that we are clicking on an object in Ogre we use a ray query. The ray is traced from the place were the mouse is and then goes perpendicularly to the screen. The query will result in a list of objects that were in the ray's way. An object is in the way, if its bounding box is in the way.
This is the code that I used, first we must declare a RaySceneQuery *mRaySceneQuery as a global, and then initialize it:
This is the code that I used, first we must declare a RaySceneQuery *mRaySceneQuery as a global, and then initialize it:
mRaySceneQuery = mSceneMgr->createRayQuery(Ray());
then in the mouse clicking event we make the following sorted query and try to see if the touched the Entity named "Head" :bool GuiScene::mousePressed(const OIS::MouseEvent &arg, OIS::MouseButtonID id)
{
OgreApplication::mousePressed( arg, id );
mGUISystem->injectMouseButtonDown(convertOISMouseButtonToCegui(id));
CEGUI::Point mousePos = CEGUI::MouseCursor::getSingleton().getPosition();
Ray mouseRay = mCamera->getCameraToViewportRay(mousePos.d_x/float(mWindow->getWidth()), mousePos.d_y/float(mWindow->getHeight()));
mRaySceneQuery->setRay(mouseRay);
mRaySceneQuery->setSortByDistance(true);
// Execute query
RaySceneQueryResult &result = mRaySceneQuery->execute();
RaySceneQueryResult::iterator itr;
// Get results, create a node/entity on the position
for ( itr = result.begin(); itr != result.end(); itr++ )
{
if (itr->movable && itr->movable->getName() == "Head")
{
soundMgr->StopSound( &jaguarSoundChannel );
soundMgr->PlaySound( jaguarSound, headNode, &jaguarSoundChannel );
break;
} // if
}
return true;
}
Now if you touch the bounding box a jaguar sound will be heard.
Labels:
Collisions,
Mouse,
Object Picking,
ogre,
Ogre3D,
Query,
Ray,
RaySceneQuery
Friday, August 10, 2007
Cegui and Ogre
Now that the project is starting to become more complex, I felt that the use of a GUI would help. In Ogre's Wiki it is recommended to use CEGUI. CEGUI is a free library usefull for creating windows and widgets such as buttons, listboxes or textboxes.
Has a guide I used this tutorial available in the wiki here.
First of all, before going to the code, CEGUI has several configuration files, you can see an example in your [OGRE_HOME]/media/gui directory. This is what they do:
.tga - Image File with all the textures of all widgets
.looknfeel - XML file that describes the look of all widgets and their behaviour.
.schema - XML file where all the widgets are listed and all configurations are linked.
.layout - XML file describing the windows that you want to put in one sheet in the Scene.
For now we'll be using the default look and feel, so the only thing that we have to create is a .layout file. Here an example that creates a window with four buttons:
Initialization :
In MouseListener class:
And that is it, this example is for Ogre 1.4.x and CEGUI 0.5.x for further explanations please look at the practical example. This is the final result:
Has a guide I used this tutorial available in the wiki here.
First of all, before going to the code, CEGUI has several configuration files, you can see an example in your [OGRE_HOME]/media/gui directory. This is what they do:
.tga - Image File with all the textures of all widgets
.looknfeel - XML file that describes the look of all widgets and their behaviour.
.schema - XML file where all the widgets are listed and all configurations are linked.
.layout - XML file describing the windows that you want to put in one sheet in the Scene.
For now we'll be using the default look and feel, so the only thing that we have to create is a .layout file. Here an example that creates a window with four buttons:
<?xml version="1.0" ?>
<GUILayout>
<Window Type="DefaultWindow" Name="DemoLayout">
<Window Type="TaharezLook/FrameWindow" Name="Main">
<Property Name="UnifiedSize" Value="{{0.35,0},{0.6,0}}" />
<Property Name="UnifiedPosition" Value="{{0.05,0},{0.05,0}}" />
<!-- <Property Name="RelativeMinSize" Value="w:0.2 h:0.2" />
<Property Name="RelativeMaxSize" Value="w:1.0 h:1.0" /> -->
<Property Name="Text" Value="Sound and Gui Test" />
<Property Name="CloseButtonEnabled" Value="False" />
<Window Type="TaharezLook/Button" Name="cmdQuit">
<Property Name="Text" Value="Quit" />
<Property Name="UnifiedPosition" Value="{{0.2,0},{0.8,0}}" />
<Property Name="UnifiedSize" Value="{{0.6,0},{0.07,0}}" />
</Window>
<Window Type="TaharezLook/Button" Name="cmdSound">
<Property Name="UnifiedPosition" Value="{{0.2,0},{0.6,0}}" />
<Property Name="UnifiedSize" Value="{{0.6,0},{0.07,0}}" />
<Property Name="Text" Value="Sound" />
</Window>
<Window Type="TaharezLook/Button" Name="cmdInstantAction">
<Property Name="UnifiedPosition" Value="{{0.2,0},{0.5,0}}" />
<Property Name="UnifiedSize" Value="{{0.6,0},{0.07,0}}" />
<Property Name="Text" Value="InstantAction" />
</Window>
<Window Type="TaharezLook/Button" Name="cmdMusic">
<Property Name="UnifiedPosition" Value="{{0.2,0},{0.7,0}}" />
<Property Name="UnifiedSize" Value="{{0.6,0},{0.07,0}}" />
<Property Name="Text" Value="Music" />
</Window>
</Window>
</Window>
</GUILayout>
Now we have to load this layout to our application:Initialization :
mGUIRenderer = new CEGUI::OgreCEGUIRenderer(mWindow, Ogre::RENDER_QUEUE_OVERLAY, false, 3000, mSceneMgr);
mGUISystem = new CEGUI::System(mGUIRenderer);
CEGUI::Logger::getSingleton().setLoggingLevel(CEGUI::Informative);
CEGUI::SchemeManager::getSingleton().loadScheme((CEGUI::utf8*)"TaharezLookSkin.scheme");
mGUISystem->setDefaultMouseCursor((CEGUI::utf8*)"TaharezLook", (CEGUI::utf8*)"MouseArrow");
mGUISystem->setDefaultFont((CEGUI::utf8*)"BlueHighway-12");
CEGUI::Window* sheet = CEGUI::WindowManager::getSingleton().loadWindowLayout("myLayout.layout");
mGUISystem->setGUISheet( sheet );
// set the mouse cursor initially in the middle of the screen
mGUISystem->injectMousePosition((float)mWindow->getWidth() / 2.0f, (float)mWindow->getHeight() / 2.0f);
Creating Handler's for the buttons:CEGUI::Window *win;
CEGUI::Window *m_win = CEGUI::WindowManager::getSingleton().getWindow( "Main" );
win = m_win->getChild("cmdQuit");
win->subscribeEvent( CEGUI::PushButton::EventClicked, CEGUI::Event::Subscriber( &GuiScene::handleQuit, this ));
bool GuiScene::handleQuit(const CEGUI::EventArgs& e)
{
this->stop();
return true;
}
Taking care of the IO:In MouseListener class:
bool GuiScene::mouseMoved(const OIS::MouseEvent &mouseEventRef)
{
mGUISystem->injectMouseMove(mouseEventRef.state.X.rel, mouseEventRef.state.Y.rel);
return true;
}
bool GuiScene::mousePressed(const OIS::MouseEvent &arg, OIS::MouseButtonID id)
{
mGUISystem->injectMouseButtonDown(convertOISMouseButtonToCegui(id));
return true;
}
And that is it, this example is for Ogre 1.4.x and CEGUI 0.5.x for further explanations please look at the practical example. This is the final result:
Tuesday, July 17, 2007
Mesh Exporting, Billboards, Movable Text
After importing my model with the help of an exporter, I started to animate the scene.
The wheels roll nicely and the car bounces a little bit.
There are two more innovations in this scene.
I introduced the billboards which are textures that are always facing the camera.
BillboardSet* bbset = mSceneMgr->createBillboardSet("BBSet",1); bbset->setMaterialName("Examples/Flare"); Billboard* bb = bbset->createBillboard( Vector3( 0,0,0 ) ); FloatRect coords( 0.0, 0.0, 1.0, 1.0 ); bb->setTexcoordRect(coords); billboardNode->attachObject( bbset );
In fig.2 we can see a flare made with a billboard.
We also added the MovableText class to put text on top of objects.
MovableText * msg = new MovableText("fireCarLabel", "Carro dos
bombeiros","Console",12,ColourValue(0.5f,1.0,0.5,1.0f));
The wheels roll nicely and the car bounces a little bit.
There are two more innovations in this scene.
I introduced the billboards which are textures that are always facing the camera.
BillboardSet* bbset = mSceneMgr->createBillboardSet("BBSet",1); bbset->setMaterialName("Examples/Flare"); Billboard* bb = bbset->createBillboard( Vector3( 0,0,0 ) ); FloatRect coords( 0.0, 0.0, 1.0, 1.0 ); bb->setTexcoordRect(coords); billboardNode->attachObject( bbset );
In fig.2 we can see a flare made with a billboard.
We also added the MovableText class to put text on top of objects.
MovableText * msg = new MovableText("fireCarLabel", "Carro dos
bombeiros","Console",12,ColourValue(0.5f,1.0,0.5,1.0f));
Labels:
Billboard,
Lexi Exporter,
Mesh Exporting,
Movable Text,
ogre,
Ogre3D
Subscribe to:
Posts (Atom)




