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

TexCoord3.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_3_H_
00026 #define TEX_COORD_3_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 TexCoord3{
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         };
00055 
00056         /// 配列
00057         float array[3];
00058     };
00059 
00060     //--------------------------------------------------------------------------
00061     // 定数
00062     //--------------------------------------------------------------------------
00063     /// ゼロ座標
00064     static const TexCoord3 zero;
00065 
00066     /// 単位座標
00067     static const TexCoord3 unit;
00068 
00069     /// U単位座標
00070     static const TexCoord3 unitU;
00071 
00072     /// V単位座標
00073     static const TexCoord3 unitV;
00074 
00075     /// W単位座標
00076     static const TexCoord3 unitW;
00077 
00078     //--------------------------------------------------------------------------
00079     // コンストラクタ
00080     //--------------------------------------------------------------------------
00081     /**
00082      * コンストラクタ
00083      *
00084      * このコンストラクタは初期値の設定を行わないため値は不定です。
00085      */
00086     inline TexCoord3(){}
00087 
00088     /**
00089      * コンストラクタ
00090      * @param sourceU Uの初期値
00091      * @param sourceV Vの初期値
00092      * @param sourceW Wの初期値
00093      */
00094     inline TexCoord3(float sourceU, float sourceV, float sourceW) :
00095         u(sourceU), v(sourceV), w(sourceW){
00096     }
00097 
00098     /**
00099      * コンストラクタ
00100      * @param source 初期値配列
00101      */
00102     inline explicit TexCoord3(const float* const source) :
00103         u(source[0]), v(source[1]), w(source[2]){
00104     }
00105 
00106     //--------------------------------------------------------------------------
00107     // 値の設定
00108     //--------------------------------------------------------------------------
00109     /**
00110      * 値の設定
00111      * @param sourceU Uの設定値
00112      * @param sourceV Vの設定値
00113      * @param sourceW Wの設定値
00114      */
00115     inline void set(float sourceU, float sourceV, float sourceW){
00116         u = sourceU;
00117         v = sourceV;
00118         w = sourceW;
00119     }
00120 
00121     /**
00122      * 値の設定
00123      * @param source 設定値配列
00124      */
00125     inline void set(const float* const source){
00126         u = source[0];
00127         v = source[1];
00128         w = source[2];
00129     }
00130 
00131     //--------------------------------------------------------------------------
00132     // 演算
00133     //--------------------------------------------------------------------------
00134     /**
00135      * 加算
00136      * @param addCoord 加算する三次元テクスチャ座標
00137      * @return 加算された三次元テクスチャ座標
00138      */
00139     inline TexCoord3 operator +(const TexCoord3& addCoord) const{
00140         return TexCoord3(u + addCoord.u, v + addCoord.v, w + addCoord.w);
00141     }
00142 
00143     /**
00144      * 減算
00145      * @param subCoord 減算する三次元テクスチャ座標
00146      * @return 減算された三次元テクスチャ座標
00147      */
00148     inline TexCoord3 operator -(const TexCoord3& subCoord) const{
00149         return TexCoord3(u - subCoord.u, v - subCoord.v, w - subCoord.w);
00150     }
00151 
00152     /**
00153      * 乗算
00154      * @param mulValue 乗算する値
00155      * @return 乗算された三次元テクスチャ座標
00156      */
00157     inline TexCoord3 operator *(float mulValue) const{
00158         return TexCoord3(u * mulValue, v * mulValue, w * mulValue);
00159     }
00160 
00161     /**
00162      * 乗算
00163      * @param mulValue 乗算する値
00164      * @param mulCoord 乗算する三次元テクスチャ座標
00165      * @return 乗算された三次元テクスチャ座標
00166      */
00167     inline friend TexCoord3 operator *(
00168         float mulValue, const TexCoord3& mulCoord){
00169         return TexCoord3(mulCoord.u * mulValue, mulCoord.v * mulValue,
00170             mulCoord.w * mulValue);
00171     }
00172 
00173     /**
00174      * +演算子
00175      * @return 三次元テクスチャ座標のコピー
00176      */
00177     inline TexCoord3 operator +() const{ return *this; }
00178 
00179     /**
00180      * -演算子
00181      * @return 値の符号が反転した三次元テクスチャ座標
00182      */
00183     inline TexCoord3 operator -() const{ return TexCoord3(-u, -v, -w); }
00184 
00185     //--------------------------------------------------------------------------
00186     // 代入演算
00187     //--------------------------------------------------------------------------
00188     /**
00189      * 代入加算
00190      * @param addCoord 加算する三次元テクスチャ座標
00191      * @return 加算された三次元テクスチャ座標
00192      */
00193     inline TexCoord3& operator +=(const TexCoord3& addCoord){
00194         u += addCoord.u;
00195         v += addCoord.v;
00196         w += addCoord.w;
00197         return *this;
00198     }
00199 
00200     /**
00201      * 代入減算
00202      * @param subCoord 減算する三次元テクスチャ座標
00203      * @return 減算された三次元テクスチャ座標
00204      */
00205     inline TexCoord3& operator -=(const TexCoord3& subCoord){
00206         u -= subCoord.u;
00207         v -= subCoord.v;
00208         w -= subCoord.w;
00209         return *this;
00210     }
00211 
00212     /**
00213      * 代入乗算
00214      * @param mulValue 乗算する値
00215      * @return 乗算された三次元テクスチャ座標
00216      */
00217     inline TexCoord3& operator *=(float mulValue){
00218         u *= mulValue;
00219         v *= mulValue;
00220         w *= mulValue;
00221         return *this;
00222     }
00223 
00224     //--------------------------------------------------------------------------
00225     // 論理演算
00226     //--------------------------------------------------------------------------
00227     /**
00228      * 三次元テクスチャ座標が同じかどうか
00229      * @param target 比較する三次元テクスチャ座標
00230      * @return 同じ値であればtrueを返す
00231      */
00232     inline bool operator ==(const TexCoord3& target) const{
00233         return ((u == target.u) && (v == target.v) && (w == target.w));
00234     }
00235 
00236     /**
00237      * 三次元テクスチャ座標が同じかどうか
00238      * @param target 比較する三次元テクスチャ座標
00239      * @param epsilon 誤差
00240      * @return 誤差の範囲内で同じ値であればtrueを返す
00241      */
00242     inline bool epsilonEquals(
00243         const TexCoord3& target, float epsilon) const{
00244         Assert(epsilon >= 0.f);
00245         return (
00246             (Math::abs(u - target.u) <= epsilon) &&
00247             (Math::abs(v - target.v) <= epsilon) &&
00248             (Math::abs(w - target.w) <= epsilon));
00249     }
00250 
00251     /**
00252      * 三次元テクスチャ座標が同じでないかどうか
00253      * @param target 比較する三次元テクスチャ座標
00254      * @return 同じでない値であればtrueを返す
00255      */
00256     inline bool operator !=(const TexCoord3& target) const{
00257         return ((u != target.u) || (v != target.v) || (w != target.w));
00258     }
00259 
00260     /**
00261      * 三次元テクスチャ座標が同じでないかどうか
00262      * @param target 比較する三次元テクスチャ座標
00263      * @param epsilon 誤差
00264      * @return 誤差の範囲内で同じでない値であればtrueを返す
00265      */
00266     inline bool notEpsilonEquals(
00267         const TexCoord3& target, float epsilon) const{
00268         Assert(epsilon >= 0.f);
00269         return (
00270             (Math::abs(u - target.u) > epsilon) ||
00271             (Math::abs(v - target.v) > epsilon) ||
00272             (Math::abs(w - target.w) > epsilon));
00273     }
00274 
00275     //--------------------------------------------------------------------------
00276     // その他
00277     //--------------------------------------------------------------------------
00278     /**
00279      * 文字列化
00280      * @return 三次元テクスチャ座標の文字列表記
00281      */
00282     inline String toString() const{
00283         String returnString;
00284         returnString.format("( %.8f, %.8f, %.8f )", u, v, w);
00285         return returnString;
00286     }
00287 
00288     //--------------------------------------------------------------------------
00289 private:
00290 
00291 };
00292 
00293 //------------------------------------------------------------------------------
00294 } // End of namespace Lamp
00295 #endif // End of TEX_COORD_3_H_
00296 //------------------------------------------------------------------------------

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