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
it is in C++
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;
}
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;
}
cheers