HALO bubble shield effect,path finder+minimap+objectives WIP

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Post Reply
devsh
Competition winner
Posts: 2049
Joined: Tue Dec 09, 2008 6:00 pm
Location: UK
Contact:

HALO bubble shield effect,path finder+minimap+objectives WIP

Post by devsh »

Image

This is work in progress, I set up my own waypoints on the quake 3 level...
I am writing my own path finder and I am designing this cool in-game PDA/mobile system which informs you of your objectives, paths to objective, distance to objective, direct distance to objective all on a cool refractive lit up translucent display, it can also display a mini map.

Im planning to make it fuzz/distort the image as 16 stripes shifting (UV coord modification) when the modes are changed to make it look cooler

This is WIP and I will most probs never use it again. I should finish the whole project in a week.

However I am unsure if I will so I am posting the source free for you to use and modify and use in commercial apps as long as you credit me.

Controls, B=display lights up in blue, G= display lights up in green

SOURCE : http://www.megaupload.com/?d=IMQIMD80
grumpymonkey
Posts: 222
Joined: Mon Jan 19, 2009 10:03 pm
Location: Miami, Florida
Contact:

Post by grumpymonkey »

not sure exactly what I'm looking at here. The screenshot is less than, umm... o.0, I'm going to go with 'exciting'

The link is dead btw, as you can probably tell by my vague review
Image
devsh
Competition winner
Posts: 2049
Joined: Tue Dec 09, 2008 6:00 pm
Location: UK
Contact:

Post by devsh »

maybe it hasn't processed yet
fmx

Post by fmx »

The link is still down, you should upload to Mediafire or something else, I can tell you from personal experience that MU is not very reliable (also avoid rapidshare)

Looks like a funky effect, although it isn't possible to make head or tail from that screenshot exactly what it's supposed to do
ent1ty
Competition winner
Posts: 1106
Joined: Sun Nov 08, 2009 11:09 am

Post by ent1ty »

I suppose it's some sort of runner vision, you know, from mirrors edge? It shows you the possible routes.
irrRenderer 1.0
Height2Normal v. 2.1 - convert height maps to normal maps

Step back! I have a void pointer, and I'm not afraid to use it!
ACE247
Posts: 704
Joined: Tue Mar 16, 2010 12:31 am

Post by ACE247 »

Download works now. :)
devsh
Competition winner
Posts: 2049
Joined: Tue Dec 09, 2008 6:00 pm
Location: UK
Contact:

Post by devsh »

right another update... the thing now actually attempts to find a path.. however as you may see, it runs into a dead end. Do not think I havent thought about that, I just havent done it today because the function for handling dead ends and forks in the path is a lot of work, basically I would have to implement a last in first out array of possible other waypoints the system could have gone and resume the path finding from there. Also I left the rotating waypoints which are not in the path for debugging. So on the next update a path to the objective which is not going through walls is going to be found, plus the rotating nodes will dissapear. I will handle dynamic recalculation of paths in the second update.

Download the same thing and just swap the main.cpp code for this

Code: Select all

#include <irrlicht.h>
#include <math.h>
#include <iostream>

using namespace irr;

#ifdef _MSC_VER
#pragma comment(lib, "Irrlicht.lib")
#endif

core::vector3df dispcol = core::vector3df(0.6,1.3,2.0);

class MyEventReceiver : public IEventReceiver
{
public:
	// This is the one method that we have to implement
	virtual bool OnEvent(const SEvent& event)
	{
		// Remember whether each key is down or up
		if (event.EventType == irr::EET_KEY_INPUT_EVENT) {
			KeyIsDown[event.KeyInput.Key] = event.KeyInput.PressedDown;
			if (event.KeyInput.Key==KEY_KEY_G)
                dispcol = core::vector3df(0.6,1.3,0.0);
			else if (event.KeyInput.Key==KEY_KEY_B)
                dispcol = core::vector3df(0.6,1.3,2.0);
		}

		return false;
	}

	// This is used to check whether a key is being held down
	virtual bool IsKeyDown(EKEY_CODE keyCode) const
	{
		return KeyIsDown[keyCode];
	}

	MyEventReceiver()
	{
		for (u32 i=0; i<KEY_KEY_CODES_COUNT; ++i)
			KeyIsDown[i] = false;
	}

private:
	// We use this array to store the current state of each key
	bool KeyIsDown[KEY_KEY_CODES_COUNT];
};

class Tetraeder : public scene::ISceneNode
{
	core::aabbox3d<f32> Box;
	video::S3DVertex Vertices[4];
	video::SMaterial Material;

public:

	Tetraeder(scene::ISceneNode* parent, scene::ISceneManager* mgr, s32 id)
		: scene::ISceneNode(parent, mgr, id)
	{
		Material.Wireframe = true;
		Material.Thickness = 8.f;
		Material.BackfaceCulling = false;
		Material.Lighting = false;

		Vertices[0] = video::S3DVertex(0,-10,10, 1,1,0,
				video::SColor(255,110,236,255), 0, 1);
		Vertices[1] = video::S3DVertex(10,-10,-10, 1,0,0,
				video::SColor(255,110,236,255), 1, 1);
		Vertices[2] = video::S3DVertex(0,10,0, 0,1,1,
				video::SColor(255,110,236,255), 1, 0);
		Vertices[3] = video::S3DVertex(-10,-10,-10, 0,0,1,
				video::SColor(255,110,236,255), 0, 0);


		Box.reset(Vertices[0].Pos);
		for (s32 i=1; i<4; ++i)
			Box.addInternalPoint(Vertices[i].Pos);

        setAutomaticCulling(scene::EAC_OFF);
	}


	virtual void OnRegisterSceneNode()
	{
		if (IsVisible)
			SceneManager->registerNodeForRendering(this);

		ISceneNode::OnRegisterSceneNode();
	}


