龙马谷

 找回密码
 立即注册

QQ登录

只需一步,快速开始

龙马谷VIP会员办理客服QQ:82926983(如果临时会话没有收到回复,请先加QQ好友再发。)
1 [已完结] GG修改器新手入门与实战教程 31课 2 [已完结] GG修改器美化修改教程 6课 3 [已完结] GG修改器Lua脚本新手入门教程 12课
4 [已完结] 触动精灵脚本新手入门必学教程 22课 5 [已完结] 手游自动化脚本入门实战教程 9课 6 [已完结] C++射击游戏方框骨骼透视与自瞄教程 27课
7 [已完结] C++零基础UE4逆向开发FPS透视自瞄教程 29课 8 [已完结] C++零基础大漠模拟器手游自动化辅助教程 22课
以下是天马阁VIP教程,本站与天马阁合作,赞助VIP可以获得天马阁对应VIP会员,名额有限! 点击进入天马阁论坛
1 [已完结] x64CE与x64dbg入门基础教程 7课 2 [已完结] x64汇编语言基础教程 16课 3 [已完结] x64辅助入门基础教程 9课
4 [已完结] C++x64内存辅助实战技术教程 149课 5 [已完结] C++x64内存检测与过检测技术教程 10课 6 [已完结] C+x64二叉树分析遍历与LUA自动登陆教程 19课
7 [已完结] C++BT功能原理与x64实战教程 29课 8 [已完结] C+FPS框透视与自瞄x64实现原理及防护思路
查看: 1228|回复: 0

[C++源码] C++ FPS游戏坐标转屏幕坐标的类库源码

[复制链接]

28

主题

3

回帖

38

积分

编程入门

Rank: 1

龙马币
73


C++ FPS游戏坐标转屏幕坐标的类库源码

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

  1. #pragma once
  2. #include <windows.h>

  3. typedef struct _WORD_LOCATION_
  4. {
  5.     float x;
  6.     float y;
  7.     float z;
  8. }WORD_LOCATION;

  9. typedef struct _CUT_COOR_
  10. {
  11.     float x;
  12.     float y;
  13.     float z;
  14.     float w;
  15. }CUT_COOR;

  16. typedef struct _NDC_COOR_
  17. {
  18.     float x;
  19.     float y;
  20.     float z;
  21. }NDC_COOR;

  22. typedef struct _SCREEN_COOR_
  23. {
  24.     float x;
  25.     float y;
  26. }SCREEN_COOR;

  27. typedef struct _SCREEN_PARAM_
  28. {
  29.     float height;
  30.     float width;
  31. }SCREEN_PARAM;

  32. class World2Screen
  33. {
  34. public:
  35.     float PersonMatrix[4][4];
  36.     WORD_LOCATION WordLocation;
  37.     CUT_COOR CutCoor;
  38.     NDC_COOR NDCCoor;
  39.     SCREEN_COOR ScreenCoor;
  40.     SCREEN_PARAM ScreenParam;
  41. public:
  42.     World2Screen(WORD_LOCATION Word, float* PersonMatrix);
  43.     void Word2CutCoor();
  44.     bool InVisualField();
  45.     void Cut2NDCCoor();
  46.     void NDC2ScreenCoor();

  47. };
复制代码

  1. #include "World2Screen.h"

  2. World2Screen::World2Screen(WORD_LOCATION Word, float* PersonMatrix)
  3. {
  4.     this->WordLocation.x = Word.x;
  5.     this->WordLocation.y = Word.y;
  6.     this->WordLocation.z = Word.z;
  7.     memcpy_s(this->PersonMatrix,sizeof(this->PersonMatrix),PersonMatrix,sizeof(this->PersonMatrix));
  8. }

  9. void World2Screen::Word2CutCoor()
  10. {   
  11.     this->CutCoor.x = this->PersonMatrix[0][0] * this->WordLocation.x + this->PersonMatrix[0][1] * this->WordLocation.y + this->PersonMatrix[0][2] * this->WordLocation.z + this->PersonMatrix[0][3];
  12.     this->CutCoor.y = this->PersonMatrix[1][0] * this->WordLocation.x + this->PersonMatrix[1][1] * this->WordLocation.y + this->PersonMatrix[1][2] * this->WordLocation.z + this->PersonMatrix[1][3];
  13.     this->CutCoor.z = this->PersonMatrix[2][0] * this->WordLocation.x + this->PersonMatrix[2][1] * this->WordLocation.y + this->PersonMatrix[2][2] * this->WordLocation.z + this->PersonMatrix[2][3];
  14.     this->CutCoor.w = this->PersonMatrix[3][0] * this->WordLocation.x + this->PersonMatrix[3][1] * this->WordLocation.y + this->PersonMatrix[3][2] * this->WordLocation.z + this->PersonMatrix[3][3];
  15. }

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

  20. void World2Screen::Cut2NDCCoor()
  21. {
  22.     this->NDCCoor.x = this->CutCoor.x / this->CutCoor.w;
  23.     this->NDCCoor.y = this->CutCoor.y / this->CutCoor.w;
  24.     this->NDCCoor.z = this->CutCoor.z / this->CutCoor.w;
  25. }

  26. void World2Screen::NDC2ScreenCoor()
  27. {
  28.     this->ScreenCoor.x = this->ScreenParam.width / 2 + (this->ScreenParam.width / 2) * this->NDCCoor.x;
  29.     this->ScreenCoor.y = this->ScreenParam.height / 2 - (this->ScreenParam.height / 2) * this->NDCCoor.y;
  30. }
复制代码

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

龙马谷| C/C++辅助教程| 安卓逆向安全| 论坛导航| 免责申明|Archiver|
拒绝任何人以任何形式在本论坛发表与中华人民共和国法律相抵触的言论,本站内容均为会员发表,并不代表龙马谷立场!
任何人不得以任何方式翻录、盗版或出售本站视频,一经发现我们将追究其相关责任!
我们一直在努力成为最好的编程论坛!
Copyright© 2018-2021 All Right Reserved.
在线客服
快速回复 返回顶部 返回列表