📄 cinformation.cpp
字号:
#include "CInformation.h"
CInformation::CInformation(LPDIRECT3DDEVICE9 pDevice,HWND hWnd):
_pFont(NULL),
_hWnd(hWnd),
_fps(0.0f)
{
_FrameCnt = 0; //累加帧数
_TimeElapsed = 0.0f;//累加帧消耗时间
creatFont(pDevice);
}
CInformation::~CInformation()
{
SAFE_RELEASE(_pFont);
}
void CInformation::creatFont( LPDIRECT3DDEVICE9 pDevice)
{
D3DXCreateFont(pDevice,20,0,FW_BOLD,1,FALSE,DEFAULT_CHARSET,
OUT_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH|FF_DONTCARE,
"Arial",&_pFont);
}
void CInformation::drawFPS(float fElapsedTime)
{
sprintf_s(_allFPS,"FPS: %f",_fps);
//增加帧数
_FrameCnt++;
//增加时间
_TimeElapsed += fElapsedTime;
if(_TimeElapsed >= 1.0f) // 当时间超过一秒时开始计算每秒帧数
{
//_fps = (float)1 / fElapsedTime;
_fps = (float)_FrameCnt / _TimeElapsed;
sprintf_s(_allFPS,"FPS: %f",_fps);
_TimeElapsed = 0.0f;
_FrameCnt = 0;
}
RECT destRect;
SetRect( &destRect, 10, 10, 100, 100 );
_pFont->DrawText( NULL, _allFPS, -1, &destRect, DT_NOCLIP,
D3DXCOLOR( 1.0f, 0.0f, 0.0f, 1.0f ) );
}
void CInformation::drawCursorPos()
{
POINT p;
GetCursorPos( &p );
ScreenToClient( _hWnd, &p );
if(_pFont!=NULL)
{
sprintf_s(_strXY,"CursorPos:%d, %d", p.x, p.y );
RECT destRect;
SetRect( &destRect, 10, 30, 100, 100 );
_pFont->DrawText( NULL, _strXY, -1, &destRect, DT_NOCLIP,
D3DXCOLOR( 1.0f, 0.0f, 0.0f, 1.0f ) );
}
}
void CInformation::drawCameraPos(D3DXVECTOR3 pos)
{
sprintf_s(_strPointPos,"CameraPos:%0.2f, %0.2f,%0.2f", pos.x, pos.y ,pos.z);
RECT destRect;
SetRect( &destRect, 10, 50, 100, 100 );
_pFont->DrawText( NULL, _strPointPos, -1, &destRect, DT_NOCLIP,
D3DXCOLOR( 1.0f, 0.0f, 0.0f, 1.0f ) );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -