Summary of the invention
The purpose of this invention is to provide the method and apparatus that a kind of mobile terminal desktop pattern is realized, it can realize the animation effect of mobile terminal desktop smoothly.
For achieving the above object, the present invention adopts following technical scheme:
The method that a kind of mobile terminal desktop pattern is realized comprises:
Step 1: the master data of mobile terminal desktop pattern is written in the buffer memory, and this master data comprises image information, translational speed and animation frame;
Step 2: desktop pattern is defined as polygon, and creates corresponding apex coordinate and the texture coordinate of polygonized structure body and function to deposit desktop pattern;
Step 3: the polygon of drawing the texture image that comprises desktop pattern according to current apex coordinate;
Step 4: judge the desktop pattern current states, if rotation mobile status, then execution in step 5a;
Step 5a:, draw the vector v 0 of desktop pattern current location to destination locations according to the current location of desktop pattern and the destination locations that will go thereof;
Step 6a: according to the angle of current desktop pattern rotation, draw towards vector of unit length, and according to the size of desktop pattern this vector of unit length is amplified suitable multiple and draws vector v 1;
Step 7a: draw vector v 2 with vector v 0-v1, vector v 2 dwindled suitable multiple draw vector v 3, again with vector v 1+v3 draw desktop pattern newly towards vector v 4;
The vector of unit length of step 10a: compute vector v4, and draw the angle that desktop pattern will rotate according to the vector of unit length of this v4, according to postrotational position, the said polygonal summit of this angle calculation, more said polygonal summit is moved on to new position;
Step 11:, obtain the reposition of desktop pattern according to the component of vector v 4 at X axle and Y axle;
Step 12:, change the animation frame of desktop pattern, and return step 3 according to the reposition of desktop pattern.
Preferred as technique scheme also comprises between said step 7a and the 10a:
The vector of unit length of step 8a: compute vector v0v1, whether judgment value is 1, if then carry out step 9a, if not, then carry out step 10a;
Step 9a: make the state of desktop pattern into the straight line mobile status, and be adjusted into the corresponding speed of straight line mobile status, execution in step 10a again.
Preferred as technique scheme, in the said step 4, if the desktop pattern current states is the straight line mobile status, execution in step 5b then;
Said method also comprises:
Step 5b:, draw the vector v 0 of the current location of desktop pattern to destination locations according to destination locations current location and that will go of desktop pattern;
The mould of step 6b: compute vector v0 | v0|, judge | whether v0| less than setting value, if, then carry out step 7b, if not, keep the current state of desktop pattern, and go to step 11;
Step 7b: the next point of destination that generates desktop pattern at random;
Step 8b: change the state of desktop pattern into the rotation mobile status, and go to step 11.
Preferred as technique scheme, said polygon is rectangle, trapezoidal or parallelogram.
Preferred as technique scheme, said desktop pattern is a fish.
A kind of portable terminal comprises:
Data are written into the unit, are used for the master data of mobile terminal desktop pattern is written into buffer memory, and this master data comprises image information, translational speed and animation frame;
Definition and establishment unit are used for desktop pattern is defined as polygon, and create corresponding apex coordinate and the texture coordinate of polygonized structure body and function to deposit desktop pattern;
Drawing unit is used for drawing according to current apex coordinate the polygon of the texture image that comprises desktop pattern;
Judging unit is used to judge the desktop pattern current states, if the rotation mobile status then goes to first computing unit;
First computing unit is used for according to the current location of desktop pattern and the destination locations that will go thereof, and draws the vector v 0 of desktop pattern current location to destination locations;
Second computing unit is used for the angle according to the rotation of current desktop pattern, draw towards vector of unit length, and according to the size of desktop pattern this vector of unit length is amplified suitable multiple and draws vector v 1;
The 3rd calculating unit is used to utilize vector v 0-v1 to draw vector v 2, vector v 2 is dwindled suitable multiple draws vector v 3, again with vector v 1+v3 draw desktop pattern newly towards vector v 4;
The 4th computing unit; The vector of unit length that is used for compute vector v4; And draw the angle that desktop pattern will rotate according to the vector of unit length of this v4, according to postrotational position, the said polygonal summit of this angle calculation, more said polygonal summit is moved on to new position;
The 5th computing unit is used for obtaining the reposition of desktop pattern according to the component of vector v 4 at X axle and Y axle;
Animation frame is changed the unit, is used for the reposition according to desktop pattern, changes the animation frame of desktop pattern, and returns drawing unit.
Preferred as technique scheme, said portable terminal also comprises:
The 6th computing unit is used for the vector of unit length of compute vector v0v1, and whether judgment value is 1, if then go to the first state adjustment unit, if not, then go to the 4th computing unit;
The first state adjustment unit is used for making the state of desktop pattern into the straight line mobile status, and is adjusted into the corresponding speed of straight line mobile status, goes to the 4th computing unit again.
Preferred as technique scheme, said judging unit is further used for when the desktop pattern current states is the straight line mobile status, going to the 7th computing unit;
Said portable terminal also comprises:
The 7th computing unit is used for destination locations current location and that will go according to desktop pattern, draws the vector v 0 of the current location of desktop pattern to destination locations;
The 8th computing unit is used for the mould of compute vector v0 | and v0|, judge | whether v0| is less than setting value, if then go to the point of destination generation unit, if not, then keep the current state of desktop pattern, and go to the 5th computing unit;
The point of destination generation unit is used for generating at random the next point of destination of desktop pattern;
The second state adjustment unit is used for changing the state of desktop pattern into the rotation mobile status, and goes to the 5th computing unit.
Preferred as technique scheme, said polygon is rectangle, trapezoidal or parallelogram.
Preferred as technique scheme, said desktop pattern is a fish.
The method and apparatus that mobile terminal desktop pattern provided by the invention is realized; When desktop pattern is in the rotation mobile status; Can make desktop pattern radian is smoothly arranged turn to the target location; Thereby the present invention can realize the animation effect of mobile terminal desktop smoothly, has improved user's experience.
Embodiment
In order to make the object of the invention, technical scheme and advantage clearer,, the present invention is further elaborated below in conjunction with accompanying drawing and embodiment.Should be appreciated that specific embodiment described herein only in order to explanation the present invention, and be not used in qualification the present invention.
Below, the AnimSprite among the present invention is that example describes with the fish, it will be appreciated by those skilled in the art that AnimSprite is not limited to fish, it can also be any other animal or pattern etc.
Shown in Fig. 1-5, the method that the present invention provides a kind of desktop sprites of mobile terminal to realize comprises:
Step 1: the master data of fish is written in the buffer memory, and this master data comprises image information, translational speed and animation frame;
Step 2: fish is defined as polygon, and creates corresponding apex coordinate and the texture coordinate of polygonized structure body and function to deposit fish;
Step 3: the polygon of drawing the texture image that comprises fish according to current apex coordinate;
Step 4: judge the fish current states, if rotation mobile status, then execution in step 5a;
Step 5a:, get the vector v 0 of fish current location to destination locations according to current location of fish and the destination locations that will go thereof;
Vector is a directed line segment of starting point and terminal point definition.
As shown in Figure 2, according to current location and the destination locations thereof of fish, we can obtain vector v 0=(destination locations .X-current location .X, destination locations .Y-current location .Y).
Step 6a: according to the angle of current fish rotation, draw towards vector of unit length, be α such as the anglec of rotation of fish, then should towards vector of unit length be (sin α, cos α); And according to the size of fish this vector of unit length is amplified suitable multiple and draw vector v 1;
Use vectorial length through regular meeting when using vector, the computing formula of vector length is:
Let?
the vector P of length?
We can be to its normalization after knowing vectorial length; Make that promptly the length of vector is 1, calculates as follows:
We call?
is?
a unit vector.Can according to the method calculate towards vector of unit length.
This amplification multiple is by the decision of the size of fish, and when the size of fish is big, but corresponding selection is bigger numerical value.
Continue as shown in Figure 2, vector v 1 be fish towards vector, this vector is amplified suitable multiple towards vector of unit length and is drawn by fish; Fish towards vector of unit length if original state; Can draw by its angle,, then can draw by a last circulation if begun circulation.
For example, the length of fish is 5cm, and the value of vector of unit length is 1cm, and multiple can be set to 5 so, perhaps 4,6,7 or the like.
Step 7a: draw vector v 2 with vector v 0-v1, vector v 2 dwindled suitable multiple draw vector v 3, again with vector v 1+v3 get fish newly towards vector v 4;
The plus-minus of two vectors is exactly that their component is added and subtracted respectively:
This multiple that dwindles when hope makes fish rotate less radian, then can be chosen less multiple by the rotation radian decision of fish.
Shown in Fig. 2-4, draw vector v 2 by vector v 0-v1, with vector v 2 dwindle a suitable multiple draw vector v 3 (for example, among the figure vector v 3 be about v2 1/4th), draw vector v 4 by vector v 1+v3 again, this v4 be that fish will forward to newly towards.
The vector of unit length of step 10a: compute vector v4, and get the angle that fish will rotate according to the vector of unit length of this v4, according to postrotational position, the said polygonal summit of this angle calculation, more said polygonal summit is moved on to new position; The x axle of the vector of unit length of this v4 and y axle component are the cos and the sin value of the anglec of rotation of wanting.Wherein, as shown in Figure 5, the derivation of polygon vertex rotation is following:
X is former=cos (α) * R
Y is former=sin (α) * R
X change=cos (alpha+beta) * R
Y change=sin (alpha+beta) * R
So, the former * sin of the former * cos of X change=X (β)-Y (β);
The former * cos of the former * sin of Y change=X (β)+Y (β).
Respectively polygonal four summits of forming fish are rotated calculating, the result who draws be exactly fish newly towards under apex coordinate.
Step 11:, obtain the reposition of fish according to the component of vector v 4 at X axle and Y axle;
Step 12:, change the animation frame of fish, and return step 3 according to the reposition of fish.
Because fish, is put left such as tail different forms should be arranged in different positions, tail is put to the right, tells bubble etc.Therefore, in step 12,, changed the animation frame of fish, like this, just can realize the animation effect of mobile terminal desktop on the whole smoothly according to the reposition of fish.
To sum up; The method that desktop sprites of mobile terminal of the present invention is realized when AnimSprite (being fish) is in the rotation mobile status, can make fish radian is smoothly arranged turn to the target location; Thereby the present invention can realize the animation effect of mobile terminal desktop smoothly, has improved user's experience.
When fish is rotating to behind destination locations, just no longer need continue rotation but need be towards the destination locations rectilinear motion, as shown in Figure 6 in order to carry out this judgement and adjustment, can also comprise between above-mentioned steps 7a and the 10a:
The vector of unit length of step 8a: compute vector v0v1, whether judgment value is 1, if, vector v 0, v1 conllinear then are described, fish has rotated to towards destination locations, carries out step 9a this moment, if not, then carry out step 10a;
The dot product of vector is very useful, and a lot of graphics computings are used, because there are two formula just can calculate the angle of two vectors like this.Please referring to following explanation.
Two formulas according to top can be derived
cosθ=(U
x*V
x+U
y*V
y)/(/U/*/V/);
If you?
and?
is the unit vector of the words can be further simplified:
cosθ=U
x*V
x+U
y*V
y。
Step 9a: make the state of fish into the straight line mobile status, and be adjusted into the corresponding speed of straight line mobile status, execution in step 10a again.
As shown in Figure 6, in the above-mentioned steps 4, if judge that the fish current states is the straight line mobile status, execution in step 5b then; At this moment, said method also comprises:
Step 5b:, get the vector v 0 of the current location of fish to destination locations according to destination locations current location and that will go of fish;
The mould of step 6b: compute vector v0 | v0|, judge | whether v0| is less than setting value, if then carry out step 7b, if not, then keep the current state of fish, and go to step 11;
The mould of v0 is represented the distance of point-to-point transmission, therefore, when the mould of v0 during less than certain value, represents fish near more from point of destination, when fish near point of destination or after arriving point of destination, system generates next point of destination at random.
Step 7b: the next point of destination that generates fish at random;
Step 8b: change the state of fish into the rotation mobile status, and go to step 11.
In addition, can all not influence the enforcement of technical scheme of the present invention for different shapes such as quadrilateral (like rectangle, trapezoidal or parallelogram etc.), pentagons with the pairing polygon of fish among the present invention.
Corresponding with the method that above-mentioned desktop sprites of mobile terminal is realized, the present invention also provides a kind of portable terminal, and is as shown in Figure 7, comprising:
Data are written into unit 701, are used for the master data of desktop sprites of mobile terminal is written into buffer memory, and this master data comprises image information, translational speed and animation frame;
Definition and establishment unit 702 are used for AnimSprite is defined as polygon, and create corresponding apex coordinate and the texture coordinate of polygonized structure body and function to deposit AnimSprite;
Drawing unit 703 is used for drawing according to current apex coordinate the polygon of the texture image that comprises AnimSprite;
Judging unit 704 is used to judge the AnimSprite current states, if the rotation mobile status then goes to first computing unit;
First computing unit 705 is used for according to the current location of AnimSprite and the destination locations that will go thereof, and draws the vector v 0 of AnimSprite current location to destination locations;
Second computing unit 706 is used for the angle according to the rotation of current AnimSprite, draw towards vector of unit length, and according to the size of AnimSprite this vector of unit length is amplified suitable multiple and draws vector v 1;
The 3rd calculating unit 707 is used to utilize vector v 0-v1 to draw vector v 2, vector v 2 is dwindled suitable multiple draws vector v 3, again with vector v 1+v3 draw AnimSprite newly towards vector v 4;
The 4th computing unit 710; The vector of unit length that is used for compute vector v4; And draw the angle that AnimSprite will rotate according to the vector of unit length of this v4, according to postrotational position, the said polygonal summit of this angle calculation, more said polygonal summit is moved on to new position;
The 5th computing unit 711 is used for obtaining the reposition of AnimSprite according to the component of vector v 4 at X axle and Y axle;
Animation frame is changed unit 712, is used for the reposition according to AnimSprite, changes the animation frame of AnimSprite, and returns drawing unit.
Portable terminal of the present invention when AnimSprite is in the rotation mobile status, can make AnimSprite radian is smoothly arranged turn to the target location, thereby the present invention can realize the animation effect of mobile terminal desktop smoothly, has improved user's experience.
Preferably, above-mentioned portable terminal can also comprise:
The 6th computing unit is used for the vector of unit length of compute vector v0v1, and whether judgment value is 1, if then go to the first state adjustment unit, if not, then go to the 4th computing unit;
The first state adjustment unit is used for making the state of AnimSprite into the straight line mobile status, and is adjusted into the corresponding speed of straight line mobile status, goes to the 4th computing unit again.
Preferably, above-mentioned judging unit is further used for when the AnimSprite current states is the straight line mobile status, going to the 7th computing unit;
Above-mentioned portable terminal also comprises:
The 7th computing unit is used for destination locations current location and that will go according to AnimSprite, draws the vector v 0 of the current location of AnimSprite to destination locations;
The 8th computing unit is used for the mould of compute vector v0 | and v0|, judge | whether v0| is less than setting value, if then go to the point of destination generation unit, if not, then keep the current state of AnimSprite, and go to the 5th computing unit;
The point of destination generation unit is used for generating at random the next point of destination of AnimSprite;
The second state adjustment unit is used for changing the state of AnimSprite into the rotation mobile status, and goes to the 5th computing unit.
Preferably, said polygon is rectangle, trapezoidal or parallelogram.
Preferably, said AnimSprite is a fish.
The above is merely preferred embodiment of the present invention, is not to be used for limiting practical range of the present invention; If do not break away from the spirit and scope of the present invention, the present invention is made amendment or is equal to replacement, all should be encompassed in the middle of the protection domain of claim of the present invention.