problem with tutorial of the wiki

itsalamanca

13-10-2008 17:34:03

i'm doing the tutorial of the wiki.
the part like "Quickstart (how to add MyGUI in you project)" is giving it to me a lot of problems.
i'm trying to adapt this to my code:


//#include <Ogre.h>
#include <MyGUI.h>
#include <Windows.h>


#include "Ogre.h"
#include "OgreConfigFile.h"
#include "ExampleFrameListener.h"

#if OGRE_COMPILER == OGRE_COMPILER_MSVC

#ifdef _DEBUG
#pragma comment(lib,"OgreMain_d.lib")
#pragma comment(lib,"MyGUI_d.lib")
#pragma comment(lib,"OIS_d.lib")
#else
#pragma comment(lib,"OgreMain.lib")
#pragma comment(lib,"MyGUI.lib")
#pragma comment(lib,"OIS.lib")
#endif

#endif


#ifndef _DEBUG
#define RENDERSYSTEM_D3D "RenderSystem_Direct3D9"
#define RENDERSYSTEM_GL "RenderSystem_GL"
#else
#define RENDERSYSTEM_D3D "RenderSystem_Direct3D9_D"
#define RENDERSYSTEM_GL "RenderSystem_GL_D"
#endif

#define RENDERSYSTEM_D3D_NAME "Direct3D9 Rendering Subsystem"
#define RENDERSYSTEM_GL_NAME "OpenGL Rendering Subsystem"


#include <OIS/OIS.h>
#include <OgreCEGUIRenderer.h>
#define MAX_LONG 0.3
#define MAX_ALTURA 0.4



float longitud;
float altura;
int alto=1;
int pasado=1;

class MiFrameListener : public ExampleFrameListener
{



public:

SceneNode* mNode, * mNode2;


MiFrameListener(RenderWindow* win, Camera* cam, SceneNode* node, SceneNode *node2) :
ExampleFrameListener(win, cam), mNode(node), mNode2(node2)
{
}

bool processUnbufferedKeyInput(const FrameEvent& evt)
{
// Rotar sobre el Eje Z a la izquierda
if (mKeyboard->isKeyDown(OIS::KC_Z))
{
mNode->roll(Degree(-10));
}


if (mKeyboard->isKeyDown(OIS::KC_H))
{
//probar un if o un while joder.
if(longitud<MAX_LONG && pasado){
mNode2->translate(0, 0.001,0,Ogre::Node::TS_PARENT);
longitud=longitud+0.001;
}
else {
if(longitud>=0) {
mNode2->translate(0,-0.001,0,Ogre::Node::TS_PARENT);
longitud=longitud-0.001;
pasado=0;
}
else
pasado=1;
}
//mNode2->yaw(Degree(-10));
}


// Rotar sobre el Eje Z a la derecha
if (mKeyboard->isKeyDown(OIS::KC_X))
{
if(alto && altura<MAX_ALTURA) {
mNode->translate(0,0,0.001,Ogre::Node::TS_PARENT);
altura=altura+0.001;
}
else
{
if(altura>=0)
{
alto=0;
mNode->translate(0,0,-0.001,Ogre::Node::TS_PARENT);
altura=altura-0.001;
}
else
alto=1;

}
}
return ExampleFrameListener::processUnbufferedKeyInput(evt);
}

};

/////////////////////////////////


///////////////////////

