Irrlicht plus wxDialog

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Post Reply
strale
Posts: 119
Joined: Wed Nov 23, 2005 1:58 pm
Location: Lambrugo Italy
Contact:

Irrlicht plus wxDialog

Post by strale »

Hi all

I just make up a wxDialog with embedded irrlicht
and thank to RoBaTte i succeded to make it work
so i poste the code in the hope it could be useful
:arrow: it is in C++
:arrow: and params.DriverType = EDT_OPENGL;

the class called wxIRRDialog ineritance from wxDialog and from another class called GRF3D that incapsuulate the irrlicht engine.

to use it in a wxWidget project is enough to
a) istantiate it in the main wxWidget main frame:
wxIRRDialog * objIrrDlg= new wxIRRDialog(this,Dlgtitle,400,400);

b) call the asctivate function:
objIrrDlg->Add3DShapeModel();
:!: this function encapsulate the path of the model to load so it must be changed to work properly. :!:

Code: Select all

void wxIRRDialog::Add3DShapeModel(void){ 

        wxDialog::Show(0); 
///#######################
/// change the path to point to your model 
   GRF3D::AddShape("./Media/f360.ms3d", "./Media/fskin.jpg"); 
///#######################
        wxDialog::Show(1); 
        myTimer.SetOwner(this, idTimerFired); 
        myTimer.Start(1); 

        return; 
}
:!:



The code of the irrlicht class:
GRF3D.h and GRF3D.cpp

Code: Select all


#ifndef _GRF3D_
#define _GRF3D_

//GRAPHICS
#include <irrlicht.h>

using namespace irr;
using namespace gui;
using namespace video;
using namespace core;
using namespace scene;

class GRF3D{

      private:
          IrrlichtDevice *Device ;
          IVideoDriver* driver ;
          IGUIEnvironment* env;
          ISceneManager* smgr ;
          ICameraSceneNode* camera ;
          IAnimatedMeshSceneNode* node;
          stringc AppPath ;

          char * GetAppPath(void);
          irr::video::SColor colBackground;
          irr::video::SColor colForeground;

      public:
              GRF3D(unsigned long Handle, s32 Witdh, s32 heigh);
              ~GRF3D(void);

              void Draw3D(void);

              void AddShape( char * cpShapePath, char * cImage );
              void RotateModel(void);

              void SetCameraTargetPos(float fPosX, float fPosY,float fPosZ);
              void SetCameraPos(float fPosX, float fPosY,float fPosZ);
              void MessageBox(const wchar_t *  Tilte, const wchar_t *  Message);
};

#endif

Code: Select all

#include "GRF3D.h"

using namespace irr;
using namespace gui;
using namespace video;
using namespace core;
using namespace scene;

#pragma comment(lib, "Irrlicht.lib")

GRF3D::~GRF3D(void){
        Device->drop();
}

GRF3D::GRF3D(unsigned long Handle, s32 Witdh, s32 heigh){

    SIrrlichtCreationParameters params;
    params.WindowId =   (void *) Handle ;
    params.DriverType = EDT_OPENGL;
    params.WindowSize = dimension2d<s32>(Witdh,heigh);

	Device = createDeviceEx(params);
	if (Device != 0){
         Device->setResizeAble(true);
         env = Device->getGUIEnvironment();
         driver = Device->getVideoDriver();
         smgr = Device->getSceneManager();

         camera = smgr->addCameraSceneNode  ( ) ;
         AppPath = env->getFileSystem()->getWorkingDirectory() ;
         node =0;
    }
}

///Description: return the inforation about application path
char * GRF3D::GetAppPath(void){
        return (char *) AppPath.c_str();
}

///Description: to mange camera outside the class
void GRF3D::SetCameraTargetPos(float fPosX, float fPosY,float fPosZ){
    camera->setTarget(core::vector3df(fPosX, fPosY, fPosZ));
    return;
}

///Description: to mange camera outside the class
void GRF3D::SetCameraPos(float fPosX, float fPosY,float fPosZ){
    camera->setPosition(vector3df(fPosX, fPosY, fPosZ));
    return;
}

///Description: draw a mwessage box for debug pourpose
/// \param const wchar_t * Tilte the name of the messagwe box
/// - const wchar_t  * Message the message
void GRF3D::MessageBox(const wchar_t * Tilte, const wchar_t  * Message){
        bool modal = true;
        env->addMessageBox(Tilte,Message,modal,EMBF_OK );
        return;
}

/// Description : render the 3D Must be called every time a refresh of the 3D engine is required
void GRF3D::Draw3D(void){

       Device->run() ;
       //if (Device->isWindowActive()){
                driver->beginScene(true, true, colBackground);
                smgr->drawAll();
                env->drawAll();
                driver->endScene();
        //}
        return;
}

