camelCase
The Case of the Mysterious Camel.
- Reaction score
- 362
Let's say my vectors are made up of a radian and length:
How would I go about adding two vectors to get a new one?
I've tried for a bit but I never was good at math =/
(Which says a lot about my future as a game programmer.. ><)
[EDIT]
Ehh..
Here's my solution:
Let's say I have two 2D-vectors..
The above seem to get me my solution (On paper at least, I haven't tried coding it xD) but is it efficient?
Probably not, with that expensive sqrt there.. =/
Anyone got a better way?
Code:
class vector {
float rad,
len;
};
How would I go about adding two vectors to get a new one?
I've tried for a bit but I never was good at math =/
(Which says a lot about my future as a game programmer.. ><)
[EDIT]
Ehh..
Here's my solution:
Let's say I have two 2D-vectors..
Code:
//Set up my vectors
float pi = 3.141592653589;
vector a, b;
a.rad = (pi/4);
a.len = sprt(18);
a.rad = ((3 * pi) / 2);
a.len = 1;
//Then, when I want to add them..
vector result;
float x = (cos(a.rad) * a.length + cos(b.rad) * b.length);
float y = (sin(a.rad) * a.length + sin(b.rad) * b.length);
result.rad = atan2(y, x);
result.len = sqrt(x*x + y*y); //Pythagoras' theorem
The above seem to get me my solution (On paper at least, I haven't tried coding it xD) but is it efficient?
Probably not, with that expensive sqrt there.. =/
Anyone got a better way?