(3D) angle to vectors ( my terrible math... )

Hello!

Ive created one function in the past:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
inline double vec_lenght( double *vector )
{
	return sqrt(vector[0]*vector[0]+vector[1]*vector[1]+vector[2]*vector[2]);
}

inline void angle_to_vectors( double *angle, double power, double *vector )
{

	double rad, d, v[3];
	rad = (angle[1]*M_PI/180.0) + 0.000001;
	v[1] = sin(rad) * power;
	v[0] = cos(rad) * power;
	v[2] = 0.0;

	rad = (angle[0]*M_PI/180.0) + 0.000001;
	v[2] = tan(rad) * power;

	d = vec_lenght(v);
	vector[1] = (v[1] * (power/d)) / -1.0;
	vector[0] = v[0] * (power/d);
	vector[2] = v[2] * (power/d);
}


It isint working well, it is working somehow.
I searched through the internet and never found the formula or function what works fine.

As you can tell that my function can not work with the pitch.
Changing the pitch will change the x and y coords but it only changes z.
I dont even know how right is my x and y formula.

Can someone give me a working function or formula?
Thanks!
Topic archived. No new replies allowed.