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