Page 1 of 1

RayTest, what is hitNormalWorld???

Posted: Wed Mar 18, 2015 3:19 pm
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)

Re: RayTest, what is hitNormalWorld???

Posted: Wed Mar 18, 2015 3:58 pm
by drleviathan
All of those values are approximately the same. You're seeing floating point error.

Re: RayTest, what is hitNormalWorld???

Posted: Wed Mar 18, 2015 4:08 pm
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?

Re: RayTest, what is hitNormalWorld???

Posted: Wed Mar 18, 2015 5:04 pm
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.

Re: RayTest, what is hitNormalWorld???

Posted: Wed Mar 18, 2015 5:26 pm
by Chaz
I noticed that even with this strange normal Vector3f.angle(vector3f v) returns right value, so all is ok now.