2 Replies Latest reply on Oct 11, 2012 12:39 PM by George_Johnson

    Rotate camera function

    adrianrdzv

      Hello,

       

      I'm starting to write a code for Acrobat and 3d Objects.

      What I need is a function that rotates an object given a yaw and a pitch (i.e. rotateObjectYaw(45) to rotate the object 45 degrees around, rotating the camera, not the object itself).

       

      I started modifying the CameraRotate.js and I already made it work eliminating the friction effect and performing the full delta change in one iteration.

      Yaw works perfectly, but the problem is the pitch. If I rotate the Yaw first, the pitch does not rotate around the changed axis but on the original pitch axis. I guess the problem lies somewhere around:

       

       

              //-----------------------------------------------
              // Update camera direction
              //-----------------------------------------------
              var x = Math.sin( yaw   ) * Math.cos( pitch );
              var y = Math.cos( yaw   ) * Math.cos( pitch );
              var z = Math.sin( pitch );
      
      
              cameraDirection.set( x, y, z );
      
      
              //-----------------------------------------------
              // Update camera position
              //-----------------------------------------------
              trueCameraPos.set(targetPosition);
              trueCameraPos.addScaledInPlace(cameraDirection, cameraDistance * GlobalZoomScale);
              camera.up.set(targetPosition.x, targetPosition.y, targetPosition.z + cameraDistance);
              camera.position.set(trueCameraPos);
              camera.targetPosition.set(targetPosition);
      
      

       

      But I'm not sure, and I have no idea about vector space calculations and so. Can somebody help me out?