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...
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register LoginAdvertisement