	virtual void render()
	{
		u16 indices[] = {	0,2,3, 2,1,3, 1,0,3, 2,0,1	};
		video::IVideoDriver* driver = SceneManager->getVideoDriver();

		driver->setMaterial(Material);
		driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
		driver->drawVertexPrimitiveList(&Vertices[0], 4, &indices[0], 4, 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 WayPoint;

class WayPoint
{
        core::array<WayPoint*> others;
        core::vector3df position;
        Tetraeder* node;

    public:
        WayPoint(core::vector3df Position, Tetraeder* Node) {
            position=Position;
            node=Node;
            node->setPosition(Position);
        }
        void addNeighbour(WayPoint* other) {others.push_back(other);}
        core::array<WayPoint*> &getNeighbours() {return others;}
        core::vector3df getPosition() {return position;}
        scene::ISceneNode* getNode() {return node;}
};

class MyShaderCallBack : public video::IShaderConstantSetCallBack
{
public:

	virtual void OnSetConstants(video::IMaterialRendererServices* services,
			s32 userData)
	{
        int texs[4] = {0,1,2,3};
        services->setPixelShaderConstant("tex",(float*)texs,1);
        services->setPixelShaderConstant("hex",(float*)texs+1,1);
        services->setPixelShaderConstant("screen",(float*)texs+2,1);
        services->setPixelShaderConstant("gaussbump",(float*)texs+3,1);
        services->setPixelShaderConstant("dispcol",&dispcol.X,3);
	}
};

bool findAnotherWayPoint(core::array<WayPoint*> &activeWayPoints, WayPoint* &nearestWp, WayPoint* endWp, core::vector3df objective)
{
    bool found_another = false;
    WayPoint* nearestWp2;
    float nearestWpDist = 99999999999.f;
    core::vector3df temp3;
    float temp;
    if (nearestWp->getNeighbours().size()<2)
        return false;
    for (u32 i=0; i<nearestWp->getNeighbours().size(); i++) {
        if (nearestWp->getNeighbours()[i]==endWp)
                return false;
        if (nearestWp->getNeighbours()[i]==activeWayPoints[core::max_(activeWayPoints.size()-2,irr::u32(0))])
            continue;
        temp3 = (nearestWp->getNeighbours()[i]->getPosition()-objective)*core::vector3df(1.f,20.f,1.f);
        temp = temp3.getLength();
        if (temp<nearestWpDist) {
            nearestWpDist = temp;
            nearestWp2 = nearestWp->getNeighbours()[i];
            found_another = true;
        }
    }
    if (found_another) {
        nearestWp = nearestWp2;
        activeWayPoints.push_back(nearestWp);
    }
    return found_another;
}

int main()
{
	core::array<WayPoint*> waypoints;

	MyEventReceiver receiver;

	IrrlichtDevice *device =
		createDevice(video::EDT_OPENGL, core::dimension2d<u32>(1024, 640),24,false,false,false,&receiver);

	if (device == 0)
		return 1; // could not create selected driver.

	video::IVideoDriver* driver = device->getVideoDriver();
	video::ITexture* screen = driver->addRenderTargetTexture(core::dimension2d<u32>(1024, 640), "screen", video::ECF_A32B32G32R32F);
	scene::ISceneManager* smgr = device->getSceneManager();

	scene::ISceneNodeAnimator* anim = smgr->createRotationAnimator(core::vector3df(0.f,1.f,0.f));

    Tetraeder* tnode = new Tetraeder(smgr->getRootSceneNode(),smgr,69);
    tnode->addAnimator(anim);
    tnode->setVisible(false);
	WayPoint* wayp = new WayPoint(core::vector3df(117.f,-54.f,87.5),tnode);
	waypoints.push_back(wayp);
    tnode = new Tetraeder(smgr->getRootSceneNode(),smgr,70);
    anim = smgr->createRotationAnimator(core::vector3df(0.f,1.f,0.f));
    tnode->addAnimator(anim);
    tnode->setVisible(false);
	wayp = new WayPoint(core::vector3df(112.f,74.f,-408.f),tnode);
	waypoints.push_back(wayp);
	waypoints[0]->addNeighbour(wayp);
	wayp->addNeighbour(waypoints[0]);
    tnode = new Tetraeder(smgr->getRootSceneNode(),smgr,71);
    anim = smgr->createRotationAnimator(core::vector3df(0.f,1.f,0.f));
    tnode->addAnimator(anim);
    tnode->setVisible(false);
	wayp = new WayPoint(core::vector3df(112.f,74.f,602.f),tnode);
	waypoints.push_back(wayp);
	waypoints[0]->addNeighbour(wayp);
	wayp->addNeighbour(waypoints[0]);
    tnode = new Tetraeder(smgr->getRootSceneNode(),smgr,72);
    anim = smgr->createRotationAnimator(core::vector3df(0.f,1.f,0.f));
    tnode->addAnimator(anim);
    tnode->setVisible(false);
	wayp = new WayPoint(core::vector3df(700.f,-54.f,87.5),tnode);
	waypoints.push_back(wayp);
	waypoints[0]->addNeighbour(wayp);
	wayp->addNeighbour(waypoints[0]);
    tnode = new Tetraeder(smgr->getRootSceneNode(),smgr,73);
    anim = smgr->createRotationAnimator(core::vector3df(0.f,1.f,0.f));
    tnode->addAnimator(anim);
    tnode->setVisible(false);
	wayp = new WayPoint(core::vector3df(-475.f,-54.f,87.5),tnode);
	waypoints.push_back(wayp);
	waypoints[0]->addNeighbour(wayp);
	wayp->addNeighbour(waypoints[0]);
    tnode = new Tetraeder(smgr->getRootSceneNode(),smgr,74);
    anim = smgr->createRotationAnimator(core::vector3df(0.f,1.f,0.f));
    tnode->addAnimator(anim);
    tnode->setVisible(false);
	wayp = new WayPoint(core::vector3df(-83.f,74.f,-306.f),tnode);
	waypoints.push_back(wayp);
	waypoints[1]->addNeighbour(wayp);
	wayp->addNeighbour(waypoints[1]);
    tnode = new Tetraeder(smgr->getRootSceneNode(),smgr,75);
    anim = smgr->createRotationAnimator(core::vector3df(0.f,1.f,0.f));
    tnode->addAnimator(anim);
    tnode->setVisible(false);
	wayp = new WayPoint(core::vector3df(-408.f,74.f,-287.f),tnode);
	waypoints.push_back(wayp);
	waypoints[5]->addNeighbour(wayp);
	wayp->addNeighbour(waypoints[5]);
    tnode = new Tetraeder(smgr->getRootSceneNode(),smgr,76);
    anim = smgr->createRotationAnimator(core::vector3df(0.f,1.f,0.f));
    tnode->addAnimator(anim);
    tnode->setVisible(false);
	wayp = new WayPoint(core::vector3df(-75.f,160.f,-829.f),tnode);
	waypoints.push_back(wayp);
	waypoints[5]->addNeighbour(wayp);
	wayp->addNeighbour(waypoints[5]);
    tnode = new Tetraeder(smgr->getRootSceneNode(),smgr,77);
    anim = smgr->createRotationAnimator(core::vector3df(0.f,1.f,0.f));
    tnode->addAnimator(anim);
    tnode->setVisible(false);
	wayp = new WayPoint(core::vector3df(296.f,160.f,-842.f),tnode);
	waypoints.push_back(wayp);
	waypoints[7]->addNeighbour(wayp);
	wayp->addNeighbour(waypoints[7]);
    tnode = new Tetraeder(smgr->getRootSceneNode(),smgr,78);
    anim = smgr->createRotationAnimator(core::vector3df(0.f,1.f,0.f));
    tnode->addAnimator(anim);
    tnode->setVisible(false);
	wayp = new WayPoint(core::vector3df(289.f,74.f,-415.f),tnode);
	waypoints.push_back(wayp);
	waypoints[8]->addNeighbour(wayp);
	wayp->addNeighbour(waypoints[8]);
	waypoints[9]->addNeighbour(waypoints[1]);
	waypoints[1]->addNeighbour(waypoints[9]);
    tnode = new Tetraeder(smgr->getRootSceneNode(),smgr,79);
    anim = smgr->createRotationAnimator(core::vector3df(0.f,1.f,0.f));
    tnode->addAnimator(anim);
    tnode->setVisible(false);
	wayp = new WayPoint(core::vector3df(-75.f,260.f,-829.f),tnode);
	waypoints.push_back(wayp);
	waypoints[7]->addNeighbour(wayp);
	wayp->addNeighbour(waypoints[7]);
    tnode = new Tetraeder(smgr->getRootSceneNode(),smgr,80);
    anim = smgr->createRotationAnimator(core::vector3df(0.f,1.f,0.f));
    tnode->addAnimator(anim);
    tnode->setVisible(false);
	wayp = new WayPoint(core::vector3df(-405.f,260.f,-755.f),tnode);
	waypoints.push_back(wayp);
	waypoints[10]->addNeighbour(wayp);
	wayp->addNeighbour(waypoints[10]);
    tnode = new Tetraeder(smgr->getRootSceneNode(),smgr,81);
    anim = smgr->createRotationAnimator(core::vector3df(0.f,1.f,0.f));
    tnode->addAnimator(anim);
    tnode->setVisible(false);
	wayp = new WayPoint(core::vector3df(296.f,260.f,-842.f),tnode);
	waypoints.push_back(wayp);
	waypoints[8]->addNeighbour(wayp);
	wayp->addNeighbour(waypoints[8]);
    tnode = new Tetraeder(smgr->getRootSceneNode(),smgr,82);
    anim = smgr->createRotationAnimator(core::vector3df(0.f,1.f,0.f));
    tnode->addAnimator(anim);
    tnode->setVisible(false);
	wayp = new WayPoint(core::vector3df(625.f,260.f,-831.f),tnode);
	waypoints.push_back(wayp);
	waypoints[12]->addNeighbour(wayp);
	wayp->addNeighbour(waypoints[12]);
    tnode = new Tetraeder(smgr->getRootSceneNode(),smgr,83);
    anim = smgr->createRotationAnimator(core::vector3df(0.f,1.f,0.f));
    tnode->addAnimator(anim);
    tnode->setVisible(false);
	wayp = new WayPoint(core::vector3df(610.f,320.f,95.f),tnode);
	waypoints.push_back(wayp);
	waypoints[13]->addNeighbour(wayp);
	wayp->addNeighbour(waypoints[13]);
    tnode = new Tetraeder(smgr->getRootSceneNode(),smgr,84);
    anim = smgr->createRotationAnimator(core::vector3df(0.f,1.f,0.f));
    tnode->addAnimator(anim);
    tnode->setVisible(false);
	wayp = new WayPoint(core::vector3df(260.f,265.f,95.f),tnode);
	waypoints.push_back(wayp);
	waypoints[14]->addNeighbour(wayp);
	wayp->addNeighbour(waypoints[14]);
    tnode = new Tetraeder(smgr->getRootSceneNode(),smgr,85);
    anim = smgr->createRotationAnimator(core::vector3df(0.f,1.f,0.f));
    tnode->addAnimator(anim);
    tnode->setVisible(false);
	wayp = new WayPoint(core::vector3df(610.f,310.f,475.f),tnode);
	waypoints.push_back(wayp);
	waypoints[14]->addNeighbour(wayp);
	wayp->addNeighbour(waypoints[14]);
    tnode = new Tetraeder(smgr->getRootSceneNode(),smgr,86);
    anim = smgr->createRotationAnimator(core::vector3df(0.f,1.f,0.f));
    tnode->addAnimator(anim);
    tnode->setVisible(false);
	wayp = new WayPoint(core::vector3df(610.f,310.f,705.f),tnode);
	waypoints.push_back(wayp);
	waypoints[16]->addNeighbour(wayp);
	wayp->addNeighbour(waypoints[16]);
    tnode = new Tetraeder(smgr->getRootSceneNode(),smgr,87);
    anim = smgr->createRotationAnimator(core::vector3df(0.f,1.f,0.f));
    tnode->addAnimator(anim);
    tnode->setVisible(false);
	wayp = new WayPoint(core::vector3df(610.f,225.f,1033.f),tnode);
	waypoints.push_back(wayp);
	waypoints[17]->addNeighbour(wayp);
	wayp->addNeighbour(waypoints[17]);
    tnode = new Tetraeder(smgr->getRootSceneNode(),smgr,88);
    anim = smgr->createRotationAnimator(core::vector3df(0.f,1.f,0.f));
    tnode->addAnimator(anim);
    tnode->setVisible(false);
	wayp = new WayPoint(core::vector3df(295.f,225.f,975.f),tnode);
	waypoints.push_back(wayp);
	waypoints[18]->addNeighbour(wayp);
	wayp->addNeighbour(waypoints[18]);
    tnode = new Tetraeder(smgr->getRootSceneNode(),smgr,89);
    anim = smgr->createRotationAnimator(core::vector3df(0.f,1.f,0.f));
    tnode->addAnimator(anim);
    tnode->setVisible(false);
	wayp = new WayPoint(core::vector3df(295.f,75.f,975.f),tnode);
	waypoints.push_back(wayp);
	waypoints[19]->addNeighbour(wayp);
	wayp->addNeighbour(waypoints[19]);
    tnode = new Tetraeder(smgr->getRootSceneNode(),smgr,90);
    anim = smgr->createRotationAnimator(core::vector3df(0.f,1.f,0.f));
    tnode->addAnimator(anim);
    tnode->setVisible(false);
	wayp = new WayPoint(core::vector3df(165.f,75.f,895.f),tnode);
	waypoints.push_back(wayp);
	waypoints[20]->addNeighbour(wayp);
	wayp->addNeighbour(waypoints[20]);
	waypoints[2]->addNeighbour(waypoints[21]);
	waypoints[21]->addNeighbour(waypoints[2]);
    tnode = new Tetraeder(smgr->getRootSceneNode(),smgr,91);
    anim = smgr->createRotationAnimator(core::vector3df(0.f,1.f,0.f));
    tnode->addAnimator(anim);
    tnode->setVisible(false);
	wayp = new WayPoint(core::vector3df(970.f,215.f,970.f),tnode);
	waypoints.push_back(wayp);
	waypoints[18]->addNeighbour(wayp);
	wayp->addNeighbour(waypoints[18]);
    tnode = new Tetraeder(smgr->getRootSceneNode(),smgr,92);
    anim = smgr->createRotationAnimator(core::vector3df(0.f,1.f,0.f));
    tnode->addAnimator(anim);
    tnode->setVisible(false);
	wayp = new WayPoint(core::vector3df(1115.f,150.f,600.f),tnode);
	waypoints.push_back(wayp);
	waypoints[22]->addNeighbour(wayp);
	wayp->addNeighbour(waypoints[22]);
    tnode = new Tetraeder(smgr->getRootSceneNode(),smgr,93);
    anim = smgr->createRotationAnimator(core::vector3df(0.f,1.f,0.f));
    tnode->addAnimator(anim);
    tnode->setVisible(false);
	wayp = new WayPoint(core::vector3df(629.f,75.f,476.f),tnode);
	waypoints.push_back(wayp);
	waypoints[23]->addNeighbour(wayp);
	wayp->addNeighbour(waypoints[23]);
    tnode = new Tetraeder(smgr->getRootSceneNode(),smgr,94);
    anim = smgr->createRotationAnimator(core::vector3df(0.f,1.f,0.f));
    tnode->addAnimator(anim);
    tnode->setVisible(false);
	wayp = new WayPoint(core::vector3df(277.f,75.f,476.f),tnode);
	waypoints.push_back(wayp);
	waypoints[24]->addNeighbour(wayp);
	wayp->addNeighbour(waypoints[24]);
	waypoints[2]->addNeighbour(waypoints[25]);
	waypoints[25]->addNeighbour(waypoints[2]);
    tnode = new Tetraeder(smgr->getRootSceneNode(),smgr,95);
    anim = smgr->createRotationAnimator(core::vector3df(0.f,1.f,0.f));
    tnode->addAnimator(anim);
    tnode->setVisible(false);
	wayp = new WayPoint(core::vector3df(629.f,75.f,-282.f),tnode);
	waypoints.push_back(wayp);
	waypoints[24]->addNeighbour(wayp);
	wayp->addNeighbour(waypoints[24]);
    tnode = new Tetraeder(smgr->getRootSceneNode(),smgr,96);
    anim = smgr->createRotationAnimator(core::vector3df(0.f,1.f,0.f));
    tnode->addAnimator(anim);
    tnode->setVisible(false);
	wayp = new WayPoint(core::vector3df(-390.f,305.f,475.f),tnode);
	waypoints.push_back(wayp);
	waypoints[16]->addNeighbour(wayp);
	wayp->addNeighbour(waypoints[16]);
    tnode = new Tetraeder(smgr->getRootSceneNode(),smgr,97);
    anim = smgr->createRotationAnimator(core::vector3df(0.f,1.f,0.f));
    tnode->addAnimator(anim);
    tnode->setVisible(false);
	wayp = new WayPoint(core::vector3df(-390.f,300.f,100.f),tnode);
	waypoints.push_back(wayp);
	waypoints[27]->addNeighbour(wayp);
	wayp->addNeighbour(waypoints[27]);
    tnode = new Tetraeder(smgr->getRootSceneNode(),smgr,98);
    anim = smgr->createRotationAnimator(core::vector3df(0.f,1.f,0.f));
    tnode->addAnimator(anim);
    tnode->setVisible(false);
	wayp = new WayPoint(core::vector3df(-75.f,275.f,100.f),tnode);
	waypoints.push_back(wayp);
	waypoints[28]->addNeighbour(wayp);
	wayp->addNeighbour(waypoints[28]);
    tnode = new Tetraeder(smgr->getRootSceneNode(),smgr,99);
    anim = smgr->createRotationAnimator(core::vector3df(0.f,1.f,0.f));
    tnode->addAnimator(anim);
    tnode->setVisible(false);
	wayp = new WayPoint(core::vector3df(-90.f,75.f,495.f),tnode);
	waypoints.push_back(wayp);
	waypoints[2]->addNeighbour(wayp);
	wayp->addNeighbour(waypoints[2]);
    tnode = new Tetraeder(smgr->getRootSceneNode(),smgr,100);
    anim = smgr->createRotationAnimator(core::vector3df(0.f,1.f,0.f));
    tnode->addAnimator(anim);
    tnode->setVisible(false);
	wayp = new WayPoint(core::vector3df(-390.f,75.f,495.f),tnode);
	waypoints.push_back(wayp);
	waypoints[30]->addNeighbour(wayp);
	wayp->addNeighbour(waypoints[30]);
	waypoints[6]->addNeighbour(waypoints[31]);
	waypoints[31]->addNeighbour(waypoints[6]);

	anim->drop();

	/*
	To display the Quake 3 map, we first need to load it. Quake 3 maps
	are packed into .pk3 files which are nothing else than .zip files.
	So we add the .pk3 file to our irr::io::IFileSystem. After it was added,
	we are able to read from the files in that archive as if they are
	directly stored on the disk.
	*/
	device->getFileSystem()->addZipFileArchive("../irrlicht-1.7.1/media/map-20kdm2.pk3");
	scene::IAnimatedMesh* mesh = smgr->getMesh("20kdm2.bsp");
	scene::ISceneNode* node = 0;

	if (mesh)
		node = smgr->addOctreeSceneNode(mesh->getMesh(0), 0, -1, 1024);
	if (node)
		node->setPosition(core::vector3df(-1300,-144,-1249));

	scene::ICameraSceneNode* cam = smgr->addCameraSceneNodeFPS();
	cam->setAspectRatio(16.f/10.f);


    MyShaderCallBack* mc = new MyShaderCallBack();
    s32 newMaterialType1 = driver->getGPUProgrammingServices()->addHighLevelShaderMaterialFromFiles(
				"./display.vert", "vertexMain", video::EVST_VS_2_0,
				"./display.frag", "pixelMain", video::EPST_PS_2_0,
				mc, video::EMT_SOLID);
    s32 quadMaterialType = driver->getGPUProgrammingServices()->addHighLevelShaderMaterialFromFiles(
				"./quad.vert", "vertexMain", video::EVST_VS_2_0,
				"./gblur.frag", "pixelMain", video::EPST_PS_2_0,
				mc, video::EMT_SOLID);
    mc->drop();
	mesh = smgr->getMesh("./display.3ds");
	video::ITexture* guirtt = driver->addRenderTargetTexture(core::dimension2d<u32>(1024, 640),"guirtt");
	video::ITexture* guirtt_b = driver->addRenderTargetTexture(core::dimension2d<u32>(512, 320),"guirtt_b");
	core::vector3df offset = core::vector3df(0.f,0.f,8.f*(sin(cam->getFOV()*0.5)*cam->getNearValue()/sin(core::PI-cam->getFOV()*0.5)));
	if (mesh)
        node = smgr->addMeshSceneNode(mesh,cam);
	if (node) {
		node->setMaterialTexture(0,screen);
		node->setMaterialTexture(1,driver->getTexture("./hex.jpg"));
		node->setMaterialTexture(2,guirtt);
		node->setMaterialTexture(3,guirtt_b);
		node->setMaterialFlag(video::EMF_LIGHTING,false);
		node->setMaterialFlag(video::EMF_BACK_FACE_CULLING,false);
		node->setMaterialFlag(video::EMF_TRILINEAR_FILTER,true);
		node->setMaterialType((video::E_MATERIAL_TYPE)newMaterialType1);
		node->setPosition(offset);
		node->setRotation(core::vector3df(90.f,0.f,0.f));
		node->setVisible(false);
	}
    scene::ISceneNode* node2 = node;
	mesh = smgr->getMesh("./display_2.3ds");
	if (mesh) {
	    smgr->getMeshManipulator()->makePlanarTextureMapping(mesh,1.f);
        node = smgr->addMeshSceneNode(mesh,cam,-1);
	}
	if (node) {
		node->setMaterialTexture(0,driver->getTexture("./arroway.de_metal+structure+06_d100_flat.jpg"));
		node->setMaterialTexture(1,driver->getTexture("./arroway.de_metal+structure+06_s100+(g010).jpg"));
		node->setMaterialFlag(video::EMF_LIGHTING,false);
		node->setPosition(offset);
		node->setRotation(core::vector3df(90.f,0.f,0.f));
		node->setVisible(false);
	}

	device->getCursorControl()->setVisible(false);

	int lastFPS = -1;
    core::matrix4 view,proj,crop;
    crop.setScale(core::vector3df(1.166287016,1.15942029,1.f));

    video::S3DVertex Vertices[4];
    Vertices[0] = video::S3DVertex(-1.f,1.f,-0.5, 1,1,0,
			video::SColor(255,255,255,255), 0, 1);
	Vertices[1] = video::S3DVertex(1.f,-1.f,-0.5, 1,0,0,
			video::SColor(255,255,255,255), 1, 0);
	Vertices[2] = video::S3DVertex(1.f,1.f,-0.5, 0,1,1,
			video::SColor(255,255,255,255), 1, 1);
	Vertices[3] = video::S3DVertex(-1.f,-1.f,-0.5, 0,0,1,
			video::SColor(255,255,255,255), 0, 0);
    u16 indices[] = {	3,1,0, 0,1,2    };
    video::SMaterial materialcp;
    materialcp.setTexture(0,guirtt);
    materialcp.setFlag(video::EMF_LIGHTING,false);
    materialcp.setFlag(video::EMF_BACK_FACE_CULLING,false);
    materialcp.MaterialType = (video::E_MATERIAL_TYPE)quadMaterialType;

    WayPoint* nearestWp = waypoints[0];
    float nearestWpDist = (waypoints[0]->getPosition()-cam->getPosition()).getLength();
    float temp;
    for ( u32 i=1; i<waypoints.size(); i++ ) {
        temp = (waypoints[i]->getPosition()-cam->getPosition()).getLength();
        if (temp<nearestWpDist) {
            nearestWpDist = temp;
            nearestWp = waypoints[i];
        }
    }
    core::vector3df objective(0.f,280.f,150.f);
    core::vector3df temp3;
    WayPoint* endWp = waypoints[0];
    temp3 = (endWp->getPosition()-objective)*core::vector3df(1.f,20.f,1.f);
    float endWpDist = temp3.getLength();
    for ( u32 i=1; i<waypoints.size(); i++ ) {
        temp3 = (waypoints[i]->getPosition()-objective)*core::vector3df(1.f,20.f,1.f);
        temp = temp3.getLength();
        if (temp<endWpDist) {
            endWpDist = temp;
            endWp = waypoints[i];
        }
    }
    core::array<WayPoint*> activeWayPoints;
    activeWayPoints.push_back(nearestWp);/*
    temp3 = (nearestWp->getPosition()-objective)*core::vector3df(1.f,20.f,1.f);
    nearestWpDist = temp3.getLength();
    */
    while (findAnotherWayPoint(activeWayPoints,nearestWp,endWp,objective)) {}
    activeWayPoints.push_back(endWp);


	while(device->run())
	{
		if (device->isWindowActive())
		{
			driver->beginScene(true,true);
			driver->setRenderTarget(screen,true,true, video::SColor(255,200,200,200));
			smgr->drawAll();
			driver->setRenderTarget(guirtt,true, true, video::SColor(0,0,0,0));
			driver->setMaterial(tnode->getMaterial(0));
			driver->setTransform(video::ETS_WORLD,core::matrix4());
			view = driver->getTransform(video::ETS_VIEW);
			driver->setTransform(video::ETS_VIEW,crop*view);
            driver->draw3DLine(cam->getPosition()-core::vector3df(0.f,1.f,0.f),activeWayPoints[0]->getPosition(),video::SColor(255,110,236,255));
			for ( u32 i=1; i<activeWayPoints.size(); i++) {
			    driver->draw3DLine(activeWayPoints[i-1]->getPosition(),activeWayPoints[i]->getPosition(),video::SColor(255,110,236,255));
			}
            driver->draw3DLine(objective,activeWayPoints[activeWayPoints.size()-1]->getPosition(),video::SColor(255,110,236,255));
			for ( u32 i=0; i<waypoints.size(); i++) {
			    waypoints[i]->getNode()->setVisible(true);
			    waypoints[i]->getNode()->OnAnimate(device->getTimer()->getTime());
			    waypoints[i]->getNode()->render();
			    waypoints[i]->getNode()->setVisible(false);
			}
			driver->setRenderTarget(guirtt_b,true, true, video::SColor(0,0,0,0));
			driver->setMaterial(materialcp);
            driver->drawVertexPrimitiveList(Vertices, 4, indices, 2, video::EVT_STANDARD, scene::EPT_TRIANGLES, video::EIT_16BIT);
			driver->setTransform(video::ETS_VIEW,view);
			driver->setRenderTarget(0,false, false);
			smgr->drawAll();
			node2->OnAnimate(device->getTimer()->getTime());
			node2->updateAbsolutePosition();
			node2->render();
			driver->endScene();
			if (activeWayPoints.size()>1) {
                if ((activeWayPoints[1]->getPosition()-cam->getPosition()).getLength()<(activeWayPoints[0]->getPosition()-cam->getPosition()).getLength())
                    activeWayPoints.erase(0);
			}

			int fps = driver->getFPS();

			if (lastFPS != fps)
			{
				core::stringw str = L"Irrlicht Engine - PDA FPS:";
				str += fps;

				device->setWindowCaption(str.c_str());
				lastFPS = fps;
			}
		}
		else
			device->yield();
	}

	/*
	In the end, delete the Irrlicht device.
	*/
	device->drop();
	return 0;
}

/*
That's it. Compile and play around with the program.
**/

devsh
Competition winner
Posts: 2049
Joined: Tue Dec 09, 2008 6:00 pm
Location: UK
Contact:

Post by devsh »

ok I made the tetraedrons only appear if they are part of the path, and dissappear as you complete it. The path finder finally manages dead ends!!!! This means it can finally strike a path to the obejctive (if you want to test, please move the objective coord around). Next update I will handle recalculating the path, handling a no_path error and displaying the objective at the end. In the update after that I will generate a minimap which will give you a top down view of the path and your camera frustum

Code: Select all

#include <irrlicht.h>
#include <math.h>
#include <iostream>

using namespace irr;

#ifdef _MSC_VER
#pragma comment(lib, "Irrlicht.lib")
#endif

core::vector3df dispcol = core::vector3df(0.6,1.3,2.0);

class MyEventReceiver : public IEventReceiver
{
public:
    // This is the one method that we have to implement
    virtual bool OnEvent(const SEvent& event)
    {
        // Remember whether each key is down or up
        if (event.EventType == irr::EET_KEY_INPUT_EVENT) {
            KeyIsDown[event.KeyInput.Key] = event.KeyInput.PressedDown;
            if (event.KeyInput.Key==KEY_KEY_G)
                dispcol = core::vector3df(0.6,1.3,0.0);
            else if (event.KeyInput.Key==KEY_KEY_B)
                dispcol = core::vector3df(0.6,1.3,2.0);
        }

        return false;
    }

    // This is used to check whether a key is being held down
    virtual bool IsKeyDown(EKEY_CODE keyCode) const
    {
        return KeyIsDown[keyCode];
    }

    MyEventReceiver()
    {
        for (u32 i=0; i<KEY_KEY_CODES_COUNT; ++i)
            KeyIsDown[i] = false;
    }

private:
    // We use this array to store the current state of each key
    bool KeyIsDown[KEY_KEY_CODES_COUNT];
};

class Tetraeder : public scene::ISceneNode
{
    core::aabbox3d<f32> Box;
    video::S3DVertex Vertices[4];
    video::SMaterial Material;

public:

    Tetraeder(scene::ISceneNode* parent, scene::ISceneManager* mgr, s32 id)
        : scene::ISceneNode(parent, mgr, id)
    {
        Material.Wireframe = true;
        Material.Thickness = 8.f;
        Material.BackfaceCulling = false;
        Material.Lighting = false;

        Vertices[0] = video::S3DVertex(0,-10,10, 1,1,0,
                video::SColor(255,110,236,255), 0, 1);
        Vertices[1] = video::S3DVertex(10,-10,-10, 1,0,0,
                video::SColor(255,110,236,255), 1, 1);
        Vertices[2] = video::S3DVertex(0,10,0, 0,1,1,
                video::SColor(255,110,236,255), 1, 0);
        Vertices[3] = video::S3DVertex(-10,-10,-10, 0,0,1,
                video::SColor(255,110,236,255), 0, 0);


        Box.reset(Vertices[0].Pos);
        for (s32 i=1; i<4; ++i)
            Box.addInternalPoint(Vertices[i].Pos);

        setAutomaticCulling(scene::EAC_OFF);
    }


    virtual void OnRegisterSceneNode()
    {
        if (IsVisible)
            SceneManager->registerNodeForRendering(this);

        ISceneNode::OnRegisterSceneNode();
    }


    virtual void render()
    {
        u16 indices[] = {    0,2,3, 2,1,3, 1,0,3, 2,0,1    };
        video::IVideoDriver* driver = SceneManager->getVideoDriver();

        driver->setMaterial(Material);
        driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
        driver->drawVertexPrimitiveList(&Vertices[0], 4, &indices[0], 4, 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 WayPoint;

class WayPoint
{
        core::array<WayPoint*> others;
        core::vector3df position;
        Tetraeder* node;

    public:
        WayPoint(core::vector3df Position, Tetraeder* Node) {
            position=Position;
            node=Node;
            node->setPosition(Position);
        }
        void addNeighbour(WayPoint* other) {others.push_back(other);}
        core::array<WayPoint*> &getNeighbours() {return others;}
        core::vector3df getPosition() {return position;}
        scene::ISceneNode* getNode() {return node;}
};

class MyShaderCallBack : public video::IShaderConstantSetCallBack
{
public:

    virtual void OnSetConstants(video::IMaterialRendererServices* services,
            s32 userData)
    {
        int texs[4] = {0,1,2,3};
        services->setPixelShaderConstant("tex",(float*)texs,1);
        services->setPixelShaderConstant("hex",(float*)texs+1,1);
        services->setPixelShaderConstant("screen",(float*)texs+2,1);
        services->setPixelShaderConstant("gaussbump",(float*)texs+3,1);
        services->setPixelShaderConstant("dispcol",&dispcol.X,3);
    }
};

bool findAnotherWayPoint(core::array<WayPoint*> &activeWayPoints, WayPoint* &nearestWp, WayPoint* endWp, core::vector3df objective, core::array<WayPoint*> &potentialWayPoints, core::array<WayPoint*> &discardedWP)
{
    bool found_another = false;
    WayPoint* nearestWp2;
    float nearestWpDist = 99999999999.f;
    core::vector3df temp3;
    float temp;
    if (nearestWp->getNeighbours().size()<2)
        return false;
    for (u32 i=0; i<nearestWp->getNeighbours().size(); i++) {
        if (nearestWp->getNeighbours()[i]==endWp) {
            activeWayPoints.push_back(endWp);
            return false;
        }
        if (nearestWp->getNeighbours()[i]==activeWayPoints[core::max_(activeWayPoints.size()-2,irr::u32(0))]||(discardedWP.binary_search(nearestWp->getNeighbours()[i])!=-1))
            continue;
        temp3 = (nearestWp->getNeighbours()[i]->getPosition()-objective)*core::vector3df(1.f,20.f,1.f);
        temp = temp3.getLength();
        if (temp<nearestWpDist) {
            nearestWpDist = temp;
            nearestWp2 = nearestWp->getNeighbours()[i];
            found_another = true;
        }
    }
    if (found_another) {
        irr::s32 found_ix = nearestWp->getNeighbours().binary_search(nearestWp2);
        for (s32 i=0; i<nearestWp->getNeighbours().size(); i++) {
            if (i!=found_ix&&activeWayPoints[activeWayPoints.size()-2]!=nearestWp->getNeighbours()[i])
                potentialWayPoints.push_back(nearestWp->getNeighbours()[i]);
        }
        nearestWp = nearestWp2;
        found_ix = potentialWayPoints.binary_search(nearestWp);
        if (found_ix!=-1)
            potentialWayPoints.erase(found_ix);
        activeWayPoints.push_back(nearestWp);
    }
    return found_another;
}

int main()
{
    core::array<WayPoint*> waypoints;

    MyEventReceiver receiver;

    IrrlichtDevice *device =
        createDevice(video::EDT_OPENGL, core::dimension2d<u32>(1024, 640),24,false,false,false,&receiver);

    if (device == 0)
        return 1; // could not create selected driver.

    video::IVideoDriver* driver = device->getVideoDriver();
    video::ITexture* screen = driver->addRenderTargetTexture(core::dimension2d<u32>(1024, 640), "screen", video::ECF_A32B32G32R32F);
    scene::ISceneManager* smgr = device->getSceneManager();

    scene::ISceneNodeAnimator* anim = smgr->createRotationAnimator(core::vector3df(0.f,1.f,0.f));

    Tetraeder* tnode = new Tetraeder(smgr->getRootSceneNode(),smgr,69);
    tnode->addAnimator(anim);
    tnode->setVisible(false);
    WayPoint* wayp = new WayPoint(core::vector3df(117.f,-54.f,87.5),tnode);
    waypoints.push_back(wayp);
    tnode = new Tetraeder(smgr->getRootSceneNode(),smgr,70);
    anim = smgr->createRotationAnimator(core::vector3df(0.f,1.f,0.f));
    tnode->addAnimator(anim);
    tnode->setVisible(false);
    wayp = new WayPoint(core::vector3df(112.f,74.f,-408.f),tnode);
    waypoints.push_back(wayp);
    waypoints[0]->addNeighbour(wayp);
    wayp->addNeighbour(waypoints[0]);
    tnode = new Tetraeder(smgr->getRootSceneNode(),smgr,71);
    anim = smgr->createRotationAnimator(core::vector3df(0.f,1.f,0.f));
    tnode->addAnimator(anim);
    tnode->setVisible(false);
    wayp = new WayPoint(core::vector3df(112.f,74.f,602.f),tnode);
    waypoints.push_back(wayp);
    waypoints[0]->addNeighbour(wayp);
    wayp->addNeighbour(waypoints[0]);
    tnode = new Tetraeder(smgr->getRootSceneNode(),smgr,72);
    anim = smgr->createRotationAnimator(core::vector3df(0.f,1.f,0.f));
    tnode->addAnimator(anim);
    tnode->setVisible(false);
    wayp = new WayPoint(core::vector3df(700.f,-54.f,87.5),tnode);
    waypoints.push_back(wayp);
    waypoints[0]->addNeighbour(wayp);
    wayp->addNeighbour(waypoints[0]);
    tnode = new Tetraeder(smgr->getRootSceneNode(),smgr,73);
    anim = smgr->createRotationAnimator(core::vector3df(0.f,1.f,0.f));
    tnode->addAnimator(anim);
    tnode->setVisible(false);
    wayp = new WayPoint(core::vector3df(-475.f,-54.f,87.5),tnode);
    waypoints.push_back(wayp);
    waypoints[0]->addNeighbour(wayp);
    wayp->addNeighbour(waypoints[0]);
    tnode = new Tetraeder(smgr->getRootSceneNode(),smgr,74);
    anim = smgr->createRotationAnimator(core::vector3df(0.f,1.f,0.f));
    tnode->addAnimator(anim);
    tnode->setVisible(false);
    wayp = new WayPoint(core::vector3df(-83.f,74.f,-306.f),tnode);
    waypoints.push_back(wayp);
    waypoints[1]->addNeighbour(wayp);
    wayp->addNeighbour(waypoints[1]);
    tnode = new Tetraeder(smgr->getRootSceneNode(),smgr,75);
    anim = smgr->createRotationAnimator(core::vector3df(0.f,1.f,0.f));
    tnode->addAnimator(anim);
    tnode->setVisible(false);
    wayp = new WayPoint(core::vector3df(-408.f,74.f,-287.f),tnode);
    waypoints.push_back(wayp);
    waypoints[5]->addNeighbour(wayp);
    wayp->addNeighbour(waypoints[5]);
    tnode = new Tetraeder(smgr->getRootSceneNode(),smgr,76);
    anim = smgr->createRotationAnimator(core::vector3df(0.f,1.f,0.f));
    tnode->addAnimator(anim);
    tnode->setVisible(false);
    wayp = new WayPoint(core::vector3df(-75.f,160.f,-829.f),tnode);
    waypoints.push_back(wayp);
    waypoints[5]->addNeighbour(wayp);
    wayp->addNeighbour(waypoints[5]);
    tnode = new Tetraeder(smgr->getRootSceneNode(),smgr,77);
    anim = smgr->createRotationAnimator(core::vector3df(0.f,1.f,0.f));
    tnode->addAnimator(anim);
    tnode->setVisible(false);
    wayp = new WayPoint(core::vector3df(296.f,160.f,-842.f),tnode);
    waypoints.push_back(wayp);
    waypoints[7]->addNeighbour(wayp);
    wayp->addNeighbour(waypoints[7]);
    tnode = new Tetraeder(smgr->getRootSceneNode(),smgr,78);
    anim = smgr->createRotationAnimator(core::vector3df(0.f,1.f,0.f));
    tnode->addAnimator(anim);
    tnode->setVisible(false);
    wayp = new WayPoint(core::vector3df(289.f,74.f,-415.f),tnode);
    waypoints.push_back(wayp);
    waypoints[8]->addNeighbour(wayp);
    wayp->addNeighbour(waypoints[8]);
    waypoints[9]->addNeighbour(waypoints[1]);
    waypoints[1]->addNeighbour(waypoints[9]);
    tnode = new Tetraeder(smgr->getRootSceneNode(),smgr,79);
    anim = smgr->createRotationAnimator(core::vector3df(0.f,1.f,0.f));
    tnode->addAnimator(anim);
    tnode->setVisible(false);
    wayp = new WayPoint(core::vector3df(-75.f,260.f,-829.f),tnode);
    waypoints.push_back(wayp);
    waypoints[7]->addNeighbour(wayp);
    wayp->addNeighbour(waypoints[7]);
    tnode = new Tetraeder(smgr->getRootSceneNode(),smgr,80);
    anim = smgr->createRotationAnimator(core::vector3df(0.f,1.f,0.f));
    tnode->addAnimator(anim);
    tnode->setVisible(false);
    wayp = new WayPoint(core::vector3df(-405.f,260.f,-755.f),tnode);
    waypoints.push_back(wayp);
    waypoints[10]->addNeighbour(wayp);
    wayp->addNeighbour(waypoints[10]);
    tnode = new Tetraeder(smgr->getRootSceneNode(),smgr,81);
    anim = smgr->createRotationAnimator(core::vector3df(0.f,1.f,0.f));
    tnode->addAnimator(anim);
    tnode->setVisible(false);
    wayp = new WayPoint(core::vector3df(296.f,260.f,-842.f),tnode);
    waypoints.push_back(wayp);
    waypoints[8]->addNeighbour(wayp);
    wayp->addNeighbour(waypoints[8]);
    tnode = new Tetraeder(smgr->getRootSceneNode(),smgr,82);
    anim = smgr->createRotationAnimator(core::vector3df(0.f,1.f,0.f));
    tnode->addAnimator(anim);
    tnode->setVisible(false);
    wayp = new WayPoint(core::vector3df(625.f,260.f,-831.f),tnode);
    waypoints.push_back(wayp);
    waypoints[12]->addNeighbour(wayp);
    wayp->addNeighbour(waypoints[12]);
    tnode = new Tetraeder(smgr->getRootSceneNode(),smgr,83);
    anim = smgr->createRotationAnimator(core::vector3df(0.f,1.f,0.f));
    tnode->addAnimator(anim);
    tnode->setVisible(false);
    wayp = new WayPoint(core::vector3df(610.f,320.f,95.f),tnode);
    waypoints.push_back(wayp);
    waypoints[13]->addNeighbour(wayp);
    wayp->addNeighbour(waypoints[13]);
    tnode = new Tetraeder(smgr->getRootSceneNode(),smgr,84);
    anim = smgr->createRotationAnimator(core::vector3df(0.f,1.f,0.f));
    tnode->addAnimator(anim);
    tnode->setVisible(false);
    wayp = new WayPoint(core::vector3df(260.f,265.f,95.f),tnode);
    waypoints.push_back(wayp);
    waypoints[14]->addNeighbour(wayp);
    wayp->addNeighbour(waypoints[14]);
    tnode = new Tetraeder(smgr->getRootSceneNode(),smgr,85);
    anim = smgr->createRotationAnimator(core::vector3df(0.f,1.f,0.f));
    tnode->addAnimator(anim);
    tnode->setVisible(false);
    wayp = new WayPoint(core::vector3df(610.f,310.f,475.f),tnode);
    waypoints.push_back(wayp);
    waypoints[14]->addNeighbour(wayp);
    wayp->addNeighbour(waypoints[14]);
    tnode = new Tetraeder(smgr->getRootSceneNode(),smgr,86);
    anim = smgr->createRotationAnimator(core::vector3df(0.f,1.f,0.f));
    tnode->addAnimator(anim);
    tnode->setVisible(false);
    wayp = new WayPoint(core::vector3df(610.f,310.f,705.f),tnode);
    waypoints.push_back(wayp);
    waypoints[16]->addNeighbour(wayp);
    wayp->addNeighbour(waypoints[16]);
    tnode = new Tetraeder(smgr->getRootSceneNode(),smgr,87);
    anim = smgr->createRotationAnimator(core::vector3df(0.f,1.f,0.f));
    tnode->addAnimator(anim);
    tnode->setVisible(false);
    wayp = new WayPoint(core::vector3df(610.f,225.f,1033.f),tnode);
    waypoints.push_back(wayp);
    waypoints[17]->addNeighbour(wayp);
    wayp->addNeighbour(waypoints[17]);
    tnode = new Tetraeder(smgr->getRootSceneNode(),smgr,88);
    anim = smgr->createRotationAnimator(core::vector3df(0.f,1.f,0.f));
    tnode->addAnimator(anim);
    tnode->setVisible(false);
    wayp = new WayPoint(core::vector3df(295.f,225.f,975.f),tnode);
    waypoints.push_back(wayp);
    waypoints[18]->addNeighbour(wayp);
    wayp->addNeighbour(waypoints[18]);
    tnode = new Tetraeder(smgr->getRootSceneNode(),smgr,89);
    anim = smgr->createRotationAnimator(core::vector3df(0.f,1.f,0.f));
    tnode->addAnimator(anim);
    tnode->setVisible(false);
    wayp = new WayPoint(core::vector3df(295.f,75.f,975.f),tnode);
    waypoints.push_back(wayp);
    waypoints[19]->addNeighbour(wayp);
    wayp->addNeighbour(waypoints[19]);
    tnode = new Tetraeder(smgr->getRootSceneNode(),smgr,90);
    anim = smgr->createRotationAnimator(core::vector3df(0.f,1.f,0.f));
    tnode->addAnimator(anim);
    tnode->setVisible(false);
    wayp = new WayPoint(core::vector3df(165.f,75.f,895.f),tnode);
    waypoints.push_back(wayp);
    waypoints[20]->addNeighbour(wayp);
    wayp->addNeighbour(waypoints[20]);
    waypoints[2]->addNeighbour(waypoints[21]);
    waypoints[21]->addNeighbour(waypoints[2]);
    tnode = new Tetraeder(smgr->getRootSceneNode(),smgr,91);
    anim = smgr->createRotationAnimator(core::vector3df(0.f,1.f,0.f));
    tnode->addAnimator(anim);
    tnode->setVisible(false);
    wayp = new WayPoint(core::vector3df(970.f,215.f,970.f),tnode);
    waypoints.push_back(wayp);
    waypoints[18]->addNeighbour(wayp);
    wayp->addNeighbour(waypoints[18]);
    tnode = new Tetraeder(smgr->getRootSceneNode(),smgr,92);
    anim = smgr->createRotationAnimator(core::vector3df(0.f,1.f,0.f));
    tnode->addAnimator(anim);
    tnode->setVisible(false);
    wayp = new WayPoint(core::vector3df(1115.f,150.f,600.f),tnode);
    waypoints.push_back(wayp);
    waypoints[22]->addNeighbour(wayp);
    wayp->addNeighbour(waypoints[22]);
    tnode = new Tetraeder(smgr->getRootSceneNode(),smgr,93);
    anim = smgr->createRotationAnimator(core::vector3df(0.f,1.f,0.f));
    tnode->addAnimator(anim);
    tnode->setVisible(false);
    wayp = new WayPoint(core::vector3df(629.f,75.f,476.f),tnode);
    waypoints.push_back(wayp);
    waypoints[23]->addNeighbour(wayp);
    wayp->addNeighbour(waypoints[23]);
    tnode = new Tetraeder(smgr->getRootSceneNode(),smgr,94);
    anim = smgr->createRotationAnimator(core::vector3df(0.f,1.f,0.f));
    tnode->addAnimator(anim);
    tnode->setVisible(false);
    wayp = new WayPoint(core::vector3df(277.f,75.f,476.f),tnode);
    waypoints.push_back(wayp);
    waypoints[24]->addNeighbour(wayp);
    wayp->addNeighbour(waypoints[24]);
    waypoints[2]->addNeighbour(waypoints[25]);
    waypoints[25]->addNeighbour(waypoints[2]);
    tnode = new Tetraeder(smgr->getRootSceneNode(),smgr,95);
    anim = smgr->createRotationAnimator(core::vector3df(0.f,1.f,0.f));
    tnode->addAnimator(anim);
    tnode->setVisible(false);
    wayp = new WayPoint(core::vector3df(629.f,75.f,-282.f),tnode);
    waypoints.push_back(wayp);
    waypoints[24]->addNeighbour(wayp);
    wayp->addNeighbour(waypoints[24]);
    tnode = new Tetraeder(smgr->getRootSceneNode(),smgr,96);
    anim = smgr->createRotationAnimator(core::vector3df(0.f,1.f,0.f));
    tnode->addAnimator(anim);
    tnode->setVisible(false);
    wayp = new WayPoint(core::vector3df(-390.f,305.f,475.f),tnode);
    waypoints.push_back(wayp);
    waypoints[16]->addNeighbour(wayp);
    wayp->addNeighbour(waypoints[16]);
    tnode = new Tetraeder(smgr->getRootSceneNode(),smgr,97);
    anim = smgr->createRotationAnimator(core::vector3df(0.f,1.f,0.f));
    tnode->addAnimator(anim);
    tnode->setVisible(false);
    wayp = new WayPoint(core::vector3df(-390.f,300.f,100.f),tnode);
    waypoints.push_back(wayp);
    waypoints[27]->addNeighbour(wayp);
    wayp->addNeighbour(waypoints[27]);
    tnode = new Tetraeder(smgr->getRootSceneNode(),smgr,98);
    anim = smgr->createRotationAnimator(core::vector3df(0.f,1.f,0.f));
    tnode->addAnimator(anim);
    tnode->setVisible(false);
    wayp = new WayPoint(core::vector3df(-75.f,275.f,100.f),tnode);
    waypoints.push_back(wayp);
    waypoints[28]->addNeighbour(wayp);
    wayp->addNeighbour(waypoints[28]);
    tnode = new Tetraeder(smgr->getRootSceneNode(),smgr,99);
    anim = smgr->createRotationAnimator(core::vector3df(0.f,1.f,0.f));
    tnode->addAnimator(anim);
    tnode->setVisible(false);
    wayp = new WayPoint(core::vector3df(-90.f,75.f,495.f),tnode);
    waypoints.push_back(wayp);
    waypoints[2]->addNeighbour(wayp);
    wayp->addNeighbour(waypoints[2]);
    tnode = new Tetraeder(smgr->getRootSceneNode(),smgr,100);
    anim = smgr->createRotationAnimator(core::vector3df(0.f,1.f,0.f));
    tnode->addAnimator(anim);
    tnode->setVisible(false);
    wayp = new WayPoint(core::vector3df(-390.f,75.f,495.f),tnode);
    waypoints.push_back(wayp);
    waypoints[30]->addNeighbour(wayp);
    wayp->addNeighbour(waypoints[30]);
    waypoints[6]->addNeighbour(waypoints[31]);
    waypoints[31]->addNeighbour(waypoints[6]);

    anim->drop();

    /*
    To display the Quake 3 map, we first need to load it. Quake 3 maps
    are packed into .pk3 files which are nothing else than .zip files.
    So we add the .pk3 file to our irr::io::IFileSystem. After it was added,
    we are able to read from the files in that archive as if they are
    directly stored on the disk.
    */
    device->getFileSystem()->addZipFileArchive("../irrlicht-1.7.1/media/map-20kdm2.pk3");
    scene::IAnimatedMesh* mesh = smgr->getMesh("20kdm2.bsp");
    scene::ISceneNode* node = 0;

    if (mesh)
        node = smgr->addOctreeSceneNode(mesh->getMesh(0), 0, -1, 1024);
    if (node)
        node->setPosition(core::vector3df(-1300,-144,-1249));

    scene::ICameraSceneNode* cam = smgr->addCameraSceneNodeFPS();
    cam->setAspectRatio(16.f/10.f);


    MyShaderCallBack* mc = new MyShaderCallBack();
    s32 newMaterialType1 = driver->getGPUProgrammingServices()->addHighLevelShaderMaterialFromFiles(
                "./display.vert", "vertexMain", video::EVST_VS_2_0,
                "./display.frag", "pixelMain", video::EPST_PS_2_0,
                mc, video::EMT_SOLID);
    s32 quadMaterialType = driver->getGPUProgrammingServices()->addHighLevelShaderMaterialFromFiles(
                "./quad.vert", "vertexMain", video::EVST_VS_2_0,
                "./gblur.frag", "pixelMain", video::EPST_PS_2_0,
                mc, video::EMT_SOLID);
    mc->drop();
    mesh = smgr->getMesh("./display.3ds");
    video::ITexture* guirtt = driver->addRenderTargetTexture(core::dimension2d<u32>(1024, 640),"guirtt");
    video::ITexture* guirtt_b = driver->addRenderTargetTexture(core::dimension2d<u32>(512, 320),"guirtt_b");
    core::vector3df offset = core::vector3df(0.f,0.f,8.f*(sin(cam->getFOV()*0.5)*cam->getNearValue()/sin(core::PI-cam->getFOV()*0.5)));
    if (mesh)
        node = smgr->addMeshSceneNode(mesh,cam);
    if (node) {
        node->setMaterialTexture(0,screen);
        node->setMaterialTexture(1,driver->getTexture("./hex.jpg"));
        node->setMaterialTexture(2,guirtt);
        node->setMaterialTexture(3,guirtt_b);
        node->setMaterialFlag(video::EMF_LIGHTING,false);
        node->setMaterialFlag(video::EMF_BACK_FACE_CULLING,false);
        node->setMaterialFlag(video::EMF_TRILINEAR_FILTER,true);
        node->setMaterialType((video::E_MATERIAL_TYPE)newMaterialType1);
        node->setPosition(offset);
        node->setRotation(core::vector3df(90.f,0.f,0.f));
        node->setVisible(false);
    }
    scene::ISceneNode* node2 = node;
    mesh = smgr->getMesh("./display_2.3ds");
    if (mesh) {
        smgr->getMeshManipulator()->makePlanarTextureMapping(mesh,1.f);
        node = smgr->addMeshSceneNode(mesh,cam,-1);
    }
    if (node) {
        node->setMaterialTexture(0,driver->getTexture("./arroway.de_metal+structure+06_d100_flat.jpg"));
        node->setMaterialTexture(1,driver->getTexture("./arroway.de_metal+structure+06_s100+(g010).jpg"));
        node->setMaterialFlag(video::EMF_LIGHTING,false);
        node->setPosition(offset);
        node->setRotation(core::vector3df(90.f,0.f,0.f));
        node->setVisible(false);
    }

    device->getCursorControl()->setVisible(false);

    int lastFPS = -1;
    core::matrix4 view,proj,crop;
    crop.setScale(core::vector3df(1.166287016,1.15942029,1.f));

    video::S3DVertex Vertices[4];
    Vertices[0] = video::S3DVertex(-1.f,1.f,-0.5, 1,1,0,
            video::SColor(255,255,255,255), 0, 1);
    Vertices[1] = video::S3DVertex(1.f,-1.f,-0.5, 1,0,0,
            video::SColor(255,255,255,255), 1, 0);
    Vertices[2] = video::S3DVertex(1.f,1.f,-0.5, 0,1,1,
            video::SColor(255,255,255,255), 1, 1);
    Vertices[3] = video::S3DVertex(-1.f,-1.f,-0.5, 0,0,1,
            video::SColor(255,255,255,255), 0, 0);
    u16 indices[] = {    3,1,0, 0,1,2    };
    video::SMaterial materialcp;
    materialcp.setTexture(0,guirtt);
    materialcp.setFlag(video::EMF_LIGHTING,false);
    materialcp.setFlag(video::EMF_BACK_FACE_CULLING,false);
    materialcp.MaterialType = (video::E_MATERIAL_TYPE)quadMaterialType;

    WayPoint* nearestWp = waypoints[0];
    float nearestWpDist = (waypoints[0]->getPosition()-cam->getPosition()).getLength();
    float temp;
    for ( u32 i=1; i<waypoints.size(); i++ ) {
        temp = (waypoints[i]->getPosition()-cam->getPosition()).getLength();
        if (temp<nearestWpDist) {
            nearestWpDist = temp;
            nearestWp = waypoints[i];
        }
    }
    core::vector3df objective(0.f,280.f,150.f);
    core::vector3df temp3;
    WayPoint* endWp = waypoints[0];
    temp3 = (endWp->getPosition()-objective)*core::vector3df(1.f,20.f,1.f);
    float endWpDist = temp3.getLength();
    for ( u32 i=1; i<waypoints.size(); i++ ) {
        temp3 = (waypoints[i]->getPosition()-objective)*core::vector3df(1.f,20.f,1.f);
        temp = temp3.getLength();
        if (temp<endWpDist) {
            endWpDist = temp;
            endWp = waypoints[i];
        }
    }
    core::array<WayPoint*> activeWayPoints;
    core::array<WayPoint*> potentialWayPoints;
    core::array<WayPoint*> discardedWP;
    activeWayPoints.push_back(nearestWp);/*
    temp3 = (nearestWp->getPosition()-objective)*core::vector3df(1.f,20.f,1.f);
    nearestWpDist = temp3.getLength();
    */
    bool no_path=false;
    while (findAnotherWayPoint(activeWayPoints,nearestWp,endWp,objective,potentialWayPoints,discardedWP)) {}
    while (activeWayPoints[activeWayPoints.size()-1]!=endWp) {
        if (activeWayPoints.size()>0) {
            discardedWP.push_back(activeWayPoints[activeWayPoints.size()-1]);
            activeWayPoints.erase(activeWayPoints.size()-1);
            for ( s32 i=activeWayPoints.size()-1; i>-1; i-- ) {
                s32 index;
                for ( u32 j=0; j<activeWayPoints[i]->getNeighbours().size(); j++ ) {
                    index = potentialWayPoints.binary_search(activeWayPoints[i]->getNeighbours()[j]);
                    if (index!=-1)
                        break;
                }
                if (index==-1) {
                    discardedWP.push_back(activeWayPoints[i]);
                    activeWayPoints.erase(i);
                }
                else
                    break;
            }
            nearestWp = activeWayPoints[activeWayPoints.size()-1];
        }
        else {
            no_path=true;
            break;
        }
        while (findAnotherWayPoint(activeWayPoints,nearestWp,endWp,objective,potentialWayPoints,discardedWP)) {}
    }

    while(device->run())
    {
        if (device->isWindowActive())
        {
            driver->beginScene(true,true);
            driver->setRenderTarget(screen,true,true, video::SColor(255,200,200,200));
            smgr->drawAll();
            driver->setRenderTarget(guirtt,true, true, video::SColor(0,0,0,0));
            driver->setMaterial(tnode->getMaterial(0));
            driver->setTransform(video::ETS_WORLD,core::matrix4());
            view = driver->getTransform(video::ETS_VIEW);
            driver->setTransform(video::ETS_VIEW,crop*view);
            if (activeWayPoints.size()<1)
                driver->draw3DLine(cam->getPosition()-core::vector3df(0.f,1.f,0.f),objective,video::SColor(255,110,236,255));
            else {
                driver->draw3DLine(cam->getPosition()-core::vector3df(0.f,1.f,0.f),activeWayPoints[0]->getPosition(),video::SColor(255,110,236,255));
                activeWayPoints[0]->getNode()->setVisible(true);
                activeWayPoints[0]->getNode()->OnAnimate(device->getTimer()->getTime());
                activeWayPoints[0]->getNode()->render();
                activeWayPoints[0]->getNode()->setVisible(false);
                driver->setTransform(video::ETS_WORLD,core::matrix4());
            }
            for ( u32 i=1; i<activeWayPoints.size(); i++) {
                driver->setTransform(video::ETS_WORLD,core::matrix4());
                driver->draw3DLine(activeWayPoints[i-1]->getPosition(),activeWayPoints[i]->getPosition(),video::SColor(255,110,236,255));
                activeWayPoints[i]->getNode()->setVisible(true);
                activeWayPoints[i]->getNode()->OnAnimate(device->getTimer()->getTime());
                activeWayPoints[i]->getNode()->render();
                activeWayPoints[i]->getNode()->setVisible(false);
            }
            if (activeWayPoints.size()>0)
                driver->draw3DLine(objective,activeWayPoints[activeWayPoints.size()-1]->getPosition(),video::SColor(255,110,236,255));
            driver->setRenderTarget(guirtt_b,true, true, video::SColor(0,0,0,0));
            driver->setMaterial(materialcp);
            driver->drawVertexPrimitiveList(Vertices, 4, indices, 2, video::EVT_STANDARD, scene::EPT_TRIANGLES, video::EIT_16BIT);
            driver->setTransform(video::ETS_VIEW,view);
            driver->setRenderTarget(0,false, false);
            smgr->drawAll();
            node2->OnAnimate(device->getTimer()->getTime());
            node2->updateAbsolutePosition();
            node2->render();
            driver->endScene();
            if (activeWayPoints.size()>1) {
                if ((activeWayPoints[1]->getPosition()-cam->getPosition()).getLength()<(activeWayPoints[0]->getPosition()-cam->getPosition()).getLength())
                    activeWayPoints.erase(0);
            }
            else if (activeWayPoints.size()>0) {
                if ((objective-cam->getPosition()).getLength()<(activeWayPoints[0]->getPosition()-cam->getPosition()).getLength())
                    activeWayPoints.erase(0);
            }

            int fps = driver->getFPS();

            if (lastFPS != fps)
            {
                core::stringw str = L"Irrlicht Engine - PDA FPS:";
                str += fps;

                device->setWindowCaption(str.c_str());
                lastFPS = fps;
            }
        }
        else
            device->yield();
    }

    /*
    In the end, delete the Irrlicht device.
    */
    device->drop();
    return 0;
}

/*
That's it. Compile and play around with the program.
**/
devsh
Competition winner
Posts: 2049
Joined: Tue Dec 09, 2008 6:00 pm
Location: UK
Contact:

Post by devsh »

I have achieved the basis, as in you can render the GUI into the gui RTT together with the waypoints, and all will be illumintated etc.

I will resume work on this later on when getting on with the next part of my 1 level game Apocalyptus. But for now, until I sort out the deferred shading and shadowing pipeline in it I am considering this project suspended (which reminds me I have to revive my shadowing project).
Post Reply