Jump to content

[SOLVED] Unigine::getScreenPosition() not working as expected


photo

Recommended Posts

Hi all,

I'm usnig this function to compute widget position from node(WorldExpression) absolute world position, at each update I call this function to update Gui widget position. This node is under player persecutor and its target.

For some angles (when persecutor is under target) function returns 0.

 

I've modified the source code just to log values as follows:

int getScreenPosition(Vec3 point,int &x,int &y) {
 Player player = getPlayer();
 if(player == NULL) return 0;
 int width = engine.app.getWidth();
 int height = engine.app.getHeight();
 mat4 projection = player.getProjection();
 Mat4 modelview = player.getModelview();
 projection.m00 *= float(height) / width;
 vec4 p = projection * vec4(modelview * Vec4(point,1.0f));
 log.message("--\n\tpoint:%s\n\tprojection:%s\n\tmodelview:%s\n\tp:%s",
  print_vec3(point),
  print_mat4(projection),
  print_mat4(modelview),
  print_vec4(p));
 if(p.w > 0.0f) {
  x = int(width * (0.5f + p.x * 0.5f / p.w));
  y = int(height * (0.5f - p.y * 0.5f / p.w));
  return 1;
 }
 return 0;
}

 

and this is what logs shows:

14:08:07 --
14:08:07 	point:[0.0000,0.0000,-107.0000]
14:08:07 	projection:[0.9743,0.0000,0.0000,0.0000] [0.0000,1.7321,0.0000,0.0000] [0.0000,0.0000,-1.0000,-0.2000] [0.0000,0.0000,-1.0000,0.0000]
14:08:07 	modelview:[0.4391,-0.8984,-0.0000,-0.0000] [-0.2548,-0.1246,0.9589,-2.8768] [-0.8615,-0.4211,-0.2836,-21.1491] [0.0000,0.0000,0.0000,1.0000]
14:08:07 	p:[-0.0000,-182.7014,-9.3995,-9.1993]
14:08:07 --
14:08:07 	point:[0.0000,0.0000,-107.0000]
14:08:07 	projection:[0.9743,0.0000,0.0000,0.0000] [0.0000,1.7321,0.0000,0.0000] [0.0000,0.0000,-1.0000,-0.2000] [0.0000,0.0000,-1.0000,0.0000]
14:08:07 	modelview:[0.4391,-0.8984,-0.0000,-0.0000] [-0.2548,-0.1246,0.9589,-2.8768] [-0.8615,-0.4211,-0.2836,-21.1491] [0.0000,0.0000,0.0000,1.0000]
14:08:07 	p:[-0.0000,-182.7014,-9.3995,-9.1993]
14:08:07 --
14:08:07 	point:[0.0000,0.0000,-107.0000]
14:08:07 	projection:[0.9743,0.0000,0.0000,0.0000] [0.0000,1.7321,0.0000,0.0000] [0.0000,0.0000,-1.0000,-0.2000] [0.0000,0.0000,-1.0000,0.0000]
14:08:07 	modelview:[0.4391,-0.8984,-0.0000,-0.0000] [-0.2548,-0.1246,0.9589,-2.8768] [-0.8615,-0.4211,-0.2836,-21.1491] [0.0000,0.0000,0.0000,1.0000]
14:08:07 	p:[-0.0000,-182.7014,-9.3995,-9.1993]

As p.w < 0, the x and y values are not updated, and functions exits with 0.

 

Any suggestion?

Ivan.

Link to comment
×
×
  • Create New...