function to rotate a vector
Blitz3D Forums/Blitz3D Programming/function to rotate a vector
| ||
Anyone got a function to rotate a vector? Here's the function I used and it's returning totally screwy results. x = (x * Cos(angle)) - (y * Sin(angle)) y = (y * Cos(angle)) + (x * Sin(angle)) |
| ||
r = sqrt(x*x+y*y) newangle = acos(x/r)+angle x = r*cos(newangle) y = r*sin(newangle) No idea if this works, just something I came up with |
| ||
The reason the first code fails is that x changes before it is used to calculate y. You would need something like this: tempx = x * Cos(angle) - y * Sin(angle) y = y * Cos(angle) + x * Sin(angle) x = tempx |