1 /*---------------------------------------------------------------------------* 2 Project: NintendoWare 3 File: SmParticle.cpp 4 5 Copyright (C)2009-2011 Nintendo/HAL Laboratory, Inc. All rights reserved. 6 7 These coded instructions, statements, and computer programs contain proprietary 8 information of Nintendo and/or its licensed developers and are protected by 9 national and international copyright laws. They may not be disclosed to third 10 parties or copied or duplicated in any form, in whole or in part, without the 11 prior written consent of Nintendo. 12 13 The content herein is highly confidential and should be handled accordingly. 14 15 $Revision: $ 16 *---------------------------------------------------------------------------*/ 17 18 #include "../include/SmParticle.h" 19 20 namespace 21 { 22 23 //---------------------------------------- 24 // コンストラクタ SmParticle(nw::gfx::SceneNode * parentNode)25SmParticle::SmParticle( nw::gfx::SceneNode* parentNode ) 26 { 27 m_pParentNode = parentNode; 28 m_ParticleModelInstArray.clear(); 29 m_ParticleEmitterInstArray.clear(); 30 31 for ( int i=0; i<ARRAY_COUNT; i++ ) 32 { 33 m_ParticleInstAttachedArray[i] = true; 34 } 35 } 36 37 38 //---------------------------------------- 39 // デストラクタ ~SmParticle()40SmParticle::~SmParticle() 41 { 42 43 } 44 45 46 //---------------------------------------- 47 // パーティクルモデルを追加 AddParticleModel(nw::gfx::ParticleModel * particleModel)48void SmParticle::AddParticleModel( nw::gfx::ParticleModel* particleModel ) 49 { 50 bool isPushed = m_ParticleModelInstArray.push_back( particleModel ); 51 NW_ASSERT(isPushed); 52 } 53 54 55 //---------------------------------------- 56 // パーティクルエミッタを追加 AddParticleEmitter(nw::gfx::ParticleEmitter * particleEmitter)57void SmParticle::AddParticleEmitter( nw::gfx::ParticleEmitter* particleEmitter ) 58 { 59 bool isPushed = m_ParticleEmitterInstArray.push_back( particleEmitter ); 60 NW_ASSERT(isPushed); 61 } 62 63 64 //---------------------------------------- 65 // リセットする Reset()66void SmParticle::Reset() 67 { 68 for ( int i=0; i<m_ParticleModelInstArray.size(); i++ ) 69 { 70 m_ParticleModelInstArray[i]->ForeachParticleSet(nw::gfx::ParticleSetsClear()); 71 m_ParticleModelInstArray[i]->ParticleAnimFrameController().SetFrame(0); 72 } 73 74 for ( int i=0; i<m_ParticleEmitterInstArray.size(); i++ ) 75 { 76 m_ParticleEmitterInstArray[i]->Reset(); 77 } 78 } 79 80 81 //---------------------------------------- 82 // アニメーションフレームを設定する SetAnimationFrame(f32 setFrame)83void SmParticle::SetAnimationFrame( f32 setFrame ) 84 { 85 f32 endFrame = 0.0f; 86 for ( int i=0; i<m_ParticleModelInstArray.size(); i++ ) 87 { 88 if (endFrame < m_ParticleModelInstArray[i]->ParticleAnimFrameController().GetEndFrame()) 89 { 90 endFrame = m_ParticleModelInstArray[i]->ParticleAnimFrameController().GetEndFrame(); 91 } 92 } 93 94 if (setFrame > endFrame) 95 { 96 setFrame = endFrame; 97 } 98 99 // フレームの更新がなければアニメーションは更新しません 100 if (m_AnimationFrame != setFrame) return; 101 102 // フレーム数をセット 103 for (int i=0; i<m_ParticleModelInstArray.size(); i++) 104 { 105 m_ParticleModelInstArray[i]->ParticleAnimFrameController().SetFrame( setFrame ); 106 } 107 108 m_AnimationFrame = setFrame; 109 } 110 111 112 //---------------------------------------- 113 // パーティクルを0~1で表示レベルを調整する 114 void SetVisibleZone(f32 term)115SmParticle::SetVisibleZone( f32 term ) 116 { 117 /* 118 現状、パーティクルモデル・エミッタが同数の場合のみ動作する。 119 */ 120 if( m_ParticleModelInstArray.size() != m_ParticleEmitterInstArray.size() ) 121 { 122 return; 123 } 124 125 s32 visibleNum = m_ParticleModelInstArray.size() * term; 126 127 for ( int i = 0; i < m_ParticleModelInstArray.size(); i++ ) 128 { 129 if ( i < visibleNum ) 130 { 131 attach( i ); 132 m_ParticleInstAttachedArray[i] = true; 133 } 134 else 135 { 136 detach( i ); 137 m_ParticleInstAttachedArray[i] = false; 138 } 139 } 140 } 141 142 143 #if 0 144 //---------------------------------------- 145 // アニメーションフレームを進める 146 bool SmParticle::AddAnimationFrame( f32 addFrame, bool loop = true ) 147 { 148 NW_UNUSED_VARIABLE(addFrame); 149 NW_UNUSED_VARIABLE(loop); 150 151 return false; 152 } 153 #endif 154 155 } // namespace 156 157 158