首页 > 解决方案 > C++ - 未声明的标识符/'FUNCTION'的左侧必须有类/结构/联合

问题描述

我整天都在搜索这个问题,但似乎没有一个答案可以帮助我修复错误......

我目前正在用 C++ 做一个 DLL,它连接游戏的 EndScene,并获取viewmatrix并转换到屏幕......所有代码都很好,但似乎有些变量正在搞砸一切......

我收到了这些错误

错误 1:“LocalPlayer”:未声明的标识符

错误 2:'.flMatrix' 的左侧必须有类/结构/联合

错误 3:'.WorldToScreenMatrix' 的左侧必须有类/结构/联合

这是WorldToScreen功能:

    bool WorldToScreen(float * from, float * to)
{
    HWND atual = GetActiveWindow();
    RECT m_Rect;
    GetWindowRect(atual, &m_Rect);

    float w = 0.0f;

    to[0] = LocalPlayer.WorldToScreenMatrix.flMatrix[0][0] * from[0] + LocalPlayer.WorldToScreenMatrix.flMatrix[0][1] * from[1] + LocalPlayer.WorldToScreenMatrix.flMatrix[0][2] * from[2] + LocalPlayer.WorldToScreenMatrix.flMatrix[0][3];
    to[1] = LocalPlayer.WorldToScreenMatrix.flMatrix[1][0] * from[0] + LocalPlayer.WorldToScreenMatrix.flMatrix[1][1] * from[1] + LocalPlayer.WorldToScreenMatrix.flMatrix[1][2] * from[2] + LocalPlayer.WorldToScreenMatrix.flMatrix[1][3];
    w = LocalPlayer.WorldToScreenMatrix.flMatrix[3][0] * from[0] + LocalPlayer.WorldToScreenMatrix.flMatrix[3][1] * from[1] + LocalPlayer.WorldToScreenMatrix.flMatrix[3][2] * from[2] + LocalPlayer.WorldToScreenMatrix.flMatrix[3][3];

    if (w < 0.01f)
        return false;

    float invw = 1.0f / w;
    to[0] *= invw;
    to[1] *= invw;

    int width = (int)(m_Rect.right - m_Rect.left);
    int height = (int)(m_Rect.bottom - m_Rect.top);

    float x = width / 2;
    float y = height / 2;

    x += 0.5 * to[0] * width + 0.5;
    y -= 0.5 * to[1] * height + 0.5;

    to[0] = x + m_Rect.left;
    to[1] = y + m_Rect.top;

    return true;
}

错误在这一行:

to[0] = LocalPlayer.WorldToScreenMatrix.flMatrix[0][0] * from[0] + LocalPlayer.WorldToScreenMatrix.flMatrix[0][1] * from[1] + LocalPlayer.WorldToScreenMatrix.flMatrix[0][2] * from[2] + LocalPlayer.WorldToScreenMatrix.flMatrix[0][3];
    to[1] = LocalPlayer.WorldToScreenMatrix.flMatrix[1][0] * from[0] + LocalPlayer.WorldToScreenMatrix.flMatrix[1][1] * from[1] + LocalPlayer.WorldToScreenMatrix.flMatrix[1][2] * from[2] + LocalPlayer.WorldToScreenMatrix.flMatrix[1][3];
    w = LocalPlayer.WorldToScreenMatrix.flMatrix[3][0] * from[0] + LocalPlayer.WorldToScreenMatrix.flMatrix[3][1] * from[1] + LocalPlayer.WorldToScreenMatrix.flMatrix[3][2] * from[2] + LocalPlayer.WorldToScreenMatrix.flMatrix[3][3];

LocalPlayer 结构是:

struct LocalPlayer
{
    DWORD Local;
    int Team;
    int Health;
    WorldToScreenMatrix_t WorldToScreenMatrix;
    float* Position;
    int Flags;
    int CrossHair;
    void Read()
    {
        Local = *(DWORD*)(dwClient + dwLocalPlayer);
        if (Local != NULL)
        {
            Team = *(int*)(Local + dwTeam);
            Position = (float*)(Local + dwOrigin);
            Health = *(int*)(Local + dwHealth);
            CrossHair = *(int*)(Local + dwCrossHairID);
            WorldToScreenMatrix = *(WorldToScreenMatrix_t*)(dwEngine + dw_vMatrix);
        }
    }
}LocalPlayer;

flmatrix 开启:

typedef struct
{
    float flMatrix[4][4];
}WorldToScreenMatrix_t;

哪里导致错误?

标签: c++structdirect3d

解决方案


推荐阅读