FPS矩阵的应用
矩阵的算法,也就是把三维坐标转为屏幕坐标
x1,y1为人物脚底的坐标,y2为头顶的y坐标
BOOL WordToScreen(float mcax, float mcay, float mcaz, float to[3])
{
float x1, y1,y2, w;
x1 = matrix[0][0] * mcax + matrix[0][1] * mcay + matrix[0][2] * mcaz + matrix[0][3];
y1 = matrix[1][0] * mcax + matrix[1][1] * mcay + matrix[1][2] * mcaz + matrix[1][3];
y2 = matrix[1][0] * mcax + matrix[1][1] * mcay + matrix[1][2] * (mcaz+60) + matrix[1][3];
w = matrix[3][0] * mcax + matrix[3][1] * mcay + matrix[3][2] * mcaz + matrix[3][3];
if (w < 0.01f)
return FALSE;
x1 = x1 / w;
y1 = y1 / w;
y2 = y2 / w;
to[0] = ((g_winRect.right - g_winRect.left) / 2.0 * x1) + (x1 + (g_winRect.right - g_winRect.left) / 2.0);
to[1] = -((g_winRect.bottom - g_winRect.top) / 2.0 * y1) + (y1 + (g_winRect.bottom - g_winRect.top) / 2.0);
to[2] = -((g_winRect.bottom - g_winRect.top) / 2.0 * y2) + (y2 + (g_winRect.bottom - g_winRect.top) / 2.0);
return TRUE;
}
用来绘制方框也很简单
循环读取绘制就行了
0.57是你想绘制方框的比例
float w = (EnemyXY[1]- EnemyXY[2])*0.57/2;
DrawEsp(gamehwnd, EnemyXY[0]-w, EnemyXY[2], EnemyXY[0] +w, EnemyXY[1] );
还有一种用三角函数来计算X,Y坐标的方法不需要矩阵,只需要FOV即可计算(但此方法算出坐标不准确而且过于繁琐)以后会分析。
来源:CSDN
作者:我是一个萌
链接:https://blog.csdn.net/whs100505/article/details/103686361