Bullet Help

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
ViperGuy911
Posts: 31
Joined: Tue Apr 12, 2005 12:20 am

Bullet Help

Post by ViperGuy911 »

Hi. How are you guys? I am having a problem with my bullet. Here is my code:

In main.cpp:

Code: Select all

#include <irrlicht.h>
#include <iostream>
#include "audiere.h"
#include "CDemo.h"

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

//bool fire;
//bool fullscreen = false;
bool progDeath = false;
void shoot();
#pragma comment(lib, "Irrlicht.lib")
#pragma comment(lib, "audiere.lib")

static IrrlichtDevice* device = 0;


class MyEventReceiver : public IEventReceiver
{
public:
virtual bool OnEvent(SEvent event)
{
 if (event.EventType == EET_KEY_INPUT_EVENT){      
      switch(event.KeyInput.Key){      
        case KEY_ESCAPE:
			{ 
          return progDeath = true;
			}
	  }
}

if (event.EventType == EET_MOUSE_INPUT_EVENT)
{
switch(event.MouseInput.Event) {
case EMIE_LMOUSE_LEFT_UP:
shoot();
}      
} 
   return false; 
}
};

int main()
{
	MyEventReceiver receiver;
......
  device->drop();

return 0;
}

void CDemo::shoot()
{
	scene::ISceneManager* sm = device->getSceneManager();
	scene::ICameraSceneNode* camera = sm->getActiveCamera();

	if (!camera)
		return;

	SParticleImpact imp; 
	imp.when = 0;

	// get line of camera

	core::vector3df start = camera->getPosition();
	core::vector3df end = (camera->getTarget() - start);
	end.normalize();
	start += end*5.0f;
	end = start + (end * camera->getFarValue());
	

	core::triangle3df triangle;

	core::line3d<f32> line(start, end);

	// get intersection point with map

	if (sm->getSceneCollisionManager()->getCollisionPoint(
		line, mapSelector, end, triangle))
	{
		// collides with wall
		core::vector3df out = triangle.getNormal();
		out.setLength(0.03f);

		imp.when = 1;
		imp.outVector = out;
		imp.pos = end;
	}
	else
	{
		// doesnt collide with wall
		end = (camera->getTarget() - start);
		end.normalize();
		end = start + (end * 1000);
	}

	// create fire ball
	scene::ISceneNode* node = 0;
	node = sm->addBillboardSceneNode(0,
		core::dimension2d<f32>(25,25), start);

	node->setMaterialFlag(video::EMF_LIGHTING, false);
	node->setMaterialTexture(0, device->getVideoDriver()->getTexture("fireball.bmp"));
	node->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR);
		
	f32 length = (f32)(end - start).getLength();
	const f32 speed = 0.6f;
	u32 time = (u32)(length / speed);

	scene::ISceneNodeAnimator* anim = 0;

	// set flight line

	anim = sm->createFlyStraightAnimator(start, end, time);
	node->addAnimator(anim);	
	anim->drop();

	anim = sm->createDeleteAnimator(time);
	node->addAnimator(anim);
	anim->drop();

	if (imp.when)
	{
		// create impact note
		imp.when = device->getTimer()->getTime() + (time - 100);
		Impacts.push_back(imp);
	}

}
And in the CDemo.h is the same thing as in the demo game.

It give me 2 errors when linking:

Code: Select all

Linking...
main.obj : error LNK2001: unresolved external symbol "void __cdecl shoot(void)" (?shoot@@YAXXZ)
Debug/FPS.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

FPS.exe - 2 error(s), 0 warning(s)
Sorry for all the code. So, what wrong with it?

Thank you so so so much!
darkraven
Posts: 29
Joined: Sat Mar 06, 2004 5:54 am
Location: Florida
Contact:

Post by darkraven »

From what I could tell though I'm still in learning stages is that the shoot() functions is part of the CDemo class and is never called.

void shoot(); is defining a void function called shoot() which is different from CDemo::shoot(). Since there is no shoot() function the linker doesn't know where to find the function shoot().

You need to declare a pointer to the CDemo class and call the shoot() function using it

CDemo *somevariable;

Then call the function from within the code as somevariable->shoot();

Hopefully I'm doing this correct. I'm still trying to dig into C++ from c background.
ViperGuy911
Posts: 31
Joined: Tue Apr 12, 2005 12:20 am

Post by ViperGuy911 »

Okay. In the begging of the code before int main() I added CDemo *file;
And in the event reciever I put when the mouse was left up file->shoot();
The rest of the code is the same. Is that right? Cuz I get this error message:

Code: Select all

C:\Documents and Settings\Tigran\My Documents\C++ TUTS\FPS\main.cpp(47) : error C2248: 'shoot' : cannot access private member declared in class 'CDemo'
        c:\documents and settings\tigran\my documents\c++ tuts\fps\cdemo.h(46) : see declaration of 'shoot'
Error executing cl.exe.
Thanks!
Post Reply