Автоматизированное редактирование частиц в компьютерной графике

Дипломная работа - Компьютеры, программирование

Другие дипломы по предмету Компьютеры, программирование

glVertex2d(currentX - BOUND_DIMENSION, currentY + appear_h + BOUND_DIMENSION);

glEnd();

 

//draw inner part of bound

glColor4d(boundedRectColor.Red()/255.0, boundedRectColor.Green()/255.0, boundedRectColor.Blue()/255.0,

boundedRectColor.Alpha()/255.0);

 

glBegin(GL_POLYGON);

glVertex2d(currentX, currentY);

glVertex2d(currentX + appear_w, currentY);

glVertex2d(currentX + appear_w, currentY + appear_h);

glVertex2d(currentX, currentY + appear_h);

glEnd();

if(!particleTexPtr)

return;

 

//draw texture on left-top

double tex_w = particleTexPtr->getWidth();

double tex_h = particleTexPtr->getHeight();

glEnable(GL_TEXTURE_2D);

GLint binded;

glGetIntegerv(GL_TEXTURE_BINDING_2D,&binded);

glBindTexture(GL_TEXTURE_2D, particleTexPtr->getName());

glColor4d(1.0,1.0,1.0,1.0);

 

double real_tex_w, real_tex_h;

real_tex_w = min(appear_w, tex_w);

real_tex_h = min(appear_h, tex_h);

double real_tex_s, real_tex_t;

real_tex_s = particleTexPtr->getMaxS() * ((double)real_tex_w) / ((double)tex_w);

real_tex_t = particleTexPtr->getMaxT() * ((double)real_tex_h) / ((double)tex_h);

 

glBegin(GL_POLYGON);

glTexCoord2d(0.0, 0.0);

glVertex2d(currentX, currentY);

glTexCoord2d(real_tex_s, 0.0);//texCoord[0].x,texCoord[0].y);

glVertex2d(currentX + real_tex_w, currentY);

glTexCoord2d(real_tex_s, real_tex_t);//texCoord[1].x,texCoord[1].y);

glVertex2d(currentX + real_tex_w, currentY + real_tex_h);

glTexCoord2d(0.0, real_tex_t);

glVertex2d(currentX, currentY + real_tex_h);

glEnd();

 

glBindTexture(GL_TEXTURE_2D, binded);

glDisable(GL_TEXTURE_2D);

}

 

void ParticleSystem::draw()

