Skip to content

Commit

Permalink
Screenshot Tool and Free Camera Tool by @rickomax #85
Browse files Browse the repository at this point in the history
Rebased features onto latest develop codebase
  • Loading branch information
JaCzekanski committed Sep 13, 2020
1 parent ba012fe commit 0d029fc
Show file tree
Hide file tree
Showing 30 changed files with 1,756 additions and 27 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ add_library(core STATIC
src/device/controller/peripherals/abstract_device.cpp
src/device/controller/peripherals/analog_controller.cpp
src/device/controller/peripherals/digital_controller.cpp
src/device/controller/peripherals/freecam_controller.cpp
src/device/controller/peripherals/memory_card.cpp
src/device/controller/peripherals/mouse.cpp
src/device/controller/peripherals/none.cpp
Expand All @@ -223,6 +224,7 @@ add_library(core STATIC
src/device/gpu/render/render_line.cpp
src/device/gpu/render/render_rectangle.cpp
src/device/gpu/render/render_triangle.cpp
src/device/gpu/render/render_debug.cpp
src/device/interrupt.cpp
src/device/mdec/algorithm.cpp
src/device/mdec/mdec.cpp
Expand Down Expand Up @@ -297,6 +299,7 @@ set(SOURCES
src/platform/windows/gui/debug/spu.cpp
src/platform/windows/gui/debug/timers.cpp
src/platform/windows/gui/file/open.cpp
src/platform/windows/gui/screenshot/select_directory.cpp
src/platform/windows/gui/gui.cpp
src/platform/windows/gui/help/about.cpp
src/platform/windows/gui/helper/file_dialog.cpp
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Avocado
A Modern Playstation 1 emulator.

## 3D Screenshot and free camera mod by [Rickomax](https://github.com/rickomax)
Branch not officially supported

<p align="center">
<img src=".github/screenshots/1.png" height="250">
<img src=".github/screenshots/2.png" height="250">
Expand Down
60 changes: 60 additions & 0 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ KeyBindings none() {
{"r_right", ""},
{"r_down", ""},
{"r_left", ""},
{"freecam_up", ""},
{"freecam_down", ""},
{"freecam_left", ""},
{"freecam_right", ""},
{"freecam_forward", ""},
{"freecam_backward", ""},
{"freecam_look_up", ""},
{"freecam_look_down", ""},
{"freecam_look_left", ""},
{"freecam_look_right", ""},
{"freecam_look_forward", ""},
{"freecam_look_backward", ""}
};
}

Expand Down Expand Up @@ -60,6 +72,18 @@ KeyBindings keyboard_wadx() {
{"r_right", ""},
{"r_down", ""},
{"r_left", ""},
{"freecam_up", ""},
{"freecam_down", ""},
{"freecam_left", ""},
{"freecam_right", ""},
{"freecam_forward", ""},
{"freecam_backward", ""},
{"freecam_look_up", ""},
{"freecam_look_down", ""},
{"freecam_look_left", ""},
{"freecam_look_right", ""},
{"freecam_look_forward", ""},
{"freecam_look_backward", ""}
};
}
KeyBindings keyboard_numpad() {
Expand Down Expand Up @@ -89,6 +113,18 @@ KeyBindings keyboard_numpad() {
{"r_right", ""},
{"r_down", ""},
{"r_left", ""},
{"freecam_up", ""},
{"freecam_down", ""},
{"freecam_left", ""},
{"freecam_right", ""},
{"freecam_forward", ""},
{"freecam_backward", ""},
{"freecam_look_up", ""},
{"freecam_look_down", ""},
{"freecam_look_left", ""},
{"freecam_look_right", ""},
{"freecam_look_forward", ""},
{"freecam_look_backward", ""}
};
}

Expand Down Expand Up @@ -122,6 +158,18 @@ KeyBindings controller(int n) {
{"r_right", C("+rightx")},
{"r_down", C("+righty")},
{"r_left", C("-rightx")},
{"freecam_up", ""},
{"freecam_down", ""},
{"freecam_left", ""},
{"freecam_right", ""},
{"freecam_forward", ""},
{"freecam_backward", ""},
{"freecam_look_up", ""},
{"freecam_look_down", ""},
{"freecam_look_left", ""},
{"freecam_look_right", ""},
{"freecam_look_forward", ""},
{"freecam_look_backward", ""}
};
}

