|
Blender
V2.59
|
00001 /* 00002 * $Id: MT_Tuple4.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_TUPLE4_H 00049 #define MT_TUPLE4_H 00050 00051 #include "MT_Stream.h" 00052 #include "MT_Scalar.h" 00053 00054 class MT_Tuple4 { 00055 public: 00056 MT_Tuple4() {} 00057 MT_Tuple4(const float *v) { setValue(v); } 00058 MT_Tuple4(const double *v) { setValue(v); } 00059 MT_Tuple4(MT_Scalar xx, MT_Scalar yy, MT_Scalar zz, MT_Scalar ww) { 00060 setValue(xx, yy, zz, ww); 00061 } 00062 00063 MT_Scalar& operator[](int i) { return m_co[i]; } 00064 const MT_Scalar& operator[](int i) const { return m_co[i]; } 00065 00066 MT_Scalar& x() { return m_co[0]; } 00067 const MT_Scalar& x() const { return m_co[0]; } 00068 00069 MT_Scalar& y() { return m_co[1]; } 00070 const MT_Scalar& y() const { return m_co[1]; } 00071 00072 MT_Scalar& z() { return m_co[2]; } 00073 const MT_Scalar& z() const { return m_co[2]; } 00074 00075 MT_Scalar& w() { return m_co[3]; } 00076 const MT_Scalar& w() const { return m_co[3]; } 00077 00078 MT_Scalar *getValue() { return m_co; } 00079 const MT_Scalar *getValue() const { return m_co; } 00080 00081 00082 void getValue(float *v) const { 00083 v[0] = float(m_co[0]); 00084 v[1] = float(m_co[1]); 00085 v[2] = float(m_co[2]); 00086 v[3] = float(m_co[3]); 00087 } 00088 00089 void getValue(double *v) const { 00090 v[0] = double(m_co[0]); 00091 v[1] = double(m_co[1]); 00092 v[2] = double(m_co[2]); 00093 v[3] = double(m_co[3]); 00094 } 00095 00096 void setValue(const float *v) { 00097 m_co[0] = MT_Scalar(v[0]); 00098 m_co[1] = MT_Scalar(v[1]); 00099 m_co[2] = MT_Scalar(v[2]); 00100 m_co[3] = MT_Scalar(v[3]); 00101 } 00102 00103 void setValue(const double *v) { 00104 m_co[0] = MT_Scalar(v[0]); 00105 m_co[1] = MT_Scalar(v[1]); 00106 m_co[2] = MT_Scalar(v[2]); 00107 m_co[3] = MT_Scalar(v[3]); 00108 } 00109 00110 void setValue(MT_Scalar xx, MT_Scalar yy, MT_Scalar zz, MT_Scalar ww) { 00111 m_co[0] = xx; m_co[1] = yy; m_co[2] = zz; m_co[3] = ww; 00112 } 00113 00114 protected: 00115 MT_Scalar m_co[4]; 00116 }; 00117 00118 inline bool operator==(const MT_Tuple4& t1, const MT_Tuple4& t2) { 00119 return t1[0] == t2[0] && t1[1] == t2[1] && t1[2] == t2[2] && t1[3] == t2[3]; 00120 } 00121 00122 inline MT_OStream& operator<<(MT_OStream& os, const MT_Tuple4& t) { 00123 return os << t[0] << ' ' << t[1] << ' ' << t[2] << ' ' << t[3]; 00124 } 00125 00126 #endif 00127