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
raycaster.h
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()
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()