Problem using delegates

itsalamanca

18-10-2008 18:40:18

hi, my parter and I have a big problem,
first of all my code is this:


#include <MyGUI.h>
#include <Windows.h>
#include "Ogre.h"
#include "OgreConfigFile.h"
#include "ExampleFrameListener.h"
//#include "ExampleApplication.h"
#include "OgreStringConverter.h"
#include "OgreException.h"

#define OIS_DYNAMIC_LIB
#include <OIS/OIS.h>
#include "OIS/OIS.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;

MyGUI::ButtonPtr button;//esto hay que quitarlo de aki.


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


using namespace Ogre;

class MiFrameListener : public ExampleFrameListener, public OIS::MouseListener, public OIS::KeyListener
{
public:
SceneNode *nodo;
MiFrameListener(RenderWindow* win, Camera* cam, SceneManager *sceneMgr, SceneNode *node2)
: ExampleFrameListener(win, cam, true, true, true)
{
mMouse->setEventCallback(this);
mKeyboard->setEventCallback(this);

mDirection = Vector3::ZERO;
}

bool frameStarted(const FrameEvent &evt)
{
if(mMouse)
mMouse->capture();
if(mKeyboard)
mKeyboard->capture();

return mContinue;
}

// MouseListener
bool mouseMoved(const OIS::MouseEvent &e)
{
return true;
}

bool mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id)
{
return true;
}

bool mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id) { return true; }

// KeyListener
bool keyPressed(const OIS::KeyEvent &e)
{
return true;
}

bool keyReleased(const OIS::KeyEvent &e)
{
return true;
}
protected:
Real mRotate; // The rotate constant
Real mMove; // The movement constant

SceneManager *mSceneMgr; // The current SceneManager
SceneNode *mCamNode; // The SceneNode the camera is currently attached to

bool mContinue; // Whether to continue rendering or not
Vector3 mDirection; // Value to move in the correct direction
};


class Myclass
{
public:
Root *mRoot;
Camera* mCamera;
SceneManager* mSceneMgr;
ExampleFrameListener* mFrameListener;
RenderWindow* mWindow, *mWindow2;//ver si dos ventanas
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);
//mWindow=mRoot->createRenderWindow("general", 400, 300, false,0);
//mWindow->_setPrimary();
//mWindow2=mRoot->createRenderWindow("secundaria",200,300, false,0); //con esta funcion solo creo las dos funciones, ver el uso ke le puedo dar.

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, mSceneMgr, hijo4);
mFrameListener->showDebugOverlay(true);
mRoot->addFrameListener(mFrameListener);
}

virtual void createScene(void) {

Light *light;

//mSceneMgr->setAmbientLight( ColourValue( 0, 0, 0 ) );
mSceneMgr->setShadowTechnique( SHADOWTYPE_STENCIL_ADDITIVE );

Entity* ent;
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();
entidad1->setCastShadows(true);
hijo1->attachObject(entidad1);
hijo1->setScale(10, 10, 10);

hijo2=hijo1->createChildSceneNode();
entidad2->setCastShadows(true);
hijo2->attachObject(entidad2);
hijo2->pitch(Degree(-90));
hijo2->translate (0, 0.5,0,Ogre::Node::TS_PARENT);

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

hijo4=hijo3->createChildSceneNode();
entidad4->setCastShadows(true);
hijo4->attachObject(entidad4);
hijo4->translate (0.1, 0,0,Ogre::Node::TS_PARENT);
hijo4->roll(Degree(-180));

Plane plane(Vector3::UNIT_Y, 0);

MeshManager::getSingleton().createPlane("ground",
ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane,
1500,1500,20,20,true,1,5,5,Vector3::UNIT_Z);

ent = mSceneMgr->createEntity("GroundEntity", "ground");
mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent);
ent->setMaterialName("Examples/Rockwall");
ent->setCastShadows(false);
/*
light = mSceneMgr->createLight("Light1");
light->setType(Light::LT_POINT);
light->setPosition(Vector3(0, 150, 250));
light->setDiffuseColour(1, 1.0, 1.0);
light->setSpecularColour(1, 1.0, 1.0);

light = mSceneMgr->createLight("Light3");
light->setType(Light::LT_DIRECTIONAL);
light->setDiffuseColour(1, 1.0, 1.0);
light->setSpecularColour(1, 1.0, 1.0);

light->setDirection(Vector3( 0, -1, 1 ));

light = mSceneMgr->createLight("Light2");
light->setType(Light::LT_SPOTLIGHT);
light->setDiffuseColour(1, 1.0, 1.0);
light->setSpecularColour(1, 1.0, 1.0);

light->setDirection(-1, -1, 0);
light->setPosition(Vector3(0, 300, 0));

light->setSpotlightRange(Degree(35), Degree(50));

*/ //esto solo cuando tenga puesto los fondos.


this->mCamera->lookAt(thisSceneNode->getPosition());
this->mCamera->setPosition(45, 45, 45);
}

virtual void destroyScene(void){}

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)
{
ConfigFile cf;
cf.load(mResourcePath + "resources.cfg");

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)
{
//ExampleFrameListener *menu;;

mGUI = new MyGUI::Gui();
mGUI->initialise(mWindow,"core.xml","General");

button = mGUI->createWidget<MyGUI::Button>("Button", 100, 100, 300, 26, MyGUI::ALIGN_RIGHT, "Main");
button->eventMouseButtonClick = MyGUI::newDelegate(&mFrameListener, &ExampleFrameListener::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();
}
};


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

app.go();
}


We use buffered imput and we are starting to use mygui.
We put de funcion new delegates and it is problematic, we obtend the next mistake:

c:\documents and settings\jose\mis documentos\visual studio 2005\projects\mygui3\main.cpp(326) : error C2780: 'MyGUI::delegates::IDelegate1<TP1> *MyGUI::delegates::newDelegate(void (__cdecl *)(TP1))' : se esperan 1 argumentos; 2 proporcionados
c:\mygui\myguiengine\include\mygui_delegateimplement.h(63) : vea la declaración de 'MyGUI::delegates::newDelegate'
c:\documents and settings\jose\mis documentos\visual studio 2005\projects\mygui3\main.cpp(326) : error C2782: 'MyGUI::delegates::IDelegate1<TP1> *MyGUI::delegates::newDelegate(TObj *,void (__thiscall TObj::* )(TP1))' : el parámetro de plantilla 'TObj' es ambiguo
c:\mygui\myguiengine\include\mygui_delegateimplement.h(72) : vea la declaración de 'MyGUI::delegates::newDelegate'
puede ser 'ExampleFrameListener'
o 'ExampleFrameListener *'
c:\documents and settings\jose\mis documentos\visual studio 2005\projects\mygui3\main.cpp(326) : error C2780: 'MyGUI::delegates::IDelegate2<TP1,TP2> *MyGUI::delegates::newDelegate(void (__cdecl *)(TP1,TP2))' : se esperan 1 argumentos; 2 proporcionados
c:\mygui\myguiengine\include\mygui_delegateimplement.h(63) : vea la declaración de 'MyGUI::delegates::newDelegate'
c:\documents and settings\jose\mis documentos\visual studio 2005\projects\mygui3\main.cpp(326) : error C2782: 'MyGUI::delegates::IDelegate2<TP1,TP2> *MyGUI::delegates::newDelegate(TObj *,void (__thiscall TObj::* )(TP1,TP2))' : el parámetro de plantilla 'TObj' es ambiguo
c:\mygui\myguiengine\include\mygui_delegateimplement.h(72) : vea la declaración de 'MyGUI::delegates::newDelegate'
puede ser 'ExampleFrameListener'
o 'ExampleFrameListener *'
c:\documents and settings\jose\mis documentos\visual studio 2005\projects\mygui3\main.cpp(326) : error C2780: 'MyGUI::delegates::IDelegate3<TP1,TP2,TP3> *MyGUI::delegates::newDelegate(void (__cdecl *)(TP1,TP2,TP3))' : se esperan 1 argumentos; 2 proporcionados
c:\mygui\myguiengine\include\mygui_delegateimplement.h(63) : vea la declaración de 'MyGUI::delegates::newDelegate'
c:\documents and settings\jose\mis documentos\visual studio 2005\projects\mygui3\main.cpp(326) : error C2782: 'MyGUI::delegates::IDelegate3<TP1,TP2,TP3> *MyGUI::delegates::newDelegate(TObj *,void (__thiscall TObj::* )(TP1,TP2,TP3))' : el parámetro de plantilla 'TObj' es ambiguo
c:\mygui\myguiengine\include\mygui_delegateimplement.h(72) : vea la declaración de 'MyGUI::delegates::newDelegate'
puede ser 'ExampleFrameListener'
o 'ExampleFrameListener *'
c:\documents and settings\jose\mis documentos\visual studio 2005\projects\mygui3\main.cpp(326) : error C2780: 'MyGUI::delegates::IDelegate4<TP1,TP2,TP3,TP4> *MyGUI::delegates::newDelegate(void (__cdecl *)(TP1,TP2,TP3,TP4))' : se esperan 1 argumentos; 2 proporcionados
c:\mygui\myguiengine\include\mygui_delegateimplement.h(63) : vea la declaración de 'MyGUI::delegates::newDelegate'
c:\documents and settings\jose\mis documentos\visual studio 2005\projects\mygui3\main.cpp(326) : error C2782: 'MyGUI::delegates::IDelegate4<TP1,TP2,TP3,TP4> *MyGUI::delegates::newDelegate(TObj *,void (__thiscall TObj::* )(TP1,TP2,TP3,TP4))' : el parámetro de plantilla 'TObj' es ambiguo
c:\mygui\myguiengine\include\mygui_delegateimplement.h(72) : vea la declaración de 'MyGUI::delegates::newDelegate'
puede ser 'ExampleFrameListener'
o 'ExampleFrameListener *'


