christian.wolf2 Posted July 1, 2019 Posted July 1, 2019 Hello, I am currently having an issue to find the surface of an object, a line is currently intersecting with. My code is a small tweak from the VR-demo and looks as followed: vec3 view_dir = VRPlayer::get()->getHead()->getWorldDirection(); vec3 pb = vec3(VRPlayerVR::get()->getHandNode(0)->getWorldPosition()) + VRPlayerVR::get()->getHandNode(0)->getWorldDirection(Math::AXIS_Y) * 0.05; vec3 pe = pb + VRPlayerVR::get()->getHandNode(0)->getWorldDirection(Math::AXIS_Y) * 50; vec3 dir = normalize(pe - pb); vec3 right = cross(view_dir, dir); Unigine::Vector<ObjectPtr> intersectionObjects; int foundObjects = World::get()->getIntersection(Vec3(pb), Vec3(pe), intersectionObjects); if (foundObjects) { bool foundSurface = false; for (int i = 0; i < intersectionObjects.size(); ++i) { for (int surface = 0; surface < intersectionObjects[i]->getNumSurfaces(); ++surface) { ObjectIntersectionPtr intersection = ObjectIntersection::create(); if (intersectionObjects[i]->getIntersection(pb, pe, intersection, surface)) { //we found the surface if (isObjectNodeToChangeMaterialFor(intersectionObjects[i])) { selectedObject = intersectionObjects[i]; foundSurface = true; break; } } } if (foundSurface) break; } if (foundSurface) selectionRay->setMaterial(rayMaterialGreen, 0); else selectionRay->setMaterial(rayMaterialWhite,0); } What I am trying to achieve is to check in my first step the number of objects, I am intersecting with. After that, I am iterating through each objects surface and check, which surface will be the right one. I am using no intersection mask. The current problem is, that I didn't get any valid surface, even if the intersectionObjects-list contains multiple ones, so I guess the World::getIntersection()-function are different from Object::getIntersection() regarding surface intersection. Or am I missing something?
andrey-kozlov Posted July 2, 2019 Posted July 2, 2019 Hello Christian, Object::getIntersection expects points in local space and you provide them in world space. You could use Object::getIWorldTransform to transform them.
christian.wolf2 Posted July 3, 2019 Author Posted July 3, 2019 Hello andrey, many thanks, using the getIWorldTransform indeed does the trick.
Recommended Posts