dinsdag 16 augustus 2011

Pengu Update 3

While I was looking for a billboarding way to make the names apear over the igloos. I sought and I sought and I sought and all I found was either overly complicated or about something completely different!!

what I needed was projecting a 3D point on the 2D screen, so that when I moved around the text would seem to float over the same point in 3D space.

here's the catch! the WINAPI function to Project a D3DXVECTOR3 was only moderately difficult to find.


D3DXVECTOR3* WINAPI D3DXVec3Project
    ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV, CONST D3D10_VIEWPORT *pViewport,
      CONST D3DXMATRIX *pProjection, CONST D3DXMATRIX *pView, CONST D3DXMATRIX *pWorld);

Using it, however, seemed a lot more challenging!
I ended up making some temporary stuff to catch ll the inout variables DirectX is so fond of.
here's my solution!

void TestGameApp::DrawIgloStats()
{
    D3DXVECTOR3 IgloPos;
    BOOST_FOREACH(Iglo * i, m_vCheckObjects)
    {
        //position
        IgloPos = i->GetPosition();
        D3DXVECTOR3* screenvector = new D3DXVECTOR3(0,0,0);
        D3DXVECTOR3 offset(0,60,0);
        offset+= IgloPos;
        const D3DXVECTOR3 * Passposition = &offset;


        //Viewport
        UINT numview = 1;
        D3D10_VIEWPORT pVptemp;
        m_pD3DDevice->RSGetViewports(&numview, &pVptemp);


       -------I got lazy withthe colours around here so figure it out yourself, I might fix it later..--------


        //screen coordinate
        D3DXVec3Project(screenvector, &offset ,&pVptemp, &m_pTrackingCameraLeft->GetProj(), &m_pTrackingCameraLeft->GetView(), &m_pTrackingCameraLeft->GetWorldMatrix());
        D3DXVECTOR3 Finalcoords = *screenvector;


        //printing
        float m_PinguinAmount = 50;
        tstringstream stream;
        stream << "Amount of Pinguins" << m_PinguinAmount;
        tstring printstring = stream.str();
        DrawString(m_pFont, printstring, Finalcoords.x -50 , Finalcoords.y);


    }


}

YAY
oh here's a picture of the final result:



BYE!!!

Geen opmerkingen:

Een reactie plaatsen