triger event

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
thatax
Posts: 25
Joined: Thu Jul 31, 2008 7:33 am

triger event

Post by thatax »

just like quake,put an rotating weapon in the map, pick it up when the player close to ,how to triger ?
Ion Dune
Posts: 453
Joined: Mon Nov 12, 2007 8:29 pm
Location: California, USA
Contact:

Post by Ion Dune »

You'd have to do that yourself (perhaps with a custom scene node) or maybe, if you're lucky, you might find some relevant code by scouring this forum with the search function (no guarantees though).

If you're looking for ideas, I'd recommend checking the distance from the gun (which has a rotating animator) to the player, and when the distance is low enough, remove the node and add the gun to the player's inventory.
Dark_Kilauea
Posts: 368
Joined: Tue Aug 21, 2007 1:43 am
Location: The Middle of Nowhere

Post by Dark_Kilauea »

Some physics engines have a "Trigger Mesh" that will do the detection of two objects intersecting for you. PhysX has a trigger object with a callback. Havok has phantom objects that do the same thing.

Otherwise, you could use an AABBox to detect whether the bounding boxes of the player and the weapon are intersecting, then if they are, remove the weapon and add it to the player's inventory.
rogerborg wrote:Every time someone learns to use a debugger, an angel gets their wings.
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

The distance check would no doubt be the cheapest one to do, simpler than checking intersection with a box i should think, to be even more cheap you could use the squared distance to avoid the horrible square root operation and just check it against a squared distance threshold for how close the player needs to be to the object.

So basically, every frame:

Code: Select all

for each object of interest:
  if player distance from object less than threshold
    give the item to the player/whatever is required
Image Image Image
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

Image

Since the distanceSq check would treat both objects as points, presumably you'd be OK with using aabbox3d::isPointInside() as an alternative.

Code: Select all

		bool isPointTotalInside(const vector3d<T>& p) const
		{
			return (p.X > MinEdge.X && p.X < MaxEdge.X &&
				p.Y > MinEdge.Y && p.Y < MaxEdge.Y &&
				p.Z > MinEdge.Z && p.Z < MaxEdge.Z);
		}
That's at most 6 fp comparisons, with 5 opportunities for an early exit. Depending on your level topography, you could re-order the check to get more early exits.

Contrast with vector3df::getDistanceFromSq()

Code: Select all

		T getDistanceFromSQ(const vector3d<T>& other) const
		{
			return vector3d<T>(X - other.X, Y - other.Y, Z - other.Z).getLengthSQ();
		}


		T getLengthSQ() const { return X*X + Y*Y + Z*Z; }
Which is at least 3 fp subtractions, 3 fp multiplications, and 3 fp additions, in addition to any compiler-and-options dependent overhead from creating a temporary non-inlined vector3df on the stack plus another method call.

I know which one I'd rather use if I was concerned about performance.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Oooo smarty smarty mcsmarty pants face! :lol:

Good post though rogerborg, if i were a certain Ms. Hannigan i'd be that bit more inclined to let you in my delicates now!
Image Image Image
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

It's true, chicks flip for maths nerds. That, plus the obscenely high pay, is why guys are flocking to science subjects in record numbers.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Post Reply