Partikelflächen zum Spieler drehen?



  • Für so Partikel Effekte wie Rauch und Explosionen hätte ich es gerne so, dass die 2dimensionalen Partikel sich immer zum Spieler wenden. Nur wie mach ich das denn (mit openGL)?

    Danke schon mal für eure Antworten

    MFG
    Frank



  • Deine Googlestichwort heißt Billboards 😉



  • hmm, ich hab jetzt nen guten Ansatz gefunden: http://www.lighthouse3d.com/opengl/billboarding/index.php3
    das sieht dann so aus:

    void billboardCheatSphericalBegin() {
    
        float modelview[16];
        int i,j;
    
        // save the current modelview matrix
        glPushMatrix();
    
        // get the current modelview matrix
        glGetFloatv(GL_MODELVIEW_MATRIX , modelview);
    
        // undo all rotations
        // beware all scaling is lost as well 
        for( i=0; i<3; i++ ) 
            for( j=0; j<3; j++ ) {
            if ( i==j )
                modelview[i*4+j] = 1.0;
            else
                modelview[i*4+j] = 0.0;
            }
    
        // set the modelview with no rotations
        glLoadMatrixf(modelview);
    }
    
    void billboardEnd() {
    
        // restore the previously 
        // stored modelview matrix
        glPopMatrix();
    }
    

    Nur das problem ist, ich zeichne die Vertexe eines partikels mit:

    lTexCoord2d(1,1); glVertex3f(Particles[i].Pos.x+0.5f,Particles[i].Pos.y+0.5f,Particles[i].Pos.z);//Beispielzeile für oben rechts
    

    und wenn ich jetzt zB nen Feuer mache und die Kamera verschiebe, dann sehe ich das Feuer immer so, wie als würde ich Frontal draufschauen. Ich will aber nur die einzelnen partikel immer frontal sehen, nicht das ganze System 😞

    Wisst ihr, was ih jetzt machen kann, damit es funktioniert?



  • ///1 mal pro Frame diesen Mist berechnen:
    float mv[16]; 
    float x[3], y[3]; 
    glGetFloatv(GL_MODELVIEW_MATRIX, mv);
    x[0] = mv[0];
    x[1] = mv[4];
    x[2] = mv[8];
    y[0] = mv[1];
    y[1] = mv[5];
    y[2] = mv[9];
    
    //Und dann die Billboards zeichnen (An Pos 3,1,2 mit Ausdehnung 0.3f in diesem Fall):
    Billboard(3,1,2, 0.3f x,y); 
    
    //und die funktion:
    void Billboard(float x, float y, float z, float s, float *xx, float *yy)
    {
        glBegin(GL_QUADS);
            glTexCoord2f(0,0); 
            glVertex3f( x+(-xx[0]-yy[0])*s , y+(-xx[1]-yy[1])*s , z+(-xx[2]-yy[2])*s);
    
            glTexCoord2f(1,0); 
            glVertex3f( x+(xx[0]-yy[0])*s , y+(xx[1]-yy[1])*s , z+(xx[2]-yy[2])*s);
    
            glTexCoord2f(1,1); 
            glVertex3f( x+(xx[0]+yy[0])*s , y+(xx[1]+yy[1])*s , z+(xx[2]+yy[2])*s);
    
            glTexCoord2f(0,1); 
            glVertex3f( x+(-xx[0]+yy[0])*s , y+(-xx[1]+yy[1])*s , z+(-xx[2]+yy[2])*s);
        glEnd();
    }
    

    is aus nem anderen Thread und zwar von space !! Wer suchen kann ist klar im Vorteil 😉

    MfG DasPinsch

    [ Dieser Beitrag wurde am 07.06.2003 um 20:41 Uhr von DasPinsch editiert. ]



  • Ich hab nach Billboards und nach bill boards gesucht und nix gefunden...
    Aber danke, ich probiers gleich mal aus!



  • na danke, das geht ja besser als ich jemals zu hoffen gewagt hab.
    Ab heute bist du mein persönlicher Held 😃



  • Original erstellt von <Frank>:
    na danke, das geht ja besser als ich jemals zu hoffen gewagt hab.
    Ab heute bist du mein persönlicher Held 😃

    *michgeehrtfühl* 😉

    der eigentlich code ist aber von space 😉


Anmelden zum Antworten