tolga Posted June 30, 2022 Share Posted June 30, 2022 Hi, I have a BoundBox to convert into screen rectangle. The Player::getScreenPosition is not yielding correct results. In some cases, it's correct, others not. What is the basis of the conversion, what does (0, 0) mean, top-left or bottom-left? Thanks. Link to comment
silent Posted June 30, 2022 Share Posted June 30, 2022 If getScreenPosition returns 0,0 it would mean that point was projected into the top left corner. It's not quite clear what do you mean by correct results or incorrect results? Could you please show us minimal code so we can see correct / incorrect results? Thanks! How to submit a good bug report --- FTP server for test scenes and user uploads: ftp://files.unigine.com user: upload password: 6xYkd6vLYWjpW6SN Link to comment
tolga Posted June 30, 2022 Author Share Posted June 30, 2022 (edited) Here's a piece of the code: int x0, y0, x1, y1; if (!player->getScreenPosition(x0, y0, bounds.minimum) || !player->getScreenPosition(x1, y1, bounds.maximum)) { return; } float w = Unigine::Math::abs(x1 - x0) / zoomFactor; float h = Unigine::Math::abs(y1 - y0) / zoomFactor; float level = clamp(w > h ? w / App::getWidth() : h / App::getHeight(), 0.0f, 1.0f); Vec2 center; center.x = ((x0 + x1) / 2.0f) / App::getWidth(); center.y = ((y0 + y1) / 2.0f) / App::getHeight(); Basically the center is returning false values most of the time. Edited June 30, 2022 by tolga Link to comment
tolga Posted June 30, 2022 Author Share Posted June 30, 2022 Oh forgot to mention center need to return in the range [0..1]. Link to comment
tolga Posted June 30, 2022 Author Share Posted June 30, 2022 Ok I just confirmed that, the problem is on our side. It's a problem with the camera projection. Thanks for the help anyway. Link to comment
silent Posted June 30, 2022 Share Posted June 30, 2022 Yeah, internals of this method are pretty straightforward: mat4 projection = getAspectCorrectedProjection(aspect); vec4 p = projection * vec4(modelview * Vec4(point, 1.0f)); if (p.w <= 0.0f) return 0; x = 0.5f + p.x * 0.5f / p.w; y = 0.5f - p.y * 0.5f / p.w; return 1; 1 How to submit a good bug report --- FTP server for test scenes and user uploads: ftp://files.unigine.com user: upload password: 6xYkd6vLYWjpW6SN Link to comment
tolga Posted July 1, 2022 Author Share Posted July 1, 2022 It looks like our camera transform is looking downwards and PlayerSpectator is correcting it automatically. Is it possible to get up-vector of a Mat4 or ensure it's looking upwards? Link to comment
tarragrum Posted July 4, 2022 Share Posted July 4, 2022 You can use if (dot(mat4.getColumn3(1), vec3_up) > 0.9f) { // looking upwards! } Link to comment
Recommended Posts