Jump to content

[SOLVED] Hi Team, i am getting a mismatch on mouse click and GUI selection on viewport.Visualizer::renderFrustum is not working as expected with win10/11 and with unigine 2.18.0.1


photo

Recommended Posts

Posted (edited)

Hi Team, i am getting a mismatch on mouse click and GUI selection on viewport.Visualizer::renderFrustum is not working as expected with win10/11 and with unigine 2.18.0.1

 

i have added a code on Input::isMouseButtonPressed(Input::MOUSE_BUTTON_LEFT)) and Input::isMouseButtonUp(Input::MOUSE_BUTTON_LEFT)

the selection box with white border is not aligned with the mouse drag.

pls find update method in the attached file.

see the attached source file and image file.

 

thanks.try.cpp

 

mouse_misalignement.PNG

Edited by Sakshi.P
Posted

Hello.

The issue is that the mouse position is in global coordinates, but the getProjectionFromMainWindow method expects coordinates in the window’s client area. Also, renderLine2D and renderRectangle require normalized coordinates.

You can do it like this:

Math::ivec2 client_position = main_window->getClientPosition();
Math::ivec2 client_size = main_window->getClientRenderSize();

Math::vec2 p0(m_mouse_pos_start_selection - client_position);
Math::vec2 p1(currentPos - client_position);

Math::mat4 frustum_projection = player->getProjectionFromMainWindow(p0.x, p0.y, p1.x, p1.y);

p0.x /= client_size.x;
p1.x /= client_size.x;

p0.y /= client_size.y;
p1.y /= client_size.y;

Visualizer::renderRectangle(Math::vec4(p0.x, 1.0f - p0.y, p1.x, 1.0f - p1.y), Math::vec4_white);
// or
Visualizer::renderLine2D(Math::vec2(p0.x, p0.y), Math::vec2(p0.x, p1.y), Math::vec4_white);
Visualizer::renderLine2D(Math::vec2(p0.x, p1.y), Math::vec2(p1.x, p1.y), Math::vec4_white);
Visualizer::renderLine2D(Math::vec2(p1.x, p1.y), Math::vec2(p1.x, p0.y), Math::vec4_white);
Visualizer::renderLine2D(Math::vec2(p1.x, p0.y), Math::vec2(p0.x, p0.y), Math::vec4_white);

Visualizer::renderFrustum(frustum_projection, player->getWorldTransform(), Math::vec4_green);

 

  • Like 1
  • silent changed the title to [SOLVED] Hi Team, i am getting a mismatch on mouse click and GUI selection on viewport.Visualizer::renderFrustum is not working as expected with win10/11 and with unigine 2.18.0.1
×
×
  • Create New...