goat3d

diff 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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/libs/vmath/sphvec.cc	Sun Sep 29 08:20:19 2013 +0300
     1.3 @@ -0,0 +1,27 @@
     1.4 +#include "sphvec.h"
     1.5 +#include "vector.h"
     1.6 +
     1.7 +/* theta: 0 <= theta <= 2pi, the angle around Y axis.
     1.8 + * phi: 0 <= phi <= pi, the angle from Y axis.
     1.9 + * r: radius.
    1.10 + */
    1.11 +SphVector::SphVector(scalar_t theta, scalar_t phi, scalar_t r) {
    1.12 +	this->theta = theta;
    1.13 +	this->phi = phi;
    1.14 +	this->r = r;
    1.15 +}
    1.16 +
    1.17 +/* Constructs a spherical coordinate vector from a cartesian vector */
    1.18 +SphVector::SphVector(const Vector3 &cvec) {
    1.19 +	*this = cvec;
    1.20 +}
    1.21 +
    1.22 +/* Assignment operator that converts cartesian to spherical coords */
    1.23 +SphVector &SphVector::operator =(const Vector3 &cvec) {
    1.24 +	r = cvec.length();
    1.25 +	//theta = atan2(cvec.y, cvec.x);
    1.26 +	theta = atan2(cvec.z, cvec.x);
    1.27 +	//phi = acos(cvec.z / r);
    1.28 +	phi = acos(cvec.y / r);
    1.29 +	return *this;
    1.30 +}