After a project of Android was completed some time ago, the team now started to develop games. After discussion, teammates very optimistic about cocos2d-x, so the team began to learn now sold, decided to do something to practice hands.
When doing cocos2d-x, will find some problems. For example, the version of the cocos2d-x updated too fast, the online blog is the old version of the tutorial, the new version of some methods have been abandoned or renamed, And the cocos2d-x book is very little, so it is troublesome to get started.
For this problem, I personally think it is best to take a look at the documents on the official website to study the differences between the old version and the new version, and solve the problem.
That is the question, saying that game development, to use more mathematical computing, for programmers, or with a lazy way, cocos2d-x to facilitate developers opportunistic... it provides many convenient mathematical functions to facilitate our mathematical calculation. The following are some common mathematical methods collected online!
Mathematical functions:
[C ++]
Ccp (x, y); // create a vector with coordinates x and y
CcpFromSize (s); // create a vector using the width of size s as x and height as y
Ccp (x, y); // create a vector with coordinates x and y
CcpFromSize (s); // create a vector using the width of size s as x and height as y
Addition, subtraction, multiplication, division, and operation of CCPoint
[C ++]
CcpAdd (v1, v2); // equivalent ccp (v1.x + v2.x, v1.y + v2.y );
CcpSub (v1, v2); // equivalent ccp (v1.x-v2.x, v1.y-v2.y );
CcpNeg (v) // equivalent ccp (-v. x,-v. y );
CcpMult (v, s); // equivalent ccp (v. x * s, v. y * s); s is a floating point number
CcpAdd (v1, v2); // equivalent ccp (v1.x + v2.x, v1.y + v2.y );
CcpSub (v1, v2); // equivalent ccp (v1.x-v2.x, v1.y-v2.y );
CcpNeg (v) // equivalent ccp (-v. x,-v. y );
CcpMult (v, s); // equivalent ccp (v. x * s, v. y * s); s is a floating point number
Midpoint:
[C ++]
CcpMidpoint (v1, v2); // equivalent ccp (v1.x + v2.x)/2, (v1.y + v2.y)/2 );
CcpMidpoint (v1, v2); // equivalent ccp (v1.x + v2.x)/2, (v1.y + v2.y)/2 );
Dot multiplication, cross multiplication, and projection:
[C ++]
CcpDot (v1, v2); // equivalent v1.x * v2.x + v1.y * v2.y;
CcpCross (v1, v2); // equivalent v1.x * v2.y-v1.y * v2.x;
CcpProject (v1, v2) // returns the projection vector of vector v1 on vector v2.
CcpDot (v1, v2); // equivalent v1.x * v2.x + v1.y * v2.y;
CcpCross (v1, v2); // equivalent v1.x * v2.y-v1.y * v2.x;
CcpProject (v1, v2) // returns the projection vector of vector v1 on vector v2.
Evaluate the length, distance, and their square values:
[C ++]
CcpLength (v) // returns the length of vector v, that is, the distance from vertex v to the origin.
CcpLengthSQ (v) // returns the square of the length of vector v, that is, the square of the distance from point v to the origin.
CcpDistance (v1, v2) // returns the distance from v1 to v2.
CcpDistanceSQ (v1, v2) // returns the square of the distance from point v1 to point v2.
CcpNormalize (v) // returns the standardized vector of v, that is, the length is 1
CcpLength (v) // returns the length of vector v, that is, the distance from vertex v to the origin.
CcpLengthSQ (v) // returns the square of the length of vector v, that is, the square of the distance from point v to the origin.
CcpDistance (v1, v2) // returns the distance from v1 to v2.
CcpDistanceSQ (v1, v2) // returns the square of the distance from point v1 to point v2.
CcpNormalize (v) // returns the standardized vector of v, that is, the length is 1
Rotate, 90 degrees clockwise, 90 degrees clockwise:
[C ++]
CcpRotate (v1, v2); // vector v1 rotates the angle of vector v2 and multiplied by the length of vector v2. When v2 is a standard vector with a length of 1, it is a normal rotation, and ccpForAngle can be used together.
CcpPerp (v); // equivalent to ccp (-v. y, v. x); (because the opengl coordinate system is the origin in the lower left corner, the vector v is rotated 90 degrees counterclockwise)
CcpRPerp (v); // equivalent to ccp (v. y,-v. x); Rotate 90 degrees clockwise
CcpRotate (v1, v2); // vector v1 rotates the angle of vector v2 and multiplied by the length of vector v2. When v2 is a standard vector with a length of 1, it is a normal rotation, and ccpForAngle can be used together.
CcpPerp (v); // equivalent to ccp (-v. y, v. x); (because the opengl coordinate system is the origin in the lower left corner, the vector v is rotated 90 degrees counterclockwise)
CcpRPerp (v); // equivalent to ccp (v. y,-v. x); Rotate 90 degrees clockwise
The supported conversion vectors include vectors and radians. There are also some angle-related vectors:
[C ++]
CcpForAngle (a); // returns a standard vector with an angle of radians.
CcpToAngle (v); // returns the Radian of the vector v.
CcpAngle (a, B); // returns the radians of the angle difference indicated by vectors a and B.
CcpRotateByAngle (v, degrees, angle) // return vector v uses degrees as the rotation axis point and rotates angle radians in a counterclockwise direction.
CcpForAngle (a); // returns a standard vector with an angle of radians.
CcpToAngle (v); // returns the Radian of the vector v.
CcpAngle (a, B); // returns the radians of the angle difference indicated by vectors a and B.
CcpRotateByAngle (v, degrees, angle) // return vector v uses degrees as the rotation axis point and rotates angle radians in a counterclockwise direction.
Detection of intersection of line segments:
[C ++]
CcpLineIntersect (p1, p2, p3, p4, & s, & t ); // returns whether the straight line where p1 is the start point p2 is the end line 1 and p3 is the start point p4 is the end line 2. If yes, parameters s and t return the ratio of the intersection online segment 1 and Line Segment 2.
// Obtain the intersection of s and t by p1 + s * (p2-p1) or p3 + t * (p4-p3.
CcpSegmentIntersect (A, B C, D) // returns whether the A-B of A line segment and the C-D of A line segment are intersecting
CcpIntersectPoint (A, B, C, D) // returns the intersection of A line A-B and A line C-D
CcpLineIntersect (p1, p2, p3, p4, & s, & t ); // returns whether the straight line where p1 is the start point p2 is the end line 1 and p3 is the start point p4 is the end line 2. If yes, parameters s and t return the ratio of the intersection online segment 1 and Line Segment 2.
// Obtain the intersection of s and t by p1 + s * (p2-p1) or p3 + t * (p4-p3.
CcpSegmentIntersect (A, B C, D) // returns whether the A-B of A line segment and the C-D of A line segment are intersecting
CcpIntersectPoint (A, B, C, D) // returns the intersection of A line A-B and A line C-D
Other useful:
[C ++]
CC_RADIANS_TO_DEGREES (a); // radian Rotation Angle
CC_DEGREES_TO_RADIANS (a); // converts degrees to radians.
CCRANDOM_0_1 (); // generates a random floating point number between 0 and 1.
CCRANDOM_MINUS1_1 (); // generates a random floating point number between-1 and 1.
CC_RADIANS_TO_DEGREES (a); // radian Rotation Angle
CC_DEGREES_TO_RADIANS (a); // converts degrees to radians.
CCRANDOM_0_1 (); // generates a random floating point number between 0 and 1.
CCRANDOM_MINUS1_1 (); // generates a random floating point number between-1 and 1.