Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

effect.cpp

Go to the documentation of this file.
00001 /* ***********************************************************************************
00002         Writer:         Sebastien Bloc
00003         Copyright:      2003-2004
00004         eMail:          sebastien.bloc@free.fr
00005         URL:            http://mignonsoft.free.fr
00006 
00007         This program is free software; you can redistribute it and/or
00008         modify it under the terms of the GNU General Public License
00009         as published by the Free Software Foundation; either version 2
00010         of the License, or (at your option) any later version.
00011 
00012         This program is distributed in the hope that it will be useful,
00013         but WITHOUT ANY WARRANTY; without even the implied warranty of
00014         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015         GNU General Public License for more details.
00016         http://www.gnu.org/copyleft/gpl.html
00017 *********************************************************************************** */
00018 
00019 #include "3d.h"
00020 #include "face.h"
00021 #include "effect.h"
00022 #include "controlEngine.h"
00023 
00024 extern ControlEngine ce;
00025 
00026 Effect::Effect()
00027 {
00028         Bind(NULL);
00029 }
00030 
00031 void Effect::Bind(FaceNode *_faceNode)
00032 {
00033         faceNode=_faceNode;
00034         isRunning=FALSE;
00035 }
00036 
00037 EffectApparition::EffectApparition()
00038 {
00039         nbSeconds = 0;
00040 }
00041 
00042 EffectApparition::~EffectApparition() 
00043 {
00044         Stop();
00045 }
00046 
00047 void EffectApparition::Start(BOOL _isFadeIn,double _nbSeconds)
00048 {
00049         if (isRunning)
00050         {
00051                 Stop();
00052         }
00053         isFadeIn = _isFadeIn;
00054         ce.timerRefresh.onTimer.connect(this,OnTimer);
00055         ce.timerRefresh.GetDeltaTime(TRUE,&beginTime); // conteur de temp au debut
00056 
00057         nbSeconds = _nbSeconds;
00058         isRunning = TRUE;
00059         oldTree = faceNode;
00060 }
00061 
00062 void EffectApparition::Stop()
00063 {
00064         if (!isRunning) return;
00065         ce.timerRefresh.onTimer.disconnect(this);
00066         progress=1;
00067         UnApply(faceNode,oldTree.GetRoot(),0);
00068         onEnding();
00069         onEnding.disconnect(this);
00070 }
00071 
00072 int EffectApparition::OnTimer(Timer *timer)
00073 {
00074         double nbSecondsCur = timer->GetDeltaTime(FALSE,&beginTime);
00075         progress = nbSecondsCur/nbSeconds; 
00076         // progress=0% si nbMilliSecondsCur=0
00077         // progress=100% si nbMilliSecondsCur=nbMilliseconds
00078         if (progress>=1) Stop();
00079         else Apply(faceNode,oldTree.GetRoot(),0);       
00080         return 0;
00081 }
00082 
00083 void EffectApparition::Apply(FaceNode *faceNode,FaceNode *oldFaceNode,int level)
00084 {
00085         if (!faceNode) return;
00086         Apply(faceNode->elem,oldFaceNode->elem,level);
00087         for (oldFaceNode->childs.i=0,faceNode->childs.i=0;
00088                  faceNode->childs.i.More();
00089                  faceNode->childs.i++,oldFaceNode->childs.i++)
00090         {
00091                 Apply(faceNode->childs.i.GetElem(),oldFaceNode->childs.i.GetElem(),level+1);
00092         }
00093 }
00094 
00095 void EffectApparition::UnApply(FaceNode *faceNode,FaceNode *oldFaceNode,int level)
00096 {
00097         if (!faceNode) return;
00098         UnApply(faceNode->elem,oldFaceNode->elem,level);
00099         for (oldFaceNode->childs.i=0,faceNode->childs.i=0;
00100                 faceNode->childs.i.More();
00101                 faceNode->childs.i++,oldFaceNode->childs.i++)
00102         {
00103                 UnApply(faceNode->childs.i.GetElem(),oldFaceNode->childs.i.GetElem(),level+1);
00104         }
00105 }
00106 
00107 void EffectApparition::Apply(Face *face,Face *oldFace,int level)
00108 {
00109         double progressCur = isFadeIn? progress : 1-progress;
00110         face->position.z.constValue =oldFace->position.z.constValue+20.0*(level+1)*progressCur;
00111         if (!level) face->angle.y=oldFace->angle.y+60.0*sin(progressCur*2.0*PI);
00112 }
00113 
00114 void EffectApparition::UnApply(Face *face,Face *oldFace,int level)
00115 {
00116         face->position.z.constValue =oldFace->position.z.constValue;
00117         if (!level) face->angle.y=oldFace->angle.y;
00118 }

Generated on Fri Aug 20 19:19:44 2004 for 3d Controls by doxygen 1.3.6