Expand Down Expand Up @@ -152,6 +200,18 @@ KeyBindings mouse() {
{"r_right", ""},
{"r_down", ""},
{"r_left", ""},
{"freecam_up", ""},
{"freecam_down", ""},
{"freecam_left", ""},
{"freecam_right", ""},
{"freecam_forward", ""},
{"freecam_backward", ""},
{"freecam_look_up", ""},
{"freecam_look_down", ""},
{"freecam_look_left", ""},
{"freecam_look_right", ""},
{"freecam_look_forward", ""},
{"freecam_look_backward", ""}
};
}
// clang-format on
Expand Down
2 changes: 1 addition & 1 deletion src/cpu/gte/gte.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class GTE {
void dpcs(bool useRGB0 = false);
void dcpl();
void intpl();
void rtps(int n = 0, bool setMAC0 = true);
void rtps(int n = 0, bool setMAC0 = true, bool fromRTPT = false);
void rtpt();
void avsz3();
void avsz4();
Expand Down
210 changes: 210 additions & 0 deletions src/cpu/gte/math.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,215 @@
#include <cmath>
#include "math.h"

#define ONE 4096
#define qN 10
#define qA 12
#define B 19900
#define C 3516

namespace gte {
Vector<int16_t> toVector(int16_t ir[4]) { return Vector<int16_t>(ir[1], ir[2], ir[3]); }

int isin(int x) {
int c, x2, y;

c = x << (30 - qN); // Semi-circle info into carry.
x -= 1 << qN; // sine -> cosine calc

x = x << (31 - qN); // Mask with PI
x = x >> (31 - qN); // Note: SIGNED shift! (to qN)

x = x * x >> (2 * qN - 14); // x=x^2 To Q14

y = B - (x * C >> 14); // B - x^2*C
y = (1 << qA) - (x * y >> 16); // A - x^2*(B-x^2*C)

return c >= 0 ? y : -y;
}

int icos(int x) { return isin(x + 1024); }

gte::Matrix getIdentity() {
gte::Matrix result;
result[0][0] = ONE;
result[0][1] = 0;
result[0][2] = 0;
result[1][0] = 0;
result[1][1] = ONE;
result[1][2] = 0;
result[2][0] = 0;
result[2][1] = 0;
result[2][2] = ONE;
return result;
}

gte::Matrix mulMatrix(gte::Matrix &matrixA, gte::Matrix &matrixB) {
gte::Matrix result;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
result[i][j] = 0;
}
}
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
for (int k = 0; k < 3; k++) {
result[i][j] += ((matrixB[k][j] * matrixA[i][k]) >> 12);
}
}
}
return result;
}

gte::Matrix invMatrix(gte::Matrix &matrix) {
gte::Matrix result;
int16_t determinant = 0;
for (int i = 0; i < 3; i++) {
determinant
= determinant
+ (matrix[0][i] * (matrix[1][(i + 1) % 3] * matrix[2][(i + 2) % 3] - matrix[1][(i + 2) % 3] * matrix[2][(i + 1) % 3]));
}
if (determinant == 0) {
return matrix;
}
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
result[i][j] = ((matrix[(j + 1) % 3][(i + 1) % 3] * matrix[(j + 2) % 3][(i + 2) % 3])
- (matrix[(j + 1) % 3][(i + 2) % 3] * matrix[(j + 2) % 3][(i + 1) % 3]))
/ determinant;
}
}
return result;
}

gte::Matrix rotMatrix(gte::Vector<int16_t> angles) {
gte::Matrix result;

int16_t s[3], c[3];
gte::Matrix temp[3];

s[0] = isin(angles.x);
s[1] = isin(angles.y);
s[2] = isin(angles.z);
c[0] = icos(angles.x);
c[1] = icos(angles.y);
c[2] = icos(angles.z);

// mX
result[0][0] = ONE;
result[0][1] = 0;
result[0][2] = 0;
result[1][0] = 0;
result[1][1] = c[0];
result[1][2] = -s[0];
result[2][0] = 0;
result[2][1] = s[0];
result[2][2] = c[0];
// mY
temp[0][0][0] = c[1];
temp[0][0][1] = 0;
temp[0][0][2] = s[1];
temp[0][1][0] = 0;
temp[0][1][1] = ONE;
temp[0][1][2] = 0;
temp[0][2][0] = -s[1];
temp[0][2][1] = 0;
temp[0][2][2] = c[1];
// mZ
temp[1][0][0] = c[2];
temp[1][0][1] = -s[2];
temp[1][0][2] = 0;
temp[1][1][0] = s[2];
temp[1][1][1] = c[2];
temp[1][1][2] = 0;
temp[1][2][0] = 0;
temp[1][2][1] = 0;
temp[1][2][2] = ONE;

temp[2] = mulMatrix(result, temp[0]);
result = mulMatrix(temp[2], temp[1]);

return result;
}

