我试图修改这个Digiben样本,以获得从点(冲击点)产生的粒子效果,并向上漂浮,就像火焰一样。样品有颗粒在一个圆圈内旋转......我尝试去除余弦/正弦函数,并用正常的glTranslate替换它们以增加Y值,但我无法得到任何实际结果......有谁能指出大致在哪里我应该添加/修改此代码中的翻译以获得该结果?OpenGL粒子,帮助控制方向
void ParticleMgr::init(){
tex.Load("part.bmp");
GLfloat angle = 0; // A particle's angle
GLfloat speed = 0; // A particle's speed
// Create all the particles
for(int i = 0; i < P_MAX; i++)
{
speed = float(rand()%50 + 450); // Make a random speed
// Init the particle with a random speed
InitParticle(particle[i],speed,angle);
angle += 360/(float)P_MAX; // Increment the angle so when all the particles are
// initialized they will be equally positioned in a
// circular fashion
}
}
void ParticleMgr::InitParticle(PARTICLE &particle, GLfloat sss, GLfloat aaa)
{
particle.speed = sss; // Set the particle's speed
particle.angle = aaa; // Set the particle's current angle of rotation
// Randomly set the particles color
particle.red = rand()%255;
particle.green = rand()%255;
particle.blue = rand()%255;
}
void ParticleMgr::DrawParticle(const PARTICLE &particle)
{
tex.Use();
// Calculate the current x any y positions of the particle based on the particle's
// current angle -- This will make the particles move in a "circular pattern"
GLfloat xPos = sinf(particle.angle);
GLfloat yPos = cosf(particle.angle);
// Translate to the x and y position and the #defined PDEPTH (particle depth)
glTranslatef(xPos,yPos,PDEPTH);
// Draw the first quad
glBegin(GL_QUADS);
glTexCoord2f(0,0);
glVertex3f(-5, 5, 0);
glTexCoord2f(1,0);
glVertex3f(5, 5, 0);
glTexCoord2f(1,1);
glVertex3f(5, -5, 0);
glTexCoord2f(0,1);
glVertex3f(-5, -5, 0);
glEnd(); // Done drawing quad
// Draw the SECOND part of our particle
tex.Use();
glRotatef(particle.angle,0,0,1); // Rotate around the z-axis (depth axis)
//glTranslatef(0, particle.angle, 0);
// Draw the second quad
glBegin(GL_QUADS);
glTexCoord2f(0,0);
glVertex3f(-4, 4, 0);
glTexCoord2f(1,0);
glVertex3f(4, 4, 0);
glTexCoord2f(1,1);
glVertex3f(4, -4, 0);
glTexCoord2f(0,1);
glVertex3f(-4, -4, 0);
glEnd(); // Done drawing quad
// Translate back to where we began
glTranslatef(-xPos,-yPos,-PDEPTH);
}
void ParticleMgr::run(){
for(int i = 0; i < P_MAX; i++)
{
DrawParticle(particle[i]);
// Increment the particle's angle
particle[i].angle += ANGLE_INC;
}
}
现在我增加了glPushMatrix(),glTranslate(X,Y,Z)在上面的run()函数,在循环之前右,其中x,Y,Z为敌人的位置把它们放在敌人的顶端....那是最好的地方吗?
感谢您的任何意见!
你也可以显示你正在尝试使用的修改过的代码,它不使用sin和cos吗? – NickLH
据我所知,在每遍粒子[I] .angle增加,所以我取代了'的glTranslatef(XPOS,yPos,PDEPTH);''用的glTranslatef(0,粒子[I] .angle,PDEPTH);'到希望获得Ÿaccelleration但我得到各个方向分散在整个空间粒子..... – Alex
如果你使用的glTranslatef,尽量不要使用glRotatef,因为这会造成散射。一旦你的翻译工作,然后开始把旋转回来,并小心你做的事情的顺序,翻译后跟一个旋转是不一样的旋转后跟一个翻译。 – NickLH