mirror of
https://github.com/shawns-valve/halflife.git
synced 2024-11-29 07:22:22 +00:00
102 lines
1.7 KiB
C++
102 lines
1.7 KiB
C++
|
/***
|
||
|
*
|
||
|
* Copyright (c) 1999, 2000 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>
|
||
|
|
||
|
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;
|
||
|
}
|
||
|
|
||
|
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);
|
||
|
}
|
||
|
|