gte::Matrix rotMatrixX(int16_t angle) {
gte::Matrix result;
int s = isin(angle);
int c = icos(angle);
result[0][0] = ONE;
result[0][1] = 0;
result[0][2] = 0;
result[1][0] = 0;
result[1][1] = c;
result[1][2] = -s;
result[2][0] = 0;
result[2][1] = s;
result[2][2] = c;
return result;
}

gte::Matrix rotMatrixY(int16_t angle) {
gte::Matrix result;
int s = isin(angle);
int c = icos(angle);
result[0][0] = c;
result[0][1] = 0;
result[0][2] = s;
result[1][0] = 0;
result[1][1] = ONE;
result[1][2] = 0;
result[2][0] = -s;
result[2][1] = 0;
result[2][2] = c;
return result;
}

gte::Matrix rotMatrixZ(int16_t angle) {
gte::Matrix result;
int s = isin(angle);
int c = icos(angle);
result[0][0] = c;
result[0][1] = -s;
result[0][2] = 0;
result[1][0] = s;
result[1][1] = c;
result[1][2] = 0;
result[2][0] = 0;
result[2][1] = 0;
result[2][2] = ONE;
return result;
}

gte::Vector<int32_t> applyMatrix(gte::Matrix &matrix, gte::Vector<int32_t> &vector) {
gte::Vector<int32_t> result;
result.x = (((matrix[0][0] * vector.x) + (matrix[0][1] * vector.y) + (matrix[0][2] * vector.z)) >> 12);
result.y = (((matrix[1][0] * vector.x) + (matrix[1][1] * vector.y) + (matrix[1][2] * vector.z)) >> 12);
result.z = (((matrix[2][0] * vector.x) + (matrix[2][1] * vector.y) + (matrix[2][2] * vector.z)) >> 12);
return result;
}

gte::Vector<int32_t> transVector(gte::Vector<int32_t> &vector, int32_t x, int32_t y, int32_t z) {
gte::Vector<int32_t> result;
result.x = vector.x + x;
result.y = vector.y + y;
result.z = vector.z + z;
return result;
}

gte::Vector<int32_t> normalizeVector(gte::Vector<int32_t> &vector) {
gte::Vector<int32_t> result;
float squareRoot = std::sqrt((vector.x * vector.x) + (vector.y * vector.y) + (vector.z * vector.z));
result.x = vector.x / squareRoot;
result.y = vector.y / squareRoot;
result.z = vector.z / squareRoot;
return result;
}

gte::Vector<int32_t> crossVector(gte::Vector<int32_t> &vectorA, gte::Vector<int32_t> &vectorB) {
gte::Vector<int32_t> result;
result.x = vectorA.y * vectorB.z - vectorA.z * vectorB.y;
result.y = vectorA.z * vectorB.x - vectorA.x * vectorB.z;
result.z = vectorA.x * vectorB.y - vectorA.y * vectorB.x;
return result;
}

}; // namespace gte
29 changes: 28 additions & 1 deletion src/cpu/gte/math.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct Vector {
Vector(X x, Y y, Z z) : x(x), y(y), z(z) {}

template <class Archive>
void serialize(Archive& ar) {
void serialize(Archive &ar) {
ar(x, y, z);
}
};
Expand All @@ -35,4 +35,31 @@ struct Color {
int32_t g = 0;
int32_t b = 0;
};

int isin(int x);

int icos(int x);

gte::Matrix getIdentity();

gte::Matrix mulMatrix(gte::Matrix &matrixA, gte::Matrix &matrixB);

gte::Matrix invMatrix(gte::Matrix &matrix);

gte::Matrix rotMatrix(gte::Vector<int16_t> angles);

gte::Matrix rotMatrixX(int16_t angle);

gte::Matrix rotMatrixY(int16_t angle);

gte::Matrix rotMatrixZ(int16_t angle);

gte::Vector<int32_t> applyMatrix(gte::Matrix &matrix, gte::Vector<int32_t> &vector);

gte::Vector<int32_t> transVector(gte::Vector<int32_t> &vector, int32_t x, int32_t y, int32_t z);

gte::Vector<int32_t> normalizeVector(gte::Vector<int32_t> &vector);

gte::Vector<int32_t> crossVector(gte::Vector<int32_t> &vectorA, gte::Vector<int32_t> &vectorB);

}; // namespace gte
Loading

0 comments on commit 0d029fc

Please sign in to comment.