このDigibenサンプルを修正して、スポット(衝突点)から生成し、火花のような上向きの浮遊粒子を生成します。サンプルは円で回転している粒子を持っています...私はコサイン/サイン関数を削除し、通常のglTranslateをY値の増加に置き換えようとしましたが、実際の結果は得られません...誰でも指摘してくださいおおよそどこにこのコードを翻訳してその結果を得るべきですか?今はglPushMatrix()を追加していについて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;
}
}
、glTranslate敵の位置としてX、Y、Zと右ループの前に上記ラン()関数内の(x、y、z)は、敵の上にそれらを置くために....それはそのための最高の場所ですか?
ありがとうございました!
sinとcosを使用しないで使用しようとしていた修正済みコードも表示できますか? – NickLH
私は、各パスパーティクル[i] .angleが増加したので、 'glTranslatef(xPos、yPos、PDEPTH);を' glTranslatef(0、particle [i] .angle、PDEPTH)すべての方向で空間全体に散らばっている粒子が得られます..... – Alex
glTranslatefを使用する場合は、散乱を引き起こすので、glRotatefを使用しないでください。翻訳作業が完了したら、回転を戻し始めます。あなたが行う作業の順序に注意してください。回転の後の翻訳は、回転の後の翻訳と同じではありません。 – NickLH