Object definitions, constants, and constructors
Defined:
Cp. Vect = function (x, y) {this.x = x; This.y = y;}
0 Vector constants:
Cp.vzero = CP.V (0,0);
The convenient constructor used to create the new struct:
CP.V (x, y)
Operation Operations
V, V1, v2 are all CP. Vect, s,t,d,dist for float
Cp. Bool cp.v.eql (v1, v2) – detects the equality of two vectors. When using a C + + program, Chipmunk provides an overloaded operator ==
. (Be careful when comparing floating point numbers!) )
Cp. Vect Cp.v.add (v1, v2) – Two vectors are added together. When using a C + + program, Chipmunk provides an overloaded operator +
.
Cp. Vect cp.v.sub (v1, v2) – subtracts two vectors. When using a C + + program, Chipmunk provides an overloaded operator -
.
Cp. Vect Cp.v.neg (v) – causes a vector to reverse. When using a C + + program, Chipmunk provides an overloaded one-unary negative operator -
.
Cp. Vect Cp.v.mult (V, s) – scalar multiplication. When using a C + + program, Chipmunk provides an overloaded operator *
.
Cp. Float Cp.v.dot (v1, v2) – The dot product of the vector.
Cp. Float Cp.v.cross (v1, v2) –2d vectors cross-multiply the modulo. The product of a 2D vector cross-multiply is a z-value of a 3D vector with only z-coordinates. The function returns the value of the z-coordinate.
Cp. Vect Cp.v.perp (v) – returns a vertical vector. (Rotate 90 degrees)
Cp. Vect Cp.v.rperp (v) – returns a vertical vector. (Rotation-90 degrees)
Cp. Vect Cp.v.project (v1, V2) – returns the projection of the vector v1 on the vector v2.
Cp. Vect cp.v.rotate (v1, v2) – Use a complex multiplication operation to rotate the vector v1 according to the vector v2. If the V1 is not a unit vector, the V1 is scaled.
Cp. Vect cp.v.unrotate (v1, v2) – and Cpvrotate () in contrast.
Cp. Float Cp.v.len (v) – returns the length of V.
Cp. Float cp.v.lengthsq (v) – returns the square of the length of V, which is faster than cpvlength () if it is just the length of the comparison.
Cp. Vect Cp.v.lerp (v1, V2, T) – linear interpolation between V1 and V2.
Cp. Vect Cp.v.lerpconst (V1,v2, D) – linear interpolation between V1 and V2 with length d.
Cp. Vect Cp.v.slerp (v1, V2, T) – spherical linear interpolation between V1 and V2.
Cp. Vect Cp.v.slerpconst (v1, V2, a) – a spherical linear interpolation between V1 and V2 with a Radian value not exceeding the angle a.
Cp. Vect Cp.v.normalize (v) – returns a normalized copy of a. As a special example, the Cpvzero is returned when Cpvzero is called.
Cp. Vect Cp.v.clamp (V, Len) – Secures V to Len.
Cp. Float cp.v.dist (v1, V2) – returns the distance between V1 and v2.
Cp. Float cp.v.distsq (v1, V2) – returns the square of the distance between V1 and v2. It is faster than cpvdist () if it is just a comparison of distances.
Cp. Bool cp.v.near (v1, V2, Dist) – returns True if the distance between V1 and V2 is less than Dist.
Cp. Vect Cp.v.forangle (A) – returns the vector of the given angular (in radians) units.
Cp. Float Cp.v.toangle (v) – returns the radian of the angle direction that V refers to.
Partial test
Cp. Vect Test var vect1 = CP.V (2, 3), var vect2 = cp.v (1, 1); var vect3 = new CP. Vect (2, 3); Cc.log (CP.V.EQL (Vect1, vect2)); Falsecc.log (CP.V.EQL (Vect1, vect3)); Truecc.log (Cp.v.add (Vect1, vect2)); CP.V (3, 4)
Reference:
http://www.tairan.com/archives/5670
Chipmunk vectors in Cocos2d-js: cp.vect