-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameWorld.cpp
More file actions
111 lines (88 loc) · 2.79 KB
/
GameWorld.cpp
File metadata and controls
111 lines (88 loc) · 2.79 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
106
107
108
109
110
111
//
// Created by Ben Dickson on 5/9/17.
//
#include "GameWorld.h"
inline Point PhysicalModel::getGlobalPos() const
{
Point rv;
Point p = parentElement->getGlobalPos();
rv.x = p.x + GameWorld::angles.cos(p.r) * x + GameWorld::angles.sin(p.r) * y;
rv.y = p.y - GameWorld::angles.sin(p.r) * x + GameWorld::angles.cos(p.r) * y;
rv.r = p.r + r;
free(&p);
return rv;
}
inline Point RenderModel::getGlobalPos() const
{
Point rv;
Point p = parentElement->getGlobalPos();
rv.x = p.x + GameWorld::angles.cos(p.r) * origin_x + GameWorld::angles.sin(p.r) * origin_y;
rv.y = p.y - GameWorld::angles.sin(p.r) * origin_x + GameWorld::angles.cos(p.r) * origin_y;
rv.r = p.r + angle;
free(&p);
return rv;
}
inline Point CollisionModel::getGlobalPos() const
{
Point rv;
Point p = parentElement->getGlobalPos();
rv.x = p.x + GameWorld::angles.cos(p.r) * origin_x + GameWorld::angles.sin(p.r) * origin_y;
rv.y = p.y - GameWorld::angles.sin(p.r) * origin_x + GameWorld::angles.cos(p.r) * origin_y;
rv.r = p.r + angle;
free(&p);
return rv;
}
inline Point* CollisionModel::getRectPoints() const
{
Point* rv[4];
Point p = getGlobalPos();
Point tb;
tb.x = GameWorld::angles.sin(p.r) * box_bottom;
tb.y = GameWorld::angles.cos(p.r) * box_bottom;
Point tt;
tt.x = GameWorld::angles.sin(p.r) * box_top;
tt.y = GameWorld::angles.cos(p.r) * box_top;
Point tl;
tl.x = GameWorld::angles.cos(p.r) * box_left;
tl.y = -GameWorld::angles.sin(p.r) * box_left;
Point tr;
tr.x = GameWorld::angles.cos(p.r) * box_right;
tr.y = -GameWorld::angles.sin(p.r) * box_right;
rv[0]->x = p.x + tb.x + tl.x;
rv[0]->y = p.y + tb.y + tl.y;
rv[1]->x = p.x + tb.x + tr.x;
rv[1]->y = p.y + tb.y + tr.y;
rv[2]->x = p.x + tt.x + tr.x;
rv[2]->y = p.y + tt.y + tr.y;
rv[3]->x = p.x + tt.x + tl.x;
rv[3]->y = p.y + tt.y + tl.y;
free(&p);
return *rv;
}
inline Point* RenderModel::getRectPoints() const
{
Point* rv[4];
Point p = getGlobalPos();
Point tb;
tb.x = GameWorld::angles.sin(p.r) * box_bottom;
tb.y = GameWorld::angles.cos(p.r) * box_bottom;
Point tt;
tt.x = GameWorld::angles.sin(p.r) * box_top;
tt.y = GameWorld::angles.cos(p.r) * box_top;
Point tl;
tl.x = GameWorld::angles.cos(p.r) * box_left;
tl.y = -GameWorld::angles.sin(p.r) * box_left;
Point tr;
tr.x = GameWorld::angles.cos(p.r) * box_right;
tr.y = -GameWorld::angles.sin(p.r) * box_right;
rv[0]->x = p.x + tb.x + tl.x;
rv[0]->y = p.y + tb.y + tl.y;
rv[1]->x = p.x + tb.x + tr.x;
rv[1]->y = p.y + tb.y + tr.y;
rv[2]->x = p.x + tt.x + tr.x;
rv[2]->y = p.y + tt.y + tr.y;
rv[3]->x = p.x + tt.x + tl.x;
rv[3]->y = p.y + tt.y + tl.y;
free(&p);
return *rv;
}