-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathdfm_cheat.cpp
More file actions
105 lines (91 loc) · 3.54 KB
/
dfm_cheat.cpp
File metadata and controls
105 lines (91 loc) · 3.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <unistd.h>
#include <string>
#include <thread>
#include <chrono>
#include "ANativeWindowCreator.h"
#include <thread>
dfm_decoder decoder;
ANativeWindow *native_window;
// Bresenham直线算法(纯整数运算)
void draw_line(uint32_t *pixels, int width, int height, int x0, int y0, int x1, int y1, uint32_t color)
{
int dx = abs(x1 - x0);
int dy = -abs(y1 - y0);
int sx = (x0 < x1) ? 1 : -1;
int sy = (y0 < y1) ? 1 : -1;
int err = dx + dy;
while (true)
{
if (x0 >= 0 && x0 < width && y0 >= 0 && y0 < height)
pixels[y0 * width + x0] = color;
if (x0 == x1 && y0 == y1)
break;
int e2 = 2 * err;
if (e2 >= dy)
{
err += dy;
x0 += sx;
}
if (e2 <= dx)
{
err += dx;
y0 += sy;
}
}
}
void draw_rect(uint32_t *pixels, int width, int height, int x0, int y0, int x1, int y1, uint32_t color)
{
draw_line(pixels, width, height, x0, y0, x1, y0, color);
draw_line(pixels, width, height, x0, y1, x1, y1, color);
draw_line(pixels, width, height, x0, y0, x0, y1, color);
draw_line(pixels, width, height, x1, y0, x1, y1, color);
}
vector_4d<float> world_to_screen(matrix_4d<float> matrix, vector_3d<float> world_location, int screen_width, int screen_height)
{
float px = screen_width / 2;
float py = screen_height / 2;
vector_4d<float> box;
float camera = matrix.m[0][3] * world_location.x + matrix.m[1][3] * world_location.y + matrix.m[2][3] * world_location.z + matrix.m[3][3];
float r_x = px + (matrix.m[0][0] * world_location.x + matrix.m[1][0] * world_location.y + matrix.m[2][0] * world_location.z + matrix.m[3][0]) / camera * px;
float r_y = py - (matrix.m[0][1] * world_location.x + matrix.m[1][1] * world_location.y + matrix.m[2][1] * (world_location.z - 5) + matrix.m[3][1]) / camera * py;
float r_w = py - (matrix.m[0][1] * world_location.x + matrix.m[1][1] * world_location.y + matrix.m[2][1] * (world_location.z + 205) + matrix.m[3][1]) / camera * py;
box.z = r_y - r_w;
box.x = (r_x - (r_y - r_w) / 4);
box.y = r_y;
box.w = (r_y - r_w) / 2;
return box;
}
void draw(uint32_t *pixels, int stride, int width, int height)
{
// 在这里绘制
}
void draw_thread()
{
android::ANativeWindowCreator::DisplayInfo
display_info = android::ANativeWindowCreator::GetDisplayInfo();
native_window = android::ANativeWindowCreator::Create("sf,dsdsjhdsk", display_info.width > display_info.height ? display_info.width : display_info.height, display_info.width < display_info.height ? display_info.width : display_info.height, true);
while (1)
{
std::this_thread::sleep_for(std::chrono::milliseconds(1000 / target_fps));
int width = ANativeWindow_getWidth(native_window);
int height = ANativeWindow_getHeight(native_window);
ANativeWindow_setBuffersGeometry(native_window, width, height, WINDOW_FORMAT_RGBA_8888); // 支持透明度[10](@ref)
ANativeWindow_Buffer buffer;
if (ANativeWindow_lock(native_window, &buffer, nullptr) != 0)
return;
const int pixelCount = buffer.stride * buffer.height;
uint32_t *pixels = static_cast<uint32_t *>(buffer.bits);
memset(pixels, 0x00, pixelCount * 4); // ARGB透明=0x00000000
dfm_draw(pixels, buffer.stride, width, height);
ANativeWindow_unlockAndPost(native_window);
}
}
int main()
{
std::thread draw(draw_thread);
draw.join();
return 0;
}