Private
_shaderThe first component of the vector.
The second component of the vector.
Static
Readonly
DOWNA constant vector set to [0, -1].
Static
Readonly
LEFTA constant vector set to [-1, 0].
Static
Readonly
ONEA constant vector set to [1, 1].
Static
Readonly
RIGHTA constant vector set to [1, 0].
Static
Readonly
UPA constant vector set to [0, 1].
Static
Readonly
ZEROA constant vector set to [0, 0].
用于传入shader的数据
Adds a 2-dimensional vector to another in place.
Self for chaining.
var a = new pc.Vec2(10, 10);
var b = new pc.Vec2(20, 20);
a.add(b);
// Outputs [30, 30]
console.log("The result of the addition is: " + a.toString());
The vector to add to the specified vector.
Adds two 2-dimensional vectors together and returns the result.
Self for chaining.
var a = new pc.Vec2(10, 10);
var b = new pc.Vec2(20, 20);
var r = new pc.Vec2();
r.add2(a, b);
// Outputs [30, 30]
console.log("The result of the addition is: " + r.toString());
The first vector operand for the addition.
The second vector operand for the addition.
Copies the contents of a source 2-dimensional vector to a destination 2-dimensional vector.
Self for chaining.
var src = new pc.Vec2(10, 20);
var dst = new pc.Vec2();
dst.copy(src);
console.log("The two vectors are " + (dst.equals(src) ? "equal" : "different"));
A vector to copy to the specified vector.
Returns the result of a cross product operation performed on the two specified 2-dimensional vectors.
The cross product of the two vectors.
var right = new pc.Vec2(1, 0);
var up = new pc.Vec2(0, 1);
var crossProduct = right.cross(up);
// Prints 1
console.log("The result of the cross product is: " + crossProduct);
The second 2-dimensional vector operand of the cross product.
Returns the distance between the two specified 2-dimensional vectors.
The distance between the two vectors.
var v1 = new pc.Vec2(5, 10);
var v2 = new pc.Vec2(10, 20);
var d = v1.distance(v2);
console.log("The distance between v1 and v2 is: " + d);
The second 2-dimensional vector to test.
Divides a 2-dimensional vector by another in place.
Self for chaining.
var a = new pc.Vec2(4, 9);
var b = new pc.Vec2(2, 3);
a.div(b);
// Outputs [2, 3]
console.log("The result of the division is: " + a.toString());
The vector to divide the specified vector by.
Divides one 2-dimensional vector by another and writes the result to the specified vector.
Self for chaining.
var a = new pc.Vec2(4, 9);
var b = new pc.Vec2(2, 3);
var r = new pc.Vec2();
r.div2(a, b);
// Outputs [2, 3]
console.log("The result of the division is: " + r.toString());
The dividend vector (the vector being divided).
The divisor vector (the vector dividing the dividend).
Divides each element of a vector by a number.
Self for chaining.
var vec = new pc.Vec2(3, 6);
vec.divScalar(3);
// Outputs [1, 2]
console.log("The result of the division is: " + vec.toString());
The number to divide by.
Returns the result of a dot product operation performed on the two specified 2-dimensional vectors.
The result of the dot product operation.
var v1 = new pc.Vec2(5, 10);
var v2 = new pc.Vec2(10, 20);
var v1dotv2 = v1.dot(v2);
console.log("The result of the dot product is: " + v1dotv2);
The second 2-dimensional vector operand of the dot product.
Reports whether two vectors are equal.
True if the vectors are equal and false otherwise.
var a = new pc.Vec2(1, 2);
var b = new pc.Vec2(4, 5);
console.log("The two vectors are " + (a.equals(b) ? "equal" : "different"));
The vector to compare to the specified vector.
Returns the result of a linear interpolation between two specified 2-dimensional vectors.
Self for chaining.
var a = new pc.Vec2(0, 0);
var b = new pc.Vec2(10, 10);
var r = new pc.Vec2();
r.lerp(a, b, 0); // r is equal to a
r.lerp(a, b, 0.5); // r is 5, 5
r.lerp(a, b, 1); // r is equal to b
The 2-dimensional to interpolate from.
The 2-dimensional to interpolate to.
The value controlling the point of interpolation. Between 0 and 1, the linear interpolant will occur on a straight line between lhs and rhs. Outside of this range, the linear interpolant will occur on a ray extrapolated from this line.
Multiplies a 2-dimensional vector to another in place.
Self for chaining.
var a = new pc.Vec2(2, 3);
var b = new pc.Vec2(4, 5);
a.mul(b);
// Outputs 8, 15
console.log("The result of the multiplication is: " + a.toString());
The 2-dimensional vector used as the second multiplicand of the operation.
Returns the result of multiplying the specified 2-dimensional vectors together.
Self for chaining.
var a = new pc.Vec2(2, 3);
var b = new pc.Vec2(4, 5);
var r = new pc.Vec2();
r.mul2(a, b);
// Outputs 8, 15
console.log("The result of the multiplication is: " + r.toString());
The 2-dimensional vector used as the first multiplicand of the operation.
The 2-dimensional vector used as the second multiplicand of the operation.
Multiplies each element of a vector by a number.
Self for chaining.
var vec = new pc.Vec2(3, 6);
vec.mulScalar(3);
// Outputs [9, 18]
console.log("The result of the multiplication is: " + vec.toString());
The number to multiply by.
Returns this 2-dimensional vector converted to a unit vector in place. If the vector has a length of zero, the vector's elements will be set to zero.
Self for chaining.
var v = new pc.Vec2(25, 0);
v.normalize();
// Outputs 1, 0
console.log("The result of the vector normalization is: " + v.toString());
Sets the specified 2-dimensional vector to the supplied numerical values.
Self for chaining.
var v = new pc.Vec2();
v.set(5, 10);
// Outputs 5, 10
console.log("The result of the vector set is: " + v.toString());
The value to set on the first component of the vector.
The value to set on the second component of the vector.
Subtracts a 2-dimensional vector from another in place.
Self for chaining.
var a = new pc.Vec2(10, 10);
var b = new pc.Vec2(20, 20);
a.sub(b);
// Outputs [-10, -10]
console.log("The result of the subtraction is: " + a.toString());
The vector to add to the specified vector.
Subtracts two 2-dimensional vectors from one another and returns the result.
Self for chaining.
var a = new pc.Vec2(10, 10);
var b = new pc.Vec2(20, 20);
var r = new pc.Vec2();
r.sub2(a, b);
// Outputs [-10, -10]
console.log("The result of the subtraction is: " + r.toString());
The first vector operand for the addition.
The second vector operand for the addition.
Subtracts a number from each element of a vector.
Self for chaining.
var vec = new pc.Vec2(3, 4);
vec.subScalar(2);
// Outputs [1, 2]
console.log("The result of the subtraction is: " + vec.toString());
The number to subtract.
Create a new Vec2 instance.
Example