Sorry for bumping my old thread, but I eventually got around to creating a weapon class and shooting... But the problem is, it doesn't shoot >.<
Here's the shooting functions (and its file)
Code: Select all
#include <OpenGL/OpenGL.h>
#pragma comment(lib, "libMacOSX.a")
#include <irrlicht.h>
#include "GCamera.h"
#include "GGameMain.h"
#include "GWeapon.h"
#include "resPath.h"
/*using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;*/
GWeapon::GWeapon() {
}
GWeapon::~GWeapon() {
}
void GWeapon::setupBullet() {
GGameMain::getSceneManager();
GCamera::getCamera();
}
void GWeapon::shootBullet( char** argv ) {
// Starting Point of shot //
vector3df startPos = GCamera::getCamera()->getPosition();
// End Point of Shot - must be normalized when shot //
vector3df endPos = ( GCamera::getCamera()->getTarget() - startPos );
// Whether the Shot Collides //
bool hitIsTrue = false;
endPos.normalize();
startPos += endPos*5.0f;
endPos = startPos + ( endPos*GCamera::getCamera()->getFarValue() );
/*******************************
* Used Determining Collision *
*******************************/
triangle3df tri;
line3d<f32> ray( startPos, endPos );
ITriangleSelector* collisionSelector;
if( GGameMain::getSceneManager()->getSceneCollisionManager()->getCollisionPoint( ray, collisionSelector, endPos, tri ) ) {
hitIsTrue = true;
vector3df temp = tri.getNormal();
temp.setLength(0.03f);
collisionVector = temp;
collisionPos = endPos;
} else {
//Doesn't collide with wall
endPos = ( GCamera::getCamera()->getTarget() - startPos );
endPos.normalize();
endPos = startPos + ( endPos*1000 );
}
ILightSceneNode* redLight = GGameMain::getSceneManager()->addLightSceneNode( 0, core::vector3df(0,0,0), video::SColorf(0.5f, 1.0f, 0.5f, 0.0f), 200.0f);
ISceneNodeAnimator* Anim = GGameMain::getSceneManager()->createFlyStraightAnimator( startPos, endPos, 1800, false );
redLight->addAnimator(Anim);
Anim->drop();
// attach billboard to the red light
ISceneNode* bill = GGameMain::getSceneManager()->addBillboardSceneNode(redLight, dimension2d<f32>(60, 60));
bill->setMaterialFlag(video::EMF_LIGHTING, false);
bill->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR);
bill->setMaterialTexture(0, GGameMain::getDriver()->getTexture( resPath( argv, "particlered.bmp"))); // needs to use getRes()
// add gray light
ISceneNode* grayLight = GGameMain::getSceneManager()->addLightSceneNode(0, vector3df(0,0,0), SColorf(1.0f, 0.2f, 0.2f, 0.0f), 200.0f);
// add fly fly straight animator to the gray light
Anim = GGameMain::getSceneManager()->createFlyStraightAnimator( startPos, endPos, 1800, false );
grayLight->addAnimator(Anim);
Anim->drop();
// attach billboard to light
bill = GGameMain::getSceneManager()->addBillboardSceneNode(grayLight, dimension2d<f32>(120, 120));
bill->setMaterialFlag(video::EMF_LIGHTING, false);
bill->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR);
bill->setMaterialTexture(0, GGameMain::getDriver()->getTexture( resPath( argv, "particlewhite.bmp" ))); //Needs resPath()
// add particle system
IParticleSystemSceneNode* shotParticle = GGameMain::getSceneManager()->addParticleSystemSceneNode(false, grayLight);
shotParticle->setParticleSize(dimension2d<f32>(30.0f, 40.0f));
// create and set emitter
IParticleEmitter* shotEmmiter = shotParticle->createBoxEmitter(
aabbox3d<f32>(-3,0,-3,3,1,3),
vector3df(0.0f,0.03f,0.0f),
80,100,
SColor(0,255,255,255), SColor(0,255,255,255),
400,1100 );
shotParticle->setEmitter(shotEmmiter);
shotEmmiter->drop();
// create and set affector
IParticleAffector* shotAffector = shotParticle->createFadeOutParticleAffector();
shotParticle->addAffector(shotAffector);
shotAffector->drop();
// adjust some material settings
shotParticle->setMaterialFlag(video::EMF_LIGHTING, false);
shotParticle->setMaterialTexture(0, GGameMain::getDriver()->getTexture( resPath( argv, "fireball.bmp" ))); //needs resPath()
shotParticle->setMaterialType(video::EMT_TRANSPARENT_VERTEX_ALPHA);
}
vector3df GWeapon::getCollisionOfBullet() {
return collisionPos;
}
Any idea why it doesn't work (I tried using the "flame" in the per pixel lighting tutorial)?
Edit - Oh, here is the code that checks whether space is pressed, and it should shoot
Code: Select all
//Shoot if mouse is clicked //
if ((event.EventType == EET_KEY_INPUT_EVENT &&
event.KeyInput.Key == KEY_SPACE &&
event.KeyInput.PressedDown == false) )
{
// setup shot
Player.gun.setupBullet();
// shoot
Player.gun.shootBullet( argv );
}