XNA Creators Club Online
Page 1 of 1 (1 items)
Sort Posts: Previous Next

ScreentoVector function in DXUT framework positive

Last post 11/23/2009 1:41 AM by autumn. 0 replies.
  • 11/23/2009 1:41 AM

    ScreentoVector function in DXUT framework positive

    Can someone give me an explanation about the code below? especially the first line, why we need the negative sign "-" for x? but y, z is positive ?

    D3DXVECTOR3 CD3DArcBall::ScreenToVector( float fScreenPtX, float fScreenPtY )
    {
        // Scale to screen
        FLOAT x   = -(fScreenPtX - m_Offset.x - m_nWidth/2)  / (m_fRadius* m_nWidth/2);
        FLOAT y   =  (fScreenPtY - m_Offset.y - m_nHeight/2) / (m_fRadius* m_nHeight/2);

        FLOAT z   = 0.0f;
        FLOAT mag = x*x + y*y;

        if( mag > 1.0f )
        {
            FLOAT scale = 1.0f/sqrtf(mag);
            x *= scale;
            y *= scale;
        }
        else
            z = sqrtf( 1.0f - mag );

        // Return vector
        return D3DXVECTOR3( x, y, z );
    }

     

Page 1 of 1 (1 items) Previous Next