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