POV-Ray : Newsgroups : povray.newusers : Smooth swinging camera work : Re: Smooth swinging camera work Server Time
26 Apr 2024 12:08:23 EDT (-0400)
  Re: Smooth swinging camera work  
From: SecondCup
Date: 9 Apr 2016 15:50:01
Message: <web.57095cc1e1dfd56f95dcb8070@news.povray.org>
Le_Forgeron <jgr### [at] freefr> wrote:
> Le 07/04/2016 20:34, SecondCup a écrit :
> > Hi All,
> >
> > My first posting so if I am short on etiquette please let me know! A little
> > context: learning to code for maybe one year. I've been learning POV-RAY for
> > about a month.
> >
> > I'm trying to create a video animation where the camera zooms in and pans around
> > an object at the center of the screen. I can create the two commands easily but
> > individually. I can zoom in and I can pan around the object. The problem is the
> > the smooth transition between both actions. Id like to create a small, smooth
> > arc to connect both. Right now I zoom in...stop abruptly...and then pan. Its a
> > little jolty (if thats even a word).
> >
> > Can anyone point me to a good link to help me out? Or is there a sure-fire way
> > to connect the two camera shots?
> >
>
> Greetings and welcome,
>
> My first question would be how do you pan ? (is the object a fixed point ?)
>
> And how do you zoom ?
>
> Let's assume that you pan by moving the camera (changing the location value of the
camera,
> while keeping the look_at at the object, and a constant angle for the camera),
> and that you zoom by keeping the camera at the same location while adjusting the
angle.
>
> The key to your request is overlapping a bit each part.
>
> There is many ways to do it.
>
> If your scene/camera setting was (or could be) something along:
>
> #if (clock < ZoomTime )
>  panning code
> #else
>  zooming code
> #end
>
> You could transform it into:
>
> #if (clock < FirstTime )
>  panning code
> #else
> #if (clock < SecondTime )
>  end panning and start zooming code
> #else
>  end zooming code
> #end
> #end
>
> With FirstTime < ZoomTime < SecondTime
>
> The difficulties are in all in the "end panning and start zooming code", to be
aligned with both other parts.
> And for the smoother effect, the first derivative of each movement (panning and
zooming) should be contiguous. That's
 the hard part.
> (actually, the second derivative might also have to be continuous)
>
> *OR* you can just dive into spline for the location and angle.
>
> > http://wiki.povray.org/content/Reference:Spline
>
> First, you declare the spline, then you will use it indexed with the clock.
> A natural_spline is probably the simpler to use for you.
>
> #declare CameraSpline=spline{ natural_spline
>  0, <start_xposition, start_yposition, start_zposition, start_angle>,
>  // add intermediate points as needed for your panning, especially if you are
rotating around a point
>  //
>  // transitition:
>  FirstTime, < intermediate_xposition, intermediate_yposition,
intermediate_zposition, start_angle>,
>  SecondTime, < end_xposition, end_yposition, end_zposition, intermediate_angle >,
>  EndOfTime, < end_xposition, end_yposition, end_zposition, end_angle >,
> }
>
> camera
> { location < CameraSpline(clock).x, CameraSpline(clock).y, CameraSpline(clock).z >
> //... and whatever you want too, such as right, up, direction, look_at...
> //
> // and angle to control zoom
> angle CameraSpline(clock).f
> }
>
> // then scene as usual
>
>
>
>
> > I have a feeling I may have to go over some trigonometry notes but so be it :)
> >
> >
> >


Thank you for the awesome input Le_Forgeron! Ive been working on both of your
suggestions for the past few days. Here is where i'm at with both:

Suggestion number one: The overlapping time codes.

A bit of math and coding knowledge required for this one. Took me ages to get
the transition correct. To make it a little easier for myself all I required to
do was drop the camera down vertically and then pan around (Doing away with the
zooming for now). All while focusing on slightly below the center "look_at < 0,
-10 ,0>". If the results were satisfactory I would then use the math and coding
to punch out my actual animation. Here is my code for method 1:

#declare drop = 0;
#declare pan = 0;

#declare FirstTime = .4;
#declare SecondTime = .6;
#declare ratio12 = ((clock - FirstTime)/(SecondTime - FirstTime));
#declare ratio23 = ((clock - SecondTime)/(1 - SecondTime));

#if (clock < FirstTime)              //camera drops
 #declare drop = 25 * clock;
#else
#if (clock < SecondTime)             //camera drops and rotates
 #declare drop = 10 + ratio12*5;
 #declare pan = 15 * ratio12;
#else
 #declare pan = 15 + ratio23 *165;   //camera rotates
 #declare drop = 15;
#end
#end


 camera{
    location < 0, 0 - drop, -20 >
    rotate < 0, 0 + pan, 0>
    look_at < 0, -10 ,0>
  }

This drops the camera 15 POVray units then combines both a drop (for 10 units)
and a pan (rotate around the center for 15degrees) before settling into a
horizontal pan about the y-axis for 165 degrees to complete a full 180degrees.

The problem is the transition. It still feels 'jolty' and the overlap is linear.
I was hoping for an arc. It drops vertically, then diagonally transitions in a
straight line before rotating around the point. If you have a suggestion to
'arc' the two movements together i'd love to hear them.

So with this, I tried method two: The fly-by spline method

My first time using the spline call but a tonne of fun. This command will be
used a lot! I was running into trouble with the POVray coordinate system. I cant
get the camera to rotate about the centre in 360 degrees (360 rather than 180 as
in method 1 just to get a handle on the POVraycoordinate system). I was trying
the same actions as in method one, dropping the camera then arc into a pan. For
the first couple of animation shots its really excellent, a drop then a nice
smooth arc. I cant seem to tell the camera to go behind the center point! I
tried adjusting the z-value in location but it just pulls me in and out from the
center. This is probably because I have declared 'look_at' the center. How can I
place the camera in a circular natural_spline around the center, while
maintaining the camera's focus on the center? If you can advise on my code, I'd
love to hear it! For you seasoned pros this one may be an easy fix.

Ultimately I think method 2 is the way to go without using some complex math.
Plus it also gives me some fun control over the camera and its navigation. Its
smooth and pretty dynamic.

Here is my code for the spline:

 #declare CameraSpline =
    spline {
        natural_spline

        0.0, <0,40.5,-65>
        0.1, <0,10,-65>
        0.2, <10, 5, -65>
        0.3, <30, 0, -60>
        0.4, <65, 0, -60>
        0.5, <30, 0, -30>
        0.6, <0, 0, 0>
        0.7, <-30, 0, 30>
        0.8, <-65, 0, 60>
        0.9, <-30, 0, 60>
        1.0, <0, 0, -65>

       }



  camera{
    location < CameraSpline(clock).x, CameraSpline(clock).y,
CameraSpline(clock).z >
    rotate < 0, 0, 0>
    look_at < 0 , -10 , 0>

  }

With this code I didn't try to zoom as I just wanted to get used to the two
methods. However, I did try your suggestion to use "angle CameraSpline(clock).f"
but it was giving me an error. By placing a number after the anchor points in
the spline code does one call this number using 'f' as one does when calling
'x,y,z'. Again this question may be straight-forward for you seasoned pros :)


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.