Jump to content

[SOLVED] Player::getScreenPosition not working correctly


photo

Recommended Posts

Posted

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.

Posted

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:

Posted (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 by tolga
Posted

Oh forgot to mention center need to return in the range [0..1].

 

Posted

Ok I just confirmed that, the problem is on our side. It's a problem with the camera projection. Thanks for the help anyway.

Posted

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;

 

  • Like 1

How to submit a good bug report
---
FTP server for test scenes and user uploads:

  • silent changed the title to [SOLVED] Player::getScreenPosition not working correctly
Posted

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?

Posted

You can use
 

if (dot(mat4.getColumn3(1), vec3_up) > 0.9f) { // looking upwards! }

 

×
×
  • Create New...