goat3d
view libs/vmath/sphvec.cc @ 27:4deb0b12fe14
wtf... corrupted heap?
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sun, 29 Sep 2013 08:20:19 +0300 |
parents | |
children |
line source
1 #include "sphvec.h"
2 #include "vector.h"
4 /* theta: 0 <= theta <= 2pi, the angle around Y axis.
5 * phi: 0 <= phi <= pi, the angle from Y axis.
6 * r: radius.
7 */
8 SphVector::SphVector(scalar_t theta, scalar_t phi, scalar_t r) {
9 this->theta = theta;
10 this->phi = phi;
11 this->r = r;
12 }
14 /* Constructs a spherical coordinate vector from a cartesian vector */
15 SphVector::SphVector(const Vector3 &cvec) {
16 *this = cvec;
17 }
19 /* Assignment operator that converts cartesian to spherical coords */
20 SphVector &SphVector::operator =(const Vector3 &cvec) {
21 r = cvec.length();
22 //theta = atan2(cvec.y, cvec.x);
23 theta = atan2(cvec.z, cvec.x);
24 //phi = acos(cvec.z / r);
25 phi = acos(cvec.y / r);
26 return *this;
27 }