home *** CD-ROM | disk | FTP | other *** search
/ STraTOS 1997 April & May / STraTOS 1 - 1997 April & May.iso / CD01 / INTERNET / SITES / RAND / DVIEW000.LZH / ORIGINAL.SRC / VIEW_UT.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-23  |  3.2 KB  |  122 lines

  1. /********************************************************************
  2.  FILENAME: VIEW_UT.CPP
  3.  AUTHOR  : JAKE HILL
  4.  DATE    : 12/1/94
  5.  
  6.  Copyright (c) 1994 by Jake Hill:
  7.  If you use any part of this code in your own project, please credit
  8.  me in your documentation and source code.  Thanks.
  9. ********************************************************************/
  10.  
  11. #include "VIEW.HPP"
  12. #include "TRIG.HPP"
  13.  
  14.  
  15. // This function returns TRUE it the player is on the right
  16. // of the node indexed by node_num.
  17. char View::OnRight( short node_num )
  18. {
  19.    node *ThisNode = PNode_Array[node_num];
  20.    long x1 = ThisNode->x;
  21.    long y1 = ThisNode->y;
  22.    long x2 = x1 + ThisNode->dx;
  23.    long y2 = y1 + ThisNode->dy;
  24.  
  25.    if ( ((x1-x2)*(Py-y2)) >= ((y1-y2)*(Px-x2)) )
  26.       return 1;
  27.    return 0;
  28. };
  29.  
  30. // This function returns TRUE it the player is on the right
  31. // of the line segment created by the vertexes indexed by from, and to.
  32. char View::OnRight(short from, short to)
  33. {
  34.    vertex *Vertex = &Vertex_Array[from];
  35.    long x1 = Vertex->x;
  36.    long y1 = Vertex->y;
  37.    Vertex = &Vertex_Array[to];
  38.    long x2 = Vertex->x;
  39.    long y2 = Vertex->y;
  40.  
  41.    if ( ((x1-x2)*(Py-y2)) >= ((y1-y2)*(Px-x2)) )
  42.       return 1;
  43.    return 0;
  44. };
  45.  
  46. // Note concerning LeftSideInCone & RightSideInCone.
  47. // These functions are based on the quadrants that the
  48. // view cone intersects.  The minimum resolution is an
  49. // entire quadrant.  This is not very accurate, and therefore
  50. // does not cull out as many nodes as would be ideal, but it
  51. // is a quick and dirty method that is fairly effective.
  52. // It could DEFINATELY be improved upon.
  53.  
  54. // This function returns TRUE if the LEFT Child Node
  55. // of the node indexed by node_num is in the view cone.
  56. char View::LeftSideInCone( short node_num )
  57. {
  58.    if ( LeftAngle < 0x4000 )
  59.    {
  60.       if ( PNode_Array[node_num]->lx2 > Px ) return 1;
  61.    }
  62.    else if ( LeftAngle < 0x8000 )
  63.    {
  64.       if ( PNode_Array[node_num]->ly2 > Py ) return 1;
  65.    }
  66.    else if ( LeftAngle < 0xC000 )
  67.    {
  68.       if ( PNode_Array[node_num]->lx1 < Px ) return 1;
  69.    }
  70.    else
  71.    {
  72.       if ( PNode_Array[node_num]->ly1 < Py ) return 1;
  73.    }
  74.  
  75.    return 0;
  76. };
  77.  
  78. // This function returns TRUE if the RIGHT Child Node
  79. // of the node indexed by node_num is in the view cone.
  80. char View::RightSideInCone( short node_num )
  81. {
  82.    if ( LeftAngle < 0x4000 )
  83.    {
  84.       if ( PNode_Array[node_num]->rx2 > Px ) return 1;
  85.    }
  86.    else if ( LeftAngle < 0x8000 )
  87.    {
  88.       if ( PNode_Array[node_num]->ry2 > Py ) return 1;
  89.    }
  90.    else if ( LeftAngle < 0xC000 )
  91.    {
  92.       if ( PNode_Array[node_num]->rx1 < Px ) return 1;
  93.    }
  94.    else
  95.    {
  96.       if ( PNode_Array[node_num]->ry1 < Py ) return 1;
  97.    }
  98.  
  99.    return 0;
  100. };
  101.  
  102. // This function sets the view's x,y, height, and angle values.
  103. void View::SetView(short x, short y, short h, unsigned short a)
  104. {
  105.    Px = x;
  106.    Py = y;
  107.    Ph = h;
  108.    Pangle = a;
  109.    LeftAngle = Pangle + 0x2000;
  110.    SinPangle = sine( 0x00-Pangle );
  111.    CosPangle = cosine( 0x00-Pangle );
  112. };
  113.  
  114. // This function returns the view's x,y height and angle values.
  115. void View::GetView(short *x, short *y, short *h, unsigned short *a)
  116. {
  117.    *x = Px;
  118.    *y = Py;
  119.    *h = Ph;
  120.    *a = Pangle;
  121. };
  122.