Cubism SDK‎ > ‎Frameworks‎ > ‎

Animation by Dragging

Summary

There is a function that when you touch or drag the screen, the model turns to the direction of the provided coordinates.
This is an explanation on setting up this function.

L2DTargetPoint class manages the Deformer of dragging.
Regarding to retrieve touch or to convert device Deformer, refer to the individual explanations specific to each platform.

A sample of animation

In the sample below, the dragging value is retrieved and set it in the Motion Parameter.
You can see that the Motion Parameter is added for the direction of the face, the direction of the eyeball, and the direction of the body (from side only).


//L2DTargetPoint drag;

float dragX=drag.getX();//in the range from -1 to 1
float dragY=drag.getY();//in the range from -1 to 1

//Adjust the direction of the face
live2DModel.addToParamFloat( "PARAM_ANGLE_X", dragX * 30 , 1 );//Add the value from -30 to 30
live2DModel.addToParamFloat( "PARAM_ANGLE_Y", dragY * 30 , 1 );

//Adjust the direction of the body
live2DModel.addToParamFloat( "PARAM_BODY_X"    , dragX * 10 , 1 );//Add the value from -10 to 10

//Adjust the direction of the eye
live2DModel.addToParamFloat( "PARAM_EYE_BALL_X", dragX  , 1 );//Add the value from -1 to 1
live2DModel.addToParamFloat( "PARAM_EYE_BALL_Y", dragY  , 1 );



Code needed for setting

You need to make settings of the value for the events of starting touching, moving, and finishing.
You also need to update each frame.
void set( float x , float y )
It turns to the position of the setting Deformer.
The setting value range is the value range which you can acquire.

void update()
It is calculated to be a Motion Parameter with normal move concerning the acceleration.
You need to update each frame.

How to get the value

float getX()
It gets the value in horizontal direction.
It is not updated unless you refer to update().

float getY()
It gets the value in vertical direction.
It is not updated unless you refer to update().

Comments