Sign in to follow this  
Deliverance

Newton collision of a ray and a sphere, when ray origin is inside sphere

Recommended Posts

This does not seem to work. Newton does not report a collision when ray origin is inside the sphere. Is there any workaround for this? I need this info for simulating refractions in a raytracer. Here's the code i'm using:
Vector3D normalGlobal;
float tGlobal = 10000000000.0f;
tMaterial* pMaterial = NULL;

dFloat RayCastPlacement (const NewtonBody* body, const dFloat* normal, int collisionID, void* userData, dFloat intersetParam)
{
	printf("sadfffffffffffffffffffffff\n");
	if (intersetParam < tGlobal)
	{
		tGlobal = intersetParam;
		normalGlobal.x = normal[0];
		normalGlobal.y = normal[1];
		normalGlobal.z = normal[2];
		pMaterial = (tMaterial*)NewtonBodyGetUserData(body);
	}

	return intersetParam;
}

collisionInfo RayTracer::GetClosestHit(const tRay &ray)
{
	collisionInfo closestCollPoint;
	closestCollPoint.t = 2.0f;
	closestCollPoint.isCollision = false;
		
	tGlobal = 10000000000.0f;
	Vector3D s = ray.origin;
	Vector3D d = ray.origin+ray.dir;
	NewtonWorldRayCast(nWorld, &s.x, &d.x, RayCastPlacement, NULL, NULL);
		
	if (tGlobal < 10000000000.0f)
	{
		closestCollPoint.t = tGlobal;
		closestCollPoint.isCollision = true;
		closestCollPoint.normal = normalGlobal;
		closestCollPoint.intersection =  s + ray.dir * tGlobal;		
		closestCollPoint.material = pMaterial;
		currentObjectHit = int(pMaterial);
	}

	return closestCollPoint;
}

Share this post


Link to post
Share on other sites
You might create two copies of each triangle, the second copy having a connectivity that is reversed. The idea is that the ray trace probably might be skipping intersections when the dot product of the ray direction and the triangle outward-facing normal is positive, e.g., it explicitly only looks for hits that occur from the outside going in. The duplicate triangles would make the thing think both sides are outside. It might work, anyway. But, that might confuse your raytracer, e.g., how then do you know which material your ray is exiting and which it is entering, if you always think you're on the outside of the sphere? Having two copies of the entire sphere might work, e.g, two geometries for each body. Then attach user data to both, labeling the one that is flipped....make sense?

Share this post


Link to post
Share on other sites
Why don't you ask this in dedicated ofical newton forum?

Also, newton is a physics engine, and while i saw some amazing raytracing done already in newton (check the newton forum), it probably doesn't register hits going from inside out because it's a physics engine and it discards such hits because of optimization, in physical world everything has a inside and outside..

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this