now how can i apply the node selection ?
Code: Select all
#include<irrlicht.h>
#include<iostream.h>//For cout<< functions
#include<fstream.h>//For File stream functions for log.txt
using namespace irr;
#pragma comment(lib, "Irrlicht.lib")
//All the necessary pointers to get the engine started
IrrlichtDevice *device =0;
video::IVideoDriver* driver = 0;
scene::ISceneManager* smgr = 0;
gui::IGUIEnvironment* guienv = 0;
gui::ICursorControl* cursor = 0;
scene::ICameraSceneNode *camera=0;
//These are some needed varibles that are used in many functions
core::vector3df camTargetPos=core::vector3df(0,0,0);
core::vector3df camPos=core::vector3df(0,0,0);
irr::core::position2d<irr::f32> mouseLocation ;
//change in this varible gives different speeds in the view camera
f32 camMoveSpeed=0.25f;
//intialize the engine
void intiAll()
{
cout<<"\n##Intializing Function Called!##\n";
device =createDevice(video::EDT_DIRECTX8, core::dimension2d<s32>(800,600), 16, false, false, 0);
cout<<"\n##Device Created##\n";
driver = device->getVideoDriver();
cout<<"\n##Driver Created##\n";
smgr = device->getSceneManager();
cout<<"\n##Manager Created##\n";
guienv=device->getGUIEnvironment();
cout<<"\n##GUI Created##\n";
cursor=device->getCursorControl();
cout<<"\n##Cursor Created##\n";
camera=smgr->addCameraSceneNode(0,core::vector3df(-635,750,17),core::vector3df(0,0,0));
//camera=smgr->addCameraSceneNodeFPS();
cout<<"\n##Camera Created##\n";
camTargetPos=camera->getTarget();
camPos=camera->getPosition();
cursor->setPosition(0.50f,0.35f);
}
//RPG Camera:move the view panel to the left
void moveCamLeft()
{
camTargetPos+=core::vector3df(0,0,60)*camMoveSpeed;
camPos+=core::vector3df(0,0,60)*camMoveSpeed;
camera->setTarget(irr::core::vector3df(camTargetPos));
camera->setPosition(irr::core::vector3df(camPos));
}
//RPG Camera:move the view panel to the right
void moveCamRight()
{
camTargetPos+=core::vector3df(0,0,-60)*camMoveSpeed;
camPos+=core::vector3df(0,0,-60)*camMoveSpeed;
camera->setTarget(irr::core::vector3df(camTargetPos));
camera->setPosition(irr::core::vector3df(camPos));
}
//RPG Camera:move the view panel up
void moveCamUp()
{
camTargetPos+=core::vector3df(60,0,0)*camMoveSpeed;
camPos+=core::vector3df(60,0,0)*camMoveSpeed;
camera->setTarget(irr::core::vector3df(camTargetPos.X + camMoveSpeed, camTargetPos.Y, camTargetPos.Z + camMoveSpeed));
camera->setPosition(irr::core::vector3df(camPos.X + camMoveSpeed, camPos.Y, camPos.Z + camMoveSpeed));
}
//RPG Camera:move the view panel down
void moveCamDown()
{
camTargetPos+=core::vector3df(-60,0,0)*camMoveSpeed;
camPos+=core::vector3df(-60,0,0)*camMoveSpeed;
camera->setTarget(irr::core::vector3df(camTargetPos));
camera->setPosition(irr::core::vector3df(camPos));
}
//RPG Camera:this function keeps the view panel updated
void updateViewPlane()
{
if(mouseLocation.Y<0.005) moveCamUp();
if(mouseLocation.Y>0.995) moveCamDown();
if(mouseLocation.X<0.005) moveCamLeft();
if(mouseLocation.X>0.995) moveCamRight();
}
//RPG Camera:makes the boundary for the mouse pointer to move
void boundaryMake()
{
if(mouseLocation.Y<0.0) mouseLocation.Y=0;
if(mouseLocation.Y>1.0) mouseLocation.Y=1;
if(mouseLocation.X<0.0) mouseLocation.X=0;
if(mouseLocation.X>1.0) mouseLocation.X=1;
cursor->setPosition(mouseLocation.X,mouseLocation.Y);
}
//RPG Player
//shows loading screen
void loadingScreen(irr::s32 percent)
{
static irr::video::ITexture * loadbar = NULL;
if(!loadbar) loadbar = driver->getTexture("media/load.jpg");
driver->beginScene(true, false, irr::video::SColor(0,0,0,0));
irr::gui::IGUIFont* font = guienv->getBuiltInFont();
font->draw(L"LOADING....", irr::core::rect<irr::s32>(50, 100, 50 + 200, 150), irr::video::SColor(255,255,255,255));
irr::core::rect< irr::s32 > clip(50, 50, 50 + (640 * percent/100) , 50 + 100);
if(loadbar) driver->draw2DImage(loadbar,irr::core::position2d< irr::s32 >(50,50),
irr::core::rect< irr::s32 >(0,0,550,32),
&clip,
irr::video::SColor(200, 200, 200, 200),
false
);
driver->endScene();
}
//Atlast the main function
int main()
{
intiAll();//Intialise the engine
guienv->addStaticText(L"This Is Test For RPG Engine with Irrlicht",core::rect<int>(30,30,800-30,600-150), true);//rectangle drawn
loadingScreen(25);//loads 25% of the loading jpg
//Level Loading:
scene::IAnimatedMesh* mesh = smgr->getMesh("media/test.ms3d");
scene::ISceneNode* node = smgr->addAnimatedMeshSceneNode( mesh );
node->setPosition(core::vector3df(0,0,0));
node->setMaterialFlag(video::EMF_LIGHTING, true);
node->setMaterialTexture( 0, driver->getTexture("media/wall.jpg") );
//Hill Mesh created
mesh = smgr->addHillPlaneMesh("Hill",
core::dimension2d<f32>(200,200),
core::dimension2d<s32>(50,50), 0, 20,
core::dimension2d<f32>(2,2),
core::dimension2d<f32>(1,1));
loadingScreen(75);
node = smgr->addAnimatedMeshSceneNode(mesh);
node->setPosition(core::vector3df(0,-7,0));
node->setMaterialTexture(0, driver->getTexture("media/snow.bmp"));
node->setMaterialFlag(video::EMF_LIGHTING,true);
//Player Loading:
mesh = smgr->getMesh("media/ball.ms3d");
node = smgr->addAnimatedMeshSceneNode(mesh);
node->setPosition(core::vector3df(1,1,0));
node->setMaterialFlag(video::EMF_LIGHTING, true);
node->setMaterialTexture( 0, driver->getTexture("media/wall.jpg") );
//LightNode added
scene::ISceneNode *lnode=0;
lnode = smgr->addLightSceneNode(0, core::vector3df(0,0,0),
video::SColorf(1.0f, 0.6f, 0.7f, 1.0f), 400.0f);
lnode->setPosition(core::vector3df(0,400,0));
loadingScreen(100);
while(device->run())
{
driver->beginScene(true, true, video::SColor(0,100,100,100));
smgr->drawAll();
guienv->drawAll();
camPos=camera->getPosition();
mouseLocation = cursor->getRelativePosition();
wchar_t tmp[1024];
//next statement gives the current camera position and the mouse position on the window bar
swprintf(tmp, 1024, L"Strategy View: X=%fl Y=%fl Z=%fl mX=%fl mY=%fl",camPos.X,camPos.Y,camPos.Z,mouseLocation.X,mouseLocation.Y);
device->setWindowCaption(tmp);
//check for the boundary and then update the view panel
boundaryMake();
updateViewPlane();
driver->endScene();
}
device->drop();
return 0;
}