⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gsfunc.cpp

📁 网络泡泡被.net管理
💻 CPP
📖 第 1 页 / 共 3 页
字号:

    // The x basis vector is found simply with the cross product of the y
    // and z basis vectors
    D3DVECTOR vRight = CrossProduct( vUp, vView );

    // Start building the matrix. The first three rows contains the basis
    // vectors used to rotate the view to point at the lookat point
    D3DSetIdentityMatrix( mat );
    mat._11 = vRight.x;    mat._12 = vUp.x;    mat._13 = vView.x;
    mat._21 = vRight.y;    mat._22 = vUp.y;    mat._23 = vView.y;
    mat._31 = vRight.z;    mat._32 = vUp.z;    mat._33 = vView.z;

    // Do the translation values (rotations are still about the eyepoint)
    mat._41 = - DotProduct( vFrom, vRight );
    mat._42 = - DotProduct( vFrom, vUp );
    mat._43 = - DotProduct( vFrom, vView );

    return S_OK;
}


//-----------------------------------------------------------------------------
// Name: D3DSetProjectionMatrix()
// Desc: Sets the passed in 4x4 matrix to a perpsective projection matrix built
//       from the field-of-view (fov, in y), aspect ratio, near plane (D),
//       and far plane (F). Note that the projection matrix is normalized for
//       element [3][4] to be 1.0. This is performed so that W-based range fog
//       will work correctly.
//-----------------------------------------------------------------------------
HRESULT CGsFunc::D3DSetProjectionMatrix( D3DMATRIX& mat, FLOAT fFOV, FLOAT fAspect,
                                     FLOAT fNearPlane, FLOAT fFarPlane )
{
    if( fabs(fFarPlane-fNearPlane) < 0.01f )
        return E_INVALIDARG;
    if( fabs(sin(fFOV/2)) < 0.01f )
        return E_INVALIDARG;

    FLOAT w = fAspect * ( cosf(fFOV/2)/sinf(fFOV/2) );
    FLOAT h =   1.0f  * ( cosf(fFOV/2)/sinf(fFOV/2) );
    FLOAT Q = fFarPlane / ( fFarPlane - fNearPlane );

    ZeroMemory( &mat, sizeof(D3DMATRIX) );
    mat._11 = w;
    mat._22 = h;
    mat._33 = Q;
    mat._34 = 1.0f;
    mat._43 = -Q*fNearPlane;

    return S_OK;
}




//-----------------------------------------------------------------------------
// Name: D3DSetRotateXMatrix()
// Desc: Create Rotation matrix about X axis
//-----------------------------------------------------------------------------
VOID CGsFunc::D3DSetRotateXMatrix( D3DMATRIX& mat, FLOAT fRads )
{
    D3DSetIdentityMatrix( mat );
    mat._22 =  cosf( fRads );
    mat._23 =  sinf( fRads );
    mat._32 = -sinf( fRads );
    mat._33 =  cosf( fRads );
}




//-----------------------------------------------------------------------------
// Name: D3DSetRotateYMatrix()
// Desc: Create Rotation matrix about Y axis
//-----------------------------------------------------------------------------
VOID CGsFunc::D3DSetRotateYMatrix( D3DMATRIX& mat, FLOAT fRads )
{
    D3DSetIdentityMatrix( mat );
    mat._11 =  cosf( fRads );
    mat._13 = -sinf( fRads );
    mat._31 =  sinf( fRads );
    mat._33 =  cosf( fRads );
}




//-----------------------------------------------------------------------------
// Name: D3DSetRotateZMatrix()
// Desc: Create Rotation matrix about Z axis
//-----------------------------------------------------------------------------
VOID CGsFunc::D3DSetRotateZMatrix( D3DMATRIX& mat, FLOAT fRads )
{
    D3DSetIdentityMatrix( mat );
    mat._11  =  cosf( fRads );
    mat._12  =  sinf( fRads );
    mat._21  = -sinf( fRads );
    mat._22  =  cosf( fRads );
}




//-----------------------------------------------------------------------------
// Name: D3DSetRotationMatrix
// Desc: Create a Rotation matrix about vector direction
//-----------------------------------------------------------------------------
VOID CGsFunc::D3DSetRotationMatrix( D3DMATRIX& mat, D3DVECTOR& vDir, FLOAT fRads )
{
    FLOAT     fCos = cosf( fRads );
    FLOAT     fSin = sinf( fRads );
    D3DVECTOR v    = Normalize( vDir );

    mat._11 = ( v.x * v.x ) * ( 1.0f - fCos ) + fCos;
    mat._12 = ( v.x * v.y ) * ( 1.0f - fCos ) - (v.z * fSin);
    mat._13 = ( v.x * v.z ) * ( 1.0f - fCos ) + (v.y * fSin);

    mat._21 = ( v.y * v.x ) * ( 1.0f - fCos ) + (v.z * fSin);
    mat._22 = ( v.y * v.y ) * ( 1.0f - fCos ) + fCos ;
    mat._23 = ( v.y * v.z ) * ( 1.0f - fCos ) - (v.x * fSin);

    mat._31 = ( v.z * v.x ) * ( 1.0f - fCos ) - (v.y * fSin);
    mat._32 = ( v.z * v.y ) * ( 1.0f - fCos ) + (v.x * fSin);
    mat._33 = ( v.z * v.z ) * ( 1.0f - fCos ) + fCos;

    mat._14 = mat._24 = mat._34 = 0.0f;
    mat._41 = mat._42 = mat._43 = 0.0f;
    mat._44 = 1.0f;
}


//-----------------------------------------------------------------------------
// Name: CDxSurface::GetBitMaskInfo()
// Desc: Returns the number of bits and the shift in the bit mask
//-----------------------------------------------------------------------------
VOID CGsFunc::DxGetBitMaskInfo( DWORD dwBitMask, DWORD &dwShift, DWORD &dwBits )
{
    dwShift = 0;
    dwBits  = 0; 

    if( dwBitMask )
    {
        while( (dwBitMask & 1) == 0 )
        {
            dwShift++;
            dwBitMask >>= 1;
        }
    }

    while( (dwBitMask & 1) != 0 )
    {
        dwBits++;
        dwBitMask >>= 1;
    }

}




//-----------------------------------------------------------------------------
// Name: CDxSurface::TextFormatString()
// Desc: 
//-----------------------------------------------------------------------------
VOID CGsFunc::TextFormatString(std::string &string, char* format,...)
{
	char str_out[1024];
	va_list ap;
	va_start(ap, format);
	sprintf(str_out, format, ap);
	va_end(ap);
	string = str_out;
}

static DWORD g_DefaultCharSet = DEFAULT_CHARSET;
static char	 g_strDefaultFont[100] = "";
static int	 g_DefaultFontSize = 16;
VOID CGsFunc::Font_SetDefaultFont( int size, LPCSTR szfont, DWORD CharSet )
{
	if(size>0)
		g_DefaultFontSize = size;
	if(CharSet!=0)
		g_DefaultCharSet	= CharSet;
	if(szfont)
		strcpy(g_strDefaultFont, szfont);
}
//-----------------------------------------------------------------------------
// Name: CDxSurface::TextQuickCreateFont()
// Desc: 
//-----------------------------------------------------------------------------
HFONT CGsFunc::Font_QuickCreateFont( int nSize, const char* szfont, int CharSet, BOOL bItalic, BOOL bUnderline, BOOL bStrikeOut )
{
	if(nSize==0)
		nSize	= g_DefaultFontSize;
	if(CharSet==-1)
		CharSet	= g_DefaultCharSet;
	if(szfont==NULL || szfont[0]==0)
	{
		szfont	= g_strDefaultFont;
	}
	HDC hdc		= GetDC(NULL);
	HFONT font = CreateFont(-MulDiv(nSize, GetDeviceCaps(hdc,LOGPIXELSY), 72),
					  0, 0, 0, FW_BLACK, bItalic, bUnderline, bStrikeOut,CharSet,
					  OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,
					  VARIABLE_PITCH , szfont);
	ReleaseDC(NULL, hdc);
	return font;
}


HFONT CGsFunc::Font_QuickCreateFont( GSFONT &font )
{
	return Font_QuickCreateFont(font.size, font.strFont, font.charset, font.Italic, font.Underline, font.StrikeOut);
}

CGsApp* CGsFunc::GetGsApp()
{
	return g_pGsApp;
}

/*
 * Description:		Retrieves the cpu features that the processor supports.
 *
 * Parameters:		None.
 *					 
 * Return value:	A combination of the following flags:
 *
 *					CPU_FEATURE_MMX   - The MMX instruction set is available.
 *					CPU_FEATURE_RDTSC - The rdtsc instruction is available.
 *					CPU_FEATURE_3DNOW - The 3DNow! instruction set is available.
 *
 */
DWORD CGsFunc::GetCPUCaps()
{
	SYSTEM_INFO		si;
    DWORD			dwFeatures;


	// Assume no features are present.
	dwFeatures = 0;

	// Get the system information.
    GetSystemInfo(&si);

	// If this is at least a pentium or compatibel ...
    if ( si.dwProcessorType != PROCESSOR_INTEL_386 && 
		 si.dwProcessorType != PROCESSOR_INTEL_486)
    {
		//
		// ... get the features.
		//
        __asm
        {
			//
			// Save registers.
			//
            push	eax
            push	ebx
            push	ecx
            push	edx

			//
			// Get the features.
			//
            mov		eax, 1
			cpuid
            mov		dwFeatures, edx

			//
			// Restore registers.
			//
            pop		edx
            pop		ecx
            pop		ebx
            pop		eax
        }
    }

	// Return the features.
	return dwFeatures;
}








void CGsFunc::Path_RectifyPath(char*	szDest, const char* szSrc)
{
	if(szDest==NULL)
		return;
	if(szSrc==NULL)
	{
		if(szDest[0]=='\\' && szDest[1]!='\\')
			strcpy(szDest, szDest+1);
	}
	else
	{
		if(szSrc[0]=='\\' && szSrc[1]!='\\')
			strcpy(szDest, szSrc+1);
		else
			strcpy(szDest, szSrc);
	}
	int len	= strlen(szDest);
	if(szDest[len-1]=='\\')
		szDest[len-1]=0;
	szDest[len]=0;
	szDest[len+1]=0;
}

void CGsFunc::Path_GetPathFile(char* szDest, const char* szSrc)
{
	if(szDest==NULL)
		return;
	char str[PATH_SIZE];
	Path_RectifyPath(str, szSrc);
	char*	sz	= strrchr(str, '\\');
	if(sz)
	{
		strcpy(szDest, sz+1);
	}
	else
	{
		strcpy(szDest, str);
	}
	int len	= strlen(szDest);
	szDest[len]=0;
	szDest[len+1]=0;
}

void CGsFunc::Path_GetParentPath(char* szDest, const char* szSrc)
{
	if(szDest==NULL)
		return;
	Path_RectifyPath(szDest, szSrc);
	int len	= strlen(szDest);
	char*	sz	= strrchr(szDest, '\\');
	if(sz)
	{
		sz[0]=0;
		sz[1]=0;
	}
	else
	{
		strcpy(szDest, "");
		szDest[len]=0;
		szDest[len+1]=0;
	}

}

VOID CGsFunc::Path_MakeFullPath(char* strDest, const char* szSrc)
{
	if(strDest==NULL)
		return;
	char strTemp[PATH_SIZE];
	if(szSrc!=NULL)
	{
		strcpy(strTemp, szSrc);
	}
	else
	{
		strcpy(strTemp, strDest);
	}
	if(Path_IsSysPath(strTemp))
	{
		strcpy(strDest, strTemp);
	}
	else
	{
		Path_RectifyPath(strTemp);
		char temp_path[PATH_SIZE];
		::GetCurrentDirectory(PATH_SIZE, temp_path);
		Path_RectifyPath(temp_path);
		sprintf(strDest, "%s\\%s", temp_path, strTemp);
	}
	Path_RectifyPath(strDest);
}


BOOL CGsFunc::Path_IsSysPath(LPCSTR strPath)
{
	if(NULL == strPath || strlen(strPath)<2 || strPath[0]==':')
		return FALSE;
	if(NULL!=strchr(strPath, ':')
		|| (strPath[0]=='\\' && strPath[1]=='\\'))
	{
		return TRUE;
	}


	return FALSE;
}





BOOL CGsFunc::AppSetTimer(UINT nIDEvent, UINT uElapse)
{
	if(NULL==g_pGsApp)
		return FALSE;
	if(uElapse<=0)
	{
		KillTimer(g_pGsApp->GetMainWnd(), nIDEvent);
	}
	else
	{
		if(0==SetTimer(g_pGsApp->GetMainWnd(), nIDEvent, uElapse, NULL))
			return FALSE;
	}
	return TRUE;
}







CGsDebug* CGsFunc::GetDebuger()
{
	return g_pDebug;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -