jeremywilms
30-11-2009 05:52:25
I want to be able to translate my actor locations. So I am using raycastClosestBounds, casting a ray from a given face of the actor to check if it is touching another actor in the scene, thus telling me if I should translate the actor in that direction or not.
However, I noticed whenever I cast a ray to return the closest actor the ray hits, and there are no actors for it to hit, I get an exception.
I'm looking at the source, it's thrown on the second reference to NxShape(Memory access violation). I'm assuming NxShape is pointing to a region of memory that cannot be read. Further I can assume that mScene->raycastClosestBounds() is returning null, as in, nothing hit by ray(although I haven't checked s oI may be wrong.) I'm tempted to go into the source and override the method(Where it returns a int(-1 for fail, 1 for success), requring a parameter referencing a RaycastHit object to be altered according to the most recent hit)
PhysXPointer* shapePointer = pointer_cast(nxShape->userData);
However, I noticed whenever I cast a ray to return the closest actor the ray hits, and there are no actors for it to hit, I get an exception.
I'm looking at the source, it's thrown on the second reference to NxShape(Memory access violation). I'm assuming NxShape is pointing to a region of memory that cannot be read. Further I can assume that mScene->raycastClosestBounds() is returning null, as in, nothing hit by ray(although I haven't checked s oI may be wrong.) I'm tempted to go into the source and override the method(Where it returns a int(-1 for fail, 1 for success), requring a parameter referencing a RaycastHit object to be altered according to the most recent hit)
PhysXPointer* shapePointer = pointer_cast(nxShape->userData);
RaycastHit Scene::raycastClosestBounds(const Ray& ray, Enums::ShapesType type, unsigned int group, Real maxDistance, unsigned int hintFlags) const
{
NxRay inRay;
Functions::XYZ<Vec3, NxVec3>(ray.mDirection, inRay.dir);
Functions::XYZ<Vec3, NxVec3>(ray.mOrigin, inRay.orig);
NxRaycastHit hit;
NxShape* nxShape = mScene->raycastClosestBounds(inRay, NxShapesType(int(type)), hit, group, maxDistance, hintFlags, 0);
RaycastHit out;
out.mDistance = hit.distance;
out.mFaceID = hit.faceID;
out.mFlags = hit.flags;
out.mInternalFaceID = hit.internalFaceID;
out.mMaterialIndex = hit.materialIndex;
out.mU = hit.u;
out.mV = hit.v;
Functions::XYZ<NxVec3, Vec3>(hit.worldImpact, out.mWorldImpact);
Functions::XYZ<NxVec3, Vec3>(hit.worldNormal, out.mWorldNormal);
PhysXPointer* shapePointer = pointer_cast(nxShape->userData);
out.mShape = shapePointer->get<Shape>();
out.mRigidBody = shapePointer->getParent<RigidBody>();
return out;
}