Thank you very much.
I am using Javascript. Javascript does not have built-in Vector objects, and therefore it all becomes much harder. There are a few libraries(
such as this one) that do some of the vector math for you, but you have to call them using functions instead of the standard math operators. They also are badly documented.
Because vectors are stored as a number pair, and these pairs also get labeled "x" and "y" it is still not clear to me if a vector is a cartesian coordinate, or a (direction) (velocity) pair. And in the second case, in which order should the values be stored? Or does this not matter? Does it matter if you use radians or degrees? Or are both these things irrelevant, as long as you store all your vectors this way?
I tried the following code to bounce objects up when they hit the bottom of the screen.
var Vin = new Vec2(this.rotation, this.speed);
var Vnormal = new Vec2(Math.PI, 1);
var Vnormal2 = new Vec2(Math.PI,1);
var e = 1;
vMath.dot(Vnormal, Vin);//Vnormal now is: (Vnormal . Vin)
vMath.mulS(Vnormal,1+e );//Vnormal now is: (1+e)*(Vnormal . Vin)
vMath.mulV(Vnormal,Vnormal2 );//Vnormal now is: Vnormal * (1+e)*(Vnormal . Vin)
vMath.subV(Vin, Vnormal);//Vin now is: Vin - (Vnormal * (1+e)*(Vnormal . Vin)
var Vout = Vin;//Full statement: Vout = Vin - (Vnormal * (1+e)*(Vnormal . Vin)
this.setRotation(Vout.x);
This does not work. Using some console.log statements to check the values inbetween the steps, I get back the following feedback in the console:
this.rotation = 0
this.speed = 0.01
(Vnormal . Vin) x: 3.141592653589793 y:1
(1+e)*(Vnormal . Vin) x:6.283185307179586 y:2
Vnormal * (1+e)*(Vnormal . Vin) x:19.739208802178716 y:2
Vin - (Vnormal * (1+e)*(Vnormal . Vin) x:-19.739208802178716 y:-1.9
final result: Vec2 {x: -19.739208802178716, y: -1.9}
This does not at all seem right to me. The rotation value should become either 0 or 2PI, and the speed should stay at 0.01, since I gave in full restitution.
Hopefully someone knows what I am doing wrong.