I am new here and I searched for the forum but didn`t found any result. three days further without any progress I think it is time to get some help. I have the folowing code:
shoot.cpp
Code: Select all
/* Created by --------
Date created: 17-4-2008
Using irrlicht game engine
*/
//Including the files
//defining the namespaces to acces easier
//Including the dll file
//Defining variables
struct SParticleImpact
{
u32 when;
core::vector3df pos;
core::vector3df outVector;
core::array<SParticleImpact> Impacts;
};
//ITriangleSelector* mapSelector;
core::array<SParticleImpact> Impacts;
//Defining functions
void shoot()
{
ISceneManager* sm = device->getSceneManager();
ICameraSceneNode* camera = sm->getActiveCamera();
ISceneNode* selectedSceneNode = 0;
ISceneNode* lastSelectedSceneNode = 0;
selectedSceneNode = sm->getSceneCollisionManager()->getSceneNodeFromCameraBB(camera);
SParticleImpact imp;
imp.when = 0;
vector3df start = camera->getPosition();
vector3df end = (camera->getTarget() - start);
end.normalize();
start += end*8.0f;
end = start + (end * camera->getFarValue());
triangle3df triangle;
line3d<f32> line(start, end);
// get intersection point with map
if (sm->getSceneCollisionManager()->getCollisionPoint(line, selector, end, triangle ))
{
// collides with wall
vector3df out = triangle.getNormal();
out.setLength(0.03f);
imp.when = 1;
imp.outVector = out;
imp.pos = end;
}
else
{
// doesnt collide with wall
core::vector3df start = camera->getPosition();
core::vector3df end = (camera->getTarget() - start);
end.normalize();
start += end*8.0f;
end = start + (end * camera->getFarValue());
}
// create fire ball
fire = sm->addBillboardSceneNode(0,
core::dimension2d<f32>(25,25), start);
fire->setMaterialFlag(video::EMF_LIGHTING, false);
fire->setMaterialTexture(0, device->getVideoDriver()->getTexture("C:/Gaming/irrlicht-1.4/media/fireball.bmp"));
fire->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);
fire->addAnimator(anim);
anim->drop();
anim = sm->createDeleteAnimator(time);
fire->addAnimator(anim);
anim->drop();
if(collisionB(fire, enemy))
{
printf("Enemy hit\n");
}
if (imp.when)
{
// create impact note
imp.when = device->getTimer()->getTime() + (time - 100);
Impacts.push_back(imp);
}
}
//Defining classes
Code: Select all
/* Created by -----------
Date created: 8-4-2008
Using irrlicht game engine
*/
//Including the files
#include "main.h"
#include "collision.h"
#include "shoot.h"
#include "keys.h"
#include <irrlicht.h>
//defining the namespaces to acces easier
using namespace irr;
//Including the dll files
//Defining functions
// Defining variables
ISceneNode* sphere; //draws cube in scene
//Defining classes
int main()
{
device = createDevice(EDT_DIRECT3D9, //Creating the irrlicht device with direct3D
dimension2d<s32>(screenW,screenH), //Size of window declared in main.h
64, //Bits per pixel in fullscreen mode
false, //Fullscreen true or false
false, //Stencil buffer shadows
false, //Vertical sync
0); //User defined receiver
device->setWindowCaption(L"Hero project"); //Setting the title of the window
MyEventReceiver receiver; //This is the event receiver for moving the camera
device->setEventReceiver(&receiver); //Set the receiver to the device
IVideoDriver* driver = device->getVideoDriver(); //Easier to access video driver
ISceneManager* smgr = device->getSceneManager(); //Easier to access Scenemanager
IGUIEnvironment* guienv = device->getGUIEnvironment(); //Easuer to access GUI Environment
//Mapping the correct keys for moving the camera
SKeyMap keyMap[8];
//Forward
keyMap[1].Action = EKA_MOVE_FORWARD;
keyMap[1].KeyCode = KEY_KEY_W;
//Backward
keyMap[2].Action = EKA_MOVE_BACKWARD;
keyMap[2].KeyCode = KEY_KEY_S;
//Strafe left
keyMap[3].Action = EKA_STRAFE_LEFT;
keyMap[3].KeyCode = KEY_KEY_A;
//Strafe right
keyMap[4].Action = EKA_STRAFE_RIGHT;
keyMap[4].KeyCode = KEY_KEY_D;
//Jump
keyMap[5].Action = EKA_JUMP_UP;
keyMap[5].KeyCode = KEY_SPACE;
device->getFileSystem()->addZipFileArchive("C:/Gaming/irrlicht-1.4/media/map-20kdm2.pk3"); //Load quake map
IAnimatedMesh* qMap = smgr->getMesh("20kdm2.bsp");//Load mesh from zip file above
for(int x=0; x<KEY_KEY_CODES_COUNT; x++) //For key handling
keys[x] = false;
ISceneNode* scene = 0; //Load a scene node
if(qMap)
scene = smgr->addOctTreeSceneNode(qMap->getMesh(0)); //Add scene node for rendering
if (scene)
{
scene->setPosition(vector3df(-1300, -144, -1229)); //Translate the level
selector = smgr->createOctTreeTriangleSelector(qMap->getMesh(0), scene, 128); //Optimize the scene draw only geometry
scene->setTriangleSelector(selector); //Set triangle selector for collission detection
}
ICameraSceneNode* camera = camera = smgr->addCameraSceneNodeFPS(0, 250.0f, 400.0f, 0, keyMap, 8, false, 0.5f);//Add a camera to the scene manager on the given position
camera->setPosition(vector3df(100, 100, 100)); //Change camera position
//Calculate the radius of the scene node
const core::aabbox3d<f32>& box = camera->getBoundingBox();//returns the axis of the node
core::vector3df radius = box.MaxEdge - box.getCenter();//Write the axis to a vector3df
//Animate a scene node for collision
if(selector)
{
ISceneNodeAnimator* anim = smgr->createCollisionResponseAnimator(//Create collision detection
selector, //With the triangle selector
camera, //Manipulate the camera node so it cannot walk thru walls
vector3df(radius.X+29,radius.Y+49,radius.Z+5), //Collission detection and response (radius)
vector3df(0,-2.0f,0), //Gravity per second xYz
vector3df(0,30,0)); //Ellipsoid for collision detection
selector->drop();
camera->addAnimator(anim); //Animate camera with the scene node
anim->drop();//Drop the animator
}
device->getCursorControl()->setVisible(false);//Set the visability for the mouse cursor
// add 3 animated faeries.
video::SMaterial material;
material.setTexture(0, driver->getTexture("C:/Gaming/irrlicht-1.4/media/faerie2.bmp"));
material.Lighting = true;
scene::IAnimatedMesh* faerie = smgr->getMesh("C:/Gaming/irrlicht-1.4/media/faerie.md2");
enemy = smgr->addAnimatedMeshSceneNode(faerie);
enemy->setPosition(core::vector3df(100,0,150));
enemy->setMD2Animation(scene::EMAT_RUN);
enemy->getMaterial(0) = material;
material.setTexture(0, 0);
material.Lighting = false;
// Add a light
smgr->addLightSceneNode(0, core::vector3df(100,0,280),
video::SColorf(1.0f,1.0f,1.0f,1.0f),
10000.0f);
//Makes a skybox for nice surrounding
ISceneNode* SkyBox = smgr->addSkyBoxSceneNode
(
driver->getTexture("C:/Gaming/irrlicht-1.4/media/irrlicht2_up.jpg"),
driver->getTexture("C:/Gaming/irrlicht-1.4/media/irrlicht2_dn.jpg"),
driver->getTexture("C:/Gaming/irrlicht-1.4/media/irrlicht2_ft.jpg"),
driver->getTexture("C:/Gaming/irrlicht-1.4/media/irrlicht2_bk.jpg"),
driver->getTexture("C:/Gaming/irrlicht-1.4/media/irrlicht2_rt.jpg"),
driver->getTexture("C:/Gaming/irrlicht-1.4/media/irrlicht2_lf.jpg")
);
//Infinity loop to draw everything
while(device->run())
{
if( keys[KEY_KEY_X])
{
shoot();
/*while(fire)
{
fire->setPosition(fire->getPosition());
fire->updateAbsolutePosition();
printf("pos X:%2.4f\n, pos Y:%2.4f\n, pos Z:%2.4f\n", fire->getAbsolutePosition().X, fire->getAbsolutePosition().Y, fire->getAbsolutePosition().Z);
}*/
}
driver->beginScene(true, true, SColor(255,100,101,140)); //Must draw between begin and end. Begin drawing
//////////////////////////////////////////////////////////////Begin drawing
smgr->drawAll(); //Scenemanager drawing
//Draw crosshair
driver->draw2DRectangle( SColor(255,255,255,255), rect<s32>(cenW,cenH-8,cenW+2,cenH-3) ); //above
driver->draw2DRectangle( SColor(255,255,255,255), rect<s32>(cenW+5,cenH,cenW+10,cenH+2) ); //right
driver->draw2DRectangle( SColor(255,255,255,255), rect<s32>(cenW,cenH+5,cenW+2,cenH+10) ); //down
driver->draw2DRectangle( SColor(255,255,255,255), rect<s32>(cenW-8,cenH,cenW-3,cenH+2) ); //left
driver->draw2DRectangle( SColor(255,255,255,255), rect<s32>(cenW,cenH,cenW+2,cenH+2) ); //center of screen
guienv->drawAll(); //Gui environment drawing
//////////////////////////////////////////////////////////////End drawing
driver->endScene(); //Stop drawing
}
device->drop();
return 0;
}
Code: Select all
/* Created by ---------
Date created: 17-4-2008
Using irrlicht game engine
*/
//Including the files
//defining the namespaces to acces easier
//Including the dll file
//Defining variables
//Defining functions
bool collision(ISceneNode* one, ISceneNode* two, int size) {
if(one->getPosition().getDistanceFrom(two->getPosition()) < size)
return true;
return false;
}
bool collisionB(ISceneNode* one, ISceneNode* two) {
if(one->getTransformedBoundingBox().intersectsWithBox(two->getTransformedBoundingBox()))
return true;
return false;
}
//Defining classes
Code: Select all
/* Created by ----------
Date created: 17-4-2008
Using irrlicht game engine
*/
//Including the files
#include <irrlicht.h>
#include <stdio.h>
#include <wchar.h>
//defining the namespaces to acces easier
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
//Including the dll file
#pragma comment(lib, "Irrlicht.lib")
//Defining variables
bool keys[irr::KEY_KEY_CODES_COUNT];//For key handling
IrrlichtDevice *device;
ITriangleSelector* selector=0;
IAnimatedMeshSceneNode* enemy = 0;
ISceneNode* fire = 0;
int screenW = 800;
int screenH = 600;
int cenW = screenW / 2;
int cenH = screenH / 2;
//Defining classes
class main : public IEventReceiver
{
public:
virtual bool OnEvent(const SEvent& event);
private:
};
class MyEventReceiver: public IEventReceiver
{
public:
virtual bool OnEvent(const SEvent& event)
{
if(event.EventType == irr::EET_KEY_INPUT_EVENT)
{
keys[event.KeyInput.Key] = event.KeyInput.PressedDown;
return false;
}
return false;
}
};
The wall collision is good that works great but the enemy collision doesnt work. maybe some sugestion where I can think about thanks in advanced

