dungeon_crawler

diff prototype/vmath/sphvec.cc @ 1:96de911d05d4

started a rough prototype
author John Tsiombikas <nuclear@mutantstargoat.com>
date Thu, 28 Jun 2012 06:05:50 +0300
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/prototype/vmath/sphvec.cc	Thu Jun 28 06:05:50 2012 +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 +}