include/quaternion.h
branchpyrit
changeset 44 3763b26244f0
parent 34 28f6e8b9d5d1
child 46 6493fb65f0b1
equal deleted inserted replaced
43:0b8b968b42d1 44:3763b26244f0
     1 /*
     1 /*
     2  * Pyrit Ray Tracer
     2  * quaternion.h: Quaternion class
     3  * file: quaternion.h
       
     4  *
     3  *
     5  * Radek Brich, 2006-2007
     4  * This file is part of Pyrit Ray Tracer.
       
     5  *
       
     6  * Copyright 2007  Radek Brich
       
     7  *
       
     8  * Permission is hereby granted, free of charge, to any person obtaining a copy
       
     9  * of this software and associated documentation files (the "Software"), to deal
       
    10  * in the Software without restriction, including without limitation the rights
       
    11  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
       
    12  * copies of the Software, and to permit persons to whom the Software is
       
    13  * furnished to do so, subject to the following conditions:
       
    14  *
       
    15  * The above copyright notice and this permission notice shall be included in
       
    16  * all copies or substantial portions of the Software.
       
    17  *
       
    18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
       
    19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
       
    20  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
       
    21  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
       
    22  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
       
    23  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
       
    24  * THE SOFTWARE.
     6  */
    25  */
     7 
    26 
     8 #ifndef QUATERNION_H
    27 #ifndef QUATERNION_H
     9 #define QUATER_H
    28 #define QUATER_H
    10 
    29 
    20 		};
    39 		};
    21 	};
    40 	};
    22 	Quaternion(): a(0), b(0), c(0), d(0) {};
    41 	Quaternion(): a(0), b(0), c(0), d(0) {};
    23 	Quaternion(const Float aa, const Float ab, const Float ac, const Float ad):
    42 	Quaternion(const Float aa, const Float ab, const Float ac, const Float ad):
    24 		a(aa), b(ab), c(ac), d(ad) {};
    43 		a(aa), b(ab), c(ac), d(ad) {};
    25 	Quaternion(const Vector3& v): a(1), b(v.x), c(v.y), d(v.z) {};
    44 	Quaternion(const Vector3& v): a(0), b(v.x), c(v.y), d(v.z) {};
    26 
    45 
    27 	Vector3 toVector() { return Vector3(b/a, c/a, d/a); };
    46 	Vector3 toVector() { return Vector3(b, c, d); };
    28 
    47 
    29 	Quaternion normalize()
    48 	Quaternion normalize()
    30 	{
    49 	{
    31 		Float f = 1.0f / sqrtf(a * a + b * b + c * c + d * d);
    50 		Float f = 1.0f / sqrtf(a * a + b * b + c * c + d * d);
    32 		a *= f;
    51 		a *= f;