Scripted camera motions

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Scripted camera motions

Brennan Peter Sellner
Is there any way to smoothly reposition the camera programatically?  I've
been able to use EnvironmentBase::SetCamera() to set the camera position,
but that can be quite disorienting: I would prefer to set a desired
position and the time needed to get there.  It doesn't look like it's
possible to set trajectories for the camera; am I missing something?

Thanks,

-Brennan




Reply | Threaded
Open this post in threaded view
|

Re: Scripted camera motions

Rosen Diankov-2
Hi Brennan,

There are no functions to take in camera trajectories and smoothly
interpolate. That being said, it would be easy to use the Trajectory
class to specify waypoints (use DOF=0) and increment the timer
manually through your plugin. When you want to set the camera position
at time t, call

Trajectory::SampleTrajectory(t, point);
EnviornmentBase::SetCamera(point.trans.trans, point.rot);

SampleTrajectory uses SLERP to smoothly interpolate the quaternions.

However, There currently is no way to set the camera through scripting
without making your own plugin.

Rosen,

2008/8/10 Brennan Peter Sellner <[hidden email]>:

> Is there any way to smoothly reposition the camera programatically?  I've
> been able to use EnvironmentBase::SetCamera() to set the camera position,
> but that can be quite disorienting: I would prefer to set a desired
> position and the time needed to get there.  It doesn't look like it's
> possible to set trajectories for the camera; am I missing something?
>
> Thanks,
>
> -Brennan
>
>
>
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
> Build the coolest Linux based applications with Moblin SDK & win great prizes
> Grand prize is a trip for two to an Open Source event anywhere in the world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________
> Openrave-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/openrave-users
>


Reply | Threaded
Open this post in threaded view
|

Re: Scripted camera motions

Brennan Peter Sellner
Thanks, Rosen, that worked well!

In case anyone else needs to do this at some point, the relevant
code from my Problem plugin is below.

Thanks!

-Brennan

-------------------------------------------------------------

/*************************
  * Header
  *************************/

class IpcRemoteControlProblem : public ProblemInstance
{
   <snip>
   // Iterate a camera move in progress; if no move is in progress, pop
   // one from the queue.  Called once per simulation step.
   void moveCamera();

   // Queue of camera movements: camera movement commands are
   // transmitted to the plugin and queued.
   //
   // OpenRaveSetCamera is one of my structures, with
   // 8 elements: x, y, z, q1, q2, q3, q4, and t (time)
   list<OpenRaveSetCamera> cameraQueue;
   bool cameraMoveInProgress;
   Trajectory cameraTrajectory;
   // A simple timer class that can return the time
   // (in fractional seconds) since it was last reset.
   StopWatch cameraTimer;
   <snip>
}


/*************************
  * Implementation
  *************************/

bool IpcRemoteControlProblem::SimulationStep(float fElapsedTime) {
   <snip>
   // Always update the camera position.
   moveCamera();
   <snip>
}

void IpcRemoteControlProblem::moveCamera() {

   if(cameraMoveInProgress) {
     Trajectory::TPOINT point;
     float t = (float) cameraTimer.elapsedTime();
     // SampleTrajectory uses SLERP to smoothly interpolate the
     // quaternions.
     cameraTrajectory.SampleTrajectory(t, point);
     // base is an EnvironmentBase*
     base->SetCamera(point.trans.trans, point.trans.rot);

     // If enough time has passed, stop the move.
     if(t >= cameraTrajectory.GetTotalDuration()) {
       cameraMoveInProgress = false;
     }
   }
   else if(cameraQueue.size() > 0) {
     cameraTrajectory = Trajectory(0);
     // Start from the current position.
     Trajectory::TPOINT curP;
     curP.time = 0;
     curP.trans = base->GetCameraTransform();
     cameraTrajectory.AddPoint(curP);

     // And move to the target position.
     Trajectory::TPOINT targetP;
     OpenRaveSetCamera camera = cameraQueue.front();
     targetP.time = camera.t;
     Vector pos(camera.x, camera.y, camera.z);
     Vector quat(camera.q1, camera.q2, camera.q3, camera.q4);
     targetP.trans = Transform(quat, pos);
     cameraTrajectory.AddPoint(targetP);

     RAVEPRINT(L"Moving camera to new position; taking %f seconds.\n", camera.t);

     cameraTrajectory.CalcTrajTiming(NULL, Trajectory::LINEAR, false, false);

     cameraMoveInProgress = true;
     cameraQueue.pop_front();
     cameraTimer.restart();
   }
}