Portable Half-Life SDK. GoldSource and Xash3D. Crossplatform.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

138 lines
2.5 KiB

9 years ago
/***
*
* 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 <cmath>
9 years ago
#include "hud.h"
#include "cl_util.h"
#include <string.h>
3 years ago
#if !defined(M_PI)
9 years ago
#define M_PI 3.14159265358979323846 // matches value in gcc v2 math.h
#endif
3 years ago
#if !defined(M_PI_F)
#define M_PI_F (float)M_PI
#endif
9 years ago
extern vec3_t vec3_origin;
// if C++ mangling differs from C symbol name
3 years ago
#if _MSC_VER || __WATCOMC__
vec3_t vec3_origin;
#endif
9 years ago
float Length( const float *v )
9 years ago
{
9 years ago
int i;
9 years ago
float length;
9 years ago
length = 0.0f;
9 years ago
for( i = 0; i < 3; i++ )
length += v[i] * v[i];
length = sqrt( length ); // FIXME
9 years ago
return length;
}
void VectorAngles( const float *forward, float *angles )
{
9 years ago
float tmp, yaw, pitch;
if( forward[1] == 0.0f && forward[0] == 0.0f )
9 years ago
{
yaw = 0.0f;
if( forward[2] > 0.0f )
pitch = 90.0f;
9 years ago
else
pitch = 270.0f;
9 years ago
}
else
{
yaw = ( atan2( forward[1], forward[0]) * 180.0f / M_PI_F );
if( yaw < 0.0f )
yaw += 360.0f;
9 years ago
9 years ago
tmp = sqrt( forward[0] * forward[0] + forward[1] * forward[1] );
pitch = ( atan2( forward[2], tmp ) * 180.0f / M_PI_F );
if( pitch < 0.0f )
pitch += 360.0f;
9 years ago
}
9 years ago
9 years ago
angles[0] = pitch;
angles[1] = yaw;
angles[2] = 0.0f;
9 years ago
}
9 years ago
float VectorNormalize( float *v )
9 years ago
{
9 years ago
float length, ilength;
9 years ago
9 years ago
length = v[0] * v[0] + v[1] * v[1] + v[2] * v[2];
length = sqrt( length ); // FIXME
9 years ago
9 years ago
if( length )
9 years ago
{
ilength = 1.0f / length;
9 years ago
v[0] *= ilength;
v[1] *= ilength;
v[2] *= ilength;
}
9 years ago
return length;
9 years ago
}
9 years ago
void VectorInverse( float *v )
9 years ago
{
v[0] = -v[0];
v[1] = -v[1];
v[2] = -v[2];
}
9 years ago
void VectorScale( const float *in, float scale, float *out )
9 years ago
{
9 years ago
out[0] = in[0] * scale;
out[1] = in[1] * scale;
out[2] = in[2] * scale;
9 years ago
}
9 years ago
void VectorMA( const float *veca, float scale, const float *vecb, float *vecc )
9 years ago
{
9 years ago
vecc[0] = veca[0] + scale * vecb[0];
vecc[1] = veca[1] + scale * vecb[1];
vecc[2] = veca[2] + scale * vecb[2];
9 years ago
}
9 years ago
HSPRITE LoadSprite( const char *pszName )
9 years ago
{
int i;
9 years ago
char sz[256];
9 years ago
9 years ago
if( ScreenWidth < 640 )
9 years ago
i = 320;
else
i = 640;
9 years ago
sprintf( sz, pszName, i );
9 years ago
9 years ago
return SPR_Load( sz );
9 years ago
}