Panel 发表于 2023-3-7 22:09

分享一份刚写的FPS游戏坐标转屏幕坐标的类库



```cpp
#pragma once
#include <windows.h>

typedef struct _WORD_LOCATION_
{
        float x;
        float y;
        float z;
}WORD_LOCATION;


typedef struct _CUT_COOR_
{
        float x;
        float y;
        float z;
        float w;
}CUT_COOR;

typedef struct _NDC_COOR_
{
        float x;
        float y;
        float z;
}NDC_COOR;

typedef struct _SCREEN_COOR_
{
        float x;
        float y;
}SCREEN_COOR;

typedef struct _SCREEN_PARAM_
{
        float height;
        float width;
}SCREEN_PARAM;

class World2Screen
{
public:
        float PersonMatrix;
        WORD_LOCATION WordLocation;
        CUT_COOR CutCoor;
        NDC_COOR NDCCoor;
        SCREEN_COOR ScreenCoor;
        SCREEN_PARAM ScreenParam;
public:
        World2Screen(WORD_LOCATION Word, float* PersonMatrix);
        void Word2CutCoor();
        bool InVisualField();
        void Cut2NDCCoor();
        void NDC2ScreenCoor();

       
};


```

```cpp
#include "World2Screen.h"

World2Screen::World2Screen(WORD_LOCATION Word, float* PersonMatrix)
{
        this->WordLocation.x = Word.x;
        this->WordLocation.y = Word.y;
        this->WordLocation.z = Word.z;
        memcpy_s(this->PersonMatrix,sizeof(this->PersonMatrix),PersonMatrix,sizeof(this->PersonMatrix));
}

void World2Screen::Word2CutCoor()
{       
        this->CutCoor.x = this->PersonMatrix * this->WordLocation.x + this->PersonMatrix * this->WordLocation.y + this->PersonMatrix * this->WordLocation.z + this->PersonMatrix;
        this->CutCoor.y = this->PersonMatrix * this->WordLocation.x + this->PersonMatrix * this->WordLocation.y + this->PersonMatrix * this->WordLocation.z + this->PersonMatrix;
        this->CutCoor.z = this->PersonMatrix * this->WordLocation.x + this->PersonMatrix * this->WordLocation.y + this->PersonMatrix * this->WordLocation.z + this->PersonMatrix;
        this->CutCoor.w = this->PersonMatrix * this->WordLocation.x + this->PersonMatrix * this->WordLocation.y + this->PersonMatrix * this->WordLocation.z + this->PersonMatrix;
}

bool World2Screen::InVisualField()
{
        if (this->CutCoor.w < 0.01) { return false; };
}

void World2Screen::Cut2NDCCoor()
{
        this->NDCCoor.x = this->CutCoor.x / this->CutCoor.w;
        this->NDCCoor.y = this->CutCoor.y / this->CutCoor.w;
        this->NDCCoor.z = this->CutCoor.z / this->CutCoor.w;
}

void World2Screen::NDC2ScreenCoor()
{
        this->ScreenCoor.x = this->ScreenParam.width / 2 + (this->ScreenParam.width / 2) * this->NDCCoor.x;
        this->ScreenCoor.y = this->ScreenParam.height / 2 - (this->ScreenParam.height / 2) * this->NDCCoor.y;
}

```



Panel 发表于 2023-3-7 22:15

忘记补充了,这份代码矩阵部分是4x4矩阵的,如果你的游戏人物矩阵不是4x4的就自己改一下那里的代码就能用了

Chenda1 发表于 2023-3-7 22:24

我表示看不懂楼主有没有适合小白科普的

Panel 发表于 2023-3-7 22:25

18077484116 发表于 2023-3-7 22:24
我表示看不懂楼主有没有适合小白科普的

看游戏安全方面的资料就懂是什么意思了

walykyy 发表于 2023-3-8 01:05

Panel 发表于 2023-3-7 22:25
看游戏安全方面的资料就懂是什么意思了

想学写游戏,兄弟有相关资料分享一下吗?

zsj118106 发表于 2023-3-8 08:51

先收藏了,感谢楼主分享

Panel 发表于 2023-3-8 10:22

walykyy 发表于 2023-3-8 01:05
想学写游戏,兄弟有相关资料分享一下吗?

这个不是写游戏的,你如果要去学写游戏就去网上查查资料,我也没接触过写游戏

timeslover 发表于 2023-3-8 10:53

那就是可以搞自瞄的一个步骤

zhangxinxin2ni 发表于 2023-3-13 14:43

楼主有没有好的游戏逆向相关的教程啊

Panel 发表于 2023-3-13 18:38

zhangxinxin2ni 发表于 2023-3-13 14:43
楼主有没有好的游戏逆向相关的教程啊

我之前看的是一份收费的,就不推荐了,要不然成引流了,可以去Tb这些看看
页: [1] 2
查看完整版本: 分享一份刚写的FPS游戏坐标转屏幕坐标的类库