Transferred from: http://blog.csdn.net/notbaron/article/details/38447253
Introduction to Theory
First of all we look at what orbit mean, orbit[' ɔ:bɪt][US][ˈɔrbɪt] to express the track; Sphere of influence.
Then we look at the inheritance relationship, as shown
This Orbitcamera class is the only child of the Actioncamera class.
Let's look at the CREATE function for this class as follows:
Static orbitcamera* Create
(float t, float radius, float deltaradius, float anglez, float deltaanglez, float AngleX, F Loat Deltaanglex)
This function creates a motion view action class with a starting radius, a radius difference, a starting z-angle, a difference between the z-angle of rotation, a starting x-angle, and a difference in the rotation of the X-angle.
Specific steps
We still found it in the HelloWorld.cpp file.
BOOL Helloworld::init () function, add the following code.
Autoorbit1 =orbitcamera::create (2,1,0, 0, 0, 0);
Auto Action =sequence::create (orbit1, Orbit1->reverse (), nullptr);
Auto Grossini =sprite::create ("Grossini.png");
AddChild (grossini,0, 2);
Grossini->setposition (VEC2 (50+origin.x, VISIBLESIZE.HEIGHT/2 + origin.y));
Grossini->runaction (action);
Run to get the picture will not be sent, because the screenshot can not see what effect. Small partners can try it on their own computer.
Code explanation
below we explain the meaning of the code: AUTOORBIT1 =orbitcamera::create (2,1,0, 0, 180, 0, 0);//Create an Action object, the action completion time is 2 seconds, the starting radius is 1, the radius difference is 0, the starting Z The angle is 0, the difference of the rotation z angle is 180, the starting x angle 0, the rotation x angle difference 0 Auto Grossini =sprite::create ("grossini.png");//Create an action, sequence represents the order of action inside the execution.
Orbit1->reverse () indicates that the action is mounted in the opposite direction of movement. AddChild (grossini,0, 2);//Add Sprite Grossini->setposition (VEC2 (50+origin.x, VISIBLESIZE.HEIGHT/2 + origin.y));//Set Sprite bit Grossini->runaction (action),//The wizard will run the action, the parameter Deltaanglez, Deltaanglex angle into radians (such as the Deltaanglez parameter is 180, that
Converted into radians is 180*π/180=3.14). At present, we can simply understand this first, each sprite has a camera. The camera can then move around the elf's periphery. Just like a satellite revolves around the Earth.
When satellites orbit the Earth, the earth seen from the satellites is not the same, sometimes Asia, sometimes Africa, and at some point may well be the Americas. The starting radius is the distance between the satellite and the Earth, and the radius difference is the change in distance between the satellite and the earth can be negative.
(However, the actual results of the toad were found to be no difference) starting with Z angle and rotating z angle, we can now understand that the camera rotates in the horizontal direction along the spherical surface.
The starting x angle and the x angle of rotation can be understood as the camera rotates in the vertical direction along the spherical surface.