working source for strategy view

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
smartwhiz
Posts: 120
Joined: Wed Jan 14, 2004 6:03 pm
Location: India

working source for strategy view

Post by smartwhiz »

i did it in a simple method......
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;
}
i want help in applying the select operation on to the mouse and then selecting the ball.ms3d node.....
slurmmunger

Post by slurmmunger »

I don't know if I understand You right. You need help with selecting a node with the mouse? Take a look at the following Thread
http://irrlicht.sourceforge.net/phpBB2/ ... php?t=2591
the last entry by Faust shows how selecting a node is done.
smartwhiz
Posts: 120
Joined: Wed Jan 14, 2004 6:03 pm
Location: India

Post by smartwhiz »

i got the code a bit right....
i wrote the coding similar to the one that tyn had posted some time before and the tut

Code: Select all

mcursor=device->getCursorControl()->getPosition();
		line=colmgr->getRayFromScreenCoordinates(mcursor,camera);
		selectedNode = colmgr->getSceneNodeFromRayBB(line, 1);
		if(selectedNode)
		{
			selectedNode->setMaterialFlag(video::EMF_LIGHTING, false);
			lastselectedNode=selectedNode;
		}
		else if(lastselectedNode)
		{
			lastselectedNode->setMaterialFlag(video::EMF_LIGHTING, true);
		}
still at time the model doesn't come back to the original flag.....

does anyone know a better algorithm for movement of camera in the strategy game and the selection of node?
Tyn
Posts: 932
Joined: Thu Nov 20, 2003 7:53 pm
Location: England
Contact:

Post by Tyn »

The else if is redundant since both conditions would be true 99% of the time. I would just use it as two seperate if statements, with the lastSelectedNode coming first.
smartwhiz
Posts: 120
Joined: Wed Jan 14, 2004 6:03 pm
Location: India

Post by smartwhiz »

portal effect without a billboard does anyone know more abt it?
Last edited by smartwhiz on Sat Jun 05, 2004 5:49 am, edited 1 time in total.
smartwhiz
Posts: 120
Joined: Wed Jan 14, 2004 6:03 pm
Location: India

Post by smartwhiz »

in strategy game a character gets selected and a mapped image is found at it's foot.... surrounding it... rit?
so how would u implement a 3d plane in irrlicht?
Anyone who has used a similar effect?
Tyn... that's rit.... but i felt this is more effective....
Post Reply