heres what it looks like.
Code: Select all
Trigger.h
#if !defined(AFX_TRIGGER_H__C34EFEF3_49CB_4A1F_A5E6_710CF9E38969__INCLUDED_)
#define AFX_TRIGGER_H__C34EFEF3_49CB_4A1F_A5E6_710CF9E38969__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif
class Trigger
{
vector3df pos;
ISceneNode* node;
float dist;
void (* callback)();
public:
Trigger (vector3df,ISceneNode*,float,void(*)());
void eval();
};
#endif
Code: Select all
Trigger.cpp
#include "stdafx.h"
#include "Trigger.h"
Trigger::Trigger(vector3df NodePosition, ISceneNode* CameraNode,float Distance,void(*CallBackFunction)())
{
pos=NodePosition;
node=CameraNode;
dist=Distance;
callback=*CallBackFunction;
}
void Trigger::eval()
{
if((pos.getDistanceFrom(node->getPosition()))<=dist)
{
(*callback)();
}
}
Code: Select all
Trigger *r;
r=new Trigger(vector3df (0,5,0),Game.FPSCam,100,&shoot);
/*The first parameter is the trigger position , the second is a node that you want to check , the third is the radius and the last parameter is the address to a function.*/
while(Game.device->run())
{
r->eval();
Game.MainLoop();
}