I’m trying to use Raycast on a Scene’s Octree, and it’s not behaving as I expected so I think I am confused about how to set things up properly.
I have triangle meshes to fill the scene and to do this I basically follow sample 34_DynamicGeometry to fill the vertex buffers, calculate normals, etc., of a Model from scratch and then add it as a StaticModel – basically following 34_DynamicGeometry to the letter.
After the scene objects are loaded, here’s an example of how we try a raycast:
Ray myRay = Ray(Vector3(0,0,-20), Vector3(0,1,0));
PODVector results;
RayOctreeQuery query(results, myRay, RAY_TRIANGLE, 1000.0f, DRAWABLE_GEOMETRY);
scene_->GetComponent()->Raycast(query);
std::cout << "manual ray cast number of results= " << results.Size() << std::endl;
When there is a triangle mesh surface directly above (in the y-direction and well within 1000.0f) this point, we’re not finding any hits from the raycast. (And I’m pretty sure we’re casting from the correct points and that things are where we think they are.) Occasionally we do find hits, for some reason more frequently from queries originating near the origin.
We’ve experimented with putting just one triangle directly above a query point. We’ve tried flipping the orientation of the face(s). There’s something about the behaviour or the set up we are just not understanding.
Any tips? Rookie mistakes we should know about? Thanks,
cap.