And I'd like Alyson Hannigan oiled up and duct-taped to my bed, but life is cruel.robertgarand wrote:Then I would just have to "throw" the shell and wait for impact with the collision manager
You can use a collision response animator, but it might not do everything that you want. Remember that Irrlicht is a 3d engine, not a game engine.
Code: Select all
#include <irrlicht.h>
#include <iostream>
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
#ifdef _IRR_WINDOWS_
#pragma comment(lib, "Irrlicht.lib")
#endif
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_MOUSE_INPUT_EVENT)
{
if(EMIE_LMOUSE_PRESSED_DOWN == event.MouseInput.Event)
LeftButtonIsDown = true;
else if(EMIE_LMOUSE_LEFT_UP == event.MouseInput.Event)
LeftButtonIsDown = false;
}
return false;
}
// This is used to check whether a key is being held down
virtual bool IsLeftButtonDown() const
{
return LeftButtonIsDown;
}
MyEventReceiver()
{
LeftButtonIsDown = false;
}
private:
bool LeftButtonIsDown;
};
int main()
{
MyEventReceiver receiver;
IrrlichtDevice *device = createDevice(EDT_OPENGL, core::dimension2d<s32>(800, 600));
device->setEventReceiver(&receiver);
video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
device->getFileSystem()->addZipFileArchive("../../media/map-20kdm2.pk3");
scene::IAnimatedMesh* mesh = smgr->getMesh("20kdm2.bsp");
scene::ISceneNode* world = smgr->addOctTreeSceneNode(mesh->getMesh(0), 0, -1, 128);
world->setPosition(core::vector3df(-1300,-144,-1249));
ICameraSceneNode * camera = smgr->addCameraSceneNodeFPS();
camera->setPosition(core::vector3df(20,10,20));
device->getCursorControl()->setVisible(false);
IBillboardSceneNode * projectile = smgr->addBillboardSceneNode();
projectile->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR );
projectile->setMaterialTexture(0, driver->getTexture("../../media/particle.bmp"));
projectile->setMaterialFlag(video::EMF_LIGHTING, false);
projectile->setSize(core::dimension2d<f32>(20.0f, 20.0f));
ITriangleSelector * selector = smgr->createOctTreeTriangleSelector(mesh->getMesh(0), world);
ISceneNodeAnimatorCollisionResponse * cameraAnimator
= smgr->createCollisionResponseAnimator(selector, camera, vector3df(30, 60, 30),
vector3df(0, -0.1f, 0));
camera->addAnimator(cameraAnimator);
cameraAnimator->drop();
ISceneNodeAnimatorCollisionResponse * projectileAnimator
= smgr->createCollisionResponseAnimator(selector, projectile, vector3df(5, 5, 5),
vector3df(0, -0.1f, 0));
selector->drop();
projectile->addAnimator(projectileAnimator);
projectileAnimator->drop();
projectile->setVisible(false);
f32 const PROJECTILE_SPEED = 200.f;
u32 then = device->getTimer()->getTime();
vector3df flightVector(0,0,0);
while(device->run())
{
u32 now = device->getTimer()->getTime();
f32 delta = (now - then) / 1000.f;
then = now;
if(!projectile->isVisible() && receiver.IsLeftButtonDown())
{
flightVector = PROJECTILE_SPEED * (camera->getTarget() - camera->getAbsolutePosition()).normalize();
projectile->setPosition(camera->getAbsolutePosition());
projectile->updateAbsolutePosition();
projectile->setVisible(true);
}
driver->beginScene(true, true, video::SColor(0,200,200,200));
smgr->drawAll();
driver->endScene();
if(projectile->isVisible())
{
// If the projectile isn't falling, it's hit the ground
if(!projectileAnimator->isFalling())
{
projectile->setVisible(false);
}
else
{
projectile->setPosition(projectile->getAbsolutePosition() + flightVector * delta);
projectile->updateAbsolutePosition();
}
}
}
device->drop();
return 0;
}