Blender V2.61 - r43446

MT_Tuple3.h

Go to the documentation of this file.
00001 /*
00002  * ***** BEGIN GPL LICENSE BLOCK *****
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software Foundation,
00016  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  *
00018  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
00019  * All rights reserved.
00020  *
00021  * The Original Code is: all of this file.
00022  *
00023  * Contributor(s): none yet.
00024  *
00025  * ***** END GPL LICENSE BLOCK *****
00026  */
00027 
00033 /*
00034 
00035  * Copyright (c) 2000 Gino van den Bergen <gino@acm.org>
00036  *
00037  * Permission to use, copy, modify, distribute and sell this software
00038  * and its documentation for any purpose is hereby granted without fee,
00039  * provided that the above copyright notice appear in all copies and
00040  * that both that copyright notice and this permission notice appear
00041  * in supporting documentation.  Gino van den Bergen makes no
00042  * representations about the suitability of this software for any
00043  * purpose.  It is provided "as is" without express or implied warranty.
00044  *
00045  */
00046 
00047 #ifndef MT_TUPLE3_H
00048 #define MT_TUPLE3_H
00049 
00050 #include "MT_Stream.h"
00051 #include "MT_Scalar.h"
00052 
00053 class MT_Tuple3 {
00054 public:
00055     MT_Tuple3() {}
00056     MT_Tuple3(const float *v) { setValue(v); }
00057     MT_Tuple3(const double *v) { setValue(v); }
00058     MT_Tuple3(MT_Scalar xx, MT_Scalar yy, MT_Scalar zz) { setValue(xx, yy, zz); }
00059     
00060     MT_Scalar&       operator[](int i)       { return m_co[i]; }
00061     const MT_Scalar& operator[](int i) const { return m_co[i]; }
00062     
00063     MT_Scalar&       x()       { return m_co[0]; } 
00064     const MT_Scalar& x() const { return m_co[0]; } 
00065 
00066     MT_Scalar&       y()       { return m_co[1]; }
00067     const MT_Scalar& y() const { return m_co[1]; } 
00068 
00069     MT_Scalar&       z()       { return m_co[2]; } 
00070     const MT_Scalar& z() const { return m_co[2]; } 
00071 
00072     MT_Scalar       *getValue()       { return m_co; }
00073     const MT_Scalar *getValue() const { return m_co; }
00074 
00075     void getValue(float *v) const { 
00076         v[0] = float(m_co[0]); 
00077         v[1] = float(m_co[1]); 
00078         v[2] = float(m_co[2]);
00079     }
00080     
00081     void getValue(double *v) const { 
00082         v[0] = double(m_co[0]); 
00083         v[1] = double(m_co[1]); 
00084         v[2] = double(m_co[2]);
00085     }
00086     
00087     void setValue(const float *v) {
00088         m_co[0] = MT_Scalar(v[0]); 
00089         m_co[1] = MT_Scalar(v[1]); 
00090         m_co[2] = MT_Scalar(v[2]);
00091     }
00092     
00093     void setValue(const double *v) {
00094         m_co[0] = MT_Scalar(v[0]); 
00095         m_co[1] = MT_Scalar(v[1]);
00096         m_co[2] = MT_Scalar(v[2]);
00097     }
00098     
00099     void setValue(MT_Scalar xx, MT_Scalar yy, MT_Scalar zz) {
00100         m_co[0] = xx; m_co[1] = yy; m_co[2] = zz;
00101     }
00102     
00103 protected:
00104     MT_Scalar m_co[3];                            
00105 };
00106 
00107 inline bool operator==(const MT_Tuple3& t1, const MT_Tuple3& t2) {
00108     return t1[0] == t2[0] && t1[1] == t2[1] && t1[2] == t2[2];
00109 }
00110 
00111 inline MT_OStream& operator<<(MT_OStream& os, const MT_Tuple3& t) {
00112     return os << t[0] << ' ' << t[1] << ' ' << t[2];
00113 }
00114 
00115 #endif
00116