Face to cam script for PDF3D
-
hi all,
i m starting to use javascript for PDF3D, here is an example :
tree always face, acrobat 8.1 minimum
the goal is to clone sketchup with "face to camera" function.
but as you can see in the attached PDF, each time the camera angle is around 0, the tree rotation of +180° if cam angle is positive and -180° if cam angle is negative.
here is the code :runtime.setCurrentTool(runtime.TOOL_NAME_SPIN); myMouseHandlerPositonCam= new MouseEventHandler(); myMouseHandlerPositonCam.onMouseMove= true; myMouseHandlerPositonCam.onEvent= function( event ) { var VecteurCameraXPositonCam =((scene.cameras.getByIndex(0).targetPosition.x)-(scene.cameras.getBy Index(0).position.x)); var VecteurCameraYPositonCam =((scene.cameras.getByIndex(0).targetPosition.y)-(scene.cameras.getBy Index(0).position.y)); var VecteurCameraZPositonCam =((scene.cameras.getByIndex(0).targetPosition.z)-(scene.cameras.getBy Index(0).position.z)); AngleCamPositonCam=Math.atan(VecteurCameraYPositonCam/VecteurCameraXPositonCam); for (var i=0; i < scene.meshes.count; i++) { var result = scene.meshes.getByIndex(i).name.indexOf("tree"); if (result>-1) { { m1 = new Matrix4x4().rotateAboutZ(AngleCamPositonCam+Math.PI/2) scene.meshes.getByIndex(i).transform.set(m1); scene.meshes.getByIndex(i).renderMode = ("solid"); } } } } runtime.addEventHandler( myMouseHandlerPositonCam );
i tried to add a condition :
if AngleCam > 0
then m1 = new Matrix4x4().rotateAboutZ(AngleCamPositonCam+Math.PI/2)
else m1 = new Matrix4x4().rotateAboutZ(AngleCamPositonCam-Math.PI/2)but it doesn t work...
any ideas? -
bbCodes use square brackets [ code ] and [ /code ] not < code >
-
i'm a newbie in programming ...
-
finally the problem was tan(alpha)=tan(alpha+180°)
here the result...
Advertisement