Billboarding-Problem mit DirectX und C++ EDIT: GELÖST!



  • Hallo, ich habe folgendes Problem.
    Mithilfe eines Partikelsystems unter DirectX stelle ich Feuer her.
    Das klappt soweit auch ganz gut, nur wenn ich die Kamera drehe sieht man nichts mehr, da es ja
    nur 2D ist. Nun möchte ich aber den Effekt des Billboarding nutzen, so dass sich die Partikel
    immer so passend zur Kamera drehen, dass einem 3D vorgegaukelt wird.
    Leider habe ich bisher keine wirklich gute Anleitung zu Billboarding mit Dirext und C++ gefunden,
    oder sie war zu speziell auf deren Programm zugeschnitten, dass ich nicht wusste,
    was ich für mein Programm brauche.

    Hier mal der Quellcode einer Funktion der Partikelklasse, die für die Entstehung des Feuers zuständig ist:

    // this is the function that positions, rotates, scales and renders the particle
    void PARTICLE::set_particle(LPDIRECT3DDEVICE9 pd3ddev)
    {
    
     // Before setting the world transform, do the intense mathematics!
        // a. Calculate the Differences
        static float difx, dify, difz;
        difx = CMainApp.getvCamPosx() - position.x;  //CMainApp ist die Hauptklasse, wo alles gerendert und initialisiert wird
        dify = CMainApp.getvCamPosy() - position.y;	 //getvCam holt sich die Kameraposition 	
        difz = CMainApp.getvCamPosz() - position.z;	 //position definiert den Startpunkt der Partikel
    
     // b. Calculate the Distances
        static float FlatDist, TotalDist;
        FlatDist = sqrt(difx * difx + difz * difz);
        TotalDist = sqrt(FlatDist * FlatDist + dify * dify);
    
        // c. Y Rotation
        D3DXMatrixIdentity(&matRotateY);
        matRotateY._11 = matRotateY._33 = difz / FlatDist;    // cosY
        matRotateY._31 = difx / FlatDist;    // sinY
        matRotateY._13 = -matRotateY._31;    // -sinY
    
        // d. X Rotation
        D3DXMatrixIdentity(&matRotateX);
        matRotateX._22 = matRotateX._33 = FlatDist / TotalDist;    // cosX
        matRotateX._32 = dify / TotalDist;    // sinX
        matRotateX._23 = -matRotateX._32;    // -sinX
    
        // e. Tranlation
        static D3DXMATRIX matTranslate;
        D3DXMatrixTranslation(&matTranslate, position.x, position.y, position.z);
    
        // f. Scaling
        static D3DXMATRIX matScale;
        D3DXMatrixIdentity(&matScale);
        matScale._11 = matScale._22 = matScale._33 = radius;
    
        // Now build the world matrix and set it
        pd3ddev->SetTransform(D3DTS_WORLD, &(matScale * matRotateX*  matRotateY* matTranslate));
    }
    
    void MainApplication::mainAppRender(HWND hWnd)
    {
    pd3ddev->BeginScene();    // begins the 3D scene
    
    ... // hier werden unter anderem die Panzer gezeichnet
    
    run_particles();// ruft u.a. die set_particle funktion auf
    pd3ddev->SetTransform(D3DTS_WORLD, &mworld);//Zurücksetzen auf vorherigen Stand, damit die anderen Objekte nicht wie die Partikel verschoben werden
    
    D3DXMatrixLookAtLH(&ViewMatrix,
    							&D3DXVECTOR3 (vCamPos.x, vCamPos.y, vCamPos.z),			// the camera position
    							&D3DXVECTOR3 (vLookAt.x, vLookAt.y, vLookAt.z),			// the look-at position
    							&D3DXVECTOR3 (0.0f, 1.0f,0.0f));					// the up direction
    
    D3DXMatrixPerspectiveFovLH(&matProjection,
                                 FOV,    // the horizontal field of view
                                 ASPECT, // aspect ratio
                                 NEAR_Z,    // the near view-plane
                                 FAR_Z);    // the far view-plane
    pd3ddev->SetTransform(D3DTS_PROJECTION, &matProjection);    // set the projection
    
    ...
    
    pd3ddev->EndScene();    // ends the 3D scene
    
    pd3ddev->Present(NULL, NULL, NULL, NULL);   // displays the created frame on the screen
    
    tickcount = GetTickCount();
    
    return;
    }
    

    Ich hatte mal irgendetwas gelesen, dass man für das Billboarding die inverse Viewmatrix nehmen und Rotationen raus nehmen muss.
    Müsste ich die Anpassungen für die Viewmatrix nun in der Partikelklasse machen, oder nach dem Rendern der Partikel in der MainApplication?

    Gruß Urmel 1


Anmelden zum Antworten