3dphotoshoot

view libs/vmath/sphvec.cc @ 17:aef7f51f6397

resource loading works
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 10 Jun 2015 06:56:27 +0300
parents
children
line source
1 /*
2 libvmath - a vector math library
3 Copyright (C) 2004-2015 John Tsiombikas <nuclear@member.fsf.org>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published
7 by the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #include "sphvec.h"
19 #include "vector.h"
21 /* theta: 0 <= theta <= 2pi, the angle around Y axis.
22 * phi: 0 <= phi <= pi, the angle from Y axis.
23 * r: radius.
24 */
25 SphVector::SphVector(scalar_t theta, scalar_t phi, scalar_t r) {
26 this->theta = theta;
27 this->phi = phi;
28 this->r = r;
29 }
31 /* Constructs a spherical coordinate vector from a cartesian vector */
32 SphVector::SphVector(const Vector3 &cvec) {
33 *this = cvec;
34 }
36 /* Assignment operator that converts cartesian to spherical coords */
37 SphVector &SphVector::operator =(const Vector3 &cvec) {
38 r = cvec.length();
39 //theta = atan2(cvec.y, cvec.x);
40 theta = atan2(cvec.z, cvec.x);
41 //phi = acos(cvec.z / r);
42 phi = acos(cvec.y / r);
43 return *this;
44 }