Controlling the 3D rotation

This example demonstrates how to use ActionScript and the 3DPlane parameters to create additional interaction (like motion effects, physic effects and so on).

1. Continue to work with the 'butterfly.fla' movie. Add the following code to the 3DPlane instance:

onClipEvent (enterFrame) {
this.rx += -(x0-this.v1.px)/30;
this.ry += (y0-this.v1.py)/30;
this.rz += (z0-this.v2.py)/80;
if (this.rx*this.rx+this.ry*this.ry+this.rz*this.rz<.001) {
this.rx=this.ry=this.rz=0; //disable small oscillations
}
}

2. Add the following code to the existing 'onLoad' event, after the ' swap' function:

//store the initial position
x0 = this.v1.px;
y0 = this.v1.py;
z0 = this.v2.py;
//push it gently in the beginning
this.rx = this.ry = 5;

This example uses linear approximation in order to avoid complex 3D calculations. This should work well for most situations. You can tune it somewhat by changing the coefficients to '30' or '80' as well as the 3DPlane friction parameter.