#include <irrlicht.h>
using namespace irr; using namespace core; using namespace scene; using namespace video; using namespace io; using namespace gui; #include<iostream>
#include<set>
int screenWidth = 1080;
int screenHeight = 720;
int bitsPerPixel = 32;
bool fullscreen = false;
bool stencilbuffer = false; bool vsync = false; int eventReceiver = 0; int clear_r = 48; int clear_g = 48; int clear_b = 48; int clear_a = 256;
IrrlichtDevice * device;
IVideoDriver * driver;
ISceneManager * sceneManager;
IGUIEnvironment * GUI;
IGUIFont * basicFont;
IGUIFont * boldFont;
ITexture * TWTexture;
enum
{
GUI_ID_CREATEWORLD, GUI_ID_LOADWORLD, GUI_ID_SAVEWORLD, GUI_ID_GENERATEWORLD,
GUI_ID_TUTORIAL, GUI_ID_INFO
};
float outerRadius = 10.0f;
float innerRadius = outerRadius * 0.866025404f;
class HexTile
: public scene::ISceneNode
{
core::aabbox3d < f32 > Box;
video::S3DVertex Vertices[ 8 ];
video::SMaterial Material;
public:
HexTile( scene::ISceneNode * parent, scene::ISceneManager * mgr, s32 id )
: scene::ISceneNode( parent, mgr, id )
{
Material.Wireframe = false;
Material.Lighting = false;
Vertices[ 0 ] = video::S3DVertex( 0, 0, 0, 0, 0, 0, video::SColor( 255, 48, 48, 48 ), 0, 0 ); Vertices[ 1 ] = video::S3DVertex( 0.0f, 0, outerRadius, 0, 0, 0, video::SColor( 255, 128, 48, 48 ), 0, 0 );
Vertices[ 2 ] = video::S3DVertex( innerRadius, 0, outerRadius * 0.5f, 0, 0, 0, video::SColor( 255, 128, 48, 48 ), 0, 0 );
Vertices[ 3 ] = video::S3DVertex( innerRadius, 0, - outerRadius * 0.5f, 0, 0, 0, video::SColor( 255, 128, 48, 48 ), 0, 0 );
Vertices[ 4 ] = video::S3DVertex( 0.0f, 0, - outerRadius, 0, 0, 0, video::SColor( 255, 128, 48, 48 ), 0, 0 );
Vertices[ 5 ] = video::S3DVertex( - innerRadius, 0, - outerRadius * 0.5f, 0, 0, 0, video::SColor( 255, 128, 48, 48 ), 0, 0 );
Vertices[ 6 ] = video::S3DVertex( - innerRadius, 0, outerRadius * 0.5f, 0, 0, 0, video::SColor( 255, 128, 48, 48 ), 0, 0 );
Vertices[ 7 ] = video::S3DVertex( 0.0f, 0, outerRadius, 0, 0, 0, video::SColor( 255, 128, 48, 48 ), 0, 0 );
Box.reset( Vertices[ 0 ].Pos );
for( s32 i = 1; i < 7; ++i )
Box.addInternalPoint( Vertices[ i ].Pos );
}
virtual void OnRegisterSceneNode()
{
if( IsVisible )
SceneManager->registerNodeForRendering( this );
ISceneNode::OnRegisterSceneNode();
}
virtual void render()
{
u16 indices[ ] = { 0, 1, 2, 0, 2, 3, 0, 3, 4, 0, 4, 5, 0, 5, 6, 0, 6, 7 };
IVideoDriver * driver = SceneManager->getVideoDriver();
driver->setMaterial( Material );
driver->setTransform( video::ETS_WORLD, AbsoluteTransformation );
driver->drawVertexPrimitiveList( & Vertices[ 0 ], 3, & indices[ 0 ], 6, video::EVT_STANDARD, scene::EPT_TRIANGLES, video::EIT_16BIT );
}
virtual const core::aabbox3d < f32 > & getBoundingBox() const
{
return Box;
}
virtual u32 getMaterialCount() const
{
return 1;
}
virtual video::SMaterial & getMaterial( u32 i )
{
return Material;
}
};
class HexMap
{
public:
std::set < HexTile * > tiles;
HexMap();
~HexMap();
void addTile( HexTile * );
};
HexMap::HexMap()
{
tiles.clear();
}
HexMap::~HexMap()
{
}
void HexMap::addTile( HexTile * tile )
{
tiles.insert( tile );
}
void thisIsNotBuildYet()
{
int rectWidth = 300;
int rectHeight = 300;
int x1 =( screenWidth - rectWidth ) / 2;
int x2 =( screenWidth + rectWidth ) / 2;
int y1 =( screenHeight - rectHeight ) / 2;
int y2 =( screenHeight + rectHeight ) / 2;
rect < s32 > rectangle = rect < s32 >( x1, y1, x2, y2 );
IGUIWindow * window = GUI->addWindow( rectangle );
const wchar_t * t = L"This section is not build yed";
IGUIStaticText * text = GUI->addStaticText( t, rect < s32 >( 0, 20, rectWidth, rectHeight ), true, true, window, - 1, true );
text->setTextAlignment( EGUIA_CENTER, EGUIA_CENTER );
}
class MyEventReceiver
: public IEventReceiver
{
public:
bool KeyIsDown[ KEY_KEY_CODES_COUNT ];
MyEventReceiver();
virtual bool OnEvent( const SEvent & );
virtual bool IsKeyDown( EKEY_CODE );
bool OnMenuItemSelected( IGUIContextMenu * menu );
};
MyEventReceiver::MyEventReceiver()
{
for( u32 i = 0; i < KEY_KEY_CODES_COUNT; ++i )
KeyIsDown[ i ] = false;
}
bool MyEventReceiver::OnEvent( const SEvent & event )
{
if( event.EventType == irr::EET_KEY_INPUT_EVENT )
{
KeyIsDown[ event.KeyInput.Key ] = event.KeyInput.PressedDown;
return true;
}
if( event.EventType == EET_GUI_EVENT )
{
switch( event.GUIEvent.EventType )
{
case EGET_MENU_ITEM_SELECTED: {
IGUIContextMenu * menu =( IGUIContextMenu * ) event.GUIEvent.Caller;
s32 id = menu->getItemCommandId( menu->getSelectedItem() );
}
break;
default:
break;
}
}
return false;
}
bool MyEventReceiver::IsKeyDown( EKEY_CODE keyCode )
{
return KeyIsDown[ keyCode ];
} int main()
{
MyEventReceiver receiver;
device = createDevice( EDT_SOFTWARE, dimension2d < u32 >( screenWidth, screenHeight ), bitsPerPixel, fullscreen, stencilbuffer, vsync, & receiver );
if( !device ) return 1;
driver = device->getVideoDriver(); sceneManager = device->getSceneManager(); GUI = device->getGUIEnvironment(); ICameraSceneNode * cam = sceneManager->addCameraSceneNode( 0, vector3df( 0, 30, - 40 ), vector3df( 0, 5, 0 ) );
cam->setFOV( 1 );
device->getCursorControl()->setVisible( true );
HexMap * hexMap = new HexMap();
float xpos, zpos;
for( int z = 0; z < 10; z++ )
for( int x = 0; x < 10; x++ )
{
HexTile * tile = new HexTile( sceneManager->getRootSceneNode(), sceneManager, 666 );
xpos = float( x ) * 2.0f * innerRadius +( z % 2 ) * innerRadius;
zpos = float( z ) * 1.5f * outerRadius;
tile->setPosition( vector3df( xpos, 0, zpos ) );
hexMap->addTile( tile );
}
while( device->run() )
{
if( device->isWindowActive() )
{
if( receiver.IsKeyDown( irr::KEY_ESCAPE ) ) {
device->drop();
return 0;
}
driver->beginScene( true, true, SColor( clear_a, clear_r, clear_g, clear_b ) ); sceneManager->drawAll(); GUI->drawAll(); position2d < s32 > m = device->getCursorControl()->getPosition(); driver->endScene(); int currentFPS = driver->getFPS();
core::stringw str = L"FPS: ";
str += currentFPS;
device->setWindowCaption( str.c_str() );
}
else
device->yield(); }
device->drop();
return 0;
}