Papervision3D LookAt problem and work around

In Papervision3D, all classes that extend DisplayObject3D inherit its lookAt function. But the problem is the result of A.lookAt(B) sometimes ends up as A back facing B. This problem is more obvious when you want to rotate a plane to face the camera. The plane becomes invisible because it’s back facing the camera. If you set the material to double-sided, the material is mirrored which is not acceptable in some cases.

To work around the problem without touching 3D rotations, you can create an empty object3D as C and place it along vector BA and call A.lookAt(C). Vector BA can be calculated as {A.x-B.x, A.y-B.y, A.z-B.z} and the position for C should be {BA.x*1.1+A.x, BA.y*1.1+A.y, BA.z*1.1+A.z}. The number 1.1 is just an arbitrary number. Any number greater than 1 will do the trick.

I’ve done this piece of ugly thing as a demonstration and the source is here.

Leave a Reply

For spam filtering purposes, please copy the number 4061 to the field below: