Shooting code dont work

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
isiahil

Shooting code dont work

Post by isiahil »

Code: Select all

//Loads a .bsp
#include<stdlib.h>
#include <irrlicht.h>
#include <windows.h>

#pragma comment (lib,"Irrlicht.lib")

using namespace irr;
using namespace scene;
using namespace gui;
using namespace video;
using namespace core;



void Shoot(void);




class EventReciever:public IEventReceiver
{
public:
	virtual bool OnEvent(SEvent Event)
	{
		if(Event.KeyInput.Key==KEY_ESCAPE)
		{
			PostQuitMessage(0);
		}

		if(Event.KeyInput.Key==KEY_SPACE)
		{
			Shoot();
		}


		
		return false;
	}
};

EventReciever reciever;
IrrlichtDevice *Device=createDevice(EDT_OPENGL,dimension2d<s32>(480,640),16,false,false,&reciever);

IVideoDriver* Driver=Device->getVideoDriver();
ISceneManager* Smgr=Device->getSceneManager();
ICameraSceneNode* camPlayer=Smgr->addCameraSceneNodeFPS();
ITriangleSelector* tsrSelector;
int main()
{
	

	Device->getFileSystem()->addZipFileArchive("../../media/map-20kdm2.pk3");

	IAnimatedMesh* mshLevel=Smgr->getMesh("20kdm2.bsp");
	ISceneNode* nodLevel=0;
	nodLevel=Smgr->addOctTreeSceneNode(mshLevel->getMesh(0));

	

	tsrSelector=Smgr->createOctTreeTriangleSelector(mshLevel->getMesh(0),nodLevel);

	nodLevel->setPosition(vector3df(-1370,-130,-1400));

	nodLevel->setTriangleSelector(tsrSelector);
	tsrSelector->drop();

	nodLevel->setMaterialFlag(EMF_LIGHTING,true);

	
	ISceneNodeAnimator* anmAnim=Smgr->createCollisionResponseAnimator(tsrSelector,camPlayer);

	camPlayer->addAnimator(anmAnim);
	anmAnim->drop();
	
	
	
	while(Device->run())
	{
		Driver->beginScene(true,true,SColor(100,100,100,100));

		Smgr->drawAll();

		
		

	

		Driver->endScene();


	}

	Device->drop();

	return 0;

	
}

void Shoot(void)
{	
	vector3df start=camPlayer->getPosition();
	vector3df end=(camPlayer->getTarget() - start);
	end.normalize();
	end=start+(end*camPlayer->getFarValue());
	triangle3df triTriangle;
	line3d<f32> line(start,end);

	ISceneNode* nodBullet;
	nodBullet=Smgr->addBillboardSceneNode(0,dimension2d<f32>(25,25),start);
	nodBullet->setMaterialTexture(0,Device->getVideoDriver()->getTexture("..\\..\\media\\particle.bmp"));
	nodBullet->setMaterialType(EMT_TRANSPARENT_ADD_COLOR);

	if(Smgr->getSceneCollisionManager()->getCollisionPoint(line,tsrSelector,end,triTriangle))
	{
		ISceneNodeAnimator* anmBullet=0;
		anmBullet=Smgr->createFlyStraightAnimator(start,end,2000);
		nodBullet->addAnimator(anmBullet);
		anmBullet->drop();
		anmBullet=Smgr->createDeleteAnimator(2000);
		nodBullet->addAnimator(anmBullet);
		anmBullet->drop();
	}
}
When i press space bar nothing happens
Domarius
Posts: 178
Joined: Thu Mar 11, 2004 9:51 am
Location: Brisbane, QLD, Australia

Post by Domarius »

Don't have time to debug your code at the moment, but I can see that you've based it on the TechDemo code.

Why don't you get the techdemo version of it working in your project, and then start to modify it the way you want it?

It worked for me. You need the SParticle struct from one of the other files.
Post Reply