Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.82 KB | None | 0 0
  1.  
  2. bool drawing::worldToScreen(vector_3d wrl, int *x, int *y)
  3. {
  4.   if ( !x || !y )
  5.   {
  6.     return false;
  7.   }
  8.  
  9.   *x = 0;
  10.   *y = 0;
  11.  
  12.   /**********************************
  13.   Credits to OGC for world2screen
  14.   **********************************/
  15.   float xy[2] =
  16.   {
  17.     (m_pExport->m_iWidth  >> 1),
  18.     (m_pExport->m_iHeight >> 1)
  19.   };
  20.  
  21.   if( actual_fov == 0.0  )
  22.   {
  23.     actual_fov = 90;
  24.   }
  25.  
  26.   if( !actual_vieworg._is_valid()
  27.     || actual_vieworg._is_zero() )
  28.   {
  29.     return false;
  30.   }
  31.  
  32.   if( !actual_viewang._is_valid()
  33.     || actual_viewang._is_zero() )
  34.   {
  35.     return false;
  36.   }
  37.  
  38.   vector_3d aim,newaim,view,tmp;
  39.  
  40.   aim._vector_copy (actual_vieworg - wrl);
  41.   view._make_vector(actual_viewang);
  42.    
  43.   if ( view._vector_anglesf( aim ) > (actual_fov / 1.8) )
  44.   {
  45.     return false;
  46.   }    
  47.  
  48.   aim._vector_rotate_z(-actual_viewang.y,newaim);
  49.   newaim._vector_rotate_y(-actual_viewang.x,tmp);
  50.   tmp._vector_rotate_x(-actual_viewang.z,newaim);
  51.  
  52.   if ( newaim.x <= 0 )
  53.   {
  54.     return false;
  55.   }
  56.  
  57.   float num = ((xy[0] / newaim.x) * (120.0 / actual_fov - 1.0 / 3.0));
  58.  
  59.   *x = xy[0] - num * newaim.y;
  60.   *y = xy[1] - num * newaim.z;
  61.  
  62. #define _BOUND_VALUE(var,min,max)                 \
  63.   if((var)>=(max)){return false/*(var)=(max)*/;}; \
  64.   if((var)<=(min)){return false/*(var)=(min)*/;}
  65.  
  66.   _BOUND_VALUE(*x,0,xy[0]*2);
  67.   _BOUND_VALUE(*y,0,xy[1]*2);
  68.  
  69.   return true;
  70.  
  71. }
  72.  
  73. bool drawing::worldToScreen(vector_3d worldCoord, int *xy)
  74. {
  75.   if ( xy )
  76.   {
  77.     if ( worldToScreen(worldCoord,&xy[0],&xy[1]) )
  78.     {
  79.       return true;
  80.     }
  81.   }
  82.   return false;
  83. }
  84.  
  85. bool drawing::worldToScreen(vector_3d worldCoord, vector_3d screenCoord)
  86. {
  87.   int xy[2] = {0,0};
  88.   if ( worldToScreen(worldCoord, &xy[0], &xy[1]) )
  89.   {
  90.     screenCoord._init(xy[0],xy[1],0);
  91.     return true;
  92.   }
  93.   return false;
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement