RayTest, what is hitNormalWorld???

Post Reply
Chaz
Posts: 44
Joined: Mon Jan 12, 2015 1:36 pm

RayTest, what is hitNormalWorld???

Post by Chaz »

Hello. What is the hitNormalWorld ? I just cast a ray in direction of camera view, and the ray hit a box, but value of hitNormalWorld are different when I rotate a camera a little bit.

Code: Select all

 Vector3f temp1 = MyUtil.SubVector(pointOfInterest,cameraPos);
                        temp1=MyUtil.AddVector(MyUtil.MulVector(temp1,100), cameraPos);

                        CollisionWorld.ClosestRayResultCallback callback =
                                new CollisionWorld.ClosestRayResultCallback(cameraPos, temp1);
                        callback.collisionFilterGroup=3;
                        dynamicsWorld.rayTest(callback.rayFromWorld,callback.rayToWorld,callback);
                        if(callback.hasHit())
                        {
                            System.out.println(callback.hitNormalWorld+" "+callback.collisionObject.getCollisionShape().getName());
                        }
For the same box side got this values
(0.0, 2.986082E-7, -1.0) Box
(0.0, 0.0, -1.0) Box
(0.0, 0.0, -1.0) Box
(0.0, 0.0, -1.0) Box
(0.0, 6.812293E-8, -1.0) Box
(0.0, 6.812293E-8, -1.0) Box
(0.0, 2.700576E-7, -1.0) Box
(0.0, 2.7722533E-7, -1.0) Box
(0.0, 0.0, -1.0) Box
(0.0, 6.272352E-6, -1.0) Box
So how to fix it? I guess that always have to be this value (0.0, 0.0, -1.0)
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: RayTest, what is hitNormalWorld???

Post by drleviathan »

All of those values are approximately the same. You're seeing floating point error.
Chaz
Posts: 44
Joined: Mon Jan 12, 2015 1:36 pm

Re: RayTest, what is hitNormalWorld???

Post by Chaz »

drleviathan wrote:All of those values are approximately the same. You're seeing floating point error.
But difference between 0.0 and 6.812293E-8 are too large to be floating point error, don't it?
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: RayTest, what is hitNormalWorld???

Post by drleviathan »

Not in my experience, especially when there are transformations involved. Yes, your box probably has identity rotation but I'll bet its not located at the origin. When vectors are transformed into the local-space of the box shape and back out floating point errors creep in. Put your box 1000 times farther from the origin than it is now and the errors will go up.

I believe it is possible to build Bullet with double precision which should reduce the floating floating point error.
Chaz
Posts: 44
Joined: Mon Jan 12, 2015 1:36 pm

Re: RayTest, what is hitNormalWorld???

Post by Chaz »

I noticed that even with this strange normal Vector3f.angle(vector3f v) returns right value, so all is ok now.
Post Reply