mirror of
https://github.com/RPCSX/rpcsx.git
synced 2026-04-20 22:05:12 +00:00
cellGem: calculate distance from sphere to camera
This commit is contained in:
parent
926de68a79
commit
a8b0c0be07
3 changed files with 25 additions and 16 deletions
|
|
@ -408,9 +408,18 @@ void ps_move_tracker<DiagnosticsEnabled>::process_contours(ps_move_info& info, u
|
|||
if (best_index == umax)
|
||||
return;
|
||||
|
||||
// Calculate distance from sphere to camera
|
||||
const f32 sphere_radius_pixels = radii[best_index];
|
||||
constexpr f32 focal_length_mm = 3.5f; // Based on common webcam specs
|
||||
constexpr f32 sensor_width_mm = 3.6f; // Based on common webcam specs
|
||||
const f32 image_width_pixels = static_cast<float>(width);
|
||||
const f32 focal_length_pixels = (focal_length_mm * image_width_pixels) / sensor_width_mm;
|
||||
const f32 distance_mm = (focal_length_pixels * CELL_GEM_SPHERE_RADIUS_MM) / sphere_radius_pixels;
|
||||
|
||||
// Set results
|
||||
info.valid = true;
|
||||
info.distance = 1500.0f;
|
||||
info.radius = radii[best_index];
|
||||
info.distance_mm = distance_mm;
|
||||
info.radius = sphere_radius_pixels;
|
||||
info.x_pos = std::clamp(static_cast<u32>(centers[best_index].x), 0u, width);
|
||||
info.y_pos = std::clamp(static_cast<u32>(centers[best_index].y), 0u, height);
|
||||
|
||||
|
|
|
|||
|
|
@ -8,13 +8,13 @@
|
|||
|
||||
struct ps_move_info
|
||||
{
|
||||
bool valid = false;
|
||||
f32 radius = 0.0f;
|
||||
f32 distance = 0.0f;
|
||||
u32 x_pos = 0;
|
||||
u32 y_pos = 0;
|
||||
u32 x_max = 0;
|
||||
u32 y_max = 0;
|
||||
bool valid = false; // The tracking result
|
||||
f32 radius = 0.0f; // Radius of the sphere in pixels
|
||||
f32 distance_mm = 0.0f; // Distance from sphere to camera in mm
|
||||
u32 x_pos = 0; // X position in pixels
|
||||
u32 y_pos = 0; // Y position in pixels
|
||||
u32 x_max = 0; // Maximum X position in pixels
|
||||
u32 y_max = 0; // Maximum Y position in pixels
|
||||
};
|
||||
|
||||
template <bool DiagnosticsEnabled = false>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue