Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool drawing::worldToScreen(vector_3d wrl, int *x, int *y)
- {
- if ( !x || !y )
- {
- return false;
- }
- *x = 0;
- *y = 0;
- /**********************************
- Credits to OGC for world2screen
- **********************************/
- float xy[2] =
- {
- (m_pExport->m_iWidth >> 1),
- (m_pExport->m_iHeight >> 1)
- };
- if( actual_fov == 0.0 )
- {
- actual_fov = 90;
- }
- if( !actual_vieworg._is_valid()
- || actual_vieworg._is_zero() )
- {
- return false;
- }
- if( !actual_viewang._is_valid()
- || actual_viewang._is_zero() )
- {
- return false;
- }
- vector_3d aim,newaim,view,tmp;
- aim._vector_copy (actual_vieworg - wrl);
- view._make_vector(actual_viewang);
- if ( view._vector_anglesf( aim ) > (actual_fov / 1.8) )
- {
- return false;
- }
- aim._vector_rotate_z(-actual_viewang.y,newaim);
- newaim._vector_rotate_y(-actual_viewang.x,tmp);
- tmp._vector_rotate_x(-actual_viewang.z,newaim);
- if ( newaim.x <= 0 )
- {
- return false;
- }
- float num = ((xy[0] / newaim.x) * (120.0 / actual_fov - 1.0 / 3.0));
- *x = xy[0] - num * newaim.y;
- *y = xy[1] - num * newaim.z;
- #define _BOUND_VALUE(var,min,max) \
- if((var)>=(max)){return false/*(var)=(max)*/;}; \
- if((var)<=(min)){return false/*(var)=(min)*/;}
- _BOUND_VALUE(*x,0,xy[0]*2);
- _BOUND_VALUE(*y,0,xy[1]*2);
- return true;
- }
- bool drawing::worldToScreen(vector_3d worldCoord, int *xy)
- {
- if ( xy )
- {
- if ( worldToScreen(worldCoord,&xy[0],&xy[1]) )
- {
- return true;
- }
- }
- return false;
- }
- bool drawing::worldToScreen(vector_3d worldCoord, vector_3d screenCoord)
- {
- int xy[2] = {0,0};
- if ( worldToScreen(worldCoord, &xy[0], &xy[1]) )
- {
- screenCoord._init(xy[0],xy[1],0);
- return true;
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement