2002-08-17 05:27:34 +00:00
|
|
|
/*
|
|
|
|
math.h
|
|
|
|
|
|
|
|
Built-in math function definitions
|
|
|
|
|
|
|
|
Copyright (C) 2002 Bill Currie <taniwha@quakeforge.net>
|
|
|
|
Copyright (C) 2002 Jeff Teunissen <deek@quakeforge.net>
|
|
|
|
|
|
|
|
This file is part of the Ruamoko Standard Library.
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify it
|
|
|
|
under the terms of the GNU Lesser General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2.1 of the License, or (at
|
|
|
|
your option) any later version.
|
|
|
|
|
|
|
|
This library 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.
|
|
|
|
|
|
|
|
See the GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
$Id$
|
|
|
|
*/
|
2002-08-15 21:00:51 +00:00
|
|
|
#ifndef __ruamoko_math_h
|
|
|
|
#define __ruamoko_math_h
|
2002-08-15 06:56:37 +00:00
|
|
|
|
2010-12-16 11:20:58 +00:00
|
|
|
/**
|
|
|
|
Generate a random number such that 0 <= n <= 1 (0 to 1 inclusive)
|
2002-08-17 05:27:34 +00:00
|
|
|
*/
|
2010-12-01 23:04:18 +00:00
|
|
|
@extern float random (void);
|
2002-08-17 05:27:34 +00:00
|
|
|
|
2010-12-16 11:20:58 +00:00
|
|
|
/**
|
|
|
|
Returns the integer component of \a f
|
2002-08-17 05:27:34 +00:00
|
|
|
*/
|
2011-03-25 07:46:32 +00:00
|
|
|
@extern int ftoi (float f);
|
2002-08-17 05:27:34 +00:00
|
|
|
|
2010-12-16 11:20:58 +00:00
|
|
|
/**
|
|
|
|
Returns the float representation of \a i
|
2002-08-17 05:27:34 +00:00
|
|
|
*/
|
2011-03-25 07:46:32 +00:00
|
|
|
@extern float itof (int i);
|
2002-08-17 05:27:34 +00:00
|
|
|
|
2010-12-16 11:20:58 +00:00
|
|
|
/**
|
|
|
|
Rounds \a f to the nearest integer value and returns it. Does not change the type.
|
2002-08-17 05:27:34 +00:00
|
|
|
*/
|
2010-12-16 11:20:58 +00:00
|
|
|
@extern float rint (float f);
|
2002-08-17 05:27:34 +00:00
|
|
|
|
2010-12-16 11:20:58 +00:00
|
|
|
/**
|
|
|
|
Returns \a f, rounded down to the next lower integer
|
2002-08-17 05:27:34 +00:00
|
|
|
*/
|
2010-12-16 11:20:58 +00:00
|
|
|
@extern float floor (float f);
|
2002-08-17 05:27:34 +00:00
|
|
|
|
2010-12-16 11:20:58 +00:00
|
|
|
/**
|
|
|
|
Returns \a f, rounded up to the next highest integer
|
2002-08-17 05:27:34 +00:00
|
|
|
*/
|
2010-12-16 11:20:58 +00:00
|
|
|
@extern float ceil (float f);
|
2002-08-17 05:27:34 +00:00
|
|
|
|
2010-12-16 11:20:58 +00:00
|
|
|
/**
|
|
|
|
Returns the absolute value of \a f
|
2002-08-17 05:27:34 +00:00
|
|
|
*/
|
2010-12-01 23:04:18 +00:00
|
|
|
@extern float fabs (float f);
|
2002-08-17 05:27:34 +00:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* VECTORS *
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
@extern vector v_forward, v_up, v_right;
|
|
|
|
|
2010-12-16 11:20:58 +00:00
|
|
|
/**
|
|
|
|
Transform vector \a v into a unit vector (a vector with a length of 1).
|
2002-08-17 05:27:34 +00:00
|
|
|
The direction is not changed, except for (possible) roundoff errors.
|
|
|
|
*/
|
2010-12-01 23:04:18 +00:00
|
|
|
@extern vector normalize (vector v);
|
2002-08-17 05:27:34 +00:00
|
|
|
|
2010-12-16 11:20:58 +00:00
|
|
|
/**
|
|
|
|
Return the length of vector \a v
|
2002-08-17 05:27:34 +00:00
|
|
|
*/
|
2010-12-01 23:04:18 +00:00
|
|
|
@extern float vlen (vector v);
|
2002-08-17 05:27:34 +00:00
|
|
|
|
2010-12-16 11:20:58 +00:00
|
|
|
/**
|
|
|
|
Returns the yaw angle ("bearing"), in degrees, associated with vector \a v.
|
2002-08-17 05:27:34 +00:00
|
|
|
*/
|
2010-12-01 23:04:18 +00:00
|
|
|
@extern float vectoyaw (vector v);
|
2002-08-17 05:27:34 +00:00
|
|
|
|
2010-12-16 11:20:58 +00:00
|
|
|
/**
|
|
|
|
Returns a vector 'pitch yaw 0' corresponding to vector \a v.
|
2002-08-17 05:27:34 +00:00
|
|
|
*/
|
2010-12-01 23:04:18 +00:00
|
|
|
@extern vector vectoangles (vector v);
|
|
|
|
|
2010-12-16 11:20:58 +00:00
|
|
|
/**
|
|
|
|
Returns the sine of \a x.
|
|
|
|
*/
|
2010-12-01 23:04:18 +00:00
|
|
|
@extern float sin (float x);
|
2010-12-16 11:20:58 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the cosine of \a x.
|
|
|
|
*/
|
2010-12-01 23:04:18 +00:00
|
|
|
@extern float cos (float x);
|
2010-12-16 11:20:58 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the tangent of \a x.
|
|
|
|
*/
|
2010-12-01 23:04:18 +00:00
|
|
|
@extern float tan (float x);
|
2010-12-16 11:20:58 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the arcsine of \a x.
|
|
|
|
*/
|
2010-12-01 23:04:18 +00:00
|
|
|
@extern float asin (float x);
|
2010-12-16 11:20:58 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the arccosine of \a x.
|
|
|
|
*/
|
2010-12-01 23:04:18 +00:00
|
|
|
@extern float acos (float x);
|
2010-12-16 11:20:58 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the arctangent of \a x.
|
|
|
|
*/
|
2010-12-01 23:04:18 +00:00
|
|
|
@extern float atan (float x);
|
|
|
|
@extern float atan2 (float y, float x);
|
2010-12-16 11:20:58 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the natural log of \a x.
|
|
|
|
*/
|
2010-12-01 23:04:18 +00:00
|
|
|
@extern float log (float x);
|
2010-12-16 11:20:58 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the base-10 log of \a x.
|
|
|
|
*/
|
2010-12-01 23:04:18 +00:00
|
|
|
@extern float log10 (float x);
|
2010-12-16 11:20:58 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns \a x to the \a y power
|
|
|
|
*/
|
2010-12-01 23:04:18 +00:00
|
|
|
@extern float pow (float x, float y);
|
2010-12-16 11:20:58 +00:00
|
|
|
|
2010-12-01 23:04:18 +00:00
|
|
|
@extern float sinh (float x);
|
|
|
|
@extern float cosh (float x);
|
|
|
|
@extern float tanh (float x);
|
|
|
|
@extern float asinh (float x);
|
|
|
|
@extern float acosh (float x);
|
|
|
|
@extern float atanh (float x);
|
2004-02-03 06:24:43 +00:00
|
|
|
|
2002-08-17 05:27:34 +00:00
|
|
|
#endif //__ruamoko_math_h
|