{

if(!particleTexPtr)

return;

 

if (isFinishedb)

return;

 

//if (int(startInTime*maj_kof) > 0)

if(startInTime > 0.0)

return;

 

glMatrixMode(GL_MODELVIEW);

 

MYPoint2D *ptrVert = verCoord;

MYParticleColor *ptrColor = color;

int count = 0;

double progress, x, y, w, h, r, g, b, a;

bool is_rotate = (data.pAngleRotate != 0.0);

for (int i = 0; i < EXPL_MAX; ++i)

{

progress = pTM[i];

x = pX[i];

y = pY[i];

if(progress > 0.0)

{

progress /= data.pLifeTime;

 

getWidth();">w = (data.pKFScaleEndW + progress * (data.pKFScaleBeginW - data.pKFScaleEndW)) * particleTexPtr->getWidth();

getHeight();">h = (data.pKFScaleEndH + progress * (data.pKFScaleBeginH - data.pKFScaleEndH)) * particleTexPtr->getHeight();

 

if(is_rotate)

{

double real_alpha = fmod(data.pAngleRotate * 360.0 * progress, 360.0);

glPushMatrix();

glTranslated(x, y, 0.0);

glRotated(real_alpha, 0.0, 0.0, 1.0);//clock wise direction

x = y = 0.0;

}

 

x -= w/2.0;//only CENTERS of particles initially placed in AppearingBox (0.5,0.5 origin)

y -= h/2.0;//only CENTERS of particles initially placed in AppearingBox (0.5,0.5 origin)

 

r = data.pRedEnd + progress * (data.pRedBegin - data.pRedEnd);

g = data.pGreenEnd + progress * (data.pGreenBegin - data.pGreenEnd);

b = data.pBlueEnd + progress * (data.pBlueBegin - data.pBlueEnd);

a = data.pAlphaEnd + progress * (data.pAlphaBegin - data.pAlphaEnd);

 

ptrColor->r = r; ptrColor->g = g; ptrColor->b = b; ptrColor->a = a; ptrColor++;

ptrColor->r = r; ptrColor->g = g; ptrColor->b = b; ptrColor->a = a; ptrColor++;

ptrColor->r = r; ptrColor->g = g; ptrColor->b = b; ptrColor->a = a; ptrColor++;

ptrColor->r = r; ptrColor->g = g; ptrColor->b = b; ptrColor->a = a; ptrColor++;

ptrColor->r = r; ptrColor->g = g; ptrColor->b = b; ptrColor->a = a; ptrColor++;

ptrColor->r = r; ptrColor->g = g; ptrColor->b = b; ptrColor->a = a; ptrColor++;

 

if(is_rotate)

{

double* m = viewMatrixCache;

glGetDoublev(GL_MODELVIEW_MATRIX, m);

double x2 = x + w;

double y2 = y + h;

double* tp = (double*)ptrVert;

 

ptrVert->x = m[0]*x + m[4]*y + m[12];ptrVert->y = m[1]*x + m[5]*y + m[13];ptrVert++;

ptrVert->x = m[0]*x2 + m[4]*y + m[12];ptrVert->y = m[1]*x2 + m[5]*y + m[13];ptrVert++;

ptrVert->x = m[0]*x2 + m[4]*y2 + m[12];ptrVert->y = m[1]*x2 + m[5]*y2 + m[13]; ptrVert++;

ptrVert->x = tp[0]; ptrVert->y = tp[1]; ptrVert++;

ptrVert->x = tp[4]; ptrVert->y = tp[5]; ptrVert++;

ptrVert->x = m[0]*x + m[4]*y2 + m[12];ptrVert->y = m[1]*x + m[5]*y2 + m[13];ptrVert++;

 

glPopMatrix();

}

else

{

ptrVert->x = x;ptrVert->y = y;ptrVert++;

ptrVert->x = x+w;ptrVert->y = y;ptrVert++;

ptrVert->x = x+w;ptrVert->y = y+h;ptrVert++;

ptrVert->x = x;ptrVert->y = y;ptrVert++;

ptrVert->x = x+w;ptrVert->y = y+h;ptrVert++;

ptrVert->x = x;ptrVert->y = y+h;ptrVert++;

}

 

count++;

}

}

 

glPushMatrix();

glTranslated(currentX, currentY, 0.0);

 

glEnable(GL_TEXTURE_2D);

GLint binded;

glGetIntegerv(GL_TEXTURE_BINDING_2D,&binded);

glBindTexture(GL_TEXTURE_2D, particleTexPtr->getName());

 

glEnableClientState(GL_VERTEX_ARRAY);

glVertexPointer(2, GL_DOUBLE, 0, verCoord);

 

glEnableClientState(GL_TEXTURE_COORD_ARRAY);

glTexCoordPointer(2, GL_DOUBLE, 0, texCoord);

 

glEnableClientState(GL_COLOR_ARRAY);

glColorPointer(4, GL_DOUBLE, 0, color);

 

glDrawArrays(GL_TRIANGLES, 0, count*6);

 

glDisableClientState(GL_COLOR_ARRAY);

glDisableClientState(GL_TEXTURE_COORD_ARRAY);

glDisableClientState(GL_VERTEX_ARRAY);

 

glBindTexture(GL_TEXTURE_2D,binded);

glDisable(GL_TEXTURE_2D);

 

glPopMatrix();

}

 

bool ParticleSystem::save(TiXmlElement* root_ptr) const

