vec_for_screen(VECTOR*, VIEW*): VECTOR*

The opposite of the vec_to_screen instruction. It converts XY screen coordinates, given through the vector, to a world position of the given view. Because a unique 3D position can not be determined from a XY screen position alone, a screen distance must also be given in the Z coordinate of the vector. This function can be used to place entities into a level on mouse click on the screen.

Parameters:

VECTOR* vector to be converted
VIEW* View pointer to be used for the conversion

Returns:

VECTOR* - screen coordinates converted to world positon.

Modifies:

VECTOR*

Speed:

Fast

Remarks:

Prior engine versions (A7 and earlier) used a more crude algorithm that didn't take into account the angle of the ray through the XY screen position to the screen center axis. This does not matter for coordinates on the screen, as the difference is less than one pixel, but it matters for coordinates that are far off the screen center. In that case, A8 gives more precise results.

Example (lite-C):

void main()
{
  level_load(NULL);
  while(1)
  {
    mouse_mode = 4;  
    VECTOR v;
    v.x = mouse_pos.x;
    v.y = mouse_pos.y;
    v.z = 200;
    vec_for_screen(v,camera);
    if(mouse_left) {
      beep();
      ent_create(SPHERE,v,NULL);
    }
    wait(1);
  }
}

See also:

vec_to_screen► latest version online