/*---------------------------------------------------------------------------* Project: NintendoWare File: gfx_ParticleRandom.h Copyright (C)2009-2010 Nintendo Co., Ltd./HAL Laboratory, Inc. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. $Revision: 21453 $ *---------------------------------------------------------------------------*/ #ifndef NW_GFX_PARTICLERANDOM_H_ #define NW_GFX_PARTICLERANDOM_H_ #include namespace nw { namespace gfx { //--------------------------------------------------------------------------- //! @brief パーティクル用の乱数を生成するクラスです。 //--------------------------------------------------------------------------- class ParticleRandom { public: //! @brief コンストラクタです。 ParticleRandom() { m_Seed = 0; } //! @brief コピーコンストラクタです。 //! //! @param[in] source コピー元です。 ParticleRandom(const ParticleRandom& source) { Set(source); } //! @brief 乱数種を設定します。 //! //! @param[in] seed 乱数種です。 void Srand(u32 seed) { m_Seed = seed; } //! @brief 整数で乱数を取得します。 //! //! @param[in] maxValue 取得する上限です。この値にはなりません。 //! @return 整数で0からmaxValue-1の整数を返します。 u16 Next(u16 maxValue) { MixRandomSeed(); return (u16)(m_Seed >> 8) % maxValue; } //! @brief 浮動小数点数で0から1の乱数を取得します。 //! //! @return 浮動小数点数で0から1の数値を返します。0を含み、1を含みません。 f32 NextFloat() { MixRandomSeed(); return (f32)((m_Seed >> 16) & 0xffff) / 65536.0f; } //! @brief 浮動小数点数で-1から1の乱数を取得します。 //! //! @return 浮動小数点数で-1から1の数値を返します。-1, 0, 1を含みません。 f32 NextFloatSignedOne(); //! @brief 浮動小数点数で-0.5から0.5の乱数を取得します。 //! //! @return 浮動小数点数で-0.5から0.5の数値を返します。-0.5, 0, 0.5を含みません。 f32 NextFloatSignedHalf(); //! @brief ParticleRandomを設定します。 //! //! @param[in] source コピー元です。 void Set(const ParticleRandom& source) { m_Seed = source.m_Seed; } private: //! @brief 乱数種を更新します。 void MixRandomSeed() { m_Seed = (m_Seed * 214013u) + 2531011u; } u32 m_Seed; }; } // namespace gfx } // namespace nw #endif // NW_GFX_PARTICLERANDOM_H_