Jump to content

[SOLVED] World::getIntersection and Object::getIntersection


photo

Recommended Posts

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?

Link to comment

Hello Christian,

Object::getIntersection expects points in local space and you provide them in world space. You could use Object::getIWorldTransform to transform them.

Link to comment
  • silent changed the title to [SOLVED] World::getIntersection and Object::getIntersection
×
×
  • Create New...