23#include <plugins/openni/utils/conversions.h>
47world2projection(xn::DepthGenerator *depthgen,
48 unsigned int num_points,
49 const XnPoint3D * world,
54 if (width == 0 || height == 0) {
55 xn::DepthMetaData depth_md;
56 depthgen->GetMetaData(depth_md);
57 width = depth_md.XRes();
58 height = depth_md.YRes();
63 if ((st = depthgen->GetFieldOfView(fov)) != XN_STATUS_OK) {
64 throw Exception(
"Failed to get field of view, ignoring. (%s)", xnGetStatusString(st));
67 float world_x_to_z = tan(fov.fHFOV / 2) * 2;
69 float world_y_to_z = tan(fov.fVFOV / 2) * 2;
71 XnFloat coeff_x = width / world_x_to_z;
72 XnFloat coeff_y = height / world_y_to_z;
74 XnUInt32 half_res_x = width / 2;
75 XnUInt32 half_res_y = height / 2;
77 for (
unsigned int i = 0; i < num_points; ++i) {
78 proj[i].X = coeff_x * world[i].X / world[i].Z + half_res_x;
79 proj[i].Y = half_res_y - coeff_y * world[i].Y / world[i].Z;
80 proj[i].Z = world[i].Z;
Fawkes library namespace.