i probe a lot things and i have not idea.

Somebody can help me????
thanks.

Altren

18-10-2008 19:03:23

I already answered you same question http://www.ogre3d.org/phpBB2addons/viewtopic.php?t=8367!

itsalamanca

18-10-2008 19:07:30

yes, but i have to use other form to solve, and i want to use the funcion that is into the MyframeListener, and it is the problematic.

Altren

19-10-2008 02:51:24

Looks like you don't understand how eventMouseButtonClick and all gui events work. eventMouseButtonClick calls your delegate every time when button was clicked. So you delegate is sth that printing "Hello, world!" for example or doing some other useful stuff.
So in your case you should add new member function to MiFrameListener with specific to event signature (see eventMouseButtonClick declaration). For examplevoid handleButtonClick(MyGUI::WidgetPtr _sender)
{
_sender->setCaption("Button was clicked");
}
And then change you livi with event tobutton->eventMouseButtonClick = MyGUI::newDelegate(&mFrameListener, &MiFrameListener::handleButtonClick);
mFrameListener also need to have type MiFrameListener, not ExampleFrameListener because ExampleFrameListener don't have your functions.MiFrameListener* mFrameListener;

itsalamanca

19-10-2008 11:51:35

i probe this in my "new" code:


#include <MyGUI.h>
#include <Windows.h>
#include "Ogre.h"
#include "OgreConfigFile.h"
#include "ExampleFrameListener.h"
//#include "ExampleApplication.h"
#include "OgreStringConverter.h"
#include "OgreException.h"

#define OIS_DYNAMIC_LIB
#include <OIS/OIS.h>
#include "OIS/OIS.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;

MyGUI::ButtonPtr button;//esto hay que quitarlo de aki.


using namespace Ogre;


class Menu
{
public:
Menu(){};
~Menu(){};
void handleButtonClick(MyGUI::WidgetPtr _sender)
{
_sender->setCaption("Button was clicked");
button->_destroyDrawItem();
}
};


class Myclass
{
public:
Root *mRoot;
Camera* mCamera;
SceneManager* mSceneMgr;
ExampleFrameListener* mFrameListener;
RenderWindow* mWindow, *mWindow2;//ver si dos ventanas
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);
//mWindow=mRoot->createRenderWindow("general", 400, 300, false,0);
//mWindow->_setPrimary();
//mWindow2=mRoot->createRenderWindow("secundaria",200,300, false,0); //con esta funcion solo creo las dos funciones, ver el uso ke le puedo dar.

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)
{
}

virtual void createScene(void) {
}

virtual void destroyScene(void){}

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)
{
ConfigFile cf;
cf.load(mResourcePath + "resources.cfg");

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

ResourceGroupManager::getSingleton().addResourceLocation(
String(macBundlePath() + "/" + archName), typeName, secName);
#else
ResourceGroupManager::getSingleton().addResourceLocation(
archName, typeName, secName);
#endif
}
}
}

virtual void creaMiMenu(void)
{
Menu menu;
mGUI = new MyGUI::Gui();
mGUI->initialise(mWindow,"core.xml","General");
button = mGUI->createWidget<MyGUI::Button>("Button", 100, 100, 300, 26, MyGUI::ALIGN_RIGHT, "Main");
button->eventMouseButtonClick = MyGUI::newDelegate(&menu, &Menu::handleButtonClick);
}

virtual void createResourceListener(void)
{
}
virtual void loadResources(void)
{
ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
}
virtual void go(void)
{
if (!inicializar())
return;
mRoot->startRendering();
destroyScene();
}
};


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

app.go();
}



the compiler doesn't give me problems, but when i execute it, y click over the button and nothing chages.
?¿?¿?¿

thanks.

Altren

19-10-2008 14:50:27

Read this http://www.ogre3d.org/wiki/index.php/MyGUI_quickstart
Where' all your mGUI->inject*** functions? You must have them if you want to use gui.

itsalamanca

19-10-2008 16:09:36

the problems continues, and i do every thing like the wiki says:


mGUI = new MyGUI::Gui();
mGUI->initialise(mWindow,"core.xml","General");
button = mGUI->createWidget<MyGUI::Button>("Button", 100, 100, 300, 26, MyGUI::ALIGN_RIGHT, "Main");
button->eventMouseButtonClick = MyGUI::newDelegate(this, &Myclass::mousePressed);


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




the mistake::

error C2784: 'MyGUI::delegates::IDelegate1<TP1> *MyGUI::delegates::newDelegate(void (__cdecl *)(TP1))' : no se pudo deducir el argumento de plantilla para 'void (__cdecl *)(TP1)' desde 'bool (__thiscall Myclass::* )(const OIS::MouseEvent &,OIS::MouseButtonID)'


i'm so desesperate, i am not be able to do this my self, i need to see some example code of my gui.

thanks.

Altren

19-10-2008 16:28:49

there's some demos coming with MyGUI source

itsalamanca

20-10-2008 17:26:55

well, i'm here again,
now i have some control for the mouse events, there is only one problem, i don't see the arrow of the mouse. i mean, i see but it doesn't move.
the code is the same and a put you a capture:

Upload another image. Register for free. Link to this page. Please don't change any codes while linking!

Please use clickable thumbnail codes (they save ImageShack's bandwidth):
Thumbnail for Websites
Thumbnail for forums (1)
Thumbnail for forums (2)
Link back to ImageShack or use the banners and buttons.

QuickPost this image to any blog!
with this image.


Include details
Hotlink for forums (1)
Hotlink for forums (2)
[url=http://imageshack.us][img="http://img50.imageshack.us/img50/3350/capturadequenosememueveac9.png" alt=""] Hotlink for forums (1)
[/url] [url=http://g.imageshack.us/img50/capturadequenosememueveac9.png/1/][img=http://img50.imageshack.us/img50/capturadequenosememueveac9.png/1/w800.png][/url] Hotlink for forums (2)
Hotlink for Websites
Hotlink for Websites
Show image to friends
+ Show Advanced Linking
DO NOT Use Link Below when posting. Use FORUM Links above for posts
Direct link to image



thanks

Altren

20-10-2008 23:56:31

Sorry, but you need to learn how to use OIS with Ogre. Read some tutorials or learn from source code.