Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

TexCoord4.h

Go to the documentation of this file.
00001 //------------------------------------------------------------------------------
00002 // Lamp : Open source game middleware
00003 // Copyright (C) 2004  Junpei Ohtani ( Email : junpee@users.sourceforge.jp )
00004 //
00005 // This library is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public
00007 // License as published by the Free Software Foundation; either
00008 // version 2.1 of the License, or (at your option) any later version.
00009 //
00010 // This library 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 GNU
00013 // Lesser General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU Lesser General Public
00016 // License along with this library; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 //------------------------------------------------------------------------------
00019 
00020 /** @file
00021  * 四次元テクスチャ座標ヘッダ
00022  * @author Junpee
00023  */
00024 
00025 #ifndef TEX_COORD_4_H_
00026 #define TEX_COORD_4_H_
00027 
00028 #include <Core/System/Math.h>
00029 #include <Core/Primitive/String.h>
00030 
00031 namespace Lamp{
00032 
00033 //------------------------------------------------------------------------------
00034 /**
00035  * 四次元テクスチャ座標
00036  *
00037  * このクラスは継承しないで下さい。
00038  */
00039 class TexCoord4{
00040 public:
00041     //--------------------------------------------------------------------------
00042     // メンバ変数
00043     //--------------------------------------------------------------------------
00044     /// メンバ変数
00045     union{
00046         /// 各要素
00047         struct{
00048             /// U値
00049             float u;
00050             /// V値
00051             float v;
00052             /// W値
00053             float w;
00054             /// X値
00055             float x;
00056         };
00057 
00058         /// 配列
00059         float array[4];
00060     };
00061 
00062     //--------------------------------------------------------------------------
00063     // 定数
00064     //--------------------------------------------------------------------------
00065     /// ゼロ座標
00066     static const TexCoord4 zero;
00067 
00068     /// 単位座標
00069     static const TexCoord4 unit;
00070 
00071     /// U単位座標
00072     static const TexCoord4 unitU;
00073 
00074     /// V単位座標
00075     static const TexCoord4 unitV;
00076 
00077     /// W単位座標
00078     static const TexCoord4 unitW;
00079 
00080     /// X単位座標
00081     static const TexCoord4 unitX;
00082 
00083     //--------------------------------------------------------------------------
00084     // コンストラクタ
00085     //--------------------------------------------------------------------------
00086     /**
00087      * コンストラクタ
00088      *
00089      * このコンストラクタは初期値の設定を行わないため値は不定です。
00090      */
00091     inline TexCoord4(){}
00092 
00093     /**
00094      * コンストラクタ
00095      * @param sourceU Uの初期値
00096      * @param sourceV Vの初期値
00097      * @param sourceW Wの初期値
00098      * @param sourceX Xの初期値
00099      */
00100     inline TexCoord4(
00101         float sourceU, float sourceV, float sourceW, float sourceX) :
00102         u(sourceU), v(sourceV), w(sourceW), x(sourceX){
00103     }
00104 
00105     /**
00106      * コンストラクタ
00107      * @param source 初期値配列
00108      */
00109     inline explicit TexCoord4(const float* const source) :
00110         u(source[0]), v(source[1]), w(source[2]), x(source[3]){
00111     }
00112 
00113     //--------------------------------------------------------------------------
00114     // 値の設定
00115     //--------------------------------------------------------------------------
00116     /**
00117      * 値の設定
00118      * @param sourceU Uの設定値
00119      * @param sourceV Vの設定値
00120      * @param sourceW Wの設定値
00121      * @param sourceX Xの設定値
00122      */
00123     inline void set(float sourceU, float sourceV, float sourceW, float sourceX){
00124         u = sourceU;
00125         v = sourceV;
00126         w = sourceW;
00127         x = sourceX;
00128     }
00129 
00130     /**
00131      * 値の設定
00132      * @param source 設定値配列
00133      */
00134     inline void set(const float* const source){
00135         u = source[0];
00136         v = source[1];
00137         w = source[2];
00138         x = source[3];
00139     }
00140 
00141     //--------------------------------------------------------------------------
00142     // 演算
00143     //--------------------------------------------------------------------------
00144     /**
00145      * 加算
00146      * @param addCoord 加算する四次元テクスチャ座標
00147      * @return 加算された四次元テクスチャ座標
00148      */
00149     inline TexCoord4 operator +(const TexCoord4& addCoord) const{
00150         return TexCoord4(u + addCoord.u, v + addCoord.v,
00151             w + addCoord.w, x + addCoord.x);
00152     }
00153 
00154     /**
00155      * 減算
00156      * @param subCoord 減算する四次元テクスチャ座標
00157      * @return 減算された四次元テクスチャ座標
00158      */
00159     inline TexCoord4 operator -(const TexCoord4& subCoord) const{
00160         return TexCoord4(u - subCoord.u, v - subCoord.v,
00161             w - subCoord.w, x - subCoord.x);
00162     }
00163 
00164     /**
00165      * 乗算
00166      * @param mulValue 乗算する値
00167      * @return 乗算された四次元テクスチャ座標
00168      */
00169     inline TexCoord4 operator *(float mulValue) const{
00170         return TexCoord4(u * mulValue, v * mulValue,
00171             w * mulValue, x * mulValue);
00172     }
00173 
00174     /**
00175      * 乗算
00176      * @param mulValue 乗算する値
00177      * @param mulCoord 乗算する四次元テクスチャ座標
00178      * @return 乗算された四次元テクスチャ座標
00179      */
00180     inline friend TexCoord4 operator *(
00181         float mulValue, const TexCoord4& mulCoord){
00182         return TexCoord4(mulCoord.u * mulValue, mulCoord.v * mulValue,
00183             mulCoord.w * mulValue, mulCoord.x * mulValue);
00184     }
00185 
00186     /**
00187      * +演算子
00188      * @return 四次元テクスチャ座標のコピー
00189      */
00190     inline TexCoord4 operator +() const{ return *this; }
00191 
00192     /**
00193      * -演算子
00194      * @return 値の符号が反転した四次元テクスチャ座標
00195      */
00196     inline TexCoord4 operator -() const{ return TexCoord4(-u, -v, -w, -x); }
00197 
00198     //--------------------------------------------------------------------------
00199     // 代入演算
00200     //--------------------------------------------------------------------------
00201     /**
00202      * 代入加算
00203      * @param addCoord 加算する四次元テクスチャ座標
00204      * @return 加算された四次元テクスチャ座標
00205      */
00206     inline TexCoord4& operator +=(const TexCoord4& addCoord){
00207         u += addCoord.u;
00208         v += addCoord.v;
00209         w += addCoord.w;
00210         x += addCoord.x;
00211         return *this;
00212     }
00213 
00214     /**
00215      * 代入減算
00216      * @param subCoord 減算する四次元テクスチャ座標
00217      * @return 減算された四次元テクスチャ座標
00218      */
00219     inline TexCoord4& operator -=(const TexCoord4& subCoord){
00220         u -= subCoord.u;
00221         v -= subCoord.v;
00222         w -= subCoord.w;
00223         x -= subCoord.x;
00224         return *this;
00225     }
00226 
00227     /**
00228      * 代入乗算
00229      * @param mulValue 乗算する値
00230      * @return 乗算された四次元テクスチャ座標
00231      */
00232     inline TexCoord4& operator *=(float mulValue){
00233         u *= mulValue;
00234         v *= mulValue;
00235         w *= mulValue;
00236         x *= mulValue;
00237         return *this;
00238     }
00239 
00240     //--------------------------------------------------------------------------
00241     // 論理演算
00242     //--------------------------------------------------------------------------
00243     /**
00244      * 四次元テクスチャ座標が同じかどうか
00245      * @param target 比較する四次元テクスチャ座標
00246      * @return 同じ値であればtrueを返す
00247      */
00248     inline bool operator ==(const TexCoord4& target) const{
00249         return ((u == target.u) && (v == target.v) &&
00250             (w == target.w) && (x == target.x));
00251     }
00252 
00253     /**
00254      * 四次元テクスチャ座標が同じかどうか
00255      * @param target 比較する四次元テクスチャ座標
00256      * @param epsilon 誤差
00257      * @return 誤差の範囲内で同じ値であればtrueを返す
00258      */
00259     inline bool epsilonEquals(
00260         const TexCoord4& target, float epsilon) const{
00261         Assert(epsilon >= 0.f);
00262         return (
00263             (Math::abs(u - target.u) <= epsilon) &&
00264             (Math::abs(v - target.v) <= epsilon) &&
00265             (Math::abs(w - target.w) <= epsilon) &&
00266             (Math::abs(x - target.x) <= epsilon));
00267     }
00268 
00269     /**
00270      * 四次元テクスチャ座標が同じでないかどうか
00271      * @param target 比較する四次元テクスチャ座標
00272      * @return 同じでない値であればtrueを返す
00273      */
00274     inline bool operator !=(const TexCoord4& target) const{
00275         return ((u != target.u) || (v != target.v) ||
00276             (w != target.w) || (x != target.x));
00277     }
00278 
00279     /**
00280      * 四次元テクスチャ座標が同じでないかどうか
00281      * @param target 比較する四次元テクスチャ座標
00282      * @param epsilon 誤差
00283      * @return 誤差の範囲内で同じでない値であればtrueを返す
00284      */
00285     inline bool notEpsilonEquals(
00286         const TexCoord4& target, float epsilon) const{
00287         Assert(epsilon >= 0.f);
00288         return (
00289             (Math::abs(u - target.u) > epsilon) ||
00290             (Math::abs(v - target.v) > epsilon) ||
00291             (Math::abs(w - target.w) > epsilon) ||
00292             (Math::abs(x - target.x) > epsilon));
00293     }
00294 
00295     //--------------------------------------------------------------------------
00296     // その他
00297     //--------------------------------------------------------------------------
00298     /**
00299      * 文字列化
00300      * @return 四次元テクスチャ座標の文字列表記
00301      */
00302     inline String toString() const{
00303         String returnString;
00304         returnString.format("( %.8f, %.8f, %.8f, %.8f )", u, v, w, x);
00305         return returnString;
00306     }
00307 
00308     //--------------------------------------------------------------------------
00309 private:
00310 
00311 };
00312 
00313 //------------------------------------------------------------------------------
00314 } // End of namespace Lamp
00315 #endif // End of TEX_COORD_4_H_
00316 //------------------------------------------------------------------------------

Generated on Wed Mar 16 10:29:37 2005 for Lamp by doxygen 1.3.2