class Myclass : public Ogre::FrameListener, public OIS::MouseListener , public OIS::KeyListener
{
public:
Root *mRoot;
Camera* mCamera;
SceneManager* mSceneMgr;
ExampleFrameListener* mFrameListener;
RenderWindow* mWindow;
Ogre::String mResourcePath;
SceneNode* thisSceneNode;
SceneNode *hijo1;
SceneNode *hijo2, *hijo3, *hijo4, *hijo5, *hijo6, *hijo7;
MyGUI::Gui* mGUI;

Myclass(){}
~Myclass(){}


virtual bool inicializar(void)
{

String pluginsPath;
#ifndef OGRE_STATIC_LIB
pluginsPath = mResourcePath + "plugins.cfg";
#endif
mRoot = new Root(pluginsPath,
mResourcePath + "ogre.cfg", mResourcePath + "Ogre.log");
setupResources();
bool carryOn = configure();
if (!carryOn) return false;

chooseSceneManager();
createCamera();
createViewports();

TextureManager::getSingleton().setDefaultNumMipmaps(5);

createResourceListener();
loadResources();
creaMiMenu();
createScene();
createFrameListener();

return true;

}

virtual bool configure(void)
{
if(mRoot->showConfigDialog())
{
mWindow = mRoot->initialise(true);
return true;
}
else
{
return false;
}
}

virtual void chooseSceneManager(void)
{
mSceneMgr = mRoot->createSceneManager(ST_GENERIC, "ExampleSMInstance");
}
virtual void createCamera(void)
{
mCamera = mSceneMgr->createCamera("PlayerCam");

mCamera->setPosition(Vector3(0,0,500));
mCamera->lookAt(Vector3(0,0,-300));
mCamera->setNearClipDistance(5);

}
virtual void createFrameListener(void)
{
mFrameListener= new MiFrameListener(mWindow, mCamera,hijo3, hijo4);
mFrameListener->showDebugOverlay(true);
mRoot->addFrameListener(mFrameListener);
}

virtual void createScene(void) {
Entity* entidad1= mSceneMgr->createEntity("Cil_base", "Cil_base.mesh");
Entity *entidad2=mSceneMgr->createEntity("Cil_pieza1", "Cil_pieza1.mesh");
Entity *entidad3=mSceneMgr->createEntity("Cil_pieza2", "Cil_pieza2.mesh");
Entity *entidad4=mSceneMgr->createEntity("Cil_pieza3", "Cil_pieza3.mesh");

thisSceneNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
hijo1=thisSceneNode->createChildSceneNode();
hijo1->attachObject(entidad1);
hijo1->setScale(10, 10, 10);

hijo2=hijo1->createChildSceneNode();
hijo2->attachObject(entidad2);

hijo2->pitch(Degree(-90));
hijo2->translate (0, 0.5,0,Ogre::Node::TS_PARENT);

hijo3=hijo2->createChildSceneNode();
hijo3->attachObject(entidad3);

hijo4=hijo3->createChildSceneNode();
hijo4->attachObject(entidad4);

hijo4->translate (0.1, 0,0,Ogre::Node::TS_PARENT);
hijo4->roll(Degree(-180));

this->mCamera->lookAt(thisSceneNode->getPosition());
this->mCamera->setPosition(0, 0, 45);
} // pure virtual - this has to be overridden

virtual void destroyScene(void){} // Optional to override this

virtual void createViewports(void)
{
Viewport* vp = mWindow->addViewport(mCamera);
vp->setBackgroundColour(ColourValue(0,0,0));

mCamera->setAspectRatio(
Real(vp->getActualWidth()) / Real(vp->getActualHeight()));
}

virtual void setupResources(void)
{
// Load resource paths from config file
ConfigFile cf;
cf.load(mResourcePath + "resources.cfg");

// Go through all sections & settings in the file
ConfigFile::SectionIterator seci = cf.getSectionIterator();

String secName, typeName, archName;
while (seci.hasMoreElements())
{
secName = seci.peekNextKey();
ConfigFile::SettingsMultiMap *settings = seci.getNext();
ConfigFile::SettingsMultiMap::iterator i;
for (i = settings->begin(); i != settings->end(); ++i)
{
typeName = i->first;
archName = i->second;
#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
// OS X does not set the working directory relative to the app,
// In order to make things portable on OS X we need to provide
// the loading with it's own bundle path location
ResourceGroupManager::getSingleton().addResourceLocation(
String(macBundlePath() + "/" + archName), typeName, secName);
#else
ResourceGroupManager::getSingleton().addResourceLocation(
archName, typeName, secName);
#endif
}
}
}

virtual void creaMiMenu(void)
{
mGUI = new MyGUI::Gui();
mGUI->initialise(mWindow,"core.xml","General");
MyGUI::ButtonPtr button = mGUI->createWidget<MyGUI::Button>("Button", 10, 10, 300, 26, MyGUI::ALIGN_DEFAULT, "Main");
button->setCaption("exit");
button->eventMouseButtonClick = MyGUI::newDelegate(this, &Myclass::mousePressed);
}

virtual void createResourceListener(void)
{

}
virtual void loadResources(void)
{
// Initialise, parse scripts etc
ResourceGroupManager::getSingleton().initialiseAllResourceGroups();

}
virtual void go(void)
{
if (!inicializar())
return;

mRoot->startRendering();

// clean up
destroyScene();
}
/*******************************************************************************/

bool Myclass::frameStarted(const Ogre::FrameEvent& evt)
{
mGUI->injectFrameEntered(evt.timeSinceLastFrame);
//...
}

bool Myclass::mouseMoved( const OIS::MouseEvent &arg )
{
mGUI->injectMouseMove(arg);
//...
}

bool Myclass::mousePressed( const OIS::MouseEvent &arg, OIS::MouseButtonID id )
{
mGUI->injectMousePress(arg, id);
//...
}

bool Myclass::mouseReleased( const OIS::MouseEvent &arg, OIS::MouseButtonID id )
{
mGUI->injectMouseRelease(arg, id);
//...
}

bool Myclass::keyPressed( const OIS::KeyEvent &arg )
{
mGUI->injectKeyPress(arg);
//...
}

bool Myclass::keyReleased( const OIS::KeyEvent &arg )
{
mGUI->injectKeyRelease(arg);
//...
}


/******************************************************************************/


};

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpszCmdLine,int nCmdShow)
{
Myclass app=Myclass();

app.go();


}



The compiler says something of:
'MyGUI::delegates::IDelegate1<TP1> *MyGUI::delegates::newDelegate(void (__cdecl *)(TP1))'

how do i use this????
is the adaption well?????


thanks.

Altren

13-10-2008 17:44:24

You also should read this: http://www.ogre3d.org/wiki/index.php/My ... _delegates
button->eventMouseButtonClick = MyGUI::newDelegate(this, &Myclass::mousePressed);this line mean that Myclass::mousePressed will be called after clicking on button. Any event need to have special signature as described in tutorial you used and in eventMouseButtonClick declaration. Function for delegate must have signature void mousePressedEvent(MyGUI::WidgetPtr _widget)
and then you writebutton->eventMouseButtonClick = MyGUI::newDelegate(this, &Myclass::mousePressedEvent);

itsalamanca

13-10-2008 18:02:31

ok, thanks, but my cuestion know is, i have the buton and i have the mouse handle the entitys, i mean i can't pulse the button beause i have not any arrow.

some ideas????

Altren

14-10-2008 00:04:11

You need to use OIS::Mouse and OIS::Keyboard setEventCallback for your class. At the moment Myclass::mouseMoved, Myclass::mousePressed, Myclass::keyPressed, etc. not used at all.