RayCasting

themadme

28-02-2008 14:34:12

Ummm, ok, im directly using physx to use raycasting. Somehow the ray cast does not update everyframe, always giving the same rayhit distance and such. Is there something I'm missing? or not doing right? Been looking at PhysX documents, which don't give out much information.


Ray.dir = RacerMaxStats[ NumRacer ].GravityVec;
Ray.orig = CurrentActor->getNxActor()->getCMassGlobalPosition();

Hit = PhysicsScene->getNxScene()->raycastClosestShape( Ray, NX_STATIC_SHAPES, RayHit );

if( Hit )
{
if( RayHit.distance < MAXDISTANCE )
{
return true;
}
}

help would be very much appreciated for this newbie :roll:

Dutchie

28-02-2008 15:53:12

i do it like this:


NxOgre::RayCaster *RAY = new NxOgre::RayCaster(Origin, Direction, Distance ,NxOgre::RayCaster::RCT_CLOSEST, PhysXScene);

RAY->castShape(NxOgre::RayCaster::AF_NONE);
if(RAY->mReport.count() > 0) {
do things...
}


thanks to Caphalor and nullsquared for helping me solve my "problem". i hope it will help you too :)

themadme

28-02-2008 23:52:58

thanks for the reply.

Ok so i use the NxOgre for the raycasting ( too use to programming in PhysX alone, NxOgre is soo useful )

Anyway, umm you see what im trying to do is where i have an object trying to detect if there is a certain type of ground below the object.

If there is ground below, I need to get the normal of that ground, and use it to create a force on the object to move it down towards it.

Then i need to check to see if the object is at a certain distance above the ground, using the raycasting still, where it will return true.

this is what i got so far



Ray = new NxOgre::RayCaster( CurrentActor->getCMassGlobalPosition(), CurrentActor->getCMassGlobalPosition(),
fMAXRAYDISTANCE, NxOgre::RayCaster::RCT_CLOSEST, PhysicsScene );

Ray->castShape( NxOgre::RayCaster::AF_STATIC_ONLY );

if( Ray->getClosestRaycastHit().mRaycastHit.shape )
{

// code right below does not seem to give out the correct normal values that i would wish for

RacerMaxStats[ NumRacer ].GravityVec = NxOgre::toVector3( Ray->getClosestRaycastHit().mRaycastHit.worldNormal ) * fGRAVITY;

// and this does not work out either
if( Ray->getClosestRaycastHit().mRaycastHit.distance < fMAXRACERDISTANCE )
{
return true;
}
}
else
{
RacerMaxStats[ NumRacer ].GravityVec = Ogre::Vector3( 0.0, 0.0, 0.0 );
}

return false;


Anyone with any ideas?