disable shapes from raycasting

recon

03-10-2009 21:06:08

Ok since some of my questions in this thread http://www.ogre3d.org/addonforums/viewtopic.php?f=6&t=11149 where left unanswered I thought of a workaround, namely setting the ShapeFlags_DisableRaycasting flag to true for all shapes that should be excluded from a ray cast. But it simply doesn't work, the raycastClosestShape() still returns shapes with disabled raycasting :?

So what am I doing wrong?

betajaen

03-10-2009 21:24:18

You could always use a callback to manually filter the raycast yourself, otherwise have you tried a GroupMask?

recon

03-10-2009 22:53:41

You could always use a callback to manually filter the raycast yourself

Perhaps, could you maybe give me a simple code example of how this would work?

Have you tried a GroupMask?

Yes but as I stated in the previous thread it didn't work as I expected, could you explain how I would, and I quote myself, "perform a ray cast on all shapes and, for example, exclude all actor/shapes of group id 2 and 3"

Also, I did some testing and I found that setting ShapeFlags_DisableRaycasting flag to true only does something before the actor is created, later when I try to do the same thing while the game is running nothing changes by looping through mShapes of NxOgre::Actor calling setFlag(...). Are we not supposed to be able to change the shape's flag's anywhere in the code?

Hope I'm not being a pain for you, all this PhysX stuff is all new to me =P

betajaen

03-10-2009 23:30:27

Perhaps, could you maybe give me a simple code example of how this would work?

Sure. Roughly it goes:

class raycast_callback : public NxOgre::Callback
{
public:
void onHitEvent(const RaycastHit& hit)
{
return (your_check_here_using_hit) // return false to break
}
};


raycast_callback callback;
mScene->raycastAllBounds(ray, &callback, ....);




Yes but as I stated in the previous thread it didn't work as I expected, could you explain how I would, and I quote myself, "perform a ray cast on all shapes and, for example, exclude all actor/shapes of group id 2 and 3"

Unfortantly, I'm not sure on GroupMasks. But I don't know if you noticed (I found it buried away in an example) but the groups option should be like this;

//note: 1 means to only hit group 0 objects (1<<0).
NxShape * s = gScene->raycastClosestShape(NxRay(jetWorldPos, down), NX_ALL_SHAPES, hit, 1, 1.0f, NX_RAYCAST_SHAPE|NX_RAYCAST_DISTANCE);


So pass on 1 as the "groups" parameter in raycast. If you know this already dis-regard, and just do my callback above.


Also, I did some testing and I found that setting ShapeFlags_DisableRaycasting flag to true only does something before the actor is created, later when I try to do the same thing while the game is running nothing changes by looping through mShapes of NxOgre::Actor calling setFlag(...). Are we not supposed to be able to change the shape's flag's anywhere in the code?

No, you can change the flags. But TBH I don't know the specifics of setting each flag after the shape has been created, I haven't sat down and tested them.

Hope I'm not being a pain for you, all this PhysX stuff is all new to me =P

Nope. It's okay; At least your trying and giving me lots of history to work with. ;)

recon

03-10-2009 23:40:08

Thanks a bunch, this is probably enough to get me going.
I'll start off with callbacks, see if it works any better :)

recon

04-10-2009 03:05:25

I found a problem using callbacks as you suggested, the RaycastHit's seems to be giving me bogus pointers to the mShape and mRigidBody, and there seems to be no parameter that makes those pointers set :?
What gives?

recon

04-10-2009 16:28:54

I just found this http://developer.nvidia.com/forums/index.php?showtopic=1508 and that's the exact same problem I'm having.

Two solutions explained where
solution a: Fire your ray a delta outside the gun. So the ray will not intersect your player.
solution b: Insert your player in a group, insert all the other player into another group and all the IA controlled character in another group. You don't need a group for every player. In that way, IA character can't hit each other, but I hope they are not that dumb.


Solution A wouldn't work in my case, so I thought I'd go with B. Only problem is I don't fully understand what he means nor how to implement it :?
What is "IA controlled characters"? And what parameters would I send to the raycastClosestShape(...) to make it work?
It seems so weird that there are no simple solution for what I am trying, I just want to ignore a few actors when doing raycastClosestShape() :|
I'll continue testing, but if anyone has any insight on this please do share your solution :roll:

recon

05-10-2009 01:20:01

Finally! I got my first workaround to do the job :D
Basically I just changed this:


for(unsigned int i=0; i<mShapeHandles.size(); ++i)
{
mShapeHandles[i]->setFlag(ShapeFlags_DisableRaycasting, true); // wont do shit >.<
}


to this:


for(unsigned int i=0; i<mShapeHandles.size(); ++i)
{
GetActor()->getNxActor()->getShapes()[i]->setFlag((NxShapeFlag)ShapeFlags_DisableRaycasting, true); // now this works everywhere in my code ^^
}


It's a bit of a hack, but at least it works :wink: