Skip to content

Commit

Permalink
temp
Browse files Browse the repository at this point in the history
  • Loading branch information
horror-proton committed Aug 19, 2024
1 parent b7ae83e commit d203b40
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions 3rdparty/include/Arknights-Tile-Pos/TileCalc2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,21 @@ inline vec3d camera_euler_angles_yxz(const Level& /*level*/, bool side = false)
}

inline matrix4x4 camera_matrix_from_trans(
const vec3d& pos,
const vec3d& euler,
[[maybe_unused]] const vec3d& pos,
[[maybe_unused]] const vec3d& euler,
double ratio,
double fov_2_y = 20 * degree,
double far = 1000,
double near = 0.3)
{
/*
const double cos_y = std::cos(euler[0]);
const double sin_y = std::sin(euler[0]);
const double cos_x = std::cos(euler[1]);
const double sin_x = std::sin(euler[1]);
*/
const double tan_f = std::tan(fov_2_y);
/*
const matrix4x4 translate = {
1, 0, 0, -pos[0], //
Expand All @@ -66,6 +69,7 @@ inline matrix4x4 camera_matrix_from_trans(
0, -sin_x, -cos_x, 0, //
0, 0, 0, 1,
};
*/
const double elem1 = -(far + near) / (far - near); // unable to inline, MSVC bug?
const double elem2 = -(far * near * 2) / (far - near);
const matrix4x4 proj = matrix4x4 {
Expand All @@ -77,16 +81,19 @@ inline matrix4x4 camera_matrix_from_trans(
// clang-format on
};

/*
return proj * matrixX * matrixY * translate;
*/
return proj;
}

inline cv::Point world_to_screen(const Level& level, const vec3d& world_pos, bool side, const vec3d& offset = {})
{
static constexpr double width = 1280;
static constexpr double height = 720;
static constexpr int width = 1280;
static constexpr int height = 720;
const vec3d pos_cam = camera_pos(level, side, width, height) + offset;
const vec3d euler = camera_euler_angles_yxz(level, side);
const matrix4x4 matrix = camera_matrix_from_trans(pos_cam, euler, height / width);
const matrix4x4 matrix = camera_matrix_from_trans(pos_cam, euler, static_cast<double>(height) / width);
auto result = matrix * cv::Point3d(world_pos);
result = result / result(3);
result = (result + cv::Vec4d::ones()) / 2.;
Expand Down

0 comments on commit d203b40

Please sign in to comment.