so, this is one for the math-savvy folks here...
say i have a surface, and a ball to collide against it - this surface is represented as a plane defined by normal vector...
this is all in 2d, and is part of my quad-tree simulation thing....
the surface normal is contained in each quad that has a surface segment going through it... anyways, that's all sorted out, but now - i need to get stuff bumping off of it....
in order to simplify things, i have that "surface normal" vector normalized at a pre-compute step, so i don't have to calculate that in run-time....
and then, my plan is, in order to actually check the colliding of objects against said surface, i'd just "rotate" them into "local space" by building a transform matrix out of the normal vector...
the math sounds coherent - but i can't seem to get this to work for the life of me....
a rotation is (i hope) defined in matrix form like this:
rx = vx* cos(r) + vy*sin(r);
ry = vx*-sin(r) + vy*cos(r);
so i figured that already having the unit-length surface normal vector, i could very well build a matrix around it and use that to rotate other vectors from "world space" into "surface space"...
which kinda makes sense, since the normal vector's x and y values should directly match the cos and sin of the angle between that and the world-space idea of "up"...
so i figured i could just substitute:
rx = vx* nrml.x + vy*nrml.y;
ry = vx*-nrml.y + vy*nrml.x;
and skip a bunch of expensive computation steps - i could almost hear the CPU applauding this idea....
but then, it didn't really work... and i'm not sure exactly WHAT i messed up this time....
i wonder if i should have swapped X and Y somewhere... googling for an answer has proven fruitless for a few days now... so now i ask here
how does one build a rot-matrix around a normalized vector?
and i thank you in advance!
say i have a surface, and a ball to collide against it - this surface is represented as a plane defined by normal vector...
this is all in 2d, and is part of my quad-tree simulation thing....
the surface normal is contained in each quad that has a surface segment going through it... anyways, that's all sorted out, but now - i need to get stuff bumping off of it....
in order to simplify things, i have that "surface normal" vector normalized at a pre-compute step, so i don't have to calculate that in run-time....
and then, my plan is, in order to actually check the colliding of objects against said surface, i'd just "rotate" them into "local space" by building a transform matrix out of the normal vector...
the math sounds coherent - but i can't seem to get this to work for the life of me....
a rotation is (i hope) defined in matrix form like this:
rx = vx* cos(r) + vy*sin(r);
ry = vx*-sin(r) + vy*cos(r);
so i figured that already having the unit-length surface normal vector, i could very well build a matrix around it and use that to rotate other vectors from "world space" into "surface space"...
which kinda makes sense, since the normal vector's x and y values should directly match the cos and sin of the angle between that and the world-space idea of "up"...
so i figured i could just substitute:
rx = vx* nrml.x + vy*nrml.y;
ry = vx*-nrml.y + vy*nrml.x;
and skip a bunch of expensive computation steps - i could almost hear the CPU applauding this idea....
but then, it didn't really work... and i'm not sure exactly WHAT i messed up this time....
i wonder if i should have swapped X and Y somewhere... googling for an answer has proven fruitless for a few days now... so now i ask here
how does one build a rot-matrix around a normalized vector?
and i thank you in advance!