Main Menu


Sponsored Links

  


  
  
Web Cartoon Maker: a Fun Way to Learn C++ Contents Previous Next

Camera

It is also possible to move 2D camera through a cartoon scene. You can use a camera when you want to show different pieces of your scene, when it is bigger than your movie size. This can be very effective as noted earlier.

There are several functions available in WCM C++ to move a camera. These are very similar to methods of some objects:

  • SetCameraPos – it is very similar to an object's SetPos method. It accepts two double coordinates and changes the position of camera. When you change a camera position, it has the same effect as moving all the objects in current scene in an opposite direction. These so called "set" functions for working with camera also insert some kind of control point in your movie at a current time, and a camera position is changing smoothly between these control points. You can try to compile the example below to see an effect of moving camera. We'll use coordinates background again so you can see how they are changing on the screen:

void Scene1 ()

{

// show coordinates

Image Coordinates ( "wcm/coordinates.emf" );

Coordinates.SetVisible ( true );


// show a ball in the center

Image Ball ( "sport/beach_ball.svg" );

Ball.SetVisible ( true );


// Place a camera at the center

SetCameraPos ( 0, 0 );

Sleep ( 1 );


// move camera to the left and up

SetCameraPos ( -100, -100 );

Sleep ( 1 );


// move camera to the right and up

SetCameraPos ( 100, -100 );

Sleep ( 1 );


// move camera to the right and bottom

SetCameraPos ( 100, 100 );

Sleep ( 1 );


// move camera to the left and bottom

SetCameraPos ( -100, 100 );

Sleep ( 1 );

}

  • SetCameraX and SetCameraY – These are almost the same as SetCameraPos but accept only one double parameter and change only one camera coordinate.

  • SetCameraAngle – this function accepts only one double parameter - camera angle in degrees. This is an equivalent of rotating all the objects in current scene in opposite direction relative to the screen center. You can try this example for better understanding:

void Scene1 ()

{

// show coordinates

Image Coordinates ( "wcm/coordinates.emf" );

Coordinates.SetVisible ( true );


// show a ball in the center

Image Ball ( "sport/beach_ball.svg" );

Ball.SetVisible ( true );


SetCameraAngle ( 0 );

Sleep ( 10 );

SetCameraAngle ( 360 );

}

  • SetCameraZoom – this function makes a camera too zoom in and out. Zooming is an equivalent of scaling your current view. It accepts one double parameter – a scale factor. Scale factor 1.0 means that there is no zooming happening. Scale factor less than 1.0 means that you are zooming out. Scale factor greater than 1.0 means that you are zooming in. Here is an example to try:

void Scene1 ()

{

// show coordinates

Image Coordinates ( "wcm/coordinates.emf" );

Coordinates.SetVisible ( true );


// show a ball in the center

Image Ball ( "sport/beach_ball.svg" );

Ball.SetVisible ( true );


SetCameraZoom ( 1 ); // no zoom

Sleep ( 3 );

SetCameraZoom ( 0.8 ); // zoom out

Sleep ( 6 );

SetCameraZoom ( 1.2 ); // zoom in

}

As you probably noted these are all "set" functions similar to "set" methods. And all of them accept numeric parameters. This means that all of them insert a control point at a current time in scene and the actual value is calculated automatically between these control points. This also means that there are "change" equivalents exist. These "change" equivalents accept one additional double parameter – duration and insert two control points – at a current time and after the duration number of seconds. The "change" functions are:

  • ChangeCameraPos

  • ChangeCameraX and ChangeCameraY

  • ChangeCameraAngle

  • ChangeCameraZoom

You can also know current camera parameters using following "get" functions. All of them do not require any parameters and return a double value

  • GetCameraX

  • GetCameraY

  • GetCameraAngle

  • GetCameraZoom

In the following example a camera will move through the set of characters and then zoom in on one of the faces.

#include <boy.h>

#include <girl.h>

#include <man.h>

#include <woman.h>


void Scene1 ()

{

Image Back ( "backgrounds/beach.svg" );

Back.SetVisible ();


Boy Max;

Max.SetVisible ( true );

Max.SetPos ( -300, 290 );


Girl Mary;

Mary.SetVisible ( true );

Mary.SetPos ( -100, 290 );


Man Mike;

Mike.SetVisible ( true );

Mike.SetPos ( 100, 290 );


Woman Wendy;

Wendy.SetVisible ( true );

Wendy.SetPos ( 300, 290 );


SetCameraPos ( -200, 0 );

ChangeCameraPos ( 200, 0, 8 );

ChangeCameraPos ( 100, 0, 2 );

ChangeCameraZoom ( 2, 2 );

}

Once compiled you will see the following movie:


Contents Previous Next
  
News

New Tales Animator Video by Alan Sturgess

Alan Sturgess shared an excellent video he made using Tales Animator! You can still download Tales Animator here. Unfortunately it is only available for Wi

...

Simple Online Character Designer

There is a prototype of simple online character designer available HERE. It is only a prototype, it does not contain many pieces yet but it can already generat

...

Book is updated

Now our book "Web Cartoon Maker: A Fun Way to Learn C++" is fully in synch with WCM 1.5! It is available for download and online reading HERE.

...

Web Cartoon Maker 1.5 is here!

Web Cartoon Maker 1.5 is finally here! You can download it HERE! Here is what was updated in version 1.5: Web Cartoon Maker Desktop Edition is now fully standal

...

read more news...


Poll