Автоматизированное редактирование частиц в компьютерной графике
Дипломная работа - Компьютеры, программирование
Другие дипломы по предмету Компьютеры, программирование
ION);
}
}
else
tmp_rect = wxRect(appear_box_position.x - BOUND_DIMENSION, appear_box_position.y - BOUND_DIMENSION,
appear_box_size.width + BOUND_DIMENSION * 2, appear_box_size.height + BOUND_DIMENSION * 2);
=tmp_rect.x&&point.x= tmp_rect.x && point.x < (tmp_rect.x + tmp_rect.width) &&
=tmp_rect.y&&point.y= tmp_rect.y && point.y < (tmp_rect.y + tmp_rect.height) )
{
res.psLayer = (int)i;
system_rect = tmp_rect;
break;
}
}
if( res.psLayer == -1/*no selected ps*/ || chain_is_run )
return res;
//selecting system has been finded, and - maybe we touched on some pss bottom(-s)
if( (point.x >= system_rect.x) && (point.x < system_rect.x + BOUND_DIMENSION) )
res.isLeft = true;
=system_rect.x+system_rect.width-BOUND_DIMENSION))">if( (point.x = system_rect.x + system_rect.width - BOUND_DIMENSION) )
res.isRight = true;
if( (point.y >= system_rect.y) && (point.y < system_rect.y + BOUND_DIMENSION) )
res.isTop = true;
=system_rect.y+system_rect.height-BOUND_DIMENSION))">if( (point.y = system_rect.y + system_rect.height - BOUND_DIMENSION) )
res.isBottom = true;
return res;
}
void ParticleSystemChain::ChooseSystemAtLayer(int layer)
{
=(int)all_ps.size()))">if( (layer = (int)all_ps.size()) )
choosedSystemLayer = -1;
else
choosedSystemLayer = layer;
}
int ParticleSystemChain::GetChoosedSystemLayer() const
{
return choosedSystemLayer;
}
void ParticleSystemChain::SelectSystemAtLayer(int layer)
{
=(int)all_ps.size()))">if( (layer = (int)all_ps.size()) )
selectedSystemLayer = -1;
else
selectedSystemLayer = layer;
}
int ParticleSystemChain::GetSelectedSystemLayer() const
{
return selectedSystemLayer;
}
ParticleSystemChainWorkMode ParticleSystemChain::GetWorkMode() const
{
return workMode;
}
void ParticleSystemChain::SetWorkMode(ParticleSystemChainWorkMode mode)
{
::iteratorbegin_iter=all_ps.begin();">vector::iterator begin_iter = all_ps.begin();
::iteratorend_iter=all_ps.end();">vector::iterator end_iter = all_ps.end();
vector::iterator iter = begin_iter;
if(mode == ParticleSystemChainWorkMode_PLAYBACK || mode == ParticleSystemChainWorkMode_PLAYBACK_LOOP)
{
while(iter != end_iter)
{
(*iter)->start();
++iter;
}
timer.reset();
}
else//if(mode == ParticleSystemChainWorkMode_STATIC)
{
while(iter != end_iter)
{
(*iter)->stopExtra();
++iter;
}
}
workMode = mode;
}
void ParticleSystemChain::CallbackSystems()
{
if(workMode == ParticleSystemChainWorkMode_STATIC)
return;
double sec_interval = timer.getMilliseconds() / 1000.0;
timer.reset();
::iteratoriter=all_ps.begin();">vector::iterator iter = all_ps.begin();
bool chain_is_run = false;
while(iter != all_ps.end())
{
(*iter)->callback(sec_interval);
if(!(*iter)->isFinished())
chain_is_run = true;
++iter;
}
if(chain_is_run)
return;
//!chain_is_run
if(workMode == ParticleSystemChainWorkMode_PLAYBACK)
SetWorkMode(ParticleSystemChainWorkMode_STATIC);
else// if(workMode == ParticleSystemChainWorkMode_PLAYBACK_LOOP)
SetWorkMode(ParticleSystemChainWorkMode_PLAYBACK_LOOP);//just restart
}
void ParticleSystemChain::DrawSystems()
{
::iteratoriter=all_ps.begin();">vector::iterator iter = all_ps.begin();
if(workMode != ParticleSystemChainWorkMode_STATIC)
{
glEnable(GL_BLEND);
glBlendFunc(blendModeSrc, blendModeDst);
while(iter != all_ps.end())
{
(*iter)->draw();
++iter;
}
glDisable(GL_BLEND);
}
else
{
int i = 0;
while(iter != all_ps.end())
{
ParticleSystem* curr_ps = (*iter);
if(i == selectedSystemLayer)
curr_ps->setBoundColor(PSBOUND_SELECTED_COLOR);
else if(i == choosedSystemLayer)
curr_ps->setBoundColor(PSBOUNS_CHOOSED_COLOR);
else
curr_ps->setBoundColor(PSBOUND_COLOR);
curr_ps->drawBound();
++iter, ++i;
}
}
}
int ParticleSystemChain::GetBlendModeSrc() const
{
return blendModeSrc;
}
int ParticleSystemChain::GetBlendModeDst() const
{
return blendModeDst;
}
void ParticleSystemChain::SetBlendModeSrc(int mode)
{
blendModeSrc = mode;
}
void ParticleSystemChain::SetBlendModeDst(int mode)
{
blendModeDst = mode;
}
ParticleSystem* ParticleSystemChain::GetSystemAtLayer(int layer)
{
=(int)all_ps.size())">if( layer = (int)all_ps.size() )
return NULL;
return all_ps.at(layer);
}
MYRect ParticleSystemChain::GetInitialSystemsRect(unsigned int *systems_counter) const//systems bound rect on gl
{
*systems_counter = (unsigned int)all_ps.size();
double min_x = 0.0;
double min_y = 0.0;
double max_x = 0.0;
double max_y = 0.0;
::const_iteratorbegin_iter=all_ps.begin();">vector::const_iterator begin_iter = all_ps.begin();
::const_iteratorend_iter=all_ps.end();">vector::const_iterator end_iter = all_ps.end();
vector::const_iterator iter = begin_iter;
while(iter != end_iter)
{
bool thereis_begin_ps = (iter == begin_iter);
(*iter)->data.initialX)">if(thereis_begin_ps || min_x > (*iter)->data.initialX)
data.initialX;">min_x = (*iter)->data.initialX;
(*iter)->data.initialY)">if(thereis_begin_ps || min_y > (*iter)->data.initialY)
data.initialY;">min_y = (*iter)->data.initialY;
data.initialX+(*iter)->data.pAppearBoxSize.width;">double new_max = (*iter)->data.initialX + (*iter)->data.pAppearBoxSize.width;
if(thereis_begin_ps || max_x < new_max)
max_x = new_max;
data.initialY+(*iter)->data.pAppearBoxSize.height;">new_max = (*iter)->data.initialY + (*iter)->data.pAppearBoxSize.height;
if(thereis_begin_ps || max_y < new_max)
max_y = new_max;
++iter;
}
MYPoint2D pos = MYPoint2DMake(min_x, min_y);
MYSize2D sz = MYSize2DMake(max_x - min_x, max_y - min_y);
return(MYRectMake(pos,sz));
}
int ParticleSystemChain::GetNumofSystems() const
{
return (int)all_ps.size();
}
//internals
ParticleSystemChain::ParticleSystemChain()
{
workMode = DEFAULT_PARTICLE_SYSTEM_CHAIN_WORK_MODE;
blendModeSrc = GL_ONE;
blendModeDst = GL_ONE_MINUS_SRC_ALPHA;
selectedSystemLayer = choosedSystemLayer = -1;
}
ParticleSystemChain::~ParticleSystemChain()
{
RemoveAll();
}
bool ParticleSystemChain::saveSystems(TiXmlElement* root) const
{
TiXmlElement tmp("SYSTEMS_DATA");
TiXmlElement *sys_data = (TiXmlElement*)root->InsertEndChild(tmp);
if(!sys_data)
return false;
sys_data->SetAttribute(ITEM_SELECTED, selectedSystemLayer);
if(all_ps.size() == 0)
return true;
::const_iteratoriter=all_ps.end();">vector::const_iterator iter = all_ps.end();
do
{
--iter;
if(!(*iter)->save(root))
return false;
}
while(iter != all_ps.begin());
return true;
}
bool ParticleSystemChain::loadSystems(TiXmlElement* root)
{
TiXmlElement *systems_data_ptr = (TiXmlElement*)root->FirstChild("SYSTEMS_DATA");
int selected_system_layer = -1;
if(systems_data_ptr)//new format file (ver. above 1.0)
systems_data_ptr->Attribute(ITEM_SELECTED, &selected_system_layer);
vector tmp_all_ps;
ParticleSystem *tmp_ps_ptr = new ParticleSystem();
while(bool is_success = tmp_ps_ptr->load(root))
{
tmp_all_ps.insert(tmp_all_ps.begin(), tmp_ps_ptr);
tmp_ps_ptr = new Part