184 lines
3.6 KiB
C++
184 lines
3.6 KiB
C++
/***
|
|
*
|
|
* Copyright (c) 1996-2002, Valve LLC. All rights reserved.
|
|
*
|
|
* This product contains software technology licensed from Id
|
|
* Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc.
|
|
* All Rights Reserved.
|
|
*
|
|
* Use, distribution, and modification of this source code and/or resulting
|
|
* object code is restricted to non-commercial enhancements to products from
|
|
* Valve LLC. All other use, distribution, or modification is prohibited
|
|
* without written permission from Valve LLC.
|
|
*
|
|
****/
|
|
//
|
|
// util.cpp
|
|
//
|
|
// implementation of class-less helper functions
|
|
//
|
|
|
|
#include "stdio.h"
|
|
#include "stdlib.h"
|
|
#include "math.h"
|
|
|
|
#include "hud.h"
|
|
#include "cl_util.h"
|
|
#include <string.h>
|
|
|
|
#ifndef M_PI
|
|
#define M_PI 3.14159265358979323846 // matches value in gcc v2 math.h
|
|
#endif
|
|
|
|
//vec3_t vec3_origin( 0, 0, 0 );
|
|
|
|
double sqrt(double x);
|
|
|
|
float Length(const float *v)
|
|
{
|
|
int i;
|
|
float length;
|
|
|
|
length = 0;
|
|
for (i=0 ; i< 3 ; i++)
|
|
length += v[i]*v[i];
|
|
length = sqrt (length); // FIXME
|
|
|
|
return length;
|
|
}
|
|
|
|
void VectorAngles( const float *forward, float *angles )
|
|
{
|
|
float tmp, yaw, pitch;
|
|
|
|
if (forward[1] == 0 && forward[0] == 0)
|
|
{
|
|
yaw = 0;
|
|
if (forward[2] > 0)
|
|
pitch = 90;
|
|
else
|
|
pitch = 270;
|
|
}
|
|
else
|
|
{
|
|
yaw = (atan2(forward[1], forward[0]) * 180 / M_PI);
|
|
if (yaw < 0)
|
|
yaw += 360;
|
|
|
|
tmp = sqrt (forward[0]*forward[0] + forward[1]*forward[1]);
|
|
pitch = (atan2(forward[2], tmp) * 180 / M_PI);
|
|
if (pitch < 0)
|
|
pitch += 360;
|
|
}
|
|
|
|
angles[0] = pitch;
|
|
angles[1] = yaw;
|
|
angles[2] = 0;
|
|
}
|
|
|
|
float VectorNormalize (float *v)
|
|
{
|
|
float length, ilength;
|
|
|
|
length = v[0]*v[0] + v[1]*v[1] + v[2]*v[2];
|
|
length = sqrt (length); // FIXME
|
|
|
|
if (length)
|
|
{
|
|
ilength = 1/length;
|
|
v[0] *= ilength;
|
|
v[1] *= ilength;
|
|
v[2] *= ilength;
|
|
}
|
|
|
|
return length;
|
|
|
|
}
|
|
|
|
void VectorInverse ( float *v )
|
|
{
|
|
v[0] = -v[0];
|
|
v[1] = -v[1];
|
|
v[2] = -v[2];
|
|
}
|
|
|
|
void VectorScale (const float *in, float scale, float *out)
|
|
{
|
|
out[0] = in[0]*scale;
|
|
out[1] = in[1]*scale;
|
|
out[2] = in[2]*scale;
|
|
}
|
|
|
|
void VectorMA (const float *veca, float scale, const float *vecb, float *vecc)
|
|
{
|
|
vecc[0] = veca[0] + scale*vecb[0];
|
|
vecc[1] = veca[1] + scale*vecb[1];
|
|
vecc[2] = veca[2] + scale*vecb[2];
|
|
}
|
|
|
|
HSPRITE LoadSprite(const char *pszName)
|
|
{
|
|
int i;
|
|
char sz[256];
|
|
|
|
if (ScreenWidth < 640)
|
|
i = 320;
|
|
else
|
|
i = 640;
|
|
|
|
sprintf(sz, pszName, i);
|
|
|
|
return SPR_Load(sz);
|
|
}
|
|
|
|
float g_ColorBlue[3] = { 0.6, 0.8, 1.0 };
|
|
float g_ColorRed[3] = { 1.0, 0.25, 0.25 };
|
|
float g_ColorGreen[3] = { 0.6, 1.0, 0.6 };
|
|
float g_ColorYellow[3] = { 1.0, 0.7, 0.0 };
|
|
float g_ColorGrey[3] = { 0.8, 0.8, 0.8 };
|
|
|
|
float *GetClientColor( int clientIndex )
|
|
{
|
|
switch ( g_PlayerExtraInfo[clientIndex].teamnumber )
|
|
{
|
|
case TEAM_TERRORIST: return g_ColorRed;
|
|
case TEAM_CT: return g_ColorBlue;
|
|
case TEAM_SPECTATOR:
|
|
case TEAM_UNASSIGNED: return g_ColorYellow;
|
|
case 4: return g_ColorGreen;
|
|
default: return g_ColorGrey;
|
|
}
|
|
}
|
|
|
|
void GetTeamColor(int &r, int &g, int &b, int teamIndex)
|
|
{
|
|
r = 255;
|
|
g = 255;
|
|
b = 255;
|
|
switch( teamIndex )
|
|
{
|
|
case TEAM_TERRORIST:
|
|
r *= g_ColorRed[0];
|
|
g *= g_ColorRed[1];
|
|
b *= g_ColorRed[2];
|
|
break;
|
|
case TEAM_CT:
|
|
r *= g_ColorBlue[0];
|
|
g *= g_ColorBlue[1];
|
|
b *= g_ColorBlue[2];
|
|
break;
|
|
case TEAM_SPECTATOR:
|
|
case TEAM_UNASSIGNED:
|
|
r *= g_ColorYellow[0];
|
|
g *= g_ColorYellow[1];
|
|
b *= g_ColorYellow[2];
|
|
break;
|
|
default:
|
|
r *= g_ColorGrey[0];
|
|
g *= g_ColorGrey[1];
|
|
b *= g_ColorGrey[2];
|
|
break;
|
|
}
|
|
}
|
|
|