Skip to content

Commit a93a624

Browse files
committed
Screenshot Tool and Free Camera Tool by @rickomax #85
Rebased features onto latest develop codebase gui: display button name when icon not found 3d-screenshot: enabled vertex color export Fixed adding faces to existing groups debug: gpu rect texture export (wip)
1 parent ec9d779 commit a93a624

34 files changed

+1872
-46
lines changed

CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ add_library(core STATIC
204204
src/device/controller/peripherals/abstract_device.cpp
205205
src/device/controller/peripherals/analog_controller.cpp
206206
src/device/controller/peripherals/digital_controller.cpp
207+
src/device/controller/peripherals/freecam_controller.cpp
207208
src/device/controller/peripherals/memory_card.cpp
208209
src/device/controller/peripherals/mouse.cpp
209210
src/device/controller/peripherals/none.cpp
@@ -224,6 +225,7 @@ add_library(core STATIC
224225
src/device/gpu/render/render_line.cpp
225226
src/device/gpu/render/render_rectangle.cpp
226227
src/device/gpu/render/render_triangle.cpp
228+
src/device/gpu/render/render_debug.cpp
227229
src/device/interrupt.cpp
228230
src/device/mdec/algorithm.cpp
229231
src/device/mdec/mdec.cpp
@@ -301,6 +303,7 @@ set(SOURCES
301303
src/platform/windows/gui/debug/spu.cpp
302304
src/platform/windows/gui/debug/timers.cpp
303305
src/platform/windows/gui/file/open.cpp
306+
src/platform/windows/gui/screenshot/select_directory.cpp
304307
src/platform/windows/gui/gui.cpp
305308
src/platform/windows/gui/help/about.cpp
306309
src/platform/windows/gui/helper/file_dialog.cpp

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Avocado
22
A Modern PlayStation 1 emulator.
33

4+
## 3D Screenshot and free camera mod by [Rickomax](https://github.com/rickomax)
5+
Branch not officially supported
6+
47
<p align="center">
58
<img src=".github/screenshots/1.png" height="250">
69
<img src=".github/screenshots/2.png" height="250">

src/config.cpp

+60
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,18 @@ KeyBindings none() {
3030
{"r_right", ""},
3131
{"r_down", ""},
3232
{"r_left", ""},
33+
{"freecam_up", ""},
34+
{"freecam_down", ""},
35+
{"freecam_left", ""},
36+
{"freecam_right", ""},
37+
{"freecam_forward", ""},
38+
{"freecam_backward", ""},
39+
{"freecam_look_up", ""},
40+
{"freecam_look_down", ""},
41+
{"freecam_look_left", ""},
42+
{"freecam_look_right", ""},
43+
{"freecam_look_forward", ""},
44+
{"freecam_look_backward", ""}
3345
};
3446
}
3547

@@ -60,6 +72,18 @@ KeyBindings keyboard_wadx() {
6072
{"r_right", ""},
6173
{"r_down", ""},
6274
{"r_left", ""},
75+
{"freecam_up", ""},
76+
{"freecam_down", ""},
77+
{"freecam_left", ""},
78+
{"freecam_right", ""},
79+
{"freecam_forward", ""},
80+
{"freecam_backward", ""},
81+
{"freecam_look_up", ""},
82+
{"freecam_look_down", ""},
83+
{"freecam_look_left", ""},
84+
{"freecam_look_right", ""},
85+
{"freecam_look_forward", ""},
86+
{"freecam_look_backward", ""}
6387
};
6488
}
6589
KeyBindings keyboard_numpad() {
@@ -89,6 +113,18 @@ KeyBindings keyboard_numpad() {
89113
{"r_right", ""},
90114
{"r_down", ""},
91115
{"r_left", ""},
116+
{"freecam_up", ""},
117+
{"freecam_down", ""},
118+
{"freecam_left", ""},
119+
{"freecam_right", ""},
120+
{"freecam_forward", ""},
121+
{"freecam_backward", ""},
122+
{"freecam_look_up", ""},
123+
{"freecam_look_down", ""},
124+
{"freecam_look_left", ""},
125+
{"freecam_look_right", ""},
126+
{"freecam_look_forward", ""},
127+
{"freecam_look_backward", ""}
92128
};
93129
}
94130

@@ -122,6 +158,18 @@ KeyBindings controller(int n) {
122158
{"r_right", C("+rightx")},
123159
{"r_down", C("+righty")},
124160
{"r_left", C("-rightx")},
161+
{"freecam_up", ""},
162+
{"freecam_down", ""},
163+
{"freecam_left", ""},
164+
{"freecam_right", ""},
165+
{"freecam_forward", ""},
166+
{"freecam_backward", ""},
167+
{"freecam_look_up", ""},
168+
{"freecam_look_down", ""},
169+
{"freecam_look_left", ""},
170+
{"freecam_look_right", ""},
171+
{"freecam_look_forward", ""},
172+
{"freecam_look_backward", ""}
125173
};
126174
}
127175

