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

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

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