Code: Select all
#include <windows.h>
#include "irrlicht.h"
#include "wx/wx.h"
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
ICameraSceneNode* camera = {0};
IrrlichtDevice* device = {0};
ISceneManager* smgr = {0};
IVideoDriver* driver = {0};
SExposedVideoData videodata;
HWND hwnd;
class MyApp: public wxApp
{
virtual bool OnInit();
};
IMPLEMENT_APP(MyApp)
class MyFrame: public wxFrame
{
public:
MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
void OnQuit(wxCommandEvent& event);
void OnPaint(wxPaintEvent &event);
void OnSize(wxSizeEvent &event);
void OnMotion( wxMouseEvent& event );
wxPanel* m_panel6;
wxPanel* getPanel() { return m_panel6; }
DECLARE_EVENT_TABLE()
};
enum
{
ID_Quit = 1
};
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU(ID_Quit,MyFrame::OnQuit)
EVT_PAINT(MyFrame::OnPaint)
EVT_SIZE(MyFrame::OnSize)
END_EVENT_TABLE()
bool MyApp::OnInit()
{
MyFrame *frame = new MyFrame( _("Hello World"), wxPoint(50, 50), wxSize(800,600) );
frame->Show(true);
SetTopWindow(frame);
hwnd = (HWND)frame->getPanel()->GetHandle();
irr::SIrrlichtCreationParameters param;
param.DriverType = video::EDT_DIRECT3D9;
param.WindowId = reinterpret_cast<void*>(hwnd);
param.Vsync = false;
param.Bits = 32;
param.HighPrecisionFPU = true; // para directx
SExposedVideoData videodata_temp(hwnd);
videodata = videodata_temp;
device = irr::createDeviceEx(param);
smgr = device->getSceneManager();
driver = device->getVideoDriver();
camera = smgr->addCameraSceneNode();
camera->setFarValue(5000);
camera->setNearValue(0.1f);
camera->setFOV(1.256636f);
camera->setID(0);
camera->setPosition(core::vector3df(0,0,0));
camera->setTarget(core::vector3df(0,0,1));
camera->setAspectRatio( (float)(frame->getPanel()->GetSize().x) / (float)(frame->getPanel()->GetSize().y) );
device->getSceneManager()->setActiveCamera(camera);
IMeshSceneNode* cube = smgr->addCubeSceneNode(10.0f);
cube->setName("BOX");
cube->setPosition(core::vector3df(0,0,50));
return true;
}
MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
: wxFrame(NULL, -1, title, pos, size)
{
wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
m_panel6 = new wxPanel( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
// create text ctrl with minimal size 100x60
topsizer->Add(
m_panel6,
1, // make vertically stretchable
wxEXPAND | // make horizontally stretchable
wxALL, // and make border all around
0 ); // set border width to 10
wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
button_sizer->Add(
new wxButton( this, wxID_OK, "OK" ),
0, // make horizontally unstretchable
wxALL, // make border all around (implicit top alignment)
10 ); // set border width to 10
button_sizer->Add(
new wxButton( this, wxID_CANCEL, "Cancel" ),
0, // make horizontally unstretchable
wxALL, // make border all around (implicit top alignment)
10 ); // set border width to 10
topsizer->Add(
button_sizer,
0, // make vertically unstretchable
wxALIGN_CENTER ); // no border and centre horizontally
SetSizer( topsizer ); // use the sizer for layout
m_panel6->Connect( wxEVT_MOTION, wxMouseEventHandler( MyFrame::OnMotion ), NULL, this );
topsizer->SetSizeHints( this ); // set size hints to honour minimum size
}
void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
{
Close(true);
}
void MyFrame::OnPaint(wxPaintEvent &event)
{
if( driver )
{
camera->setAspectRatio( (float)(m_panel6->GetSize().x) / (float)(m_panel6->GetSize().y) );
driver->beginScene(true,true,video::SColor(0,160,160,160),videodata);
smgr->drawAll();
driver->endScene();
}
event.Skip();
}
void MyFrame::OnSize(wxSizeEvent &event)
{
if( driver )
{
driver->OnResize( core::dimension2d<irr::u32>(m_panel6->GetSize().x,m_panel6->GetSize().y) );
camera->setAspectRatio( (float)(m_panel6->GetSize().x) / (float)(m_panel6->GetSize().y) );
}
event.Skip();
}
void MyFrame::OnMotion( wxMouseEvent& event )
{
wxPoint currentPos = event.GetPosition();
core::vector3df intersection;
core::triangle3df hitTriangle;
core::line3d<f32> line;
line = smgr->getSceneCollisionManager()->getRayFromScreenCoordinates( core::position2d<s32>(currentPos.x,currentPos.y) );
ISceneNode* node = smgr->getSceneCollisionManager()->getSceneNodeAndCollisionPointFromRay( line, intersection, hitTriangle );
char buf[1024] = {0};
if( node )
{
strcpy(buf,node->getName());
}
else
{
strcpy(buf,"XXX");
}
sprintf( &buf[strlen(buf)], " -> %d,%d", currentPos.x, currentPos.y );
this->SetTitle(buf);
}