Calculate angle of an object[solved]

billybob
Posts: 4
Joined: Thu Jun 13, 2013 12:25 am

Calculate angle of an object[solved]

Post by billybob »

Hello everyone,

I am trying to figure out how to calculate the thickness of an object i send a raytest into while taking into account the angle of the object. This should change depending on the angle of the ray and also the rotation of the collision object.

So for e.g i am doing this

Code: Select all

btCollisionWorld::ClosestRayResultCallback rayCallback(btRayFrom,btRayTo);
mCollisionWorld->rayTest(btRayFrom, btRayTo, rayCallback);
float thickness=100.0f;
if (rayCallback.hasHit())
{
btVector3 normal = rayCallback.m_hitNormalWorld;
float angle = btDegrees(normal.angle(btVector3(0,1,0)));
float actualThickness = thickness/btCos(angle);
}
I really must have been asleep in maths because i can't get it to work, also i have to take into account more than just the Y Axis too i'm guessing. Any help would be greatly appreciated.

Thanks,

Billy

*Edit*

Changed title to better reflect the problem. Please see last post.
Last edited by billybob on Fri Jun 14, 2013 5:59 am, edited 2 times in total.
billybob
Posts: 4
Joined: Thu Jun 13, 2013 12:25 am

Re: Calculate thickness of an object

Post by billybob »

I think one of the problems could be getting the angle of the object, just printing out the angle looks completely wrong.

Code: Select all

btVector3 normal = rayCallback.m_hitNormalWorld;
float angleY = normal.angle(btVector3(0,1,0));
std::cout << "Angle y-axis: " << btDegrees(angleY) << "\n";
Is this the correct way of doing it? I have attached a dodgy picture to help explain. The yellow line is the ray, i want to calculate the angle that the face is on that the ray is hitting so i can calculate the thickness.
You do not have the required permissions to view the files attached to this post.
billybob
Posts: 4
Joined: Thu Jun 13, 2013 12:25 am

Re: Calculate thickness of an object

Post by billybob »

I don't know what is wrong but i can't get the correct angle. Looking at this thread http://bulletphysics.org/Bullet/phpBB3/ ... f=9&t=3538 it is very similar to that, the m_hitNormalWorld can't be used to calculate the angle i am looking for.

Just to simplify it, forget my first post. How can i calculate accurately the vertical slope of a face i am hitting with a ray because using below is not giving accurate results

Code: Select all

btVector3 normal = rayCallback.m_hitNormalWorld;
float angleY = normal.angle(btVector3(0,1,0));
std::cout << "Angle: " << btDegrees(angleY) << std::endl;
The app is reporting the angle as 73, from the screenshot below you can see this is wrong, it should be about 60. The wireframe is produced from btIDebugDraw class which i completely borrowed from the demo's and the yellow line is the ray visualized.
You do not have the required permissions to view the files attached to this post.
billybob
Posts: 4
Joined: Thu Jun 13, 2013 12:25 am

Re: Calculate angle of an object[solved]

Post by billybob »