[ad_1]
Kevin ven der Velden’s reply is shut, however will get the categories improper.
The dot product of two vectors returns a scalar (float)
var prodVec = cc.pDot(inVector, thisNVector);
So this is not eligible as an argument for the componentwise multiplication operate pCompMult
as a result of it isn’t a vector.
In the case the place your second enter is a standard vector (pointing within the route the floor is dealing with) of unit size, the dot product offers the projection of your enter vector onto this regular’s route.
Scaling the conventional by this projection offers us the vector part of our enter vector within the route away from the floor. Subtracting this from our enter as soon as offers a vector parallel to the floor. Subtracting it twice offers us our mirrored vector: shifting away from the floor by the identical quantity, in the other way.
pReflect: operate(inVector, normalVector) {
var projection = cc.pDot(inVector, thisNVector);
var retVec = cc.pSub(inVector, cc.pMult(2 * projection, normalVector));
return retVec;
},
[ad_2]