/// Description: add a node and point the camera to it
/// \param  char * cpShapePath : the path inclusive of the model name
/// \param  char * cImage : the path inclusive of the model image name
void GRF3D::AddShape( char * cpShapePath, char * cImage ){


        IAnimatedMesh* mesh = smgr->getMesh(cpShapePath);
        node = smgr->addAnimatedMeshSceneNode( mesh );
        if (node){
            node->setMaterialFlag(EMF_LIGHTING, false);
            node->setMaterialTexture( 0, driver->getTexture(cImage) );
            vector3df NodePos = node->getPosition();
            GRF3D::SetCameraTargetPos(NodePos.X,NodePos.Y, NodePos.Z);
            GRF3D::SetCameraPos(0,200,200);
        }

    return;

}

/// Description: rotate the node on the Y axe
void GRF3D::RotateModel(void){

        if(node){
            vector3df NodeRot = node->getRotation();
            NodeRot.Y += 1.1f;
            node->setRotation(NodeRot);
        }
        return;
}

the code of the xwIRRdialog class:
wxIRRDialog.h and wxIRRDialog.cpp

Code: Select all

#include <wx/wxprec.h>

#ifdef __BORLANDC__
    #pragma hdrstop
#endif

#ifndef WX_PRECOMP
    #include <wx/wx.h>
#endif

#include "GRF3D.h"

#ifndef _WXIIDLG_
#define _WXIIDLG_

class wxIRRDialog : public wxDialog, GRF3D{

    wxTimer myTimer;

    public:
     wxIRRDialog(wxWindow* parent ,const wxString & title ,int Width,int height);
     ~wxIRRDialog(void);
     void Add3DShapeModel(void);
     void OnTimer(wxTimerEvent& event);

     DECLARE_EVENT_TABLE();

 };

 #endif

Code: Select all


#include "wxIRRDialog.h"

int idTimerFired = wxNewId();
BEGIN_EVENT_TABLE(wxIRRDialog, wxDialog)
    EVT_TIMER(idTimerFired, wxIRRDialog::OnTimer)
END_EVENT_TABLE()

/// Description: double hineritance to have a wxDialog mixed to a 3D engine Class
/// - the wxDialog constructor need the parent main window
/// - the 3D engine constructor need instead the handle of the this disalog window
wxIRRDialog::wxIRRDialog(wxWindow* parent ,const wxString & title ,int Width,int height)
    :wxDialog(parent,-1, title, wxPoint(0,0), wxSize(Width,height) )
    ,GRF3D(wx_reinterpret_cast(unsigned long, this->GetHandle()), Width,height){

}

/// Description: release memory
wxIRRDialog::~wxIRRDialog(void){
    wxDialog::Destroy();
}

/// Description: Add a model to the dialog
/// -Start the timer to render the model every 1 ms
void wxIRRDialog::Add3DShapeModel(void){

        wxDialog::Show(0);
        GRF3D::AddShape("./Media/f360.ms3d", "./Media/fskin.jpg");
        wxDialog::Show(1);
        myTimer.SetOwner(this, idTimerFired);
        myTimer.Start(1);

        return;
}

///  Description: Timer is used to render the 3Dgraph
/// - if more speed is needed an OnIdle event could be managed to run the 3dEngine
void wxIRRDialog::OnTimer(wxTimerEvent& event){
        GRF3D::Draw3D();
        GRF3D::RotateModel();
        wxDialog::Refresh(FALSE);
        return;
}


that's all folks!
cheers
RoBaTte
Posts: 10
Joined: Thu Jun 07, 2007 2:34 pm

Post by RoBaTte »

Nice :D
dlangdev
Posts: 1324
Joined: Tue Aug 07, 2007 7:28 pm
Location: Beaverton OR
Contact:

Post by dlangdev »

looks like this will also work when i right mouse click a node in maya mode, though.

thanks for posting the dialog box code.
Image
strale
Posts: 119
Joined: Wed Nov 23, 2005 1:58 pm
Location: Lambrugo Italy
Contact:

Post by strale »

Hi :D

well i ried the maya mode but does not work
camera = smgr->addCameraSceneNodeMaya();


instead with
camera = smgr->addCameraSceneNodeFPS();
works but it results useless as it is impossible to interract with others GUI components

cheers
bloodbao
Posts: 15
Joined: Fri Aug 31, 2007 1:12 pm

Post by bloodbao »

At last,i pass the test!
thanks your code!

Code: Select all

wxIRRDialog::wxIRRDialog(wxWindow* parent ,const wxString & title ,int Width,int height) 
    :wxDialog(parent,-1, title, wxPoint(0,0), wxSize(Width,height) ) 
    ,GRF3D(wx_reinterpret_cast(unsigned long, this->GetHandle()), Width,height){ 
	Add3DShapeModel();//add this,can see model work!
} 
Post Reply