3dphotoshoot
diff libs/vmath/sphvec.cc @ 10:c71c477521ca
converting to GLES2 and C++
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sun, 31 May 2015 00:40:26 +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 May 31 00:40:26 2015 +0300 1.3 @@ -0,0 +1,44 @@ 1.4 +/* 1.5 +libvmath - a vector math library 1.6 +Copyright (C) 2004-2015 John Tsiombikas <nuclear@member.fsf.org> 1.7 + 1.8 +This program is free software: you can redistribute it and/or modify 1.9 +it under the terms of the GNU Lesser General Public License as published 1.10 +by the Free Software Foundation, either version 3 of the License, or 1.11 +(at your option) any later version. 1.12 + 1.13 +This program is distributed in the hope that it will be useful, 1.14 +but WITHOUT ANY WARRANTY; without even the implied warranty of 1.15 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1.16 +GNU Lesser General Public License for more details. 1.17 + 1.18 +You should have received a copy of the GNU Lesser General Public License 1.19 +along with this program. If not, see <http://www.gnu.org/licenses/>. 1.20 +*/ 1.21 +#include "sphvec.h" 1.22 +#include "vector.h" 1.23 + 1.24 +/* theta: 0 <= theta <= 2pi, the angle around Y axis. 1.25 + * phi: 0 <= phi <= pi, the angle from Y axis. 1.26 + * r: radius. 1.27 + */ 1.28 +SphVector::SphVector(scalar_t theta, scalar_t phi, scalar_t r) { 1.29 + this->theta = theta; 1.30 + this->phi = phi; 1.31 + this->r = r; 1.32 +} 1.33 + 1.34 +/* Constructs a spherical coordinate vector from a cartesian vector */ 1.35 +SphVector::SphVector(const Vector3 &cvec) { 1.36 + *this = cvec; 1.37 +} 1.38 + 1.39 +/* Assignment operator that converts cartesian to spherical coords */ 1.40 +SphVector &SphVector::operator =(const Vector3 &cvec) { 1.41 + r = cvec.length(); 1.42 + //theta = atan2(cvec.y, cvec.x); 1.43 + theta = atan2(cvec.z, cvec.x); 1.44 + //phi = acos(cvec.z / r); 1.45 + phi = acos(cvec.y / r); 1.46 + return *this; 1.47 +}