@@ -152,6 +200,18 @@ KeyBindings mouse() {
152200
{"r_right", ""},
153201
{"r_down", ""},
154202
{"r_left", ""},
203+
{"freecam_up", ""},
204+
{"freecam_down", ""},
205+
{"freecam_left", ""},
206+
{"freecam_right", ""},
207+
{"freecam_forward", ""},
208+
{"freecam_backward", ""},
209+
{"freecam_look_up", ""},
210+
{"freecam_look_down", ""},
211+
{"freecam_look_left", ""},
212+
{"freecam_look_right", ""},
213+
{"freecam_look_forward", ""},
214+
{"freecam_look_backward", ""}
155215
};
156216
}
157217
// clang-format on

src/cpu/gte/gte.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ class GTE {
149149
void dpcs(bool useRGB0 = false);
150150
void dcpl();
151151
void intpl();
152-
void rtps(int n = 0, bool setMAC0 = true);
152+
void rtps(int n = 0, bool setMAC0 = true, bool fromRTPT = false);
153153
void rtpt();
154154
void avsz3();
155155
void avsz4();

src/cpu/gte/math.cpp

+210
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,215 @@
1+
#include <cmath>
12
#include "math.h"
23

4+
#define ONE 4096
5+
#define qN 10
6+
#define qA 12
7+
#define B 19900
8+
#define C 3516
9+
310
namespace gte {
411
Vector<int16_t> toVector(int16_t ir[4]) { return Vector<int16_t>(ir[1], ir[2], ir[3]); }
12+
13+
int isin(int x) {
14+
int c, x2, y;
15+
16+
c = x << (30 - qN); // Semi-circle info into carry.
17+
x -= 1 << qN; // sine -> cosine calc
18+
19+
x = x << (31 - qN); // Mask with PI
20+
x = x >> (31 - qN); // Note: SIGNED shift! (to qN)
21+
22+
x = x * x >> (2 * qN - 14); // x=x^2 To Q14
23+
24+
y = B - (x * C >> 14); // B - x^2*C
25+
y = (1 << qA) - (x * y >> 16); // A - x^2*(B-x^2*C)
26+
27+
return c >= 0 ? y : -y;
28+
}
29+
30+
int icos(int x) { return isin(x + 1024); }
31+
32+
gte::Matrix getIdentity() {
33+
gte::Matrix result;
34+
result[0][0] = ONE;
35+
result[0][1] = 0;
36+
result[0][2] = 0;
37+
result[1][0] = 0;
38+
result[1][1] = ONE;
39+
result[1][2] = 0;
40+
result[2][0] = 0;
41+
result[2][1] = 0;
42+
result[2][2] = ONE;
43+
return result;
44+
}
45+
46+
gte::Matrix mulMatrix(gte::Matrix &matrixA, gte::Matrix &matrixB) {
47+
gte::Matrix result;
48+
for (int i = 0; i < 3; i++) {
49+
for (int j = 0; j < 3; j++) {
50+
result[i][j] = 0;
51+
}
52+
}
53+
for (int i = 0; i < 3; i++) {
54+
for (int j = 0; j < 3; j++) {
55+
for (int k = 0; k < 3; k++) {
56+
result[i][j] += ((matrixB[k][j] * matrixA[i][k]) >> 12);
57+
}
58+
}
59+
}
60+
return result;
61+
}
62+
63+
gte::Matrix invMatrix(gte::Matrix &matrix) {
64+
gte::Matrix result;
65+
int16_t determinant = 0;
66+
for (int i = 0; i < 3; i++) {
67+
determinant
68+
= determinant
69+
+ (matrix[0][i] * (matrix[1][(i + 1) % 3] * matrix[2][(i + 2) % 3] - matrix[1][(i + 2) % 3] * matrix[2][(i + 1) % 3]));
70+
}
71+
if (determinant == 0) {
72+
return matrix;
73+
}
74+
for (int i = 0; i < 3; i++) {
75+
for (int j = 0; j < 3; j++) {
76+
result[i][j] = ((matrix[(j + 1) % 3][(i + 1) % 3] * matrix[(j + 2) % 3][(i + 2) % 3])
77+
- (matrix[(j + 1) % 3][(i + 2) % 3] * matrix[(j + 2) % 3][(i + 1) % 3]))
78+
/ determinant;
79+
}
80+
}
81+
return result;
82+
}
83+
84+
gte::Matrix rotMatrix(gte::Vector<int16_t> angles) {
85+
gte::Matrix result;
86+
87+
int16_t s[3], c[3];
88+
gte::Matrix temp[3];
89+
90+
s[0] = isin(angles.x);
91+
s[1] = isin(angles.y);
92+
s[2] = isin(angles.z);
93+
c[0] = icos(angles.x);
94+
c[1] = icos(angles.y);
95+
c[2] = icos(angles.z);
96+
97+
// mX
98+
result[0][0] = ONE;
99+
result[0][1] = 0;
100+
result[0][2] = 0;
101+
result[1][0] = 0;
102+
result[1][1] = c[0];
103+
result[1][2] = -s[0];
104+
result[2][0] = 0;
105+
result[2][1] = s[0];
106+
result[2][2] = c[0];
107+
// mY
108+
temp[0][0][0] = c[1];
109+
temp[0][0][1] = 0;
110+
temp[0][0][2] = s[1];
111+
temp[0][1][0] = 0;
112+
temp[0][1][1] = ONE;
113+
temp[0][1][2] = 0;
114+
temp[0][2][0] = -s[1];
115+
temp[0][2][1] = 0;
116+
temp[0][2][2] = c[1];
117+
// mZ
118+
temp[1][0][0] = c[2];
119+
temp[1][0][1] = -s[2];
120+
temp[1][0][2] = 0;
121+
temp[1][1][0] = s[2];
122+
temp[1][1][1] = c[2];
123+
temp[1][1][2] = 0;
124+
temp[1][2][0] = 0;
125+
temp[1][2][1] = 0;
126+
temp[1][2][2] = ONE;
127+
128+
temp[2] = mulMatrix(result, temp[0]);
129+
result = mulMatrix(temp[2], temp[1]);
130+
131+
return result;
132+
}
133+
134+
gte::Matrix rotMatrixX(int16_t angle) {
135+
gte::Matrix result;
136+
int s = isin(angle);
137+
int c = icos(angle);
138+
result[0][0] = ONE;
139+
result[0][1] = 0;
140+
result[0][2] = 0;
141+
result[1][0] = 0;
142+
result[1][1] = c;
143+
result[1][2] = -s;
144+
result[2][0] = 0;
145+
result[2][1] = s;
146+
result[2][2] = c;
147+
return result;
148+
}
149+
150+
gte::Matrix rotMatrixY(int16_t angle) {
151+
gte::Matrix result;
152+
int s = isin(angle);
153+
int c = icos(angle);
154+
result[0][0] = c;
155+
result[0][1] = 0;
156+
result[0][2] = s;
157+
result[1][0] = 0;
158+
result[1][1] = ONE;
159+
result[1][2] = 0;
160+
result[2][0] = -s;
161+
result[2][1] = 0;
162+
result[2][2] = c;
163+
return result;
164+
}
165+
166+
gte::Matrix rotMatrixZ(int16_t angle) {
167+
gte::Matrix result;
168+
int s = isin(angle);
169+
int c = icos(angle);
170+
result[0][0] = c;
171+
result[0][1] = -s;
172+
result[0][2] = 0;
173+
result[1][0] = s;
174+
result[1][1] = c;
175+
result[1][2] = 0;
176+
result[2][0] = 0;
177+
result[2][1] = 0;
178+
result[2][2] = ONE;
179+
return result;
180+
}
181+
182+
gte::Vector<int32_t> applyMatrix(gte::Matrix &matrix, gte::Vector<int32_t> &vector) {
183+
gte::Vector<int32_t> result;
184+
result.x = (((matrix[0][0] * vector.x) + (matrix[0][1] * vector.y) + (matrix[0][2] * vector.z)) >> 12);
185+
result.y = (((matrix[1][0] * vector.x) + (matrix[1][1] * vector.y) + (matrix[1][2] * vector.z)) >> 12);
186+
result.z = (((matrix[2][0] * vector.x) + (matrix[2][1] * vector.y) + (matrix[2][2] * vector.z)) >> 12);
187+
return result;
188+
}
189+
190+
gte::Vector<int32_t> transVector(gte::Vector<int32_t> &vector, int32_t x, int32_t y, int32_t z) {
191+
gte::Vector<int32_t> result;
192+
result.x = vector.x + x;
193+
result.y = vector.y + y;
194+
result.z = vector.z + z;
195+
return result;
196+
}
197+
198+
gte::Vector<int32_t> normalizeVector(gte::Vector<int32_t> &vector) {
199+
gte::Vector<int32_t> result;
200+
float squareRoot = std::sqrt((vector.x * vector.x) + (vector.y * vector.y) + (vector.z * vector.z));
201+
result.x = vector.x / squareRoot;
202+
result.y = vector.y / squareRoot;
203+
result.z = vector.z / squareRoot;
204+
return result;
205+
}
206+
207+
gte::Vector<int32_t> crossVector(gte::Vector<int32_t> &vectorA, gte::Vector<int32_t> &vectorB) {
208+
gte::Vector<int32_t> result;
209+
result.x = vectorA.y * vectorB.z - vectorA.z * vectorB.y;
210+
result.y = vectorA.z * vectorB.x - vectorA.x * vectorB.z;
211+
result.z = vectorA.x * vectorB.y - vectorA.y * vectorB.x;
212+
return result;
213+
}
214+
5215
}; // namespace gte

src/cpu/gte/math.h

+28-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ struct Vector {
2323
Vector(X x, Y y, Z z) : x(x), y(y), z(z) {}
2424

2525
template <class Archive>
26-
void serialize(Archive& ar) {
26+
void serialize(Archive &ar) {
2727
ar(x, y, z);
2828
}
2929
};
@@ -35,4 +35,31 @@ struct Color {
3535
int32_t g = 0;
3636
int32_t b = 0;
3737
};
38+
39+
int isin(int x);
40+
41+
int icos(int x);
42+
43+
gte::Matrix getIdentity();
44+
45+
gte::Matrix mulMatrix(gte::Matrix &matrixA, gte::Matrix &matrixB);
46+
47+
gte::Matrix invMatrix(gte::Matrix &matrix);
48+
49+
gte::Matrix rotMatrix(gte::Vector<int16_t> angles);
50+
51+
gte::Matrix rotMatrixX(int16_t angle);
52+
53+
gte::Matrix rotMatrixY(int16_t angle);
54+
55+
gte::Matrix rotMatrixZ(int16_t angle);
56+
57+
gte::Vector<int32_t> applyMatrix(gte::Matrix &matrix, gte::Vector<int32_t> &vector);
58+
59+
gte::Vector<int32_t> transVector(gte::Vector<int32_t> &vector, int32_t x, int32_t y, int32_t z);
60+
61+
gte::Vector<int32_t> normalizeVector(gte::Vector<int32_t> &vector);
62+
63+
gte::Vector<int32_t> crossVector(gte::Vector<int32_t> &vectorA, gte::Vector<int32_t> &vectorB);
64+
3865
}; // namespace gte

0 commit comments

Comments
 (0)