summaryrefslogtreecommitdiff
path: root/src/cgame/cg_scanner.c
blob: bec5f195ef2ee61ba4a199ad882bb27535883bf7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
/*
 *  Portions Copyright (C) 2000-2001 Tim Angus
 *
 *  This program is free software; you can redistribute it and/or modify it
 *  under the terms of the OSML - Open Source Modification License v1.0 as
 *  described in the file COPYING which is distributed with this source
 *  code.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 */

#include "cg_local.h"

#define RANGE       1000.0f

#define XPOS        0.0f
#define YPOS        0.0f
#define WIDTH       640.0f
#define HEIGHT      480.0f

#define STALKWIDTH  2.0f
#define BLIPX       16.0f
#define BLIPY       8.0f

static void CG_DrawBlips( vec3_t origin, vec4_t colour )
{
  vec3_t  drawOrigin;
  vec3_t  up = { 0, 0, 1 };

  RotatePointAroundVector( drawOrigin, up, origin, -cg.refdefViewAngles[ 1 ] - 90 );
  drawOrigin[ 0 ] /= ( 2 * RANGE / WIDTH );
  drawOrigin[ 1 ] /= ( 2 * RANGE / HEIGHT );
  drawOrigin[ 2 ] /= ( 2 * RANGE / WIDTH );

  trap_R_SetColor( colour );

  if( drawOrigin[ 2 ] > 0 )
    CG_DrawPic( XPOS + ( WIDTH / 2 ) - ( STALKWIDTH / 2 ) - drawOrigin[ 0 ],
                YPOS + ( HEIGHT / 2 ) + drawOrigin[ 1 ] - drawOrigin[ 2 ],
                STALKWIDTH, drawOrigin[ 2 ], cgs.media.scannerLineShader );
  else
    CG_DrawPic( XPOS + ( WIDTH / 2 ) - ( STALKWIDTH / 2 ) - drawOrigin[ 0 ],
                YPOS + ( HEIGHT / 2 ) + drawOrigin[ 1 ],
                STALKWIDTH, -drawOrigin[ 2 ], cgs.media.scannerLineShader );
  
  CG_DrawPic( XPOS + ( WIDTH / 2 ) - ( BLIPX / 2 ) - drawOrigin[ 0 ],
              YPOS + ( HEIGHT / 2 ) - ( BLIPY / 2 ) + drawOrigin[ 1 ] - drawOrigin[ 2 ],
              BLIPX, BLIPY, cgs.media.scannerBlipShader );
  trap_R_SetColor( NULL );
}

#define RANGE2  1000.0f

#define XPOS2   20.0f
#define YPOS2   20.0f
#define WIDTH2  600.0f
#define HEIGHT2 440.0f

#define BLIPX2  24.0f
#define BLIPY2  24.0f

static void CG_DrawDir( vec3_t origin, vec4_t colour )
{
  vec3_t  drawOrigin;
  vec3_t  noZOrigin;
  vec3_t  normal, antinormal, normalDiff;
  vec3_t  view, noZview;
  vec3_t  up  = { 0.0f, 0.0f,   1.0f };
  vec3_t  top = { 0.0f, -1.0f,  0.0f };
  float   angle;
  playerState_t *ps = &cg.snap->ps;

  if( ps->stats[ STAT_STATE ] & SS_WALLCLIMBING )
  {
    if( ps->stats[ STAT_STATE ] & SS_WALLCLIMBINGCEILING )
      VectorSet( normal, 0.0f, 0.0f, -1.0f );
    else
      VectorCopy( ps->grapplePoint, normal );
  }
  else
    VectorSet( normal, 0.0f, 0.0f, 1.0f );

  AngleVectors( cg.refdefViewAngles, view, NULL, NULL );
  
  ProjectPointOnPlane( noZOrigin, origin, normal );
  ProjectPointOnPlane( noZview, view, normal );
  VectorNormalize( noZOrigin );
  VectorNormalize( noZview );

  //calculate the angle between the images of the blip and the view
  angle = RAD2DEG( acos( DotProduct( noZOrigin, noZview ) ) );
  CrossProduct( noZOrigin, noZview, antinormal );
  VectorNormalize( antinormal );

  //decide which way to rotate
  VectorSubtract( normal, antinormal, normalDiff );
  if( VectorLength( normalDiff ) < 1.0f )
    angle = 360.0f - angle;

  RotatePointAroundVector( drawOrigin, up, top, angle );

  trap_R_SetColor( colour );
  CG_DrawPic( XPOS2 + ( WIDTH2 / 2 ) - ( BLIPX2 / 2 ) - drawOrigin[ 0 ] * ( WIDTH2 / 2 ),
              YPOS2 + ( HEIGHT2 / 2 ) - ( BLIPY2 / 2 ) + drawOrigin[ 1 ] * ( HEIGHT2 / 2 ),
              BLIPX2, BLIPY2, cgs.media.scannerBlipShader );
  trap_R_SetColor( NULL );
}

/*
=============
CG_AlienSense
=============
*/
void CG_AlienSense( )
{
  int     i;
  vec3_t  origin;
  vec3_t  relOrigin;
  vec4_t  buildable = { 1.0f, 0.0f, 1.0f, 1.0f };
  vec4_t  client    = { 0.0f, 0.0f, 1.0f, 1.0f };
  
  VectorCopy( cg.refdef.vieworg, origin );
  
  //draw human buildables
  for( i = 0; i < cg.ep.numHumanBuildables; i++ )
  {
    VectorClear( relOrigin );
    VectorSubtract( cg.ep.humanBuildablePos[ i ], origin, relOrigin );

    if( VectorLength( relOrigin ) < RANGE2 )
      CG_DrawDir( relOrigin, buildable );
  }
  
  //draw human clients
  for( i = 0; i < cg.ep.numHumanClients; i++ )
  {
    VectorClear( relOrigin );
    VectorSubtract( cg.ep.humanClientPos[ i ], origin, relOrigin );

    if( VectorLength( relOrigin ) < RANGE2 )
      CG_DrawDir( relOrigin, client );
  }
}

/*
=============
CG_Scanner
=============
*/
void CG_Scanner( )
{
  int     i;
  vec3_t  origin;
  vec3_t  relOrigin;
  vec4_t  hIabove = { 0.0f, 1.0f, 0.0f, 1.0f };
  vec4_t  hIbelow = { 0.0f, 0.5f, 0.0f, 1.0f };
  vec4_t  aIabove = { 1.0f, 0.0f, 0.0f, 1.0f };
  vec4_t  aIbelow = { 0.5f, 0.0f, 0.0f, 1.0f };
  
  VectorCopy( cg.refdef.vieworg, origin );
  
  //draw human buildables below scanner plane
  for( i = 0; i < cg.ep.numHumanBuildables; i++ )
  {
    VectorClear( relOrigin );
    VectorSubtract( cg.ep.humanBuildablePos[ i ], origin, relOrigin );

    if( VectorLength( relOrigin ) < RANGE && ( relOrigin[ 2 ] < 0 ) )
      CG_DrawBlips( relOrigin, hIbelow );
  }
  
  //draw alien buildables below scanner plane
  for( i = 0; i < cg.ep.numAlienBuildables; i++ )
  {
    VectorClear( relOrigin );
    VectorSubtract( cg.ep.alienBuildablePos[ i ], origin, relOrigin );

    if( VectorLength( relOrigin ) < RANGE && ( relOrigin[ 2 ] < 0 ) )
      CG_DrawBlips( relOrigin, aIbelow );
  }
  
  //draw human clients below scanner plane
  for( i = 0; i < cg.ep.numHumanClients; i++ )
  {
    VectorClear( relOrigin );
    VectorSubtract( cg.ep.humanClientPos[ i ], origin, relOrigin );

    if( VectorLength( relOrigin ) < RANGE && ( relOrigin[ 2 ] < 0 ) )
      CG_DrawBlips( relOrigin, hIbelow );
  }
  
  //draw alien buildables below scanner plane
  for( i = 0; i < cg.ep.numAlienClients; i++ )
  {
    VectorClear( relOrigin );
    VectorSubtract( cg.ep.alienClientPos[ i ], origin, relOrigin );

    if( VectorLength( relOrigin ) < RANGE && ( relOrigin[ 2 ] < 0 ) )
      CG_DrawBlips( relOrigin, aIbelow );
  }
  
  /*CG_DrawPic( XPOS, YPOS, WIDTH, HEIGHT, cgs.media.scannerShader );*/
  
  //draw human buildables above scanner plane
  for( i = 0; i < cg.ep.numHumanBuildables; i++ )
  {
    VectorClear( relOrigin );
    VectorSubtract( cg.ep.humanBuildablePos[ i ], origin, relOrigin );

    if( VectorLength( relOrigin ) < RANGE && ( relOrigin[ 2 ] > 0 ) )
      CG_DrawBlips( relOrigin, hIabove );
  }

  //draw alien buildables above scanner plane
  for( i = 0; i < cg.ep.numAlienBuildables; i++ )
  {
    VectorClear( relOrigin );
    VectorSubtract( cg.ep.alienBuildablePos[ i ], origin, relOrigin );

    if( VectorLength( relOrigin ) < RANGE && ( relOrigin[ 2 ] > 0 ) )
      CG_DrawBlips( relOrigin, aIabove );
  }
  
  //draw human clients above scanner plane
  for( i = 0; i < cg.ep.numHumanClients; i++ )
  {
    VectorClear( relOrigin );
    VectorSubtract( cg.ep.humanClientPos[ i ], origin, relOrigin );

    if( VectorLength( relOrigin ) < RANGE && ( relOrigin[ 2 ] > 0 ) )
      CG_DrawBlips( relOrigin, hIabove );
  }

  //draw alien clients above scanner plane
  for( i = 0; i < cg.ep.numAlienClients; i++ )
  {
    VectorClear( relOrigin );
    VectorSubtract( cg.ep.alienClientPos[ i ], origin, relOrigin );

    if( VectorLength( relOrigin ) < RANGE && ( relOrigin[ 2 ] > 0 ) )
      CG_DrawBlips( relOrigin, aIabove );
  }
}