— Shang Liang

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.

1 comment
  1. JustMe says: October 30, 20092:25 pm

    Thanks but I don’t like semi-solutions or patches which tend to create more mess.
    I’d prefer a new clean and efficient lookAt() method since it seems that papervision3d developers don’t care that much for such bugs…

Submit comment

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