Ray test for bouncing particles

B_old
Posts: 79
Joined: Tue Sep 26, 2006 1:10 pm

Ray test for bouncing particles

Post by B_old »

Hi,

I'm trying to render particles that bounce of surfaces defined in the physics world using rayTest(). It is more or less working, but I always have the feeling that I don't correctly reposition a particle when I detect that it will hit a surface this frame.
Am I using rayTest() correctly?

Code: Select all

/*
rayOrg is where the ray starts
rayDir is the normalized direction of the ray
t will tell me where on the ray I hit a surface
pos will tell me where I hit a surface, rayOrg + t * rayDir == pos ???
norm will tell me the normal of the surface I hit
*/
bool PhysicsSimulation::rayTest(const Vector3 &rayOrg, const Vector3 &rayDir, float &t, Vector3 &pos, Vector3 &norm) const
{
	btCollisionWorld::ClosestRayResultCallback resultCallback(btVector3(rayOrg.x, rayOrg.y, rayOrg.z), btVector3(rayDir.x, rayDir.y, rayDir.z));


	m_dynamicsWorld->rayTest(btVector3(rayOrg.x, rayOrg.y, rayOrg.z), btVector3(rayDir.x, rayDir.y, rayDir.z), resultCallback);

	pos = Vector3(resultCallback.m_hitPointWorld[0], resultCallback.m_hitPointWorld[1], resultCallback.m_hitPointWorld[2]);
	norm = normalized(Vector3(resultCallback.m_hitNormalWorld[0], resultCallback.m_hitNormalWorld[1], resultCallback.m_hitNormalWorld[2]));

	t = resultCallback.m_closestHitFraction;

	return resultCallback.hasHit();
}
B_old
Posts: 79
Joined: Tue Sep 26, 2006 1:10 pm

Re: Ray test for bouncing particles

Post by B_old »

Ok, I obviously used the second parameter wrong. It is not supposed to be the direction of the ray bur rather the endpoint so to speak. My mistake, sorry.
Another thing I wonder and I hope I can get an answer for: Is it possible that calling rayTest() from several threads won't be faster than calling it from one thread? What I mean is, that I process several particle systens in parallel, which usually gives a good performance boost. After adding rayTest() there is virtually no difference between one or more threads. Am I doing something wrong?

EDIT: When I run in debug mode the difference between one ore several threads is clearly noticeable. What could be the reason, that I isn't working in release?