示例#1
0
	WinPoint GetClusterPoint(CMapPVCluster* pcluster)
	{
		WinPoint pt = WinPoint(
			(int)(m_rectMap.XMin() + ((pcluster->GetScreenX() - m_xMin)/(m_xMax - m_xMin))*(m_rectMap.XSize() - 2*c_nXBorder) + c_nXBorder), 
			(int)(m_rectMap.YMin() + ((pcluster->GetScreenY() - m_yMin)/(m_yMax - m_yMin))*(m_rectMap.YSize() - 2*c_nYBorder) + c_nYBorder)
			);

		return pt;
	}
示例#2
0
////////////////////////////////////////////////////////////////////////////////////////////////////
// GenerateUITexturedVertices()
//
////////////////////////////////////////////////////////////////////////////////////////////////////
void CVertexGenerator::GenerateUITexturedVertices( 	const TEXHANDLE hTexture,
        const WinRect & rectToDraw,
        const bool bSetStream )
{
    _ASSERT( hTexture != INVALID_TEX_HANDLE );
    float fMinX, fMinY, fMaxX, fMaxY;
    float fU1, fV1;
    DWORD dwWidth, dwHeight;
    UIVERTEX * pVertArray;

    CVRAMManager::Get()->GetOriginalDimensions( hTexture, &dwWidth, &dwHeight );

    if( CVBIBManager::Get()->LockDynamicVertexBuffer(
//							&m_sVGState.hUITexVertsVB,
                &m_sVGState.hPredefinedDynBuffers[ePDBT_UITexVB],
                4,
                (void**) &pVertArray ) == false )
    {
        // Failed to lock the vertex buffer.
        _ASSERT( false );
        return;
    }

    // 2d texturing, adjust the vertex positions slightly.
    fMinX = (float) rectToDraw.Min().X() - 0.5f;
    fMinY = (float) rectToDraw.Min().Y() - 0.5f;
    fMaxX = (float) rectToDraw.Max().X() - 0.5f;
    fMaxY = (float) rectToDraw.Max().Y() - 0.5f;

    // Calculate our uv coords.
    fU1 = 1.0f;
    fV1 = 1.0f;
    if( rectToDraw.XSize() < (int)dwWidth )
    {
        fU1 = (float) rectToDraw.XSize() / (float) dwWidth;
    }
    if( rectToDraw.YSize() < (int)dwHeight )
    {
        fV1 = (float) rectToDraw.YSize() / (float) dwHeight;
    }

    pVertArray[0].x = fMinX;
    pVertArray[0].y = fMinY;
    pVertArray[0].z = 0.5f;
    pVertArray[0].rhw = 1.0f;
    pVertArray[0].fU = 0.0f;
    pVertArray[0].fV = 0.0f;

    pVertArray[1].x = fMaxX;
    pVertArray[1].y = fMinY;
    pVertArray[1].z = 0.5f;
    pVertArray[1].rhw = 1.0f;
    pVertArray[1].fU = fU1;
    pVertArray[1].fV = 0.0f;

    pVertArray[2].x = fMinX;
    pVertArray[2].y = fMaxY;
    pVertArray[2].z = 0.5f;
    pVertArray[2].rhw = 1.0f;
    pVertArray[2].fU = 0.0f;
    pVertArray[2].fV = fV1;

    pVertArray[3].x = fMaxX;
    pVertArray[3].y = fMaxY;
    pVertArray[3].z = 0.5f;
    pVertArray[3].rhw = 1.0f;
    pVertArray[3].fU = fU1;
    pVertArray[3].fV = fV1;

    // Finished adding verts, unlock.
    CVBIBManager::Get()->UnlockDynamicVertexBuffer( &m_sVGState.hPredefinedDynBuffers[ePDBT_UITexVB] );

    if( bSetStream == true )
    {
        CVBIBManager::Get()->SetVertexStream( &m_sVGState.hPredefinedDynBuffers[ePDBT_UITexVB] );
    }
}
示例#3
0
	void CalculateScreenMinAndMax()
	{
		// map the sector data
		bool    bFirstCluster = true;
		const ClusterPVList* clusters = m_missionpv.GetClusters();
		for (ClusterPVLink* cLink = clusters->first(); cLink != NULL; cLink = cLink->next())
		{
			CMapPVCluster* pCluster = cLink->data();
			if (true) // pCluster->GetModels()->n() != 0
			{
				float   x = pCluster->GetScreenX();
				float   y = pCluster->GetScreenY();
				if (bFirstCluster)
				{
					bFirstCluster = false;

					m_xClusterMin = m_xClusterMax = x;
					m_yClusterMin = m_yClusterMax = y;
				}
				else
				{
					if (x < m_xClusterMin)
						m_xClusterMin = x;
					else if (x > m_xClusterMax)
						m_xClusterMax = x;

					if (y < m_yClusterMin)
						m_yClusterMin = y;
					else if (y > m_yClusterMax)
						m_yClusterMax = y;
				}
			}
		}

		const   float   c_bfr = 0.1f * 
			max(0.0001, max(m_xClusterMax - m_xClusterMin, 
				m_yClusterMax - m_yClusterMin));
		m_xClusterMin -= c_bfr;
		m_xClusterMax += c_bfr;
		m_yClusterMin -= c_bfr;
		m_yClusterMax += c_bfr;

		// figure out the minimum and maximum screen coordinates
		m_xMin = m_xClusterMin;
		m_xMax = m_xClusterMax;
		m_yMin = m_yClusterMin;
		m_yMax = m_yClusterMax;

		float fDesiredAspectRatio = float(m_rectMap.XSize() - 2*c_nXBorder)/(m_rectMap.YSize() - 2*c_nYBorder);

		// scale it so that a map with height 2 will fit exactly
		const float fMapmakerHeight = 2.2f; // 10% fudge factor
		const float fMaxHeight = fMapmakerHeight;
		const float fMaxWidth = fMaxHeight * fDesiredAspectRatio;

		// if the map is bigger than we want to display, clip the view to the max size
		if (m_xMax - m_xMin > fMaxWidth || m_yMax - m_yMin > fMaxHeight)
		{
			m_bCanDrag = true;
			m_xMax = m_xMin + min(m_xMax - m_xMin, fMaxWidth);
			m_yMax = m_yMin + min(m_yMax - m_yMin, fMaxHeight);
		}
		else
		{
			m_bCanDrag = false;
		}

		//Preserve the aspect ratio
		float fAspectRatio = (m_xMax - m_xMin) / (m_yMax - m_yMin);

		if (fAspectRatio < fDesiredAspectRatio)
		{
			// grow the X size to correct the aspect ratio
			float fXGrowth = (fDesiredAspectRatio / fAspectRatio - 1) * (m_xMax - m_xMin);
			m_xMax += fXGrowth / 2;
			m_xMin -= fXGrowth / 2;
		}
		else if (fAspectRatio > fDesiredAspectRatio)
		{
			// grow the Y size to correct the aspect ratio
			float fYGrowth = (fAspectRatio / fDesiredAspectRatio - 1) * (m_yMax - m_yMin);
			m_yMax += fYGrowth / 2;
			m_yMin -= fYGrowth / 2;
		}

		// translate by the current drag offset
		m_xMin += m_xDrag;
		m_xMax += m_xDrag;
		m_yMin += m_yDrag;
		m_yMax += m_yDrag;
	}
示例#4
0
void Window::SetRect(const WinRect& rect)
{
    MoveWindow(m_hwnd, rect.XMin(), rect.YMin(), rect.XSize(), rect.YSize(), true);
}