a question about intersections

jchmack

27-01-2007 19:30:26

i have a class with a body and an intersection

class example
{
body *mBody;
intersection *mtarget;
}

im trying to find out when my body reaches the target. So each frame i run this.

mtarget->cast();
mtarget->iterator->find(mybodiesname);

but since the find() function returns a void i have no way of knowing whether the iterator is working right. Is there a way i can see if my body has reached its target? Am i doing this right? Is the intersection appropriate for this or is there a better method?

betajaen

27-01-2007 19:35:11

I'd use a Trigger for that sort of thing, at least then the Trigger notifies you when the body enters it, rather than you checking it.

jchmack

27-01-2007 19:37:28

I'd use a Trigger for that sort of thing, at least then the Trigger notifies you when the body enters it, rather than you checking it.

thx for the quick reply im on it.

jchmack

27-01-2007 20:04:12

hmm it seems that if i make a callback trigger then ANY target which enters it will be affected. The only object i want to be affected by this particular trigger should be the body in its class. Also im not seeing a way to remove this callback trigger when im done(at least through the scene or the trigger). Im thinking about trying to make a contact pair but that would leave a floating body for my target which other things could collide with.

each of these objects is going to have a different target. Im thinking that a trigger(that had to check for ANY target entering it) would become increasingly expensive as i begin to have alot of objects. I think i could just store the Target as a point(Vector3) and then just see if that point is in my body but a point might be too small to detect collisions accurately.

jchmack

27-01-2007 20:39:55

ok im seeing that my example may not provide enough information. Im trying to make a simple flocking AI. Each guy will have his own target. I want my guys to stop once they reach their own target. So once their body enters the target zone i just want to change their action state to stop.

betajaen

27-01-2007 21:04:54

Ahh then a intersection would be a better choice, it goes:

myIntersection = new intersection(new intersection::Sphere(whereEver, radius), mScene);

if (myIntersection->iterator->count() > 0) {
while(body* b = myIntersection->iterator->next()) {
if (b == theBodyIWant)
std::cout << "You win the game!!" << std::endl;
}
}


However your system may be implemented purely through the state system, which to be fair a lot of the code would be handled by NxOgre itself.

Ridhan

28-01-2007 17:58:57

I have a few questions about this sphericalIntersection. First i want to know if a character counts as a body and if an intersection can be reallocated each frame. The purpose of this is to have the spherical intersection to move along my character's sword to check if it hits another character. So it's a fairly small sphere i'm using.
Thanks.

jchmack

29-01-2007 06:04:49

I have a few questions about this sphericalIntersection. First i want to know if a character counts as a body and if an intersection can be reallocated each frame. The purpose of this is to have the spherical intersection to move along my character's sword to check if it hits another character. So it's a fairly small sphere i'm using.
Thanks.


From what i understand the character does count as a body, BUT I think that NXOgre must treat characters differently somehow because the raycaster doesnt seem to interact normally with characters:

http://www.ogre3d.org/phpBB2addons/viewtopic.php?t=3228

Im not sure (yet) about whether the characters interact with intersections properly but ill get back to you asap.

Im also not too sure what you mean by reallocating the intersection each frame... im assuming you mean repositioning it each frame. I don't see too much of a problem. The only problem i can see is if your sword swings too quickly you may need to use CCD. Im currently going to have to do the same thing in my app because as of now some of my faster moving objects will pass through each other if the path of the object's are orthogonal (or close to orthogonal) to the plane it is supposed to collide with. And as of now NXOgre doesn't seem to support CCD from what i can see in the tutorials. Id reccomend using that method to detect colisions if your sword is moving pretty slowly. And you would probably want to use a long box(or something that more resembles your sword). But if you plan to have a quick movement (as most games do) i would recommend just using a plane (or a circular plane) and assume that your sword movments are near instant. There is a tutorial somewhere on this using examples from Marvel vs capcom that shows this.

jchmack

29-01-2007 07:36:17

well i did some testing to see if the characters interacted with the intersections. And i get something interesting...

running this code:


mtarget->cast();

if (mtarget->iterator->count() > 0)
{
while(body* b = mtarget->iterator->next())
{

std::cout << "a projectile has entered" << std::endl;
//b->setIgnoreGravity(false);
}
}



if my character enters the intersection i get a crash...

but my projectile class works fine with the intersections. Anybody get similar results? Something is different with the character class as both the raycaster as well as the intersections are kinda buggy with them.

edit: Just running a cast() each frame and having the character enter the zone crashes it. If Ridhan didn't mention this i could have been in some trouble down the line when i had to replace a lot of my bodies with the character class.

betajaen

29-01-2007 10:07:53

I believe the crash is related to the iterator->next() casting the mActor->userdata as a body, when it should be a character.

So in a sense it does work, just NxOgre treats it wrong. You can get away with it, by using PhysX intersections directly and not use my intersection code until I come up with a solution.

To check if the Actor is an NxOgre body, use the mActor->getName() method which will return "NxB" if it is, anything else it would be an unknown NxActor, a Character, or a NxOgre particle.