{

TiXmlElement element("PS");

 

element.SetAttribute(TEXTURE_ATTR, data.particleTexFileName);

element.SetDoubleAttribute(LIFE_TIME_ATTR, data.pLifeTime);

element.SetDoubleAttribute(APPEAR_DELAY_ATTR, data.pAppearDelay);

element.SetDoubleAttribute(PARTICLE_SPEED_X_ATTR, data.pMoveSpeedX);

element.SetDoubleAttribute(PARTICLE_SPEED_Y_ATTR, data.pMoveSpeedY);

element.SetDoubleAttribute(GRAVITY_X_ATTR, data.pGravityX);

element.SetDoubleAttribute(GRAVITY_Y_ATTR, data.pGravityY);

element.SetAttribute(MAX_COUNT_ATTR, data.pMaxCount);

element.SetAttribute(START_COUNT_ATTR, data.pCountOnStart);

element.SetDoubleAttribute(APPEAR_BOX_W_ATTR, data.pAppearBoxSize.width);

element.SetDoubleAttribute(APPEAR_BOX_H_ATTR, data.pAppearBoxSize.height);

element.SetDoubleAttribute(RED_BEGIN_ATTR, data.pRedBegin);

element.SetDoubleAttribute(RED_END_ATTR, data.pRedEnd);

element.SetDoubleAttribute(GREEN_BEGIN_ATTR, data.pGreenBegin);

element.SetDoubleAttribute(GREEN_END_ATTR, data.pGreenEnd);

element.SetDoubleAttribute(BLUE_BEGIN_ATTR, data.pBlueBegin);

element.SetDoubleAttribute(BLUE_END_ATTR, data.pBlueEnd);

element.SetDoubleAttribute(ALPHA_BEGIN_ATTR, data.pAlphaBegin);

element.SetDoubleAttribute(ALPHA_END_ATTR, data.pAlphaEnd);

element.SetDoubleAttribute(SCALE_BEGIN_W_ATTR, data.pKFScaleBeginW);

element.SetDoubleAttribute(SCALE_BEGIN_H_ATTR, data.pKFScaleBeginH);

element.SetDoubleAttribute(SCALE_END_W_ATTR, data.pKFScaleEndW);

element.SetDoubleAttribute(SCALE_END_H_ATTR, data.pKFScaleEndH);

element.SetDoubleAttribute(DISPERSION_X_ATTR, data.pKFDispersionX);

element.SetDoubleAttribute(DISPERSION_Y_ATTR, data.pKFDispersionY);

element.SetDoubleAttribute(PS_X_ATTR, data.initialX);

element.SetDoubleAttribute(PS_Y_ATTR, data.initialY);

element.SetDoubleAttribute(PS_SPEED_X_ATTR, data.speedChangeX);

element.SetDoubleAttribute(PS_SPEED_Y_ATTR, data.speedChangeY);

element.SetDoubleAttribute(START_DELAY_ATTR, data.startDelay);

element.SetDoubleAttribute(STOP_DELAY_ATTR, data.stopDelay);

element.SetDoubleAttribute(ROTATE_ATTR, data.pAngleRotate);

 

TiXmlElement* ptr_element = (TiXmlElement*)root_ptr->InsertEndChild(element);

return((bool)(ptr_element != NULL));

}

 

bool ParticleSystem::load(TiXmlElement*& element_ptr)

{

TiXmlElement *next_element_ptr = (TiXmlElement*)element_ptr->FirstChild("PS");

if(!next_element_ptr)

{

next_element_ptr = (TiXmlElement*)element_ptr->NextSibling("PS");

if(!next_element_ptr)

return false;

}

 

//read version 1.1 parameters

QueryIntAttribute(MAX_COUNT_ATTR,&data.pMaxCount)!=TIXML_SUCCESS)">if(next_element_ptr->QueryIntAttribute(MAX_COUNT_ATTR, &data.pMaxCount) != TIXML_S