-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGeom.cpp
More file actions
66 lines (53 loc) · 2.02 KB
/
Geom.cpp
File metadata and controls
66 lines (53 loc) · 2.02 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
#include "Geom.h"
#include <Windows.h>
#include <iostream>
int screenX = GetSystemMetrics(SM_CXSCREEN);
int screenY = GetSystemMetrics(SM_CYSCREEN);
#define EnemyPen 0x000000FF
HBRUSH EnemyBrush = CreateSolidBrush(0x000000FF);
HDC hdc = GetDC(FindWindowA(NULL, "AssaultCube"));
RECT rect;
void setRect() {
GetWindowRect(FindWindowA(NULL, "AssaultCube"), &rect);
}
Vec3 WorldToScreen(const Vec3 pos, view_matrix_t matrix) {
int width = rect.right - rect.left;
int height = rect.bottom - rect.top;
float screenX = (matrix[0][0] * pos.x) + (matrix[1][0] * pos.y) + (matrix[2][0] * pos.z) + matrix[3][0];
float screenY = (matrix[0][1] * pos.x) + (matrix[1][1] * pos.y) + (matrix[2][1] * pos.z) + matrix[3][1];
float screenW = (matrix[0][3] * pos.x) + (matrix[1][3] * pos.y) + (matrix[2][3] * pos.z) + matrix[3][3];
//camera position (eye level/middle of screen)
float camX = width / 2.f;
float camY = height / 2.f;
//convert to homogeneous position
float x = camX + (camX * screenX / screenW);
float y = camY - (camY * screenY / screenW);
if (!(screenW > 0.001f)) return { 0,0,0 };
return { x,y,0 };
}
void DrawFilledRect(int x, int y, int w, int h)
{
RECT rect = { x, y, x + w, y + h };
FillRect(hdc, &rect, EnemyBrush);
}
void DrawBorderBox(int x, int y, int w, int h, int thickness)
{
DrawFilledRect(x, y, w, thickness); //Top horiz line
DrawFilledRect(x, y, thickness, h); //Left vertical line
DrawFilledRect((x + w), y, thickness, h); //right vertical line
DrawFilledRect(x, y + h, w + thickness, thickness); //bottom horiz line
}
void DrawLine(float StartX, float StartY, float EndX, float EndY)
{
int a, b = 0;
HPEN hOPen;
HPEN hNPen = CreatePen(PS_SOLID, 2, EnemyPen);// penstyle, width, color
hOPen = (HPEN)SelectObject(hdc, hNPen);
MoveToEx(hdc, StartX, StartY, NULL); //start
a = LineTo(hdc, EndX, EndY); //end
DeleteObject(SelectObject(hdc, hOPen));
}
float Vec3SquareDistance(Vec3 v, Vec3 w) {
Vec3 difference = v - w;
return (difference.x * difference.x + difference.y * difference.y + difference.z * difference.z);
}