Game Development Community

PathCamera transition routine not working

by Pronto Games Engineer1 · in Torque Game Engine · 11/21/2006 (12:05 pm) · 0 replies

I'm really not understanding how paths work, but I'm very close to getting a camera transition working and need some help.

The transition works fine without interruption, but it doesn't work if another transition is triggered during the current transition. I try to stop the path following and run the camera on a new path, but the orientation is wrong and I get a cut to a bad camera angle that appears to have the rotation vector of "1 0 0 0".

Here's the broken part of the code for stopping the path and getting the current orientation:
$GameConn.pathCamera.setState("stop");
             %stopTrans = $GameConn.pathCamera.getTransform();
             %stopPos = getWords(%stopTrans,0,2);
             %stopRot = getWords(%stopTrans,3,6);
             $GameConn.pathCamera.reset();
             $GameConn.pathCamera.popFront();

And here's the whole transition function:
function PathCamera::transition(%this,%worldPos1,%rotation1,%worldPos2,%rotation2,%transTimeMS)
{
   if(%worldPos1 != %worldPos2){
      if(!$CineRunning){
         if( $bTransRunning == false ){
            %pathLen = VectorLen(VectorSub(%worldPos1,%worldPos2));
            %mark1pos = %worldPos1;
            %mark1rot = %rotation1;
         } else { //transition is still running
             // stop the camera make a new starting node, clear the scheduled events
             $GameConn.pathCamera.setState("stop");
             %stopTrans = $GameConn.pathCamera.getTransform();
             %stopPos = getWords(%stopTrans,0,2);
             %stopRot = getWords(%stopTrans,3,6);
             $GameConn.pathCamera.reset();
             $GameConn.pathCamera.popFront();
             $GameConn.setPosition(1.0);//move to the end of the path
             cancel($lastClearSched);
             cancel($lastSetCamObjSched);

            %pathLen = VectorLen(VectorSub(%worldPos1,%stopPos));
            %mark1pos = %stopPos;
            %mark1rot = %stopRot;

         }

          %nodeSpeed = %pathLen*1000/%transTimeMS; //in world units/second
          %transPath = new Path(){
              isLooping=false;
          };
          %tPathMark1 = new Marker(){
              position=%mark1pos;
              rotation=%mark1rot;
              scale = "1 1 1";
              seqNum = "1";
              type = "Normal";
              speed = %nodeSpeed;
              smoothingType = "Spline";
         };

          %tPathMark2 = new Marker(){
              position=%worldPos2;
              rotation=%rotation2;
              scale = "1 1 1";
              seqNum = "2";
              type = "Normal";
              speed = %nodeSpeed;
              smoothingType = "Spline";
          };

          %transPath.add(%tPathMark1);
          %transPath.add(%tPathMark2);
          if($GameConn.getCameraObject()!=$GameConn.pathCamera){
             // set camera control to the path camera for the transition
             $GameConn.setCameraObject($GameConn.pathCamera);
          }
          // set camera back to the advanced camera once the transition is complete
          // Carefull!!!!! if we initiated the transition from any camera besides advancedCamera
          // we're gonna cause trouble.
          // Update this code when we add more cameras.
          $lastSetCamObjSched = $GameConn.schedule(%transTimeMS,setCameraObject,$advCamera);

          $GameConn.pathCamera.followPath(%nodeSpeed,%transPath);
          $bTransRunning = true;
          $lastClearSched = schedule(%transTimeMS,$GameConn.player,clearTransitionFlag);

          %transPath.remove(%tPathMark1);
          %transPath.remove(%tPathMark2);
          %tPathMark1.delete();
          %tPathMark2.delete();
          %transPath.delete();
      }
   }
}