Ogrenewt collision response problems.

Evak

19-08-2006 05:14:21

Hi, We have an Ogre wrapper for blitzmax that includes ogrenewt. We spent a couple of days porting out game Aerial Antics to our ogre based engine.



http://s93153354.onlinehome.us/AA2.wmv

So far we have been really happy with newton but we have come accross one major stumbling block. We now need to be able to drop bombs on target platforms and be able to get collision feedback from newton, so we know what collided with what.

Our lead programmer is stumped and were now about to jump ship and use ODE instead. Here's a last ditch attempt at trying to discover whether there is a solution to our problem. Any help with this would be a GREAT help. Were not too excited about the prospect of having to redo a large chunk of the engine again.

Hopefully something will turn up and I can get the info back to our engine technical coder.

We really like ogre newt and want to continue using it :)

HexiDave

19-08-2006 07:24:31

Check the documentation for Materials and MaterialPairs - fairly sure that's what you're looking for. Should be able to set a contact callback so when a bomb of MaterialID 0 hits a target of MaterialID 1, it'll do one thing while contacting ground MaterialID 2 might do something else.

walaber

19-08-2006 07:25:26

Newton (and OgreNewt) have a very powerful collision response system. it is achieved through setting Materials on objects, and then creating callbacks for when objects of a specific pair of materials collide.

in the case of OgreNewt, you have to inherit from the "ContactCallback" class, and create 3 functions: "userBegin", "userProcess" and "userEnd".

here's what happens:

during OgreNewt::World::update(), it moves all of the bodies, and then checks for collision. when it does, it calls your callbacks for you, like so:

userBegin this is called if the AABB of the 2 bodies in question overlap during tis frame. this does NOT mean that they will necessarily collide, but there's a good chance. at this point, if you return "true" from the function, it tells Newton you want to kee processing this possible collision. if you return "false", it will not process the actual collision, and skip onto the next bodies to collide.

userPrcess this is called for every discreet contact between the 2 bodies. in most cases this will only be once, but in some cases you may get more than one contact per update(). anyway, inside this function you can get lots of information about the contact (contact normal, speed of collision along the normal, tangent vectors, etc). you can also alter the collision here (set a custom friction setting for this collision, apply acceleration along the contact normal, etc). again, returning "true" from this function tells Newton to accept this contact, "false" ignores it (the bodies will not collide, they will interpenetrate).

userEnd is called after all of the contacts have been processed, to give you a chance to "act" on the information gathered above. generally you would want to keep track of the contact info from the above calls, and in here do something with that data... so in your case, this is where you might want to tell your game logic that 1 object hit another object, and give it the point of impact, etc. most people also play collision sound effects at this point, with the volume scaled by the largest contact speed found in the previous callbacks.


anyway, it's actually quite simple, and extremely powerful. I use it a lot in Stunt Playground, so if you want to download the source to that and have a look, be my guest. There is also a simple demo that comes with OgreNewt (the conveyor belt demo). that demo alters the contacts, but you can see how you can use those same callbacks to simply register collision as well.

hope that helps.

[edit]
P.S. I played Ariel Antics back when I was coding with Dark Basic Pro- that was a really well done game! good luck on the remake with Ogre, the video is already very impressive.