[lgpl] [1.0.22T5] Little change to raycaster

nargil

16-04-2009 21:06:34

To support non NxOgre objects... well in a very raw way. It's something I should not be proud of, nor expect anyone to use, nor to be merged with nxogre, but still LGPL is LGPL. It's a very lazy version of what could have been done ;)

I use it for NxCharacter

raycaster.cpp

std::vector<void*>& Raycaster::Voids()
{
return mVoids;
}

bool Raycaster::cast() {

NxRay ray(mOrigin, mNormal);

if (mActors.Size())
mActors.DestroyAll();

if (mVoids.size())
mVoids.clear();

if (mAccuracy == AC_Accurate)
return _castShape(ray);
else
return _castBounds(ray);

return false;

}

bool Raycaster::onHit(const NxRaycastHit& hit) {

if (hit.shape->getActor().userData == 0)
return true;

VoidPointer* vp = static_cast<VoidPointer*>(hit.shape->getActor().userData);

switch(vp->getType()) {

case NxOgreClass_Actor:
{
ActorRaycastHit* ahit = NxNew(ActorRaycastHit)(hit);
ahit->mActor = vp->toActor();
mActors.Insert(ahit);
}
break;

case NxOgreClass_Unknown:
mVoids.push_back(vp->Ptr);
break;

// else if (vp->getType() == NxOgreClass_Character)

// else if (vp->getType() == NxOgreClass_SimpleActor)

}

return true;
}


raycaster.h

class NxPublicClass Raycaster : public NxUserRaycastReport {
...
public:
...
std::vector<void*>& Voids();
...
protected:
...
std::vector<void*> mVoids;
...
}


usage in character creation:
desc.userData = (void*) new NxOgre::VoidPointer((void*)this, NxOgre::NxOgreClass_Unknown);

usage in getting back the "this" pointer:
static_cast<NxOgre::VoidPointer*>(...->userData)->Ptr

usage in raycasting:
same as for actors, but you call Voids() instead of Actors()

betajaen

16-04-2009 21:16:34

Very Lazy, But I like. :)

I got around this problem in BloodyMess, by forcing every NxActor pretending class to be a RigidBody.

nargil

18-04-2009 08:16:55

Actually this code is poitless
If the ray hits the NxCharacter capsule the following statemet is true
if (hit.shape->getActor().userData == 0)there is alos a hit->shape->userData, but I have no clue what it is ? It's definetly not the NxController* nor the passed NxCapsuleControllerDesc::userData. The question is: what in the 7 hells it is ? I haven't found anything in the physx documentation.

betajaen

18-04-2009 10:01:45

For the shape it's a 4 character string disguised as a pointer; Both the Boxes and Capsules have this, It's used for filtering.

boxDesc.userData = (void*)'CCTS';

As for the Actor; I'm not sure, I've scanned the source and it's not clear what it is.

nargil

18-04-2009 15:46:17


As for the Actor; I'm not sure, I've scanned the source and it's not clear what it is.

me neither, but it crashes with:
std::cout << hit.shape->getActor().getName() << std::endl; , so no valid actor at all. A wonder userData is always 0.

Novodex/